/* =====================================================================
   MARA-RHC Pharmacy Inventory System — design system
   ---------------------------------------------------------------------
   Every colour resolves from a CSS custom property written by the admin
   theme (ThemeService). Nothing here hard-codes a brand or alert colour,
   so changing the theme restyles the whole product instantly.
   ===================================================================== */

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv02", "cv03", "cv04", "tnum";
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

/* ---------- derived tokens ---------- */
:root {
    --r-sm: calc(var(--radius) * 0.45);
    --r-md: calc(var(--radius) * 0.7);
    --r-lg: var(--radius);
    --r-xl: calc(var(--radius) * 1.35);

    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 4px 14px -4px rgba(16, 24, 40, .08), 0 2px 6px -2px rgba(16, 24, 40, .04);
    --shadow-lg: 0 18px 40px -12px rgba(16, 24, 40, .14), 0 4px 12px -4px rgba(16, 24, 40, .06);

    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

    --sidebar-w: 264px;
    --topbar-h: 68px;
}

/* =====================================================================
   Shell
   ===================================================================== */
.shell { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--sidebar);
    color: color-mix(in srgb, #fff 72%, var(--sidebar));
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, #fff 18%, transparent) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: color-mix(in srgb, #fff 16%, transparent); border-radius: 99px; }

.brand {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-6) var(--sp-5) var(--sp-5);
}
.brand-text strong { display: block; color: #fff; font-size: 15px; letter-spacing: -.015em; }
.brand-text span { font-size: 11.5px; opacity: .62; letter-spacing: .01em; }

.nav { padding: var(--sp-2) var(--sp-3) var(--sp-6); flex: 1; }
.nav-group { margin-bottom: var(--sp-5); }
.nav-group-label {
    font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
    opacity: .42; padding: 0 var(--sp-3) var(--sp-2);
}
.nav-item {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: 9px var(--sp-3); margin-bottom: 2px;
    border-radius: var(--r-md);
    font-size: 13.5px; font-weight: 500;
    transition: background .15s ease, color .15s ease;
    position: relative;
}
.nav-item:hover { background: color-mix(in srgb, #fff 8%, transparent); color: #fff; }
.nav-item.is-active {
    background: color-mix(in srgb, var(--accent) 92%, #000);
    color: #fff;
}
.nav-item.is-active::before {
    content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-item .icon { width: 17px; height: 17px; flex: 0 0 17px; opacity: .9; }
.nav-badge {
    margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 99px; display: grid; place-items: center;
    font-size: 11px; font-weight: 700;
    background: var(--alert-orange); color: #fff;
}
.nav-item.is-active .nav-badge { background: rgba(255,255,255,.24); }

.sidebar-foot { padding: var(--sp-4) var(--sp-3) var(--sp-5); }
.user-card {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3);
    border-radius: var(--r-md);
    background: color-mix(in srgb, #fff 7%, transparent);
}
.user-card .avatar { background: var(--accent); color: #fff; }
.user-card-text { min-width: 0; }
.user-card-text strong { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-text span { font-size: 11px; opacity: .6; }
.signout {
    margin-left: auto; width: 30px; height: 30px; flex: 0 0 30px;
    display: grid; place-items: center; border: 0; background: transparent;
    color: inherit; border-radius: var(--r-sm); cursor: pointer; opacity: .6;
}
.signout:hover { background: color-mix(in srgb, #fff 10%, transparent); opacity: 1; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: var(--sp-4);
    padding: 0 var(--sp-8);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.topbar-spacer { flex: 1; }

.project-picker {
    display: flex; align-items: center; gap: var(--sp-2);
    background: var(--accent-soft);
    border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
    border-radius: 99px;
    padding: 5px 6px 5px 14px;
}
.project-picker label {
    font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: var(--accent-deep); opacity: .8;
}
.project-picker select {
    border: 0; background: transparent; font-size: 13px; font-weight: 600;
    color: var(--accent-deep); cursor: pointer; padding-right: 4px; max-width: 240px;
}
.project-picker select:focus { outline: none; }

.icon-btn {
    width: 38px; height: 38px; display: grid; place-items: center;
    border: 1px solid var(--border); background: var(--surface);
    border-radius: var(--r-md); cursor: pointer; color: var(--ink-muted);
    position: relative; transition: .15s ease;
}
.icon-btn:hover { color: var(--ink); border-color: color-mix(in srgb, var(--ink) 22%, transparent); }
.icon-btn .dot {
    position: absolute; top: 8px; right: 9px; width: 7px; height: 7px;
    border-radius: 99px; background: var(--alert-red); border: 2px solid var(--surface);
}

.avatar {
    width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%;
    display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
    background: var(--accent-soft); color: var(--accent-deep); letter-spacing: .02em;
}
.who { display: flex; align-items: center; gap: var(--sp-3); }
.who-text strong { display: block; font-size: 13px; font-weight: 600; line-height: 1.2; }
.who-text span { font-size: 11.5px; color: var(--ink-muted); }

.page { padding: var(--sp-8); max-width: 1560px; width: 100%; margin: 0 auto; flex: 1; }

/* =====================================================================
   Page head
   ===================================================================== */
.page-head { display: flex; align-items: flex-start; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 650; letter-spacing: -.025em; line-height: 1.2; }
.page-head p { color: var(--ink-muted); margin-top: 3px; font-size: 13.5px; max-width: 72ch; }
.page-head .actions { margin-left: auto; display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* =====================================================================
   Cards
   ===================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}
.card-head {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-5) var(--sp-4);
    border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; font-weight: 620; letter-spacing: -.012em; }
.card-head p { font-size: 12.5px; color: var(--ink-muted); }
.card-head .spacer { flex: 1; }
.card-body { padding: var(--sp-5); }
.card-body.flush { padding: 0; }
.card-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: color-mix(in srgb, var(--canvas) 55%, var(--surface)); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
.kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: var(--sp-5);
    box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi-label { font-size: 12.5px; color: var(--ink-muted); font-weight: 500; }
.kpi-value { font-size: 34px; font-weight: 640; letter-spacing: -.035em; line-height: 1.1; margin: var(--sp-3) 0 var(--sp-1); font-variant-numeric: tabular-nums; }
.kpi-meta { font-size: 12px; color: var(--ink-muted); }
.kpi.is-emphasis {
    background: var(--accent-deep);
    border-color: transparent; color: #fff;
}
.kpi.is-emphasis .kpi-label, .kpi.is-emphasis .kpi-meta { color: rgba(255,255,255,.78); }

/* =====================================================================
   Alert panel (workflow §10) — colour + icon + count + label
   ===================================================================== */
.alert-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: var(--sp-3); }
.alert-chip {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-md);
    border: 1px solid color-mix(in srgb, var(--chip) 26%, transparent);
    background: color-mix(in srgb, var(--chip) 8%, var(--surface));
    transition: .15s ease; cursor: pointer;
}
.alert-chip:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.alert-chip.is-active { border-color: var(--chip); box-shadow: 0 0 0 2px color-mix(in srgb, var(--chip) 22%, transparent); }
.alert-chip .swatch {
    width: 32px; height: 32px; flex: 0 0 32px; border-radius: var(--r-sm);
    display: grid; place-items: center; background: var(--chip); color: #fff;
}
.alert-chip .swatch svg { width: 16px; height: 16px; }
.alert-chip-text { min-width: 0; }
.alert-chip-count { font-size: 19px; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.alert-chip-label { font-size: 11.5px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip-red    { --chip: var(--alert-red); }
.chip-orange { --chip: var(--alert-orange); }
.chip-yellow { --chip: var(--alert-yellow); }
.chip-blue   { --chip: var(--alert-blue); }
.chip-grey   { --chip: var(--alert-grey); }
.chip-green  { --chip: var(--alert-green); }

/* =====================================================================
   Status chips
   ===================================================================== */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 99px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    border: 1px solid transparent;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: currentColor; flex: 0 0 6px; }
.chip.no-dot::before { display: none; }
.chip-ok     { color: var(--alert-green);  background: color-mix(in srgb, var(--alert-green) 10%, transparent);  border-color: color-mix(in srgb, var(--alert-green) 24%, transparent); }
.chip-warn   { color: var(--alert-orange); background: color-mix(in srgb, var(--alert-orange) 10%, transparent); border-color: color-mix(in srgb, var(--alert-orange) 24%, transparent); }
.chip-danger { color: var(--alert-red);    background: color-mix(in srgb, var(--alert-red) 10%, transparent);    border-color: color-mix(in srgb, var(--alert-red) 24%, transparent); }
.chip-info   { color: var(--alert-blue);   background: color-mix(in srgb, var(--alert-blue) 10%, transparent);   border-color: color-mix(in srgb, var(--alert-blue) 24%, transparent); }
.chip-muted  { color: var(--ink-muted);    background: color-mix(in srgb, var(--ink-muted) 9%, transparent);     border-color: var(--border); }
.chip-accent { color: var(--accent-deep);  background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }

.code-chip {
    display: inline-flex; align-items: center; gap: 6px;
    font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
    font-size: 12px; font-weight: 600; letter-spacing: .01em;
    padding: 3px 9px; border-radius: var(--r-sm);
    background: var(--accent-soft); color: var(--accent-deep);
    border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
}

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 38px; padding: 0 16px;
    border-radius: var(--r-md); border: 1px solid transparent;
    font-size: 13.5px; font-weight: 570; cursor: pointer;
    transition: .15s ease; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover:not(:disabled) { background: var(--accent-deep); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--ink); box-shadow: var(--shadow-xs); }
.btn-ghost:hover:not(:disabled) { border-color: color-mix(in srgb, var(--ink) 24%, transparent); }
.btn-soft { background: var(--accent-soft); color: var(--accent-deep); }
.btn-soft:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.btn-danger { background: var(--alert-red); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }
.btn-danger-soft { background: color-mix(in srgb, var(--alert-red) 10%, transparent); color: var(--alert-red); border-color: color-mix(in srgb, var(--alert-red) 24%, transparent); }
.btn-sm { height: 31px; padding: 0 11px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-lg { height: 45px; padding: 0 22px; font-size: 14.5px; }
.btn-block { width: 100%; }

/* =====================================================================
   Forms
   ===================================================================== */
.field { margin-bottom: var(--sp-4); }
.field > label, .label {
    display: block; font-size: 12.5px; font-weight: 600;
    margin-bottom: 6px; letter-spacing: -.005em;
}
.hint { font-size: 11.5px; color: var(--ink-muted); margin-top: 5px; }
.hint-private {
    display: flex; gap: 6px; align-items: flex-start;
    font-size: 11.5px; margin-top: 6px;
    color: var(--alert-orange);
}

.input, .select, .textarea {
    width: 100%; height: 40px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--surface); color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
    font-size: 13.5px;
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.input::placeholder, .textarea::placeholder { color: color-mix(in srgb, var(--ink-muted) 75%, transparent); }
.input:disabled, .select:disabled { background: var(--canvas); color: var(--ink-muted); cursor: not-allowed; }
.input.is-error, .select.is-error { border-color: var(--alert-red); }
.error { font-size: 11.5px; color: var(--alert-red); margin-top: 5px; font-weight: 500; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 var(--sp-4); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }

.search-input { position: relative; }
.search-input svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-muted); pointer-events: none; }
.search-input .input { padding-left: 36px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 7px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.color-field { display: flex; align-items: center; gap: var(--sp-2); }
.color-field input[type="color"] {
    width: 42px; height: 40px; padding: 3px; cursor: pointer;
    border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
}
.color-field .input { font-family: ui-monospace, monospace; font-size: 12.5px; }

/* =====================================================================
   Tables
   ===================================================================== */
.table-wrap { overflow-x: auto; }
.table { font-size: 13px; }
.table th {
    text-align: left; font-size: 11px; font-weight: 650;
    letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted);
    padding: 11px var(--sp-4); border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--canvas) 60%, var(--surface));
    white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table td { padding: 13px var(--sp-4); border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: color-mix(in srgb, var(--canvas) 55%, transparent); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; white-space: nowrap; }
.table .strong { font-weight: 600; }
.table .muted { color: var(--ink-muted); }
.table .nowrap { white-space: nowrap; }
.table-compact td { padding: 9px var(--sp-4); }

.empty { padding: var(--sp-12) var(--sp-6); text-align: center; }
.empty-icon {
    width: 52px; height: 52px; margin: 0 auto var(--sp-4);
    border-radius: var(--r-lg); display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent-deep);
}
.empty h3 { font-size: 15px; font-weight: 600; margin-bottom: 5px; }
.empty p { color: var(--ink-muted); font-size: 13px; max-width: 46ch; margin: 0 auto; }

/* =====================================================================
   Layout helpers
   ===================================================================== */
.grid { display: grid; gap: var(--sp-5); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.grid-split { grid-template-columns: minmax(0, 1fr) minmax(0, 380px); align-items: start; }
.stack { display: grid; gap: var(--sp-5); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.row-tight { display: flex; align-items: center; gap: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); } .mt-5 { margin-top: var(--sp-5); } .mt-6 { margin-top: var(--sp-6); }
.mb-4 { margin-bottom: var(--sp-4); } .mb-5 { margin-bottom: var(--sp-5); }
.text-muted { color: var(--ink-muted); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.right { margin-left: auto; }
.mono { font-family: "JetBrains Mono", "SF Mono", ui-monospace, monospace; font-size: 12.5px; }

/* =====================================================================
   Flash / callouts
   ===================================================================== */
.flash {
    display: flex; align-items: flex-start; gap: var(--sp-3);
    padding: var(--sp-4); border-radius: var(--r-md);
    margin-bottom: var(--sp-5); font-size: 13.5px;
    border: 1px solid transparent;
    animation: slide-in .3s cubic-bezier(.2,.8,.3,1);
}
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } }
.flash svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; }
.flash-success { background: color-mix(in srgb, var(--alert-green) 8%, var(--surface)); border-color: color-mix(in srgb, var(--alert-green) 28%, transparent); color: color-mix(in srgb, var(--alert-green) 82%, var(--ink)); }
.flash-error   { background: color-mix(in srgb, var(--alert-red) 8%, var(--surface));   border-color: color-mix(in srgb, var(--alert-red) 28%, transparent);   color: color-mix(in srgb, var(--alert-red) 82%, var(--ink)); }
.flash-info    { background: color-mix(in srgb, var(--alert-blue) 8%, var(--surface));  border-color: color-mix(in srgb, var(--alert-blue) 28%, transparent);  color: color-mix(in srgb, var(--alert-blue) 82%, var(--ink)); }

.callout {
    padding: var(--sp-4); border-radius: var(--r-md);
    background: var(--accent-soft);
    border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
    font-size: 13px; color: var(--accent-deep);
}
.callout strong { font-weight: 640; }
.rule-note {
    display: flex; gap: var(--sp-2); align-items: flex-start;
    font-size: 12px; color: var(--ink-muted); line-height: 1.5;
}
.rule-note svg { width: 15px; height: 15px; flex: 0 0 15px; margin-top: 2px; opacity: .7; }

/* =====================================================================
   Charts (pure CSS/SVG — no external libraries)
   ===================================================================== */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 148px; padding-top: var(--sp-3); }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar {
    width: 100%; max-width: 34px; border-radius: var(--r-sm) var(--r-sm) 3px 3px;
    background: var(--accent);
    min-height: 3px; transition: .2s ease; position: relative;
}
.bar-col:hover .bar { background: var(--accent-deep); }
.bar-label { font-size: 10px; color: var(--ink-muted); white-space: nowrap; }
.bar-col:hover .bar::after {
    content: attr(data-value);
    position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: var(--ink); color: var(--surface); font-size: 11px; font-weight: 600;
    padding: 3px 7px; border-radius: var(--r-sm); white-space: nowrap;
}

.meter { height: 7px; border-radius: 99px; background: color-mix(in srgb, var(--ink-muted) 14%, transparent); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s ease; }
.meter.is-low > span { background: var(--alert-orange); }
.meter.is-out > span { background: var(--alert-red); }

.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3) var(--sp-4); font-size: 12px; }
.legend-item { display: flex; align-items: center; gap: 7px; color: var(--ink-muted); }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--accent); flex: 0 0 9px; }

/* =====================================================================
   Timeline
   ===================================================================== */
.timeline { position: relative; padding-left: var(--sp-6); }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 1.5px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: var(--sp-5); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
    content: ""; position: absolute; left: calc(var(--sp-6) * -1 + 2px); top: 5px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--accent);
}
.timeline-item .t-title { font-size: 13px; font-weight: 560; }
.timeline-item .t-meta { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; }

/* =====================================================================
   Line items (repeatable form rows)
   ===================================================================== */
.line-row {
    display: grid; grid-template-columns: minmax(0, 2.2fr) 110px minmax(0, 1.5fr) 40px;
    gap: var(--sp-3); align-items: end;
    padding: var(--sp-3) 0; border-bottom: 1px dashed var(--border);
}
.line-row:last-of-type { border-bottom: 0; }
.line-remove {
    width: 38px; height: 40px; display: grid; place-items: center;
    border: 1px solid var(--border); background: var(--surface);
    border-radius: var(--r-md); cursor: pointer; color: var(--ink-muted);
}
.line-remove:hover { color: var(--alert-red); border-color: color-mix(in srgb, var(--alert-red) 40%, transparent); }

/* =====================================================================
   Pagination
   ===================================================================== */
.pagination { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 33px; height: 33px; padding: 0 9px;
    display: inline-grid; place-items: center;
    border-radius: var(--r-sm); font-size: 13px;
    border: 1px solid var(--border); background: var(--surface); color: var(--ink-muted);
}
.pagination a:hover { border-color: var(--accent); color: var(--accent-deep); }
.pagination .active span, .pagination span[aria-current] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pagination .disabled span { opacity: .4; }

/* =====================================================================
   Login
   ===================================================================== */
.auth {
    min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
    background: var(--canvas);
}
.auth-form-side { display: grid; place-items: center; padding: var(--sp-8); }
.auth-card { width: 100%; max-width: 396px; }
.auth-card h1 {
    font-size: 30px; font-weight: 650; letter-spacing: -.035em; text-align: center;
    margin: var(--sp-6) 0;
}

.auth-art {
    background: var(--sidebar);
    padding: var(--sp-12); display: flex; flex-direction: column; justify-content: center;
    color: #fff; position: relative; overflow: hidden;
}
.auth-art-inner { position: relative; z-index: 1; max-width: 440px; }
.auth-art h2 { font-size: 30px; font-weight: 620; letter-spacing: -.03em; line-height: 1.22; }
.auth-art > .auth-art-inner > p { opacity: .74; margin-top: var(--sp-4); font-size: 14.5px; line-height: 1.6; }

.auth-features { margin-top: var(--sp-8); display: grid; gap: var(--sp-4); }
.auth-feature { display: flex; gap: var(--sp-3); align-items: flex-start; }
.auth-feature .tick {
    width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(255,255,255,.14);
}
.auth-feature .tick svg { width: 14px; height: 14px; }
.auth-feature strong { display: block; font-size: 13.5px; font-weight: 600; }
.auth-feature span { font-size: 12.5px; opacity: .66; line-height: 1.5; }


/* =====================================================================
   Print
   ===================================================================== */
@media print {
    .sidebar, .topbar, .actions, .no-print { display: none !important; }
    .page { padding: 0; }
    .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
}

/* =====================================================================
   Inline edit rows (admin configuration tables)
   ===================================================================== */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.row-edit > td { background: var(--surface-2, color-mix(in srgb, var(--ink) 3%, transparent)); padding: var(--sp-4) !important; }
.row-edit[hidden] { display: none; }
.row-edit .form-grid { margin-bottom: var(--sp-3); }
.row-edit-foot { display: flex; gap: 8px; align-items: center; margin-top: var(--sp-3); }
.row-edit-foot .spacer { margin-left: auto; }

/* =====================================================================
   Responsive
   ===================================================================== */
/* Desktop defaults for the mobile-only chrome; the 860px query turns them on.
   These have to be declared before that query, not after it. */
.menu-toggle { display: none; }
.topbar-brand { display: none; }
.topbar-brand img { height: 30px; width: auto; }
.nav-scrim { display: none; }

@media (max-width: 1180px) {
    .grid-main-side, .grid-split, .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .auth { grid-template-columns: minmax(0, 1fr); }
    .auth-art { display: none; }
}
@media (max-width: 860px) {
    .sidebar {
        position: fixed; z-index: 60; transform: translateX(-100%);
        transition: transform .25s cubic-bezier(.2,.8,.3,1);
        box-shadow: var(--shadow-lg);
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .nav-scrim {
        display: block;
        position: fixed; inset: 0; z-index: 50;
        background: rgba(16, 24, 40, .42);
    }
    /* Deep navy bars on a navy-tinted chip — the muted grey the other icon
       buttons use was too faint to find on a phone. */
    .menu-toggle {
        display: grid; width: 42px; height: 42px;
        color: var(--accent-deep);
        border-color: color-mix(in srgb, var(--accent) 38%, var(--border));
    }
    .menu-toggle svg { width: 21px; height: 21px; stroke-width: 2.4; }
    .menu-toggle:hover, .menu-toggle:active {
        color: #fff; background: var(--accent-deep); border-color: var(--accent-deep);
    }
    .topbar-brand { display: block; }
    .page { padding: var(--sp-5); }
    .topbar { padding: 0 var(--sp-4); gap: var(--sp-3); }
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .who-text, .topbar-title { display: none; }
    .who .avatar { margin-left: var(--sp-1); }
    .line-row { grid-template-columns: minmax(0, 1fr) 90px 40px; }
    .line-row .line-dosage { grid-column: 1 / -1; }
}

/* =====================================================================
   Brand mark — the MARA-RHC logo sits on a white chip so it reads on the
   navy sidebar as clearly as it does on a white card.
   ===================================================================== */
.brand-logo {
    /* The logo is a landscape wordmark, so the chip is landscape too — squeezing
       it into a square makes "RURAL HEALTH CONSORTIUM" unreadable. */
    height: 44px; flex: 0 0 auto;
    border-radius: var(--r-md);
    background: #fff;
    display: grid; place-items: center;
    padding: 4px 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
    overflow: hidden;
}
.brand-logo img { height: 100%; width: auto; max-width: 104px; object-fit: contain; }
.brand-logo.is-onlight { box-shadow: none; border: 1px solid var(--border); }

/* The sidebar is only 264px wide, so the mark is held back there to leave the
   brand name and tagline a full line each. */
.sidebar .brand-logo { height: 38px; }
.sidebar .brand-logo img { max-width: 74px; }
.brand-text { min-width: 0; }

/* Login: the mark stacks above the wordmark and the whole header block is
   centred over the form. The chip is sized to the logo's own aspect ratio
   rather than to a fixed height, so nothing is ever cropped. */
.auth-brand {
    display: flex; flex-direction: column; align-items: center;
    gap: var(--sp-3); text-align: center;
}
.auth-brand .brand-logo {
    height: auto; width: auto;
    padding: 10px 14px;
}
.auth-brand .brand-logo img {
    width: 150px; height: auto; max-width: 100%;
}
.auth-brand .brand-text strong { color: var(--ink); font-size: 16px; }
.auth-brand .brand-text span { color: var(--ink-muted); opacity: 1; font-size: 12px; }

/* =====================================================================
   Opening loader
   ===================================================================== */
:root {
    --ease-inout-quad: cubic-bezier(.455, .03, .515, .955);
    --ease-in-quad:    cubic-bezier(.55, .085, .68, .53);
    --ease-out-quad:   cubic-bezier(.25, .46, .45, .94);
    --loaderPill-duration: 1800ms;
}

.loaderScreen {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--surface);
    transition: opacity .4s ease, visibility .4s ease;
}
.loaderScreen.is-done { opacity: 0; visibility: hidden; pointer-events: none; }

.absCenter { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }

.loaderPill { text-align: center; }
.loaderPill-anim { height: 160px; }
.loaderPill-anim-bounce { animation: loaderPillBounce var(--loaderPill-duration) linear infinite; }
.loaderPill-anim-flop {
    transform-origin: 50% 50%;
    animation: loaderPillFlop var(--loaderPill-duration) linear infinite;
}
.loaderPill-pill {
    display: inline-block;
    box-sizing: border-box;
    width: 80px; height: 30px;
    border-radius: 15px;
    border: 1px solid var(--accent);
    background-image: linear-gradient(to right, var(--accent) 50%, var(--alert-red) 50%);
}
.loaderPill-floor { display: block; text-align: center; }
.loaderPill-floor-shadow {
    display: inline-block;
    width: 70px; height: 7px;
    border-radius: 50%;
    background-color: color-mix(in srgb, var(--accent) 26%, transparent);
    transform: translateY(-15px);
    animation: loaderPillScale var(--loaderPill-duration) linear infinite;
}
.loaderPill-text {
    margin-top: var(--sp-3);
    font-weight: 700; font-size: 12px;
    letter-spacing: .14em; text-transform: uppercase;
    color: var(--accent);
}

@keyframes loaderPillBounce {
    0%   { transform: translateY(123px); animation-timing-function: var(--ease-out-quad); }
    25%  { transform: translateY(40px);  animation-timing-function: var(--ease-in-quad); }
    50%  { transform: translateY(120px); animation-timing-function: var(--ease-out-quad); }
    75%  { transform: translateY(20px);  animation-timing-function: var(--ease-in-quad); }
    100% { transform: translateY(120px); }
}
@keyframes loaderPillFlop {
    0%   { transform: rotate(0); }
    25%  { transform: rotate(90deg); }
    50%  { transform: rotate(180deg); }
    75%  { transform: rotate(450deg); }
    100% { transform: rotate(720deg); }
}
@keyframes loaderPillScale {
    0%   { transform: translateY(-15px) scale(1, 1);   animation-timing-function: var(--ease-out-quad); }
    25%  { transform: translateY(-15px) scale(.7, 1);  animation-timing-function: var(--ease-in-quad); }
    50%  { transform: translateY(-15px) scale(1, 1);   animation-timing-function: var(--ease-out-quad); }
    75%  { transform: translateY(-15px) scale(.6, 1);  animation-timing-function: var(--ease-in-quad); }
    100% { transform: translateY(-15px) scale(1, 1); }
}

/* Respect users who have asked for reduced motion — the splash still shows,
   it simply stops bouncing. */
@media (prefers-reduced-motion: reduce) {
    .loaderPill-anim-bounce,
    .loaderPill-anim-flop,
    .loaderPill-floor-shadow { animation: none; }
    .loaderPill-anim-bounce { transform: translateY(120px); }
}

@media print { .loaderScreen { display: none !important; } }

/* =====================================================================
   Drifting medical-icon backdrop
   ---------------------------------------------------------------------
   Decorative only. The whole layer is held at a low opacity and sits at
   z-index 0 so headings, labels and inputs above it stay at full contrast.
   ===================================================================== */
.medBg {
    position: absolute; inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
    color: var(--accent);
    opacity: .5;                /* the legibility guard — raise/lower here */
}
.medBg-icon {
    position: absolute;
    display: block;
    will-change: transform;
    animation: medBgDrift var(--mb-dur, 26s) ease-in-out var(--mb-delay, 0s) infinite alternate;
}
.medBg-icon svg { width: 100%; height: 100%; }

/* Every fourth icon picks up the brand red so the backdrop reads as
   navy-and-red rather than a single flat tint. */
.medBg-icon:nth-child(4n) { color: var(--alert-red); opacity: .55; }

@keyframes medBgDrift {
    0%   { transform: translate(0, 0) rotate(0); }
    50%  { transform: translate(var(--mb-dx, 30px), var(--mb-dy, -20px)) rotate(var(--mb-spin, 12deg)); }
    100% { transform: translate(var(--mb-dx2, -25px), var(--mb-dy2, 25px)) rotate(calc(var(--mb-spin, 12deg) * -1)); }
}

@media (prefers-reduced-motion: reduce) {
    .medBg-icon { animation: none; }
}

/* The loader splash and the login form column both host the backdrop, so
   their own content has to sit above it. */
.loaderScreen .absCenter,
.auth-form-side .auth-card { position: relative; z-index: 1; }
.auth-form-side { position: relative; }

/* On the login form side the pattern is quieter still — it shares the column
   with body copy and form fields. */
/* The pattern runs at full strength across both columns; a soft radial veil
   sits between it and the content so the icons stay bold at the edges and fade
   out under the form fields and the loader label, where text has to be read. */
.auth-form-side::before,
.loaderScreen::before {
    content: "";
    position: absolute; inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(
        ellipse 460px 540px at 50% 50%,
        var(--surface) 0%,
        color-mix(in srgb, var(--surface) 90%, transparent) 42%,
        transparent 76%);
}
.loaderScreen::before {
    background: radial-gradient(
        ellipse 320px 300px at 50% 50%,
        var(--surface) 0%,
        color-mix(in srgb, var(--surface) 85%, transparent) 46%,
        transparent 74%);
}

@media print { .medBg { display: none !important; } }

/* =====================================================================
   Password field — reveal toggle
   ===================================================================== */
.input-affix { position: relative; display: block; }
.input-affix .input { padding-right: 42px; }
.input-affix .affix-btn {
    position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
    width: 30px; height: 30px;
    display: grid; place-items: center;
    border: 0; background: transparent; cursor: pointer;
    color: var(--ink-muted);
    border-radius: var(--r-sm);
    transition: color .15s ease, background .15s ease;
}
.input-affix .affix-btn:hover { color: var(--accent); background: var(--accent-soft); }
.input-affix .affix-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input-affix .affix-btn svg { width: 17px; height: 17px; }
