/* =====================================================================
   UltraReport — Web Edition
   Aesthetic: Clinical Editorial
   Palette : deep teal + warm gold on cream
   Display : Fraunces (serif), Manrope (body), JetBrains Mono (labels)
===================================================================== */

:root {
    --ink:         #0f1f24;
    --ink-soft:    #3a4b52;
    --ink-muted:   rgba(15, 31, 36, 0.55);
    --cream:       #faf8f3;
    --cream-deep:  #f2ede0;
    --surface:     #ffffff;
    --surface-2:   #f7f4eb;
    --teal:        #0f4c5c;
    --teal-deep:   #0a3240;
    --teal-soft:   rgba(15, 76, 92, 0.08);
    --gold:        #c89d4f;
    --gold-deep:   #a87d30;
    --gold-soft:   rgba(200, 157, 79, 0.12);
    --sage:        #6a8e73;
    --red:         #a73b3b;
    --red-soft:    rgba(167, 59, 59, 0.1);
    --border:      rgba(15, 31, 36, 0.08);
    --border-soft: rgba(15, 31, 36, 0.04);
    --shadow-sm:   0 1px 2px rgba(15, 31, 36, 0.04);
    --shadow-md:   0 10px 30px -15px rgba(15, 31, 36, 0.15);
    --shadow-lg:   0 30px 80px -40px rgba(15, 31, 36, 0.25);
    --radius-sm:   8px;
    --radius:      14px;
    --radius-lg:   22px;

    --font-display: 'Fraunces', 'Cormorant Garamond', Georgia, serif;
    --font-body:    'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono:    'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--cream);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-image:
        radial-gradient(circle at 12% 8%, rgba(200, 157, 79, 0.06), transparent 45%),
        radial-gradient(circle at 88% 92%, rgba(15, 76, 92, 0.05), transparent 45%);
}

button { font-family: inherit; cursor: pointer; border: 0; background: 0; color: inherit; }
a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--gold-deep); }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }

/* =====================================================================
   Typography
===================================================================== */

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--ink);
}
h1 { font-size: 2.4rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.05rem; font-weight: 600; }
em { font-style: italic; color: var(--teal); }

.eyebrow {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--gold-deep);
    font-weight: 500;
}
.muted { color: var(--ink-muted); }

/* =====================================================================
   App Shell
===================================================================== */

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--teal-deep);
    color: #e8ecee;
    padding: 2rem 1.25rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background-image:
        radial-gradient(circle at 90% 8%, rgba(200, 157, 79, 0.12), transparent 35%),
        radial-gradient(circle at 10% 92%, rgba(200, 157, 79, 0.06), transparent 40%);
    border-right: 1px solid rgba(255, 255, 255, 0.04);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.5rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 1.5rem;
}

.brand-mark {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--gold), var(--gold-deep));
    display: grid; place-items: center;
    color: var(--teal-deep);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.3rem;
    box-shadow: 0 4px 20px -6px rgba(200, 157, 79, 0.5);
}
.brand-text { display: flex; flex-direction: column; }
.brand-name {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 500;
    color: #fff;
    letter-spacing: -0.01em;
}
.brand-sub {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: rgba(200, 157, 79, 0.8);
}

.nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-label {
    font-family: var(--font-mono);
    font-size: 0.64rem;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    padding: 1rem 0.75rem 0.5rem;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem 0.85rem;
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.72);
    font-weight: 500;
    font-size: 0.93rem;
    transition: background 0.15s, color 0.15s, transform 0.15s;
    position: relative;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }
.nav-item.active {
    background: rgba(200, 157, 79, 0.14);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(200, 157, 79, 0.25);
}
.nav-item.active::before {
    content: ''; position: absolute; left: -1.25rem; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 20px;
    background: var(--gold);
    border-radius: 0 2px 2px 0;
}
.nav-item .icon {
    width: 18px; height: 18px; flex-shrink: 0;
    stroke: currentColor; fill: none; stroke-width: 1.6;
}

.sidebar-foot {
    margin-top: auto;
    padding: 1rem 0.75rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex; align-items: center; gap: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
}
.sidebar-foot .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--gold), var(--gold-deep));
    color: var(--teal-deep);
    display: grid; place-items: center;
    font-family: var(--font-display); font-weight: 600;
}
.sidebar-foot .user-name { color: #fff; font-weight: 600; font-size: 0.9rem; }
.sidebar-foot .user-role {
    font-family: var(--font-mono); font-size: 0.65rem;
    letter-spacing: 0.18em; text-transform: uppercase;
    color: rgba(200, 157, 79, 0.85);
}
.logout-btn {
    margin-left: auto;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.78rem;
    transition: color 0.15s, background 0.15s;
}
.logout-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }

/* -- Main content area -- */
.main {
    padding: 2.5rem 3rem;
    max-width: 1400px;
    width: 100%;
}

.page-header {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 2rem; margin-bottom: 2.5rem; flex-wrap: wrap;
}
.page-header .title-block { max-width: 640px; }
.page-header h1 { font-size: 2.6rem; margin-top: 0.3rem; }
.page-header p.lead { color: var(--ink-muted); margin-top: 0.5rem; max-width: 56ch; }

/* =====================================================================
   Cards & Surfaces
===================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-pad { padding: 1.75rem; }

.card-head {
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem;
}
.card-head h3 { font-size: 1.15rem; }

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(200, 157, 79, 0.3);
}
.stat::after {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(circle at 90% -20%, var(--gold-soft), transparent 50%);
    pointer-events: none;
}
.stat-label {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 0.75rem;
}
.stat-value {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 2.8rem;
    letter-spacing: -0.02em;
    line-height: 1;
    color: var(--ink);
}
.stat-meta {
    display: flex; align-items: center; gap: 0.5rem;
    margin-top: 0.8rem;
    font-size: 0.82rem;
    color: var(--ink-muted);
}
.stat .corner-mark {
    position: absolute; top: 1rem; right: 1.25rem;
    width: 26px; height: 26px;
    color: var(--gold);
    opacity: 0.55;
}

/* =====================================================================
   Buttons
===================================================================== */

.btn {
    display: inline-flex; align-items: center; gap: 0.55rem;
    padding: 0.72rem 1.35rem;
    border-radius: 999px;
    font-weight: 600; font-size: 0.88rem;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--teal);
    color: #fff;
    box-shadow: 0 6px 20px -8px rgba(15, 76, 92, 0.6);
}
.btn-primary:hover { background: var(--teal-deep); box-shadow: 0 10px 28px -10px rgba(15, 76, 92, 0.7); color: #fff; }

.btn-gold {
    background: linear-gradient(135deg, var(--gold), var(--gold-deep));
    color: #fff;
    box-shadow: 0 6px 20px -8px rgba(200, 157, 79, 0.6);
}
.btn-gold:hover { color: #fff; box-shadow: 0 10px 28px -10px rgba(200, 157, 79, 0.8); }

.btn-ghost {
    background: transparent;
    color: var(--teal);
    border: 1px solid rgba(15, 76, 92, 0.22);
}
.btn-ghost:hover { background: var(--teal-soft); color: var(--teal-deep); }

.btn-subtle {
    background: var(--surface-2);
    color: var(--ink);
    border: 1px solid var(--border);
}
.btn-subtle:hover { background: var(--cream-deep); }

.btn-danger {
    background: transparent;
    color: var(--red);
    border: 1px solid rgba(167, 59, 59, 0.25);
}
.btn-danger:hover { background: var(--red-soft); }

.btn-sm { padding: 0.5rem 1rem; font-size: 0.8rem; }
.btn-icon {
    padding: 0.55rem; width: 36px; height: 36px; justify-content: center;
    border-radius: 10px;
}
.btn .icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* =====================================================================
   Forms
===================================================================== */

.form-group { margin-bottom: 1.25rem; }
.form-grid { display: grid; gap: 1.25rem; }
.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 900px) {
    .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
}

.label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 0.5rem;
    font-weight: 500;
}
.label .req { color: var(--red); }

.input, .textarea, .select {
    width: 100%;
    padding: 0.75rem 0.95rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    color: var(--ink);
    font-size: 0.95rem;
    font-family: var(--font-body);
}
.input:focus, .textarea:focus, .select:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 76, 92, 0.08);
    background: #fff;
}
.textarea { resize: vertical; min-height: 120px; line-height: 1.55; font-family: var(--font-body); }
.textarea.tall { min-height: 180px; }

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%230f1f24' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

.form-hint { font-size: 0.78rem; color: var(--ink-muted); margin-top: 0.35rem; }
.form-error { font-size: 0.82rem; color: var(--red); margin-top: 0.4rem; }

/* =====================================================================
   Tables
===================================================================== */

.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.table thead th {
    text-align: left;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-muted);
    font-weight: 500;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.table tbody td {
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }

.table .mono { font-family: var(--font-mono); font-size: 0.86rem; color: var(--teal); }
.table .patient-name { font-weight: 600; }
.table .patient-sub { font-size: 0.8rem; color: var(--ink-muted); margin-top: 0.15rem; }

/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-weight: 500;
}
.badge-draft { background: var(--gold-soft); color: var(--gold-deep); }
.badge-final { background: rgba(106, 142, 115, 0.15); color: var(--sage); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* =====================================================================
   Dashboard specifics
===================================================================== */

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}
@media (max-width: 1100px) { .dashboard-grid { grid-template-columns: 1fr; } }

.chart-card {
    padding: 1.5rem 1.75rem;
    min-height: 280px;
    position: relative;
}
.sparkline { width: 100%; height: 120px; margin-top: 1rem; }
.sparkline path.fill { fill: url(#sparkFill); }
.sparkline path.line { fill: none; stroke: var(--teal); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.distribution-list { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1rem; }
.dist-row { display: flex; flex-direction: column; gap: 0.3rem; }
.dist-row-top { display: flex; justify-content: space-between; font-size: 0.88rem; }
.dist-row-name { font-weight: 500; }
.dist-row-count { font-family: var(--font-mono); color: var(--teal); }
.dist-bar { height: 6px; background: var(--cream-deep); border-radius: 999px; overflow: hidden; }
.dist-bar-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--gold)); border-radius: 999px; transition: width 0.6s ease-out; }

/* =====================================================================
   New Report form — 2-column layout
===================================================================== */

.report-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1.75rem;
    align-items: flex-start;
}
@media (max-width: 1200px) { .report-layout { grid-template-columns: 1fr; } }

.section-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.section-head h3 { font-family: var(--font-display); font-weight: 500; font-size: 1.2rem; }
.section-hr {
    height: 1px;
    background: linear-gradient(90deg, var(--border), transparent);
    margin: 1.5rem 0;
}

/* Image gallery */
.img-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}
.img-tile {
    position: relative;
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    background: var(--cream-deep);
    border: 1px solid var(--border);
}
.img-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-tile .rm {
    position: absolute; top: 0.35rem; right: 0.35rem;
    width: 24px; height: 24px; border-radius: 50%;
    background: rgba(15, 31, 36, 0.72); color: #fff;
    display: grid; place-items: center;
    font-size: 0.75rem;
    opacity: 0; transition: opacity 0.15s;
}
.img-tile:hover .rm { opacity: 1; }
.img-tile .cap {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: linear-gradient(transparent, rgba(15, 31, 36, 0.8));
    color: #fff; padding: 0.5rem 0.6rem 0.5rem;
    font-size: 0.72rem; line-height: 1.3;
}
.img-drop {
    aspect-ratio: 1;
    border: 1.5px dashed rgba(15, 76, 92, 0.3);
    border-radius: 10px;
    display: grid; place-items: center;
    cursor: pointer;
    text-align: center;
    padding: 1rem;
    font-size: 0.82rem;
    color: var(--ink-muted);
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.img-drop:hover { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }
.img-drop .icon { width: 28px; height: 28px; margin-bottom: 0.3rem; stroke: currentColor; stroke-width: 1.5; fill: none; }

/* =====================================================================
   Login page
===================================================================== */

.login-wrap {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) { .login-wrap { grid-template-columns: 1fr; } }

.login-aside {
    background: var(--teal-deep);
    color: #fff;
    padding: 3.5rem;
    position: relative;
    overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between;
    background-image:
        radial-gradient(circle at 80% 15%, rgba(200, 157, 79, 0.18), transparent 40%),
        radial-gradient(circle at 10% 85%, rgba(200, 157, 79, 0.08), transparent 40%);
}
@media (max-width: 900px) { .login-aside { display: none; } }

.login-aside .brand { border: 0; padding: 0; margin: 0; }
.login-pitch h2 {
    font-size: 3.4rem;
    font-weight: 500;
    color: #fff;
    max-width: 14ch;
    line-height: 1.05;
    margin-bottom: 1.25rem;
}
.login-pitch h2 em { color: var(--gold); }
.login-pitch p {
    color: rgba(255, 255, 255, 0.7);
    max-width: 38ch;
    line-height: 1.6;
}
.login-aside .decorative {
    position: absolute;
    bottom: -60px; right: -80px;
    width: 400px; height: 400px;
    border-radius: 50%;
    border: 1px solid rgba(200, 157, 79, 0.15);
    pointer-events: none;
}
.login-aside .decorative::after {
    content: ''; position: absolute;
    inset: 40px; border-radius: 50%;
    border: 1px solid rgba(200, 157, 79, 0.1);
}

.login-main {
    padding: 4rem 3rem;
    display: flex; align-items: center; justify-content: center;
    background: var(--cream);
    background-image:
        radial-gradient(circle at 70% 30%, rgba(200, 157, 79, 0.08), transparent 40%);
}
.login-card { max-width: 400px; width: 100%; }
.login-card h1 {
    font-size: 2.6rem;
    margin-bottom: 0.35rem;
}
.login-card .lead { color: var(--ink-muted); margin-bottom: 2.5rem; }

.login-card .form-group { margin-bottom: 1.25rem; }
.login-card .btn { width: 100%; justify-content: center; padding: 0.95rem 1rem; }
.login-card .btn-primary { font-size: 0.95rem; }

.login-meta {
    margin-top: 2rem;
    padding: 1.25rem;
    background: rgba(200, 157, 79, 0.08);
    border-radius: 10px;
    border-left: 3px solid var(--gold);
    font-size: 0.85rem;
}
.login-meta strong { font-family: var(--font-display); font-weight: 500; display: block; margin-bottom: 0.4rem; color: var(--gold-deep); }
.login-meta code { font-family: var(--font-mono); font-size: 0.82rem; background: #fff; padding: 0.1rem 0.4rem; border-radius: 4px; }

/* =====================================================================
   Alerts / toast
===================================================================== */

#toast-host {
    position: fixed; top: 1.5rem; right: 1.5rem;
    z-index: 9999;
    display: flex; flex-direction: column; gap: 0.75rem;
    pointer-events: none;
}
.toast {
    min-width: 260px;
    background: var(--ink);
    color: #fff;
    padding: 0.9rem 1.25rem;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    display: flex; align-items: center; gap: 0.75rem;
    animation: slideIn 0.25s ease-out;
    pointer-events: auto;
    font-size: 0.9rem;
}
.toast.ok    { background: var(--sage); }
.toast.error { background: var(--red); }
.toast.info  { background: var(--teal); }
.toast .icon { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; flex-shrink: 0; }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeInUp 0.35s ease-out both; }
.fade-in-2 { animation: fadeInUp 0.35s 0.1s ease-out both; }
.fade-in-3 { animation: fadeInUp 0.35s 0.2s ease-out both; }

/* =====================================================================
   Modal
===================================================================== */

.modal-bg {
    position: fixed; inset: 0;
    background: rgba(15, 31, 36, 0.45);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: grid; place-items: center;
    padding: 2rem;
    animation: fadeIn 0.2s;
}
.modal {
    max-width: 720px; width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.25s ease-out;
}
.modal-head {
    padding: 1.5rem 2rem;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1.3rem; }
.modal-body { padding: 2rem; }
.modal-foot {
    padding: 1.25rem 2rem;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 0.75rem;
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =====================================================================
   Tabs
===================================================================== */

.tabs {
    display: flex; gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}
.tab {
    padding: 0.8rem 1.25rem;
    border-bottom: 2px solid transparent;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ink-muted);
    transition: color 0.15s, border-color 0.15s;
    cursor: pointer;
}
.tab:hover { color: var(--teal); }
.tab.active { color: var(--teal); border-color: var(--teal); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeInUp 0.25s ease-out; }

/* =====================================================================
   Empty state
===================================================================== */

.empty {
    padding: 4rem 2rem;
    text-align: center;
    color: var(--ink-muted);
}
.empty .icon { width: 48px; height: 48px; opacity: 0.35; margin: 0 auto 1rem; stroke: currentColor; fill: none; stroke-width: 1.5; }
.empty h4 { font-family: var(--font-display); font-weight: 500; font-size: 1.2rem; color: var(--ink); margin-bottom: 0.35rem; }

/* =====================================================================
   Spinner
===================================================================== */

.spinner {
    width: 20px; height: 20px;
    border: 2px solid rgba(15, 76, 92, 0.15);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-wrap {
    padding: 4rem; display: grid; place-items: center;
    color: var(--ink-muted);
}

/* =====================================================================
   Printable report page
===================================================================== */

.print-page {
    max-width: 820px;
    margin: 2rem auto;
    background: #fff;
    padding: 3rem 3.5rem;
    box-shadow: var(--shadow-lg);
    color: var(--ink);
    font-family: 'Georgia', serif;
    line-height: 1.6;
}
.print-head {
    border-bottom: 2px solid var(--teal);
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 2rem;
}
.print-hospital h1 { font-family: var(--font-display); font-size: 1.9rem; margin-bottom: 0.3rem; color: var(--teal-deep); }
.print-hospital .addr { font-size: 0.88rem; color: var(--ink-muted); }
.print-reg {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    color: var(--ink-muted);
    text-align: right;
}
.print-reg strong { display: block; font-size: 1rem; color: var(--teal); letter-spacing: 0.1em; margin-top: 0.2rem; }

.print-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    text-align: center;
    margin: 2rem 0 1.5rem;
    color: var(--teal-deep);
    letter-spacing: -0.01em;
}
.print-title-rule {
    display: flex; align-items: center; gap: 1rem;
    margin: 1.5rem 0 2rem;
}
.print-title-rule::before, .print-title-rule::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}

.print-patient {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem 2rem;
    margin-bottom: 2rem;
    padding: 1.25rem 1.5rem;
    background: var(--surface-2);
    border-radius: 8px;
}
.print-patient .row { display: flex; justify-content: space-between; font-size: 0.92rem; }
.print-patient .row .k {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.print-section { margin-bottom: 1.8rem; }
.print-section h4 {
    font-family: var(--font-display);
    font-size: 1.15rem;
    color: var(--teal);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
    margin-bottom: 0.75rem;
    font-weight: 500;
}
.print-section p { white-space: pre-wrap; }

.print-images {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}
.print-images figure { border: 1px solid var(--border); border-radius: 4px; overflow: hidden; background: var(--cream-deep); }
.print-images img { width: 100%; height: 220px; object-fit: contain; background: #fff; display: block; }
.print-images figcaption { padding: 0.5rem 0.75rem; font-size: 0.78rem; color: var(--ink-muted); font-family: var(--font-body); }

.print-sign {
    margin-top: 3.5rem;
    display: flex; justify-content: flex-end;
}
.print-sign .box {
    text-align: center;
    min-width: 240px;
}
.print-sign .line {
    border-top: 1px solid var(--ink);
    padding-top: 0.5rem;
    font-family: var(--font-display);
    font-size: 1.05rem;
    color: var(--teal-deep);
}
.print-sign .title {
    font-size: 0.82rem;
    color: var(--ink-muted);
    font-family: var(--font-body);
    margin-top: 0.25rem;
}

.print-foot {
    margin-top: 3rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--ink-muted);
    text-align: center;
    font-family: var(--font-body);
    letter-spacing: 0.05em;
}

.print-toolbar {
    max-width: 820px;
    margin: 2rem auto 0;
    display: flex; gap: 0.75rem; justify-content: flex-end;
}

@media print {
    body { background: #fff; }
    .sidebar, .page-header, .btn, .print-toolbar, #toast-host { display: none !important; }
    .app-shell { display: block; }
    .main { padding: 0; max-width: none; }
    .print-page { box-shadow: none; margin: 0; padding: 1.5cm; max-width: none; }
}

/* =====================================================================
   Utilities
===================================================================== */

.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.space-y > * + * { margin-top: 1rem; }
.space-y-lg > * + * { margin-top: 1.5rem; }
.grow { flex: 1; }
.text-right { text-align: right; }
.hidden { display: none !important; }

.divider-v {
    width: 1px; align-self: stretch;
    background: var(--border);
    margin: 0 0.5rem;
}

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        height: auto;
        grid-template-columns: 1fr;
        padding: 1.25rem;
    }
    .main { padding: 1.5rem; }
    h1 { font-size: 1.8rem; }
    .page-header h1 { font-size: 2rem; }
}

/* Scrollbar polish (webkit only) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(15, 31, 36, 0.15);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(15, 31, 36, 0.25); background-clip: padding-box; border: 2px solid transparent; }
