/* ==========================================================================
   Smart Homeo ERP - shared stylesheet (pure CSS, no framework)
   Sections: tokens, base, app shell, components, forms, tables, prescription, print
   ========================================================================== */

:root {
  --brand: #0e5e6f;
  --brand-dark: #0a4654;
  --brand-soft: #e7f1f3;
  --ink: #1b2430;
  --muted: #5b6678;
  --faint: #8b95a5;
  --line: #e0e4ea;
  --line-strong: #cbd2dc;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --subtle: #f8f9fb;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --ok-line: #abefc6;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --warn-line: #fedf89;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-line: #f0c4bf;
  --radius: 10px;
  --radius-sm: 8px;
  --sidebar: 240px;
  --font: "Inter", "Hind Siliguri", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
table { border-collapse: collapse; width: 100%; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.req { color: var(--danger); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex: none;
}
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); line-height: 1.2; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; font-size: 13.5px; transition: background-color .15s, color .15s;
}
.nav a:hover { background: var(--subtle); color: var(--ink); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.sidebar-foot .label-sm { font-size: 11.5px; color: var(--faint); margin-bottom: 6px; }

.main { margin-left: var(--sidebar); padding: 28px 32px 48px; max-width: 1320px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; margin-bottom: 22px; }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: 20px; }
.split { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 24px; align-items: start; }
.split-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.g2, .g3, .g4, .g12 { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.s2 { grid-column: span 2; }
.s3 { grid-column: span 3; }
.s4 { grid-column: span 4; }
.s5 { grid-column: span 5; }
.s7 { grid-column: span 7; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sticky { position: sticky; top: 20px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-body { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-title { font-size: 15px; font-weight: 600; }
.card-hint { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.card-sep { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }

.stat { padding: 16px 18px; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat-value.ok { color: var(--ok); }
.stat-value.warn { color: var(--warn); }

/* ---------- Buttons and badges ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; font-size: 13px; font-weight: 500; line-height: 1.2;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: none;
  transition: background-color .15s, border-color .15s, opacity .15s, color .15s; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: #fd5b21; color: #fff; }
.btn-primary:hover { opacity: 0.8; }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--subtle); }
.btn-danger { background: var(--surface); border-color: var(--danger-line); color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.link-btn { background: none; border: 0; padding: 2px 4px; font-size: 12px; color: var(--muted); border-radius: 4px; }
.link-btn:hover { color: var(--danger); }
.link-btn.brand { color: var(--brand); font-weight: 500; }
.link-btn.brand:hover { color: var(--brand-dark); text-decoration: underline; }

.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--subtle); color: var(--muted); border: 1px solid var(--line); }
.badge-brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }

/* ---------- Forms ---------- */
.label { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.field {
  width: 100%; padding: 8px 12px; font-size: 14px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
.field::placeholder { color: var(--faint); }
.field:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14, 94, 111, .15); }
.field[readonly] { background: #f1f3f6; color: var(--muted); }
textarea.field { resize: vertical; min-height: 92px; }
.check-group { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.check:hover { background: var(--subtle); }
.check input { accent-color: var(--brand); width: 15px; height: 15px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }
.file-btn input { display: none; }

/* ---------- Lists and tables ---------- */
.table-wrap { overflow-x: auto; }
.table th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--subtle); }
.table .right { text-align: right; white-space: nowrap; }
.cell-strong { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); }
.cell-clip { max-width: 280px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-main { min-width: 0; }
.list-title { font-weight: 600; font-size: 13.5px; }

.visit-box { padding: 12px; background: var(--subtle); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-top: 16px; }
.visit-list { display: flex; flex-direction: column; gap: 8px; max-height: 170px; overflow-y: auto; margin-top: 8px; }
.visit-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 12.5px; }

/* ---------- Repertory ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 210px; overflow-y: auto; padding: 10px; background: var(--subtle); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.chip { display: inline-flex; align-items: center; gap: 6px; text-align: left; padding: 6px 12px; font-size: 12.5px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); color: #2f3a4a; transition: border-color .15s, background-color .15s; }
.chip:hover { border-color: var(--brand); }
.chip.is-selected { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }
.suggest-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.suggest { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); transition: border-color .15s; }
.suggest:hover { border-color: var(--brand); }
.suggest-name { font-weight: 600; font-size: 13.5px; }
.suggest-name span { color: var(--brand); font-weight: 500; font-size: 12px; margin-left: 4px; }
.suggest-meta { font-size: 12px; color: var(--muted); }

/* ---------- Prescription pad ---------- */
.rx-pad { background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 28px; min-height: 700px; display: flex; flex-direction: column; justify-content: space-between; color: #1b2430; }
.rx-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 2px solid var(--brand); }
.rx-doc-name { font-size: 21px; font-weight: 600; color: var(--brand); line-height: 1.2; }
.rx-doc-line { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rx-doc-degree { font-size: 12.5px; font-weight: 500; margin-top: 3px; }
.rx-meta { text-align: right; font-size: 12px; color: var(--muted); flex: none; }
.rx-meta strong, .rx-meta .v { color: var(--ink); font-weight: 500; }
.rx-type { display: inline-block; margin-bottom: 8px; padding: 3px 10px; font-size: 12px; font-weight: 500; color: var(--brand); border: 1px solid var(--brand); border-radius: 6px; }
.rx-patient { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 10px 12px; margin-bottom: 20px; font-size: 12px; background: var(--subtle); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.rx-patient span { display: block; color: var(--muted); }
.rx-patient strong { font-weight: 600; overflow-wrap: anywhere; }
.rx-body { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); gap: 18px; min-height: 380px; }
.rx-side { padding-right: 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 18px; }
.rx-h { font-size: 12px; font-weight: 600; color: var(--brand); padding-bottom: 4px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.rx-text { font-size: 12.5px; color: #2f3a4a; white-space: pre-line; line-height: 1.6; overflow-wrap: anywhere; }
.rx-main { display: flex; flex-direction: column; justify-content: space-between; }
.rx-symbol { font-family: Georgia, "Times New Roman", serif; font-size: 30px; font-weight: 700; color: var(--brand); line-height: 1; margin-bottom: 12px; }
.rx-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.rx-item-name { font-weight: 600; font-size: 14px; }
.rx-item-name span { color: var(--brand); font-weight: 500; }
.rx-item-line { font-size: 12.5px; color: #2f3a4a; padding-left: 16px; margin-top: 2px; }
.rx-item-sub { font-size: 12px; color: var(--muted); padding-left: 16px; }
.rx-advice { margin-top: 24px; padding-top: 12px; border-top: 1px dashed var(--line-strong); }
.rx-advice ul { list-style: disc; padding-left: 18px; font-size: 12.5px; color: #2f3a4a; display: flex; flex-direction: column; gap: 4px; }
.rx-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.rx-sign { text-align: center; }
.rx-sign i { display: block; width: 140px; border-bottom: 1px solid var(--faint); margin-bottom: 4px; }

/* ---------- Modal and toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(20, 28, 38, .5); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal.open { display: flex; }
.modal-box { width: 100%; max-width: 520px; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); max-height: 92vh; overflow-y: auto; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: 360px; padding: 11px 16px; background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 500; border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0, 0, 0, .2); z-index: 120; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .split-even { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { position: static; width: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px 16px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; }
  .sidebar-foot .label-sm { display: none; }
  .main { margin-left: 0; padding: 20px 16px 40px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .g2, .g3, .g12 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .s2, .s3, .s4, .s5, .s7 { grid-column: auto; }
  .g4 .s2 { grid-column: span 2; }
  .suggest-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 20px; }
  .rx-pad { padding: 18px; }
  .rx-patient { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Print ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  body * { visibility: hidden; }
  #prescription-print-area, #prescription-print-area * { visibility: visible; }
  #prescription-print-area { position: absolute; left: 0; top: 0; width: 100%; border: 0; border-radius: 0; padding: 0; margin: 0; }
  .no-print, .sidebar, .toast { display: none !important; }
}