:root {
  --bg: #f3f6f9;
  --card: #ffffff;
  --text: #17212b;
  --muted: #6b7785;
  --line: #e2e8ee;
  --primary: #0e7c7b;
  --primary-dark: #0a5e5d;
  --primary-soft: #e3f3f2;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn: #b7791f;
  --ok: #1e8449;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }
h1, h2, h3 { margin: 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: #c5d0da; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f1c4bf; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 13px 20px; font-size: 16px; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; width: 100%; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .fixed { flex: 0 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.check input { width: auto; }
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-group label { flex-direction: row; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; color: var(--text); font-weight: 500; cursor: pointer; }
.radio-group input { width: auto; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(160deg, #e6f4f3 0%, #f3f6f9 60%); }
.login-card { width: 100%; max-width: 360px; background: #fff; padding: 28px; border-radius: 14px;
  box-shadow: 0 10px 30px rgba(14, 124, 123, .12); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; text-align: center; }
.login-card p { margin: 0; text-align: center; }
.login-logo, .brand-logo { width: 46px; height: 46px; border-radius: 12px; background: var(--primary); color: #fff;
  font-weight: 800; font-size: 24px; display: grid; place-items: center; margin: 0 auto; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 60px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none;
  color: var(--primary); font-weight: 600; cursor: pointer; font-size: 12px; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #0f2a33; color: #d6e2e8; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; font-weight: 700; color: #fff; }
.brand-logo { width: 34px; height: 34px; font-size: 18px; margin: 0; flex: none; }
#brand-name { line-height: 1.2; }
nav { display: flex; flex-direction: column; padding: 6px 8px; gap: 2px; flex: 1; overflow-y: auto; }
nav a { color: #c3d3da; text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
nav a.active { background: var(--primary); color: #fff; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot .btn { color: #c3d3da; border-color: rgba(255,255,255,.15); }
.user-box { font-size: 13px; }
.user-box b { color: #fff; display: block; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar h2 { font-size: 18px; }
.page { padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.toolbar label { min-width: 140px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.accent .v { color: var(--primary); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f7f9fb; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #fafcfd; }
tfoot td { font-weight: 700; background: #f7f9fb; }
tr.cancelled td { color: #9aa5b1; text-decoration: line-through; }
tr.cancelled td.actions, tr.cancelled td .badge { text-decoration: none; }
td.actions { white-space: nowrap; text-align: right; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--primary-soft); color: var(--primary-dark); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.gray { background: #eef1f4; color: var(--muted); }
.badge.warn { background: #fdf3e1; color: var(--warn); }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* ---------- OPD screen ---------- */
.opd-layout { display: grid; grid-template-columns: minmax(420px, 1.1fr) 1fr; gap: 16px; align-items: start; }
.search-box { position: relative; }
.search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.1); max-height: 320px; overflow-y: auto; }
.search-results .item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.search-results .item:hover, .search-results .item.hl { background: var(--primary-soft); }
.search-results .item small { color: var(--muted); }
.patient-tag { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--primary-soft);
  border-radius: 8px; padding: 8px 12px; margin: 10px 0; font-weight: 600; color: var(--primary-dark); }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.doc-btn { text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; cursor: pointer; font: inherit; }
.doc-btn:hover { border-color: var(--primary); }
.doc-btn.sel { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px var(--primary-soft); }
.doc-btn b { display: block; font-size: 14px; }
.doc-btn small { color: var(--muted); display: block; }
.doc-btn .fee { font-weight: 700; color: var(--primary-dark); margin-top: 4px; display: flex; justify-content: space-between; }
.bill { background: #f7f9fb; border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.bill .line { display: flex; justify-content: space-between; }
.bill .line.total { font-size: 20px; font-weight: 800; color: var(--primary-dark); border-top: 1px dashed #c8d2db; padding-top: 6px; }
.share-preview { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ---------- modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 42, 51, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; }
.modal-head, .modal-foot { padding: 14px 18px; display: flex; align-items: center; gap: 10px; }
.modal-head { justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-foot { justify-content: flex-end; border-top: 1px solid var(--line); }
.modal-foot .error-text { margin-right: auto; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #17212b; color: #fff;
  padding: 10px 18px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-weight: 500; }
.toast.err { background: var(--danger); }
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); color: var(--muted); z-index: 70; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .opd-layout { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  nav { flex-direction: row; overflow-x: auto; padding: 0 8px 8px; }
  nav a { white-space: nowrap; }
  .sidebar-foot { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .page { padding: 14px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}

/* ---------- PRINT ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff; }
}
/* Thermal slip (58mm roll → 48mm printable, 80mm → 72mm) */
.slip { width: 48mm; padding: 1mm 0 4mm; font-family: Arial, Helvetica, sans-serif; color: #000; font-size: 11px; line-height: 1.3; }
.slip.w80 { width: 72mm; font-size: 12.5px; }
.slip .c { text-align: center; }
.slip .h1 { font-size: 15px; font-weight: 800; text-transform: uppercase; }
.slip.w80 .h1 { font-size: 18px; }
.slip .small { font-size: 9.5px; }
.slip hr { border: 0; border-top: 1px dashed #000; margin: 4px 0; }
.slip .token-label { font-size: 11px; font-weight: 700; letter-spacing: .1em; }
.slip .token { font-size: 40px; font-weight: 900; line-height: 1; margin: 2px 0; }
.slip .doc { font-size: 13px; font-weight: 800; }
.slip .kv { display: flex; justify-content: space-between; gap: 6px; }
.slip .kv span:last-child { text-align: right; font-weight: 700; }
.slip .net { font-size: 15px; font-weight: 900; }
.slip .dup { border: 1.5px solid #000; display: inline-block; padding: 0 6px; font-weight: 800; margin-top: 2px; }
/* A4 report print */
.a4 { padding: 0; font-size: 11.5px; color: #000; font-family: Arial, sans-serif; }
.a4 h2 { font-size: 16px; margin-bottom: 2px; }
.a4 .sub { margin-bottom: 10px; color: #333; }
.a4 table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.a4 th, .a4 td { border: 1px solid #999; padding: 4px 6px; position: static; background: none; color: #000; }
.a4 th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.a4 .actions, .a4 .no-print { display: none !important; }
