:root {
  color-scheme: light;
  --bg: #f4f7f2;
  --surface: #ffffff;
  --surface-2: #eef4ee;
  --surface-3: #e4ece5;
  --ink: #16231f;
  --muted: #65746d;
  --line: #cbd8cf;
  --line-strong: #aebfb5;
  --brand: #0e7c66;
  --brand-dark: #17352f;
  --amber: #d99a29;
  --red: #d85a4e;
  --blue: #4369c9;
  --green: #22845f;
  --shadow: 0 18px 42px rgba(23, 53, 47, 0.12);
  --radius: 8px;
  --sidebar: 280px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(244, 247, 242, 0.95), rgba(237, 243, 237, 0.96)),
    repeating-linear-gradient(90deg, rgba(23, 53, 47, 0.03) 0 1px, transparent 1px 84px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  max-width: 100%;
  display: block;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 18px;
  color: #f7faf5;
  background: var(--brand-dark);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-block {
  display: grid;
  gap: 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: #f6f9f4;
  color: var(--brand-dark);
  font-weight: 900;
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.brand-copy {
  margin: 4px 0 0;
  color: rgba(247, 250, 245, 0.72);
  font-size: 0.86rem;
  line-height: 1.45;
}

.role-panel {
  display: grid;
  gap: 10px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sidebar .eyebrow {
  color: rgba(247, 250, 245, 0.58);
}

.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.role-button,
.nav-button,
.btn,
.chip-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, color 160ms ease;
}

.role-button {
  padding: 9px 10px;
  color: rgba(247, 250, 245, 0.78);
  background: rgba(255, 255, 255, 0.07);
  text-align: left;
  font-size: 0.8rem;
}

.role-button[aria-pressed="true"] {
  color: var(--brand-dark);
  background: #f6f9f4;
  border-color: rgba(255, 255, 255, 0.24);
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  padding: 11px 12px;
  color: rgba(247, 250, 245, 0.78);
  background: transparent;
  text-align: left;
}

.nav-button:hover,
.role-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.18);
}

.nav-button[aria-current="page"] {
  color: #ffffff;
  background: rgba(14, 124, 102, 0.42);
  border-color: rgba(255, 255, 255, 0.18);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  color: rgba(247, 250, 245, 0.7);
  font-size: 0.82rem;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #f7faf5;
  font-size: 0.78rem;
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 18px 26px;
  background: rgba(244, 247, 242, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.page-title {
  margin: 0;
  font-size: 2.05rem;
  line-height: 1.12;
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  gap: 22px;
  padding: 26px;
}

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 22px;
  align-items: start;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.three-col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.panel,
.stat-card,
.record-card,
.pass-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-title {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.25;
}

.panel-copy {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  min-height: 126px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  gap: 12px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.stat-value {
  font-size: 2.35rem;
  font-weight: 900;
  line-height: 1;
}

.stat-note {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.visual-panel {
  position: relative;
  min-height: 340px;
  overflow: hidden;
  background: var(--surface);
}

.visual-panel img {
  width: 100%;
  height: 100%;
  min-height: 300px;
  object-fit: cover;
  border-radius: calc(var(--radius) - 1px);
}

.visual-caption {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  padding: 14px;
  color: #f7faf5;
  background: rgba(23, 53, 47, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
}

.visual-caption strong {
  display: block;
  margin-bottom: 4px;
}

.visual-caption span {
  color: rgba(247, 250, 245, 0.76);
  font-size: 0.88rem;
}

.stage-list,
.activity-list,
.check-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stage-item,
.activity-item,
.check-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 54px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stage-index {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--brand-dark);
  font-weight: 800;
  font-size: 0.82rem;
}

.text-muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.status,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  width: max-content;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.status.active,
.status.approved,
.status.confirmed,
.status.applied,
.status.checked-in {
  color: #0d513f;
  background: #dff3e8;
}

.status.pending,
.status.pending-approval,
.status.payment-pending,
.status.plan-selected {
  color: #70480f;
  background: #f7e5bd;
}

.status.suspended,
.status.rejected,
.status.revoked,
.status.disabled,
.status.failed,
.status.cancelled {
  color: #802d26;
  background: #f6d7d4;
}

.status.used,
.status.expired,
.status.checked-out {
  color: #37466e;
  background: #dbe3fb;
}

.tag {
  color: var(--brand-dark);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 104px;
  padding: 10px 13px;
  color: var(--brand-dark);
  background: var(--surface);
  border-color: var(--line-strong);
  font-weight: 800;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--brand);
}

.btn.primary {
  color: #ffffff;
  background: var(--brand);
  border-color: var(--brand);
}

.btn.dark {
  color: #ffffff;
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.btn.warn {
  color: #ffffff;
  background: var(--red);
  border-color: var(--red);
}

.btn.ghost {
  min-width: auto;
  color: var(--brand-dark);
  background: transparent;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.chip-button {
  min-width: 0;
  padding: 8px 10px;
  color: var(--brand-dark);
  background: var(--surface-2);
  border-color: var(--line);
  font-size: 0.82rem;
  font-weight: 800;
}

.chip-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--brand-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.three-col > .form-grid {
  grid-template-columns: 1fr;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.field {
  display: grid;
  gap: 7px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(14, 124, 102, 0.15);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

th {
  color: var(--muted);
  background: #f7faf6;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.record-grid,
.pass-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.record-card,
.pass-card {
  display: grid;
  gap: 12px;
  padding: 15px;
}

.record-card h3,
.pass-card h3 {
  margin: 0;
  font-size: 1rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 1.05rem;
}

.gate-console {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.scanner-pad {
  min-height: 330px;
  display: grid;
  place-items: center;
  padding: 20px;
  color: #f7faf5;
  background: var(--brand-dark);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.scanner-frame {
  width: min(260px, 100%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, transparent 48%, rgba(105, 179, 155, 0.32) 48% 52%, transparent 52%),
    linear-gradient(180deg, transparent 48%, rgba(105, 179, 155, 0.32) 48% 52%, transparent 52%);
}

.scanner-frame span {
  max-width: 180px;
  color: rgba(247, 250, 245, 0.78);
  text-align: center;
  line-height: 1.45;
}

.qr-grid {
  width: 132px;
  height: 132px;
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  grid-template-rows: repeat(11, 1fr);
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.qr-grid span {
  background: #edf3ec;
  border-radius: 2px;
}

.qr-grid span.active {
  background: var(--brand-dark);
}

.offline-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  color: var(--brand-dark);
  background: #f7e5bd;
  border: 1px solid #e1bd6d;
  border-radius: var(--radius);
}

.empty-state {
  min-height: 130px;
  display: grid;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.settings-list {
  display: grid;
  gap: 12px;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 36px));
}

.toast {
  padding: 13px 14px;
  color: #f7faf5;
  background: var(--brand-dark);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toast.error {
  background: #802d26;
}

.toast.success {
  background: #0d513f;
}

.auth-card {
  max-width: 820px;
}

.kbd {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf6;
  color: var(--brand-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}

.mobile-only {
  display: none;
}

@media (max-width: 1180px) {
  .section-grid,
  .gate-console {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-grid,
  .pass-grid,
  .three-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

  .brand-block {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }

  .role-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    position: static;
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .page-title {
    font-size: 1.65rem;
  }

  .stat-value {
    font-size: 2rem;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .workspace {
    padding: 18px;
  }

  .two-col,
  .form-grid,
  .record-grid,
  .pass-grid,
  .three-col,
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .setting-row,
  .offline-banner {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .role-grid,
  .nav-list,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .stat-card,
  .record-card,
  .pass-card {
    box-shadow: none;
  }

  .visual-caption {
    position: static;
    max-width: 100%;
    margin-top: 12px;
  }

  .visual-panel {
    overflow: visible;
  }

  .page-title {
    font-size: 1.4rem;
  }

  .stat-value {
    font-size: 1.75rem;
  }
}
