/* SMC Staff Web — design tokens from Figma */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-2: #1e293b;
  --ink-3: #334155;
  --ink-4: #475569;
  --muted: #64748b;
  --muted-2: #94a3b8;

  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-soft: #eef2ff;
  --primary-softer: #e0e7ff;

  --success: #10b981;
  --success-dark: #059669;
  --success-soft: #ecfdf5;
  --success-ink: #065f46;

  --warning: #f59e0b;
  --warning-soft: #fffbeb;
  --warning-ink: #92400e;

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-ink: #991b1b;

  --dept-records: #6366f1;
  --dept-exam: #ea580c;
  --dept-lab: #0891b2;
  --dept-pharm: #059669;
  --dept-finance: #10b981;
  --dept-appt: #7c3aed;
  --dept-checkup: #2563eb;
  --dept-vaccine: #16a34a;

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;

  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.06);
  --shadow-lg: 0 10px 30px rgba(15,23,42,0.10);

  --density: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Thai", "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }

/* ===== App shell ===== */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  background: var(--bg);
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 0 24px 0;
}
.sidebar-brand { padding: 0 24px 20px; }
.sidebar-brand h1 {
  font-size: 20px; font-weight: 700; color: var(--ink);
  margin: 0; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--primary);
  display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 800;
  box-shadow: 0 4px 10px color-mix(in oklab, var(--primary) 40%, transparent);
}
.sidebar-brand .sub {
  font-size: 11px; color: var(--muted); margin-top: 6px; font-weight: 500;
}
.nav-section-label {
  padding: 18px 24px 6px;
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted-2); font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 24px;
  font-size: 13px; font-weight: 500;
  color: var(--ink-3);
  position: relative; cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  width: 100%; text-align: left;
  line-height: 1.2;
}
.nav-item .ico { width: 18px; display: inline-grid; place-items: center; font-size: 14px; }
.nav-item:hover { background: var(--surface-muted); color: var(--ink); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
}
.nav-item.active::before {
  content: ""; position: absolute;
  left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--primary);
}
.nav-item .count {
  margin-left: auto;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
}
.nav-item.active .count { background: var(--primary); color: #fff; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  margin-top: 24px; padding: 16px 24px;
  display: flex; align-items: center; gap: 10px;
  font-size: 12px;
}
.sidebar-foot .av {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #fbcfe8, #fce7f3);
  display: grid; place-items: center; font-size: 14px;
}
.sidebar-foot .who strong { display: block; color: var(--ink); font-weight: 700; font-size: 12px; }
.sidebar-foot .who span { color: var(--muted); font-size: 10px; }

/* Top bar */
.topbar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 5;
}
.topbar .title {
  font-size: 15px; font-weight: 700; color: var(--ink);
}
.topbar .sub { font-size: 11px; color: var(--muted); }
.topbar .title-group { display: flex; flex-direction: column; gap: 2px; }
.topbar .spacer { flex: 1; }
.topbar .clock {
  font-size: 12px; color: var(--ink-3); font-weight: 600;
  padding: 6px 12px; background: var(--surface-alt); border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.topbar .iconbtn {
  width: 36px; height: 36px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--ink-3); position: relative;
}
.topbar .iconbtn:hover { background: var(--surface-alt); }
.topbar .iconbtn .dot {
  position: absolute; top: 6px; right: 7px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--surface);
}

/* Main content */
.main {
  display: flex; flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}
.page {
  padding: 24px;
  display: grid;
  gap: 16px;
  max-width: 1440px;
  width: 100%;
}

/* ===== Cards & primitives ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: calc(20px * var(--density));
}
.card.tight { padding: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h3 {
  margin: 0; font-size: 13px; font-weight: 700; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.card-head .subline { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card-head .right { display: flex; align-items: center; gap: 8px; }

.stat {
  background: var(--surface-muted);
  border-radius: 8px; padding: 12px 16px;
  flex: 1; min-width: 0;
}
.stat label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.stat value, .stat .value {
  display: block; font-size: 20px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums;
}
.stat.primary .value { color: var(--primary); }
.stat.success .value { color: var(--success); }
.stat.purple .value { color: #8b5cf6; }
.stat.muted .value { color: var(--muted-2); }

.stat-row { display: flex; gap: 12px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
  background: var(--surface-alt); color: var(--ink-3);
  line-height: 1;
}
.badge.primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge.success { background: var(--success-soft); color: var(--success-ink); }
.badge.warning { background: var(--warning-soft); color: var(--warning-ink); }
.badge.danger { background: var(--danger-soft); color: var(--danger-ink); }
.badge.dept-exam { background: #fff7ed; color: #9a3412; }
.badge.dept-lab  { background: #ecfeff; color: #155e75; }
.badge.dept-pharm{ background: #ecfdf5; color: #065f46; }
.badge.dept-appt { background: #f5f3ff; color: #5b21b6; }
.badge.dept-checkup { background: #eff6ff; color: #1e40af; }
.badge.dept-vaccine { background: #f0fdf4; color: #166534; }
.badge.dept-records { background: var(--primary-soft); color: var(--primary-dark); }

.dot-led {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--success); box-shadow: 0 0 0 3px color-mix(in oklab, var(--success) 20%, transparent);
}
.dot-led.warn { background: var(--warning); box-shadow: 0 0 0 3px color-mix(in oklab, var(--warning) 20%, transparent); }
.dot-led.danger { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 20%, transparent); }
.dot-led.muted { background: var(--muted-2); box-shadow: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px; font-size: 13px; font-weight: 700;
  background: var(--surface); color: var(--ink-3);
  border: 1px solid var(--border-strong);
  transition: all 0.12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); }
.btn.primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 2px 6px color-mix(in oklab, var(--primary) 30%, transparent);
}
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.btn.success:hover { background: var(--success-dark); border-color: var(--success-dark); }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-alt); }
.btn.sm { padding: 6px 12px; font-size: 12px; }
.btn.lg { padding: 12px 18px; font-size: 14px; }
.btn.block { width: 100%; }

/* Inputs */
.input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 14px;
  color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 20%, transparent);
}
.search-field {
  position: relative;
}
.search-field .ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted-2);
}
.search-field .input { padding-left: 36px; }

/* Row item (for lists) */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface-muted);
  border-radius: var(--r-md);
  transition: background 0.12s;
  cursor: pointer;
  border: 1px solid transparent;
}
.row:hover { background: #eef2ff; border-color: var(--primary-softer); }
.row.active { background: var(--primary-soft); border-color: var(--primary); }
.row .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #fbcfe8, #fce7f3);
  display: grid; place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}
.row .avatar.blue { background: linear-gradient(135deg, #dbeafe, #bfdbfe); }
.row .avatar.green { background: linear-gradient(135deg, #d1fae5, #a7f3d0); }
.row .avatar.amber { background: linear-gradient(135deg, #fef3c7, #fde68a); }
.row .avatar.purple { background: linear-gradient(135deg, #ede9fe, #ddd6fe); }
.row .info { flex: 1; min-width: 0; }
.row .info .name {
  font-size: 13px; font-weight: 700; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .info .sub {
  font-size: 11px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .meta { font-size: 11px; color: var(--muted); text-align: right; flex-shrink: 0; }
.row .q {
  font-size: 11px; font-weight: 800; color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 6px;
  min-width: 44px; text-align: center;
}
.row .q.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Alerts */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px; border-radius: var(--r-md);
  background: var(--warning-soft); border: 1px solid var(--warning);
  color: var(--warning-ink);
}
.alert.danger { background: var(--danger-soft); border-color: #fca5a5; color: var(--danger-ink); }
.alert.info { background: var(--primary-soft); border-color: var(--primary-softer); color: var(--primary-dark); }
.alert.success { background: var(--success-soft); border-color: #a7f3d0; color: var(--success-ink); }
.alert .alert-ico { flex-shrink: 0; font-size: 16px; line-height: 1.2; }
.alert .alert-body strong { display: block; font-weight: 800; font-size: 13px; margin-bottom: 2px; }
.alert .alert-body small { font-size: 11px; opacity: 0.85; }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-main-aside { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; }
.grid-main-aside.wide { grid-template-columns: minmax(0, 1fr) 420px; }
.grid-soap { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Patient header card */
.patient-head {
  display: flex; align-items: center; gap: 16px;
  padding: 16px;
}
.patient-head .pic {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, #fbcfe8, #fce7f3);
  display: grid; place-items: center; font-size: 22px;
  flex-shrink: 0;
}
.patient-head .primary-info h2 {
  margin: 0; font-size: 16px; font-weight: 700; color: var(--ink);
  display: flex; align-items: center; gap: 10px;
}
.patient-head .sub {
  font-size: 12px; color: var(--muted); margin-top: 4px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.patient-head .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* Vitals */
.vitals {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
.vital {
  background: var(--surface-muted);
  border-radius: 8px;
  padding: 12px;
}
.vital label { font-size: 10px; color: var(--muted); letter-spacing: 0.02em; text-transform: uppercase; font-weight: 700; }
.vital .v { font-size: 18px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.vital .u { font-size: 10px; color: var(--muted); margin-left: 3px; font-weight: 500; }
.vital.warn { background: var(--warning-soft); }
.vital.warn .v { color: var(--warning-ink); }
.vital.danger { background: var(--danger-soft); }
.vital.danger .v { color: var(--danger-ink); }
.vital.ok { background: var(--success-soft); }
.vital.ok .v { color: var(--success-ink); }

/* SOAP */
.soap-box {
  background: var(--primary-soft); border: 1px solid var(--primary-softer);
  border-radius: var(--r-lg); padding: 14px;
}
.soap-box .lbl {
  font-size: 12px; font-weight: 800; color: var(--primary-dark);
  margin-bottom: 6px; letter-spacing: 0.02em;
}
.soap-box .body {
  font-size: 13px; line-height: 1.55; color: var(--ink-2);
  min-height: 80px;
}
.soap-box textarea {
  width: 100%; background: transparent; border: 0; resize: none;
  font-size: 13px; line-height: 1.55; color: var(--ink-2);
  outline: none;
  min-height: 80px;
}
.soap-box.o { background: #fff7ed; border-color: #fed7aa; }
.soap-box.o .lbl { color: #9a3412; }
.soap-box.a { background: #ecfeff; border-color: #a5f3fc; }
.soap-box.a .lbl { color: #155e75; }
.soap-box.p { background: var(--success-soft); border-color: #a7f3d0; }
.soap-box.p .lbl { color: var(--success-ink); }

/* Segmented */
.seg {
  display: inline-flex; background: var(--surface-alt); border-radius: 8px; padding: 3px; gap: 2px;
}
.seg button {
  padding: 6px 12px; font-size: 12px; font-weight: 600; color: var(--muted);
  border-radius: 6px;
}
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Queue column dashboard */
.queue-col {
  display: grid; gap: 8px;
  align-content: start;
}
.queue-chip {
  padding: 10px 12px; border-radius: 8px;
  background: var(--surface-muted); border: 1px solid var(--border);
  font-size: 12px;
  display: flex; align-items: center; gap: 10px;
  cursor: grab;
  transition: box-shadow 0.12s;
}
.queue-chip:hover { box-shadow: var(--shadow-md); }
.queue-chip .num { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); min-width: 34px; }
.queue-chip .n { font-weight: 700; color: var(--ink); font-size: 12px; }
.queue-chip .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.queue-chip.p1 { border-left: 3px solid var(--danger); }
.queue-chip.p2 { border-left: 3px solid var(--warning); }
.queue-chip.p3 { border-left: 3px solid var(--primary); }

/* Kv pair */
.kv { display: flex; justify-content: space-between; font-size: 12px; padding: 6px 0; }
.kv .k { color: var(--muted); }
.kv .v { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.kv + .kv { border-top: 1px dashed var(--border); }

/* Tabs (page-level) */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab:hover { color: var(--ink-3); }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* Drug / Lab rows */
.line {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-muted);
}
.line + .line { margin-top: 8px; }
.line .chk {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--success); color: #fff;
  display: grid; place-items: center; font-size: 12px;
}
.line .chk.warn { background: var(--warning); }
.line .chk.idle { background: var(--surface); border: 2px solid var(--border-strong); color: transparent; }
.line .name { font-weight: 700; font-size: 13px; color: var(--ink); }
.line .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.line .qty {
  font-size: 12px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 6px;
}
.line .price { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Totals */
.total {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  font-size: 13px;
}
.total + .total { border-top: 1px dashed var(--border); }
.total.grand {
  background: #0f172a; color: #fff; border-radius: 8px; padding: 14px 16px;
  font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums;
  margin-top: 8px;
}

/* Tweak panel */
.tweaks-panel {
  position: fixed; right: 16px; bottom: 16px;
  z-index: 100;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 16px;
  display: none;
}
.tweaks-panel.open { display: block; }
.tweaks-panel h4 { margin: 0 0 12px; font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tweaks-panel h4::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.tweak-row { margin-bottom: 12px; }
.tweak-row label { display: block; font-size: 11px; color: var(--muted); font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.swatches { display: flex; gap: 6px; }
.sw { width: 28px; height: 28px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; transition: transform .1s; }
.sw.active { border-color: var(--ink); transform: scale(1.08); }
.seg.fullwidth { display: flex; width: 100%; }
.seg.fullwidth button { flex: 1; }

/* Dark mode */
body.dark {
  --bg: #0b1220;
  --surface: #0f172a;
  --surface-muted: #111b2e;
  --surface-alt: #1e293b;
  --border: #1f2a44;
  --border-strong: #334155;
  --ink: #f1f5f9;
  --ink-2: #e2e8f0;
  --ink-3: #cbd5e1;
  --ink-4: #94a3b8;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --primary-soft: #1e1b4b;
  --primary-softer: #312e81;
  --success-soft: #022c22;
  --warning-soft: #2d1f04;
  --danger-soft: #2b0b0b;
  --success-ink: #6ee7b7;
  --warning-ink: #fcd34d;
  --danger-ink: #fca5a5;
}
body.dark .row:hover { background: #1a2440; border-color: var(--primary); }
body.dark .row.active { background: #1e1b4b; }
body.dark .total.grand { background: var(--primary-dark); }

/* Density: compact */
body.compact { --density: 0.8; }
body.compact .page { gap: 12px; }
body.compact .row { padding: 8px 12px; }
body.compact .nav-item { padding: 8px 24px; }
body.compact .vital { padding: 10px; }
body.compact .vital .v { font-size: 16px; }

/* Sparkline mini */
.mini-bar {
  height: 6px; border-radius: 999px; background: var(--surface-alt); overflow: hidden;
}
.mini-bar i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

/* Scrollbars light */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }
body.dark ::-webkit-scrollbar-thumb { background: #334155; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: flex; align-items: center; gap: 10px;
  animation: toast-in 0.3s ease-out;
}
@keyframes toast-in { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* Fade between screens */
.screen-enter { animation: fade-in 0.25s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
