/* =========================================================
   DiagCore Diagnostic Suite — Design System
   Palette:  #14607A clinical teal-blue · #0F4459 dark · #2E8B74 teal (normal/healthy)
             #C97A28 amber (low/pending) · #C0392B red (critical/high)
             #1B222B ink · #F4F7F9 canvas · #FFFFFF panel
   Type:     Sora (display/SaaS headings) · Inter (UI/body) · Roboto Mono (data/values)
   Signature: the reference-range indicator on lab results
   ========================================================= */

:root {
    --primary: #14607A;
    --primary-dark: #0F4459;
    --primary-soft: #DCEAF0;
    --teal: #2E8B74;
    --teal-soft: #DFF0EA;
    --ink: #1B222B;
    --ink-soft: #647082;
    --canvas: #F4F7F9;
    --panel: #FFFFFF;
    --border: #E1E8EC;
    --healthy: #2E8B74;
    --healthy-soft: #DFF0EA;
    --low: #C97A28;
    --low-soft: #FBEBD8;
    --critical: #C0392B;
    --critical-soft: #F8DEDA;
    --neutral-soft: #E7ECEF;
    --neutral: #647082;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --shadow-card: 0 1px 2px rgba(27,34,43,0.04), 0 8px 24px -12px rgba(20,96,122,0.18);
    --font-display: 'Sora', -apple-system, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Roboto Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }

body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--canvas);
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
    display: grid; place-items: center;
    width: 34px; height: 34px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
}
.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 16px;
    line-height: 1.1;
    display: flex; flex-direction: column;
}
.brand-name em { font-style: normal; font-size: 11px; font-weight: 500; color: var(--ink-soft); letter-spacing: .03em; text-transform: uppercase; font-family: var(--font-body); }
.brand-lg .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
.brand-lg .brand-name { font-size: 20px; }

/* =========================================================
   APP SHELL
   ========================================================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--primary-dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 24px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand-name { color: #fff; }
.sidebar .brand-mark { background: var(--teal); }

.nav { margin-top: 36px; display: flex; flex-direction: column; gap: 2px; }
.nav-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    color: rgba(255,255,255,0.4);
    margin: 18px 10px 8px;
}
.nav-label:first-child { margin-top: 0; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.78);
    font-size: 14px;
    font-weight: 500;
    transition: background .15s ease, color .15s ease;
}
.nav-link svg { flex-shrink: 0; opacity: .85; }
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: var(--teal); color: #fff; }

.sidebar-foot { margin-top: auto; }
.center-card {
    background: rgba(46,139,116,0.2);
    border: 1px solid rgba(46,139,116,0.4);
    border-radius: var(--radius-md);
    padding: 14px;
}
.center-card strong { display: block; font-size: 12px; color: rgba(255,255,255,0.6); font-weight: 500; margin-bottom: 4px; }
.center-card p { margin: 0; font-family: var(--font-display); font-size: 14px; color: #fff; font-weight: 600; }

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

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 32px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar-title h1 { font-family: var(--font-display); font-size: 22px; font-weight: 700; margin: 0; }
.topbar-center { font-size: 12.5px; color: var(--ink-soft); }
.topbar-user { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary-dark);
    display: grid; place-items: center;
    font-weight: 700; font-family: var(--font-display);
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 13px; }
.user-meta small { color: var(--ink-soft); font-size: 11px; }

.content { padding: 28px 32px 60px; display: flex; flex-direction: column; gap: 24px; }

/* =========================================================
   ALERTS
   ========================================================= */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; }
.alert-success { background: var(--healthy-soft); color: var(--healthy); border: 1px solid #c6e0d8; }
.alert-error { background: var(--critical-soft); color: var(--critical); border: 1px solid #edc3bb; }

/* =========================================================
   KPI ROW
   ========================================================= */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.kpi-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    box-shadow: var(--shadow-card);
    display: flex; flex-direction: column; gap: 6px;
}
.kpi-label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-family: var(--font-display); font-size: 32px; font-weight: 700; }
.kpi-foot { font-size: 12.5px; color: var(--ink-soft); }
.kpi-card-alert { background: var(--primary); border-color: var(--primary); }
.kpi-card-alert .kpi-label, .kpi-card-alert .kpi-foot { color: rgba(255,255,255,0.75); }
.kpi-card-alert .kpi-value { color: #fff; }

/* =========================================================
   PANELS / TABLES
   ========================================================= */
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px 8px;
    box-shadow: var(--shadow-card);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.panel-head h2 { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 10px; }
.panel-head-row { align-items: center; }
.link-cta { font-size: 13px; font-weight: 600; color: var(--primary); }
.count-pill {
    background: var(--primary-soft); color: var(--primary-dark);
    font-family: var(--font-mono); font-size: 12px; font-weight: 700;
    padding: 2px 9px; border-radius: 999px;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--ink-soft); font-weight: 600;
    padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.empty-row { text-align: center; color: var(--ink-soft); padding: 24px; }

.chip {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 3px 10px; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary-dark);
    font-size: 12.5px; font-weight: 600;
}
.chip-mono { font-family: var(--font-mono); }
.chip-lg { font-size: 15px; padding: 5px 14px; }

.badge { display: inline-flex; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--neutral-soft); color: var(--neutral); }
.badge-healthy { background: var(--healthy-soft); color: var(--healthy); }
.badge-critical { background: var(--critical-soft); color: var(--critical); }
.badge-low { background: var(--low-soft); color: var(--low); }

/* Order / invoice status badges */
.badge-status-scheduled { background: #E3EAF6; color: #2E5596; }
.badge-status-samplecollected { background: #EAE3F5; color: #6A4EA0; }
.badge-status-inprogress { background: var(--low-soft); color: var(--low); }
.badge-status-reportready { background: #E0ECFB; color: #2E6DA4; }
.badge-status-completed { background: var(--healthy-soft); color: var(--healthy); }
.badge-status-cancelled { background: var(--critical-soft); color: var(--critical); }
.badge-status-unpaid { background: var(--critical-soft); color: var(--critical); }
.badge-status-partiallypaid { background: var(--low-soft); color: var(--low); }
.badge-status-paid { background: var(--healthy-soft); color: var(--healthy); }

/* Result flag badges */
.badge-flag-low { background: var(--low-soft); color: var(--low); }
.badge-flag-high { background: var(--low-soft); color: var(--low); }
.badge-flag-critical { background: var(--critical-soft); color: var(--critical); }
.badge-flag-normal { background: var(--healthy-soft); color: var(--healthy); }

.row-actions { text-align: right; white-space: nowrap; }
.icon-btn {
    background: transparent; border: 1px solid var(--border); border-radius: 8px;
    width: 28px; height: 28px; color: var(--ink-soft);
    display: inline-grid; place-items: center; font-size: 14px;
    transition: all .15s ease;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }

/* =========================================================
   SIGNATURE ELEMENT — REFERENCE RANGE INDICATOR
   (shows where a patient's lab value falls vs normal range)
   ========================================================= */
.result-list { display: flex; flex-direction: column; gap: 4px; }
.result-row {
    display: grid; grid-template-columns: 1.4fr 1fr 1.6fr 0.8fr;
    gap: 16px; align-items: center;
    padding: 12px 4px; border-bottom: 1px solid var(--border);
}
.result-row:last-child { border-bottom: none; }
.result-row-name strong { font-size: 14px; }
.result-row-input { display: flex; align-items: center; gap: 8px; }
.range-bar { position: relative; height: 8px; border-radius: 999px; background: var(--neutral-soft); }
.range-band { position: absolute; top: 0; bottom: 0; background: var(--healthy-soft); border-radius: 999px; }
.range-marker {
    position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%;
    background: var(--primary); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--primary);
    transform: translate(-50%, -50%);
}
.range-marker-low, .range-marker-high { background: var(--low); box-shadow: 0 0 0 1px var(--low); }
.range-marker-critical { background: var(--critical); box-shadow: 0 0 0 1px var(--critical); }
.range-marker-normal { background: var(--healthy); box-shadow: 0 0 0 1px var(--healthy); }

/* Pipeline / order journey (dashboard) */
.pipeline-list { display: flex; flex-direction: column; gap: 18px; padding-bottom: 8px; }
.pipeline-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 18px; background: var(--canvas); }
.pipeline-meta { display: flex; flex-direction: column; margin-bottom: 14px; }
.pipeline-meta strong { font-family: var(--font-display); font-size: 15px; }
.journey-sub { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.stage-tracker { display: flex; align-items: flex-start; }
.stage-step { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 0 0 auto; width: 92px; }
.stage-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--panel); border: 2px solid var(--border); }
.stage-step.is-done .stage-dot { background: var(--teal); border-color: var(--teal); }
.stage-step.is-current .stage-dot { background: var(--primary); border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.stage-label { font-size: 11px; text-align: center; color: var(--ink-soft); line-height: 1.25; }
.stage-step.is-current .stage-label { color: var(--ink); font-weight: 600; }
.stage-step.is-done .stage-label { color: var(--teal); }
.stage-connector { flex: 1 1 auto; height: 2px; background: var(--border); margin-top: 6px; }
.stage-connector.is-done { background: var(--teal); }

/* Patient / order detail */
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; font-size: 13.5px; }
.detail-grid > div { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 600; }

/* Checkbox grid (order booking — select tests) */
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.checkbox-item {
    display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--ink);
    border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--canvas);
}
.checkbox-item input { accent-color: var(--primary); }
.checkbox-price { margin-left: auto; font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); }
.form-hint { font-size: 12px; color: var(--ink-soft); margin: -6px 0 4px; }

/* =========================================================
   FORMS / BUTTONS
   ========================================================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; padding: 10px 18px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600; border: 1px solid transparent;
    transition: all .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
    font: inherit; font-family: var(--font-body); font-size: 14px; font-weight: 500; color: var(--ink);
    padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--canvas); resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); background: #fff; }
.field-wide { grid-column: span 2; }
.field textarea[name="parameters"] { font-family: var(--font-mono); font-size: 12.5px; }

.filter-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
    padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    font-size: 13.5px; background: var(--canvas); font-family: inherit;
}
.filter-bar input { flex: 1; min-width: 200px; }

.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mini-input { width: 90px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); font-family: var(--font-mono); }
.mini-select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; font-family: inherit; }

/* =========================================================
   MODAL
   ========================================================= */
.modal-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 100;
    background: rgba(27,34,43,0.5);
    align-items: center; justify-content: center;
    padding: 20px;
}
.modal-backdrop.is-open { display: flex; }
.modal {
    background: #fff; border-radius: var(--radius-lg);
    width: 100%; max-width: 620px;
    max-height: 88vh; overflow-y: auto;
    padding: 24px 26px 22px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-family: var(--font-display); font-size: 18px; margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* =========================================================
   AUTH / LOGIN PAGE
   ========================================================= */
.auth-body { background: var(--primary-dark); }
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-panel {
    background: var(--canvas);
    display: flex; flex-direction: column; justify-content: center;
    padding: 60px 80px;
}
.auth-title { font-family: var(--font-display); font-size: 32px; font-weight: 700; margin: 26px 0 6px; }
.auth-sub { color: var(--ink-soft); margin: 0 0 22px; font-size: 14.5px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; }
.auth-hint { margin-top: 14px; font-size: 12.5px; color: var(--ink-soft); }
.auth-hint code { background: var(--primary-soft); color: var(--primary-dark); padding: 1px 6px; border-radius: 4px; font-family: var(--font-mono); }

.auth-side {
    position: relative;
    background: radial-gradient(120% 140% at 15% 10%, #1C7B9C 0%, var(--primary) 45%, var(--primary-dark) 100%);
    display: flex; flex-direction: column; justify-content: flex-end;
    padding: 60px;
    overflow: hidden;
}
.auth-side-copy { position: relative; z-index: 2; color: #fff; max-width: 420px; }
.auth-side .eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: 12px; opacity: .75; margin-bottom: 10px; }
.auth-side h2 { font-family: var(--font-display); font-size: 28px; line-height: 1.3; font-weight: 600; margin: 0; }
.wave-field { position: absolute; inset: 0; opacity: 0.5; }
.pulse-line { width: 100%; height: 100%; }

/* =========================================================
   INVOICE / REPORT DOCUMENTS
   ========================================================= */
.invoice-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.invoice-actions-note { font-size: 12.5px; color: var(--ink-soft); margin: 0 0 8px; }

.invoice-sheet {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 44px;
    box-shadow: var(--shadow-card);
}
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--ink); padding-bottom: 20px; margin-bottom: 24px; }
.report-brand { display: flex; align-items: flex-start; gap: 14px; }
.report-logo { width: 52px; height: 52px; object-fit: contain; border-radius: 8px; }
.invoice-hospital-name { font-family: var(--font-display); font-size: 22px; margin: 0 0 6px; font-weight: 700; }
.invoice-hospital-meta { font-size: 13px; color: var(--ink-soft); line-height: 1.6; margin: 0; }
.invoice-id-block { text-align: right; display: flex; flex-direction: column; gap: 2px; }
.invoice-number { font-family: var(--font-mono); font-size: 19px; font-weight: 700; color: var(--primary-dark); }
.invoice-date { font-size: 13px; color: var(--ink-soft); }
.invoice-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); font-weight: 600; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 28px; font-size: 13.5px; line-height: 1.6; }
.invoice-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 22px; }
.invoice-table th { text-align: left; padding: 10px 4px; border-bottom: 2px solid var(--ink); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.invoice-table td { padding: 10px 4px; border-bottom: 1px solid var(--border); }
.invoice-table th:last-child, .invoice-table td:last-child { text-align: right; }
.invoice-table tfoot td { border-bottom: none; font-weight: 600; padding-top: 6px; }
.invoice-balance-row td { font-size: 16px; font-family: var(--font-display); border-top: 2px solid var(--ink); padding-top: 12px; color: var(--primary-dark); }
.invoice-table-compact { font-size: 12.5px; }
.invoice-payments { margin-bottom: 20px; }
.invoice-footer-note { text-align: center; color: var(--ink-soft); font-size: 13px; font-style: italic; margin-top: 20px; }
.report-title-heading { font-family: var(--font-display); font-size: 17px; font-weight: 700; margin: 24px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.report-result-table th:not(:first-child), .report-result-table td:not(:first-child) { text-align: left; }
.invoice-signature-row { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); }
.invoice-signature-line { width: 220px; text-align: right; border-top: 1px solid var(--ink); padding-top: 4px; }

@media print {
    .sidebar, .topbar, .invoice-actions, .invoice-actions-note, .alert, .btn { display: none !important; }
    .app-shell, .app-main, .content { display: block !important; padding: 0 !important; margin: 0 !important; }
    body { background: #fff !important; }
    .invoice-sheet, .panel { box-shadow: none !important; border: none !important; }
    .two-col { display: block !important; }
    .two-col .panel { margin-bottom: 20px; page-break-inside: avoid; }
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1180px) {
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .two-col { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-side { display: none; }
    .auth-panel { padding: 40px 28px; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; left: -280px; z-index: 40; transition: left .2s ease; }
    .sidebar.is-open { left: 0; }
    .app-main { width: 100%; }
    .content { padding: 20px; }
    .topbar { padding: 16px 20px; }
    .form-grid, .checkbox-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: span 1; }
    .result-row { grid-template-columns: 1fr; gap: 8px; }
    .detail-grid { grid-template-columns: 1fr; }
}
