:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #1d2725;
  --muted: #64716d;
  --line: #d7e0dd;
  --primary: #0d766f;
  --primary-2: #0f5f85;
  --warning: #b7791f;
  --danger: #b42318;
  --critical: #7f1d1d;
  --ok: #16803c;
  --shadow: 0 16px 35px rgba(28, 45, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.sidebar {
  background: #182321;
  color: #f8fffd;
  padding: 24px 18px;
}

.sidebar.single-purpose .nav {
  display: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #22a699;
  color: #06211e;
  font-size: 1.4rem;
  font-weight: 800;
}

.brand span,
.eyebrow,
.clock span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.sidebar .brand span {
  color: #afc5c0;
}

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

.nav-item {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  color: #dbe8e5;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: #2a3a37;
  color: #ffffff;
}

.nav-item[hidden] {
  display: none;
}

.main {
  min-width: 0;
  padding: 26px;
}

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

.session-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.84rem;
}

.session-bar strong {
  color: var(--ink);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.85rem;
}

h2 {
  font-size: 1rem;
}

.clock {
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: right;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.metrics,
.split-layout {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.toolbar {
  grid-template-columns: repeat(2, minmax(180px, 260px)) auto;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
}

.primary,
.secondary,
.danger {
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 800;
}

.primary {
  background: var(--primary);
  color: white;
}

.secondary {
  background: var(--surface-2);
  color: var(--ink);
}

.danger {
  background: #fee4e2;
  color: var(--danger);
}

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

.metric,
.panel,
.patient-card,
.tv-display {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

body[data-route="tv"] .app-shell,
body[data-route="patient"] .app-shell {
  grid-template-columns: 1fr;
}

body[data-route="tv"] .sidebar,
body[data-route="patient"] .sidebar {
  display: none;
}

body[data-route="tv"] .topbar {
  display: none;
}

body[data-route="tv"] .main {
  padding: 18px;
}

body[data-route="tv"] .tv-display {
  min-height: 58vh;
}

body[data-route="patient"] .main {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.metric {
  padding: 14px;
}

.metric span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

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

.split-layout {
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  align-items: start;
}

.panel {
  overflow: hidden;
}

.login-panel,
.lookup-panel {
  margin-bottom: 14px;
}

.login-panel[hidden] {
  display: none;
}

.login-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.7fr) auto auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.queue-list,
.recent-list,
.setup-list,
.report-table,
.choice-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.queue-row,
.recent-row,
.setup-row,
.report-row {
  display: grid;
  gap: 10px;
  align-items: center;
  min-height: 56px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.queue-row {
  grid-template-columns: 92px minmax(0, 1fr) auto;
}

.queue-number {
  font-size: 1.25rem;
  font-weight: 900;
}

.queue-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

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

.transfer-control {
  min-width: 150px;
  flex: 1 1 170px;
  color: var(--muted);
  font-size: 0.74rem;
}

.transfer-control select {
  min-height: 42px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px;
}

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

.status-waiting {
  border-left: 5px solid var(--primary-2);
}

.status-called {
  border-left: 5px solid var(--warning);
}

.status-serving {
  border-left: 5px solid var(--ok);
}

.status-skipped {
  border-left: 5px solid var(--danger);
}

.age-green {
  color: var(--ok);
}

.age-yellow {
  color: var(--warning);
}

.age-red {
  color: var(--danger);
}

.age-critical {
  color: var(--critical);
}

.patient-card {
  display: grid;
  gap: 16px;
  max-width: 620px;
  padding: 24px;
}

.patient-pass {
  border-top: 1px solid var(--line);
}

.pass-head {
  border-bottom: 0;
}

.pass-body {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 0 14px 14px;
}

.pass-body img {
  width: 160px;
  height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.pass-body strong {
  display: block;
  font-size: 2rem;
}

.pass-body span {
  display: block;
  margin: 8px 0;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.patient-number {
  font-size: clamp(3.2rem, 9vw, 6rem);
  line-height: 1;
  font-weight: 950;
}

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

.patient-field {
  min-height: 74px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
}

.patient-field span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.tv-display {
  display: grid;
  place-items: center;
  min-height: 320px;
  margin-bottom: 14px;
  background: #102a2a;
  color: #ffffff;
  text-align: center;
}

.tv-display p {
  color: #bde8e3;
  font-weight: 900;
  letter-spacing: 0;
}

.tv-display strong {
  font-size: clamp(5rem, 16vw, 10rem);
  line-height: 1;
}

.tv-display span {
  font-size: clamp(1.6rem, 5vw, 3.2rem);
  font-weight: 900;
}

.recent-row {
  grid-template-columns: 90px minmax(0, 1fr) 110px;
}

.clinic-message {
  padding: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.setup-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.report-row {
  grid-template-columns: 92px 1fr 1fr 1fr;
}

.audit-row {
  align-items: start;
}

.choice-list {
  padding: 0 0 14px;
}

.choice-item {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.choice-item span {
  color: var(--muted);
}

.needs-login .toolbar,
.needs-login .metrics,
.needs-login .split-layout,
.needs-login .report-table {
  opacity: 0.42;
  pointer-events: none;
}

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .toolbar,
  .metrics,
  .split-layout,
  .login-grid,
  .patient-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .main,
  .sidebar {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .clock {
    text-align: left;
  }

  .queue-row,
  .recent-row,
  .report-row,
  .pass-body {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1 1 120px;
  }
}
