/* ===== Life Medical EHR — design system ===== */
:root {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --ink: #16243a;
  --ink-soft: #5b6b82;
  --line: #e3e9f1;
  --brand: #0e6ba8;
  --brand-dark: #0a5586;
  --sidebar: #0f1e33;
  --sidebar-ink: #c6d3e4;
  --good: #17825c;
  --good-bg: #e7f5ef;
  --warn: #a16207;
  --warn-bg: #fdf3d7;
  --bad: #b42332;
  --bad-bg: #fceaec;
  --info-bg: #e8f1f9;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(22, 36, 58, .08), 0 4px 16px rgba(22, 36, 58, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; }
a { color: var(--brand); text-decoration: none; }

/* ===== Login ===== */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #0f1e33 0%, #14365c 55%, #0e6ba8 100%); padding: 24px;
  flex-direction: column;
}
.login-card {
  background: var(--panel); border-radius: 18px; padding: 36px 40px; width: 460px; max-width: 100%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo { font-size: 42px; }
.login-brand h1 { font-size: 24px; margin: 6px 0 4px; }
.login-step h2 { font-size: 16px; margin: 18px 0 12px; }
.login-users { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.login-user {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer;
  background: #fbfcfe; transition: border-color .15s, background .15s; text-align: left;
}
.login-user:hover { border-color: var(--brand); background: var(--info-bg); }
.login-user .lu-name { font-weight: 600; font-size: 14px; }
.login-user .lu-role { font-size: 12px; color: var(--ink-soft); text-transform: capitalize; }
.pin-input {
  width: 100%; font-size: 30px; letter-spacing: 14px; text-align: center; padding: 10px;
  border: 1.5px solid var(--line); border-radius: 10px; margin-bottom: 14px;
}
.pin-input:focus { outline: none; border-color: var(--brand); }
.login-error { color: var(--bad); font-size: 13px; margin-top: 10px; text-align: center; }
.login-hints {
  margin-top: 22px; padding: 10px 14px; background: var(--info-bg); border-radius: 10px;
  font-size: 12px; color: var(--ink-soft);
}

/* ===== Footer / powered-by ===== */
.app-footer {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 4px 14px; font-size: 12px; color: rgba(255, 255, 255, .72);
}
.login-footer { margin-top: 22px; padding: 0 16px; text-align: center; }
.foot-powered { display: inline-flex; align-items: center; gap: 6px; }
.bb-mark { display: inline-block; vertical-align: middle; border-radius: 4px; flex-shrink: 0; }
.bb-name { font-weight: 700; color: #fff; letter-spacing: .2px; }
.sidebar-foot {
  padding: 10px 18px 14px; font-size: 11px; color: rgba(255, 255, 255, .5);
  display: flex; align-items: center; gap: 6px; border-top: 1px solid rgba(255, 255, 255, .06);
}
.sidebar-foot .bb-name { color: rgba(255, 255, 255, .82); font-weight: 700; }

/* ===== Shell ===== */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; background: var(--sidebar); color: var(--sidebar-ink); display: flex;
  flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.sidebar-brand { font-weight: 700; color: #fff; padding: 20px 18px 14px; font-size: 15px; }
.side-nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.side-nav a {
  color: var(--sidebar-ink); padding: 9px 12px; border-radius: 8px; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
}
.side-nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.side-nav a.active { background: var(--brand); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .9; }
.badge {
  background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700;
  padding: 1px 7px; margin-left: auto;
}
.sidebar-user { padding: 14px 18px; border-top: 1px solid rgba(255, 255, 255, .1); }
.side-user-name { color: #fff; font-weight: 600; font-size: 13.5px; }
.side-user-role { font-size: 12px; text-transform: capitalize; margin-bottom: 8px; }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; gap: 14px; align-items: center; padding: 12px 26px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40;
}
.global-search { position: relative; flex: 1; max-width: 520px; }
.global-search input {
  width: 100%; padding: 9px 14px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 14px;
  background: var(--bg);
}
.global-search input:focus { outline: none; border-color: var(--brand); background: #fff; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 6px; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 60;
  max-height: 340px; overflow: auto;
}
.search-result { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.search-result:hover { background: var(--info-bg); }
.view { padding: 24px 26px 60px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* ===== Cards / layout ===== */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card h3 { font-size: 15px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 1000px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.stat-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; cursor: pointer; }
.stat-card .stat-num { font-size: 28px; font-weight: 700; }
.stat-card .stat-label { font-size: 13px; color: var(--ink-soft); }
.stat-card.alert .stat-num { color: var(--bad); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 21px; }

/* ===== Tables ===== */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft); padding: 8px 10px; border-bottom: 1.5px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover { background: var(--info-bg); }
.tbl-wrap { overflow-x: auto; }

/* ===== Chips / pills ===== */
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.chip-red { background: var(--bad-bg); color: var(--bad); }
.chip-green { background: var(--good-bg); color: var(--good); }
.chip-amber { background: var(--warn-bg); color: var(--warn); }
.chip-blue { background: var(--info-bg); color: var(--brand-dark); }
.chip-gray { background: #eef1f6; color: var(--ink-soft); }
.flag-H, .flag-L { color: var(--bad); font-weight: 700; }

/* ===== Buttons / forms ===== */
.btn {
  border: none; border-radius: 9px; padding: 8px 15px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; background: #e8edf4; color: var(--ink); transition: filter .12s;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); filter: none; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.25); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--brand); cursor: pointer; padding: 0; font-size: 13px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
label.fld { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 2px; }
input[type=text], input[type=date], input[type=time], input[type=search], input[type=password],
input[type=number], input[type=email], select, textarea {
  width: 100%; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
textarea { resize: vertical; min-height: 70px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 30, 51, .55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 20px; overflow: auto;
}
.modal {
  background: #fff; border-radius: 14px; width: 640px; max-width: 100%;
  box-shadow: 0 24px 80px rgba(0,0,0,.35); animation: pop .16s ease-out;
}
.modal.modal-lg { width: 860px; }
@keyframes pop { from { transform: translateY(10px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal-x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-soft); }

/* ===== Toasts ===== */
.toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; border-radius: 10px; padding: 11px 16px; font-size: 13.5px;
  box-shadow: var(--shadow); max-width: 380px; animation: pop .18s ease-out;
}
.toast.err { background: var(--bad); }
.toast.ok { background: var(--good); }

/* ===== Patient banner ===== */
.pt-banner {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 20px; margin-bottom: 16px;
}
.pt-banner-top { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.pt-banner-top h2 { margin: 0; font-size: 21px; }
.pt-meta { color: var(--ink-soft); font-size: 13.5px; }
.pt-banner-chips { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bg-active {
  background: repeating-linear-gradient(45deg, var(--bad-bg), var(--bad-bg) 12px, #fff 12px, #fff 24px);
  border: 1.5px solid var(--bad); border-radius: 10px; padding: 8px 14px; font-size: 13px;
  color: var(--bad); font-weight: 600; margin-top: 10px;
}

/* ===== Chart tabs ===== */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 9px 15px; font-size: 13.5px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
  border: none; background: none; white-space: nowrap; border-bottom: 2.5px solid transparent; margin-bottom: -2px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ===== Alerts / callouts ===== */
.callout { border-radius: 10px; padding: 12px 16px; margin-bottom: 12px; font-size: 13.5px; }
.callout-red { background: var(--bad-bg); border: 1px solid #f3c2c8; color: #7c1622; }
.callout-amber { background: var(--warn-bg); border: 1px solid #ead79b; color: #6b4708; }
.callout-blue { background: var(--info-bg); border: 1px solid #c6dcef; color: #0d4f7c; }
.callout-green { background: var(--good-bg); border: 1px solid #bce3d2; color: #0e5c40; }
.callout h4 { margin: 0 0 4px; font-size: 13.5px; }

/* ===== Rx safety alert list ===== */
.rx-alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; font-size: 13.5px; border-left: 4px solid; }
.rx-alert.major { background: var(--bad-bg); border-color: var(--bad); }
.rx-alert.moderate { background: var(--warn-bg); border-color: var(--warn); }
.rx-alert.minor { background: var(--info-bg); border-color: var(--brand); }
.rx-alert .rx-sev { font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; }

/* ===== SOAP note ===== */
.soap-block { margin-bottom: 10px; }
.soap-block .soap-tag {
  display: inline-block; width: 22px; height: 22px; border-radius: 6px; background: var(--brand);
  color: #fff; font-weight: 700; text-align: center; line-height: 22px; font-size: 12px; margin-right: 8px;
}
.note-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.note-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.note-body p { margin: 4px 0 10px; white-space: pre-wrap; }

/* ===== SVG charts ===== */
.trend-chart { width: 100%; height: auto; }
.trend-chart .axis { stroke: var(--line); stroke-width: 1; }
.trend-chart .grid-label { font-size: 10px; fill: var(--ink-soft); }
.trend-chart .refband { fill: var(--good-bg); opacity: .7; }
.sparkline { vertical-align: middle; }

/* ===== Report / result viewer ===== */
.report-pre {
  white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ===== Schedule ===== */
.sched-row { display: flex; gap: 14px; align-items: center; padding: 10px 6px; border-bottom: 1px solid var(--line); }
.sched-time { font-weight: 700; width: 60px; }
.sched-status select { width: auto; }

/* ===== Superbill print ===== */
.superbill { font-size: 13.5px; }
.superbill h2 { margin-bottom: 2px; }
.superbill table { margin: 8px 0 16px; }
@media print {
  .sidebar, .topbar, .tabs, .btn, .toast-root, .no-print { display: none !important; }
  .view { padding: 0; max-width: none; }
  .card, .pt-banner { box-shadow: none; border: none; padding: 0; }
  body { background: #fff; }
  /* when a modal (e.g. superbill) is open, print only the modal content */
  body:has(#modalOverlay) .app-shell { display: none !important; }
  .modal-overlay { position: static; padding: 0; background: none; overflow: visible; }
  .modal { box-shadow: none; width: 100%; max-width: none; }
  .modal-head, .modal-foot { display: none !important; }
}

/* ===== Misc ===== */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-soft); font-weight: 600; }
.kv dd { margin: 0; }
.empty { color: var(--ink-soft); font-size: 13.5px; padding: 14px 4px; text-align: center; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); font-weight: 700; margin: 14px 0 6px; }
code.inline { background: #eef1f6; border-radius: 5px; padding: 1px 6px; font-size: 12.5px; }
