/* =================================================================
   Clinic — Patient Management
   Design system: calm clinical. Deep teal primary, warm-cool white,
   semantic status colours that double as lab-flag meaning.
   Display: Fraunces (restraint). Body/data: Inter (tabular).
   ================================================================= */

:root {
    --bg:        #F4F7F6;
    --surface:   #FFFFFF;
    --surface-2: #FAFCFB;
    --ink:       #15241F;
    --muted:     #5E6E68;
    --faint:     #8A9892;
    --border:    #E3EAE7;
    --border-2:  #D3DEDA;

    --teal:      #14776A;
    --teal-700:  #0F5E54;
    --teal-050:  #E6F1EF;

    --ok:        #1E8E5A;   /* normal / completed */
    --ok-050:    #E5F4EC;
    --warn:      #B8730C;   /* high */
    --warn-050:  #FBF1E1;
    --danger:    #C0392B;   /* low / critical */
    --danger-050:#F8E8E6;
    --info:      #2C6FB0;
    --info-050:  #E7F0F8;

    --radius:    14px;
    --radius-sm: 9px;
    --shadow:    0 1px 2px rgba(20,40,34,.04), 0 8px 24px -12px rgba(20,40,34,.12);
    --shadow-sm: 0 1px 2px rgba(20,40,34,.06);
    --sidebar:   254px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    font-feature-settings: "tnum" 1, "cv05" 1;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -.01em;
    margin: 0;
    color: var(--ink);
}

a { color: var(--teal-700); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar);
    flex: 0 0 var(--sidebar);
    background: #0E2C28;
    color: #CFE0DC;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex; align-items: center; gap: 11px;
    padding: 4px 8px 20px;
    color: #fff;
}
.brand .mark {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(150deg, #2AA897, var(--teal));
    display: grid; place-items: center;
    font-family: "Fraunces", serif; font-weight: 600; font-size: 19px; color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand b { font-family: "Fraunces", serif; font-weight: 600; font-size: 18px; letter-spacing: -.01em; }
.brand span { display:block; font-size: 11px; color: #7FA39C; letter-spacing: .04em; text-transform: uppercase; }

.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #B9D0CB;
    font-weight: 500; font-size: 14.5px;
    min-height: 44px;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--teal); color: #fff; }
.nav-link svg { width: 19px; height: 19px; flex: 0 0 19px; stroke-width: 1.9; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 12px 8px; }
.sidebar-foot { margin-top: auto; font-size: 12.5px; color: #6E938C; padding: 12px 8px 0; }
.sidebar-foot form { margin-top: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Topbar (mobile menu) ---------- */
.topbar {
    display: none;
    align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: #0E2C28; color: #fff;
    position: sticky; top: 0; z-index: 40;
}
.topbar .brand { padding: 0; color: #fff; }
.menu-btn {
    background: rgba(255,255,255,.1); border: none; color: #fff;
    width: 44px; height: 44px; border-radius: 10px; cursor: pointer;
    display: grid; place-items: center;
}
.menu-btn svg { width: 22px; height: 22px; }

.content { padding: 28px 32px 64px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------- Page header ---------- */
.page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head .eyebrow {
    font-size: 12px; font-weight: 600; letter-spacing: .07em;
    text-transform: uppercase; color: var(--teal); margin-bottom: 6px;
}
.page-head h1 { font-size: 30px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px;
    border-radius: var(--radius-sm);
    font: inherit; font-weight: 600; font-size: 14.5px;
    border: 1px solid transparent; cursor: pointer; white-space: nowrap;
    transition: background .14s, border-color .14s, color .14s;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-700); text-decoration: none; color:#fff; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--border-2); }
.btn-ghost:hover { background: var(--surface-2); text-decoration: none; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #E7C9C5; }
.btn-danger:hover { background: var(--danger-050); text-decoration: none; }
.btn-sm { min-height: 36px; padding: 0 13px; font-size: 13.5px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px 22px; }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 22px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 16.5px; }
.card-head .sub { font-size: 13px; color: var(--faint); font-family: "Inter",sans-serif; font-weight: 500; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.col-span-2 { grid-column: span 2; }

/* ---------- Stat tiles ---------- */
.stat { padding: 18px 20px; }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat .num { font-family: "Fraunces", serif; font-size: 34px; font-weight: 600; margin-top: 4px; letter-spacing: -.02em; }
.stat .num small { font-size: 14px; color: var(--faint); font-family:"Inter"; font-weight: 500; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
    text-align: left; font-weight: 600; font-size: 12px; letter-spacing: .04em;
    text-transform: uppercase; color: var(--faint);
    padding: 11px 14px; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Badges / flags ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 100px;
    font-size: 12px; font-weight: 600; line-height: 1.4;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok     { background: var(--ok-050);     color: var(--ok); }
.badge-warn   { background: var(--warn-050);   color: var(--warn); }
.badge-danger { background: var(--danger-050); color: var(--danger); }
.badge-info   { background: var(--info-050);   color: var(--info); }
.badge-muted  { background: #EEF2F0; color: var(--muted); }

.flag-high   { color: var(--warn);   font-weight: 600; }
.flag-low    { color: var(--danger); font-weight: 600; }
.flag-normal { color: var(--ok); }

/* ---------- Avatar ---------- */
.avatar {
    width: 42px; height: 42px; border-radius: 11px; flex: 0 0 42px;
    display: grid; place-items: center;
    background: var(--teal-050); color: var(--teal-700);
    font-weight: 600; font-size: 15px;
}
.avatar.lg { width: 64px; height: 64px; flex-basis: 64px; border-radius: 16px; font-size: 22px; font-family:"Fraunces",serif; }
.patient-cell { display: flex; align-items: center; gap: 12px; }
.patient-cell .meta { font-size: 12.5px; color: var(--faint); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field .hint { font-size: 12px; color: var(--faint); font-weight: 400; }
.input, .select, textarea.input {
    width: 100%; min-height: 44px;
    padding: 10px 13px;
    border: 1px solid var(--border-2); border-radius: var(--radius-sm);
    font: inherit; color: var(--ink); background: var(--surface);
    transition: border-color .14s, box-shadow .14s;
}
textarea.input { min-height: 90px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, textarea.input:focus {
    outline: none; border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-050);
}
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.error { color: var(--danger); font-size: 12.5px; margin-top: 5px; }

/* ---------- Repeater rows (labs / rx items) ---------- */
.repeater-row {
    display: grid; gap: 10px; align-items: end;
    padding: 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); margin-bottom: 10px; background: var(--surface-2);
}
.rm-row {
    background: none; border: none; cursor: pointer; color: var(--danger);
    width: 40px; height: 44px; border-radius: 8px; display: grid; place-items: center;
}
.rm-row:hover { background: var(--danger-050); }

/* ---------- Flash / alerts ---------- */
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 16px; border-radius: var(--radius-sm);
    background: var(--ok-050); color: #14603C;
    border: 1px solid #BFE3CE; margin-bottom: 20px; font-weight: 500;
}
.flash svg { width: 19px; height: 19px; flex: 0 0 19px; }
.alert-err { background: var(--danger-050); color: #8E261B; border-color: #E7C9C5; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab {
    padding: 11px 16px; font-weight: 600; font-size: 14px; color: var(--muted);
    border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; background: none; border-top:none; border-left:none; border-right:none; font-family:inherit;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--teal-700); border-bottom-color: var(--teal); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Trend (signature element) ---------- */
.trend-card { padding: 16px 18px; }
.trend-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.trend-head .name { font-weight: 600; font-size: 14.5px; }
.trend-head .latest { font-family: "Fraunces", serif; font-size: 22px; font-weight: 600; }
.trend-head .unit { font-size: 12px; color: var(--faint); font-weight: 500; }
.trend-meta { font-size: 12px; color: var(--faint); margin-top: 2px; }
.trend-canvas { margin-top: 8px; }
.delta { font-size: 12.5px; font-weight: 600; }
.delta.up { color: var(--warn); }
.delta.down { color: var(--ok); }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .icon { width: 46px; height: 46px; margin: 0 auto 12px; color: var(--border-2); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.stack > * + * { margin-top: 18px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.search {
    display: flex; align-items: center; gap: 8px; background: var(--surface);
    border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 0 12px; min-height: 44px;
}
.search input { border: none; outline: none; font: inherit; flex: 1; background: none; min-height: 42px; }
.search svg { width: 18px; height: 18px; color: var(--faint); }
.pagination { display: flex; gap: 4px; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 38px; height: 38px; padding: 0 10px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13.5px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}
.pagination .active span, .pagination span[aria-current] { background: var(--teal); color: #fff; border-color: var(--teal); }
.list-link { color: inherit; }
.list-link:hover { text-decoration: none; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

/* ---------- Print (prescription) ---------- */
@media print {
    .sidebar, .topbar, .no-print, .btn { display: none !important; }
    .main, body { background: #fff; }
    .content { padding: 0; max-width: 100%; }
    .card { box-shadow: none; border-color: #ccc; }
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .col-span-2 { grid-column: span 1; }
}
@media (max-width: 820px) {
    .sidebar { display: none; position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; box-shadow: 0 0 60px rgba(0,0,0,.4); }
    .sidebar.open { display: flex; }
    .topbar { display: flex; }
    .scrim { display: none; position: fixed; inset: 0; background: rgba(8,20,17,.45); z-index: 45; }
    .scrim.open { display: block; }
    .content { padding: 20px 16px 56px; }
    .page-head h1 { font-size: 25px; }
    .form-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 110px 1fr; }
}
@media (max-width: 560px) {
    .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
    .stat .num { font-size: 28px; }
    .page-head { align-items: flex-start; }
}
