/*
 * World Home Care — Operations Console
 * Design system v2 — professional/clinical SaaS aesthetic
 *
 * Signature: an ink-navy sidebar with a single teal accent rail on the active
 * item, a light neutral canvas, flat white cards with hairline borders, and
 * tabular-figure alignment on every financial number. No blur, no gradients,
 * no shimmer — the visual language of software people trust with patient
 * records and money, not a marketing page.
 */

/* ============================= TOKENS ============================= */
:root {
    /* Ink (sidebar) */
    --ink: #0B1626;
    --ink-raised: #101E33;
    --ink-border: #223047;
    --ink-text: #C7D2E3;
    --ink-text-dim: #7C8AA3;
    --ink-text-bright: #FFFFFF;

    /* Neutrals (canvas + surfaces) */
    --canvas: #F3F5F8;
    --surface: #FFFFFF;
    --surface-sunken: #F8F9FB;
    --border: #E3E7ED;
    --border-strong: #CBD2DE;
    --text: #10182D;
    --text-soft: #4B5670;
    --text-faint: #8A93A6;

    /* Brand accent — clinical teal, deliberately not blue/terracotta */
    --accent: #0C7B67;
    --accent-dark: #095F50;
    --accent-soft: #E3F4F0;
    --accent-ring: rgba(12, 123, 103, .28);

    /* Printed-document brand color (invoices, diagnostic reports, P&L) — separately
       customizable from the app accent above, since letterhead branding and app UI
       don't have to match. Overridden per-request from Settings; these are fallbacks. */
    --doc-accent: var(--doc-accent);
    --doc-accent-soft: #fdeeec;
    --doc-accent-tint: #f6cdc8;

    /* Semantic status */
    --success: #157A46;
    --success-soft: #E7F6ED;
    --success-border: #BCE4CB;
    --warning: #A8590A;
    --warning-soft: #FCF0DF;
    --warning-border: #F3D6A6;
    --danger: #B3261E;
    --danger-soft: #FBEAE9;
    --danger-border: #F0C4C1;
    --info: #1F4FA6;
    --info-soft: #EAF0FC;
    --info-border: #C4D5F4;

    /* Layout */
    --sidebar-width: 15.25rem;
    --topbar-height: 58px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .10), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 6px 16px rgba(16, 24, 40, .10);
    --shadow-pop: 0 10px 30px rgba(16, 24, 40, .16);

    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --ease: cubic-bezier(.2, .8, .2, 1);
}

/* ============================= RESET / BASE ============================= */
*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--canvas);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.dashboard-bg { background: var(--canvas); min-height: 100vh; }

h1, h2, h3, h4 { font-family: var(--font-ui); font-weight: 600; letter-spacing: -.01em; margin: 0; }

a { color: var(--accent); }

table { font-variant-numeric: tabular-nums; }

::selection { background: var(--accent-soft); color: var(--accent-dark); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ============================= LOGIN ============================= */
.login-bg {
    background: var(--ink);
    background-image:
        radial-gradient(circle at 15% 20%, rgba(12,123,103,.18) 0%, transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(12,123,103,.10) 0%, transparent 40%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.ultra-glass {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
    padding: 2.25rem 2.25rem 1.75rem;
    width: 100%;
    max-width: 380px;
}

.login-logo-wrap { text-align: center; margin-bottom: 1.25rem; }

.login-logo {
    width: 52px; height: 52px;
    border-radius: var(--radius-md);
    background: var(--ink);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .02em;
}

.login-title {
    text-align: center;
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 0 .2rem;
}

.login-subtitle {
    text-align: center;
    color: var(--text-faint);
    font-size: .85rem;
    margin: 0 0 1.5rem;
}

.login-label {
    display: block;
    color: var(--text-soft);
    font-weight: 600;
    font-size: .8rem;
    margin-bottom: .3rem;
}

.glass-input {
    width: 100%;
    padding: .65rem .8rem;
    margin-bottom: 1rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: .92rem;
    font-family: var(--font-ui);
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}

.glass-input::placeholder { color: var(--text-faint); }

.glass-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.glass-button {
    width: 100%;
    padding: .68rem;
    background: var(--accent);
    border: 1px solid var(--accent-dark);
    border-radius: var(--radius-sm);
    color: #fff;
    font-weight: 600;
    font-size: .92rem;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: background-color .15s var(--ease);
}

.glass-button:hover { background: var(--accent-dark); }
.glass-button:active { background: var(--accent-dark); }

.login-forgot { text-align: center; margin-top: 1rem; }
.login-forgot a { color: var(--text-faint); text-decoration: none; font-size: .82rem; }
.login-forgot a:hover { color: var(--accent); text-decoration: underline; }

.login-error {
    margin-top: 1rem;
    background: var(--danger-soft);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm);
    padding: .65rem .8rem;
    text-align: center;
    color: var(--danger);
    font-weight: 600;
    font-size: .85rem;
}

.login-hint { text-align: center; color: var(--text-faint); font-size: .78rem; margin-top: 1rem; }

/* ============================= SIDEBAR ============================= */
.app-sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--ink);
    border-right: 1px solid var(--ink-border);
    z-index: 50;
    display: flex;
    flex-direction: column;
    transition: transform .25s var(--ease);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 18px;
    border-bottom: 1px solid var(--ink-border);
}

.sidebar-brand-icon {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: .72rem;
    letter-spacing: .02em;
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-weight: 600;
    font-size: .92rem;
    color: var(--ink-text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    flex: 1;
    padding: 10px 10px;
    overflow-y: auto;
}

.sidebar-nav ul { list-style: none; margin: 0; padding: 0; }

.nav-item { margin: 1px 0; border-radius: var(--radius-sm); position: relative; }

.nav-item a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 8px 12px;
    text-decoration: none;
    color: var(--ink-text);
    font-weight: 500;
    font-size: .855rem;
    border-radius: var(--radius-sm);
    border-left: 2px solid transparent;
    transition: background-color .12s var(--ease), color .12s var(--ease);
}

.nav-item:hover a { background: var(--ink-raised); color: var(--ink-text-bright); }

.nav-item.active a {
    background: var(--ink-raised);
    color: var(--ink-text-bright);
    font-weight: 600;
    border-left-color: var(--accent);
}

.nav-icon { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; opacity: .9; }

.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.btn-glass .icon, .btn-sm .icon { vertical-align: -2px; margin-right: 1px; }
.topbar-toggle .icon { vertical-align: -4px; }

.nav-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer { padding: 12px 14px 16px; border-top: 1px solid var(--ink-border); }

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink-text-dim);
    text-decoration: none;
    font-weight: 500;
    font-size: .82rem;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    transition: background-color .12s var(--ease), color .12s var(--ease);
}

.sidebar-footer a:hover { background: rgba(239, 68, 68, .12); color: #FCA5A5; }

/* ============================= TOPBAR ============================= */
.app-topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-soft);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
}

.topbar-toggle:hover { background: var(--surface-sunken); }

.topbar-title { font-weight: 600; font-size: 1rem; color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-right select {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-ui);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 5px;
    background: var(--surface-sunken);
    border-radius: 999px;
    border: 1px solid var(--border);
    font-weight: 600;
    font-size: .82rem;
    color: var(--text-soft);
}

.topbar-user-icon {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ============================= MAIN ============================= */
.app-main {
    margin-left: var(--sidebar-width);
    padding-top: calc(var(--topbar-height) + 20px);
    padding-left: 24px;
    padding-right: 24px;
    padding-bottom: 40px;
    min-height: 100vh;
}

/* ============================= CARDS ============================= */
.glass-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    padding: 20px 22px;
    margin-bottom: 18px;
}

.glass-card h2 {
    font-size: 1.05rem;
    font-weight: 650;
    color: var(--text);
    margin-bottom: 16px;
}

.glass-card h3 {
    font-size: .92rem;
    font-weight: 650;
    color: var(--text);
    margin-bottom: 10px;
}

.glass-card p { color: var(--text-soft); }

/* ============================= STAT CARDS ============================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    padding: 18px 20px;
}

.stat-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.stat-icon {
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--accent-dark);
    background: var(--accent-soft);
    flex-shrink: 0;
}

.stat-icon.purple { color: #6941C6; background: #F1EBFC; }
.stat-icon.pink   { color: #C11574; background: #FCE7F3; }
.stat-icon.blue   { color: #1F4FA6; background: var(--info-soft); }
.stat-icon.green  { color: var(--success); background: var(--success-soft); }

.stat-label {
    font-size: .78rem;
    color: var(--text-faint);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.stat-value {
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

/* ============================= FORMS ============================= */
.glass-card label {
    display: block;
    font-weight: 600;
    color: var(--text-soft);
    margin-bottom: .28rem;
    font-size: .82rem;
}

.glass-card input,
.glass-card select,
.glass-card textarea {
    width: 100%;
    padding: .55rem .7rem;
    margin-bottom: 13px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: .88rem;
    font-family: var(--font-ui);
    transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}

.glass-card input[type="checkbox"],
.glass-card input[type="radio"] {
    width: auto;
    margin-bottom: 0;
    accent-color: var(--accent);
}

.glass-card input::placeholder,
.glass-card textarea::placeholder { color: var(--text-faint); }

.glass-card input:focus,
.glass-card select:focus,
.glass-card textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.glass-card input:disabled,
.glass-card select:disabled,
.glass-card textarea:disabled {
    background: var(--surface-sunken);
    color: var(--text-faint);
    cursor: not-allowed;
}

.glass-card select option { background: var(--surface); color: var(--text); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.form-full { grid-column: 1 / -1; }

/* ============================= BUTTONS ============================= */
.btn-glass {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: .5rem 1.05rem;
    background: var(--accent);
    border: 1px solid var(--accent-dark);
    border-radius: var(--radius-sm);
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    font-family: var(--font-ui);
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    line-height: 1.3;
    transition: background-color .12s var(--ease), border-color .12s var(--ease), opacity .12s var(--ease);
}

.btn-glass:hover { background: var(--accent-dark); }
.btn-glass:active { opacity: .9; }

.btn-glass.full-width { width: 100%; }

.btn-glass.muted {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text-soft);
}
.btn-glass.muted:hover { background: var(--surface-sunken); border-color: var(--text-faint); color: var(--text); }

.btn-glass.danger { background: var(--danger); border-color: #8F1E19; }
.btn-glass.danger:hover { background: #8F1E19; }

.btn-glass.success { background: var(--success); border-color: #0F5E36; }
.btn-glass.success:hover { background: #0F5E36; }

.btn-sm { padding: .32rem .7rem !important; font-size: .76rem !important; }

.btn-danger { background: var(--danger) !important; border-color: #8F1E19 !important; }

.toolbar-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar-row form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar-row input, .toolbar-row select { margin-bottom: 0; width: auto; }
.toolbar-row label { margin-bottom: 0; }

/* ============================= TABLES ============================= */
.glass-card table { width: 100%; border-collapse: collapse; }

.glass-card th, .glass-card td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.glass-card th {
    background: var(--surface-sunken);
    color: var(--text-faint);
    font-weight: 650;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.glass-card td { color: var(--text); font-size: .855rem; }

.glass-card tbody tr:hover td { background: var(--surface-sunken); }

.glass-card tbody tr:last-child td { border-bottom: none; }

/* Numeric-looking cells align cleanly */
.glass-card td code { font-family: var(--font-mono); font-size: .8rem; background: var(--surface-sunken); padding: 1px 6px; border-radius: 4px; }

/* Responsive stacked tables on small screens (data-label populated by app.js) */
@media (max-width: 680px) {
    .glass-card table.responsive-table,
    .glass-card table {
        border: none;
    }
    .glass-card table thead { display: none; }
    .glass-card table tbody tr {
        display: block;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        margin-bottom: 10px;
        padding: 6px 4px;
    }
    .glass-card table tbody tr td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        text-align: right;
        border-bottom: 1px solid var(--border);
        padding: 8px 10px;
    }
    .glass-card table tbody tr td:last-child { border-bottom: none; }
    .glass-card table tbody tr td[data-label]::before {
        content: attr(data-label);
        font-weight: 650;
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--text-faint);
        text-align: left;
        margin-right: auto;
    }
}

/* ============================= BADGES / ALERTS ============================= */
.service-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 650;
    margin-bottom: .6rem;
    border: 1px solid transparent;
}

.badge-active { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge-inactive { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.service-inactive { opacity: .55; }

.alert-success {
    background: var(--success-soft);
    border: 1px solid var(--success-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--success);
    font-weight: 600;
    font-size: .85rem;
    margin-bottom: 14px;
}

.alert-error {
    background: var(--danger-soft);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--danger);
    font-weight: 600;
    font-size: .85rem;
    margin-bottom: 14px;
}

.alert-muted {
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    color: var(--text-faint);
    font-size: .85rem;
    text-align: center;
}

.kpi-positive { color: var(--success) !important; font-weight: 650; }
.kpi-negative { color: var(--danger) !important; font-weight: 650; }

/* ============================= SERVICES GRID ============================= */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
    margin-top: 1rem;
}

.service-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.1rem;
    text-align: center;
    transition: box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.service-card:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }

.service-card-icon { display: flex; align-items: center; justify-content: center; color: var(--accent); margin-bottom: .6rem; }
.service-card-title { font-size: .95rem; font-weight: 650; color: var(--text); margin-bottom: .3rem; }
.service-card-desc { font-size: .8rem; color: var(--text-faint); margin-bottom: .8rem; min-height: 2.2em; }
.service-card-actions { display: flex; gap: .5rem; justify-content: center; }

/* ============================= DYNAMIC ROWS ============================= */
.dynamic-rows { display: flex; flex-direction: column; gap: .5rem; }
.dynamic-row { display: flex; gap: .5rem; align-items: center; }
.dynamic-row select, .dynamic-row input { flex: 1; min-width: 0; margin-bottom: 0; }
.dynamic-row .btn-sm { flex: 0 0 auto; }
.inv-row select { flex: 2; }
.inv-row input { flex: 1; }

/* ============================= FILTER TABS ============================= */
.filter-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-tabs .active-tab { background: var(--accent) !important; color: #fff !important; border-color: var(--accent-dark) !important; }
.filter-form { display: flex; align-items: center; gap: 8px; }
.filter-form label { font-size: .8rem; font-weight: 600; white-space: nowrap; color: var(--text-soft); }

/* ============================= QUICK ACTIONS / CHARTS ============================= */
.quick-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.quick-btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 20px !important; font-size: .85rem; font-weight: 600; }
.quick-icon { font-size: 1.05rem; }

.chart-card { padding: 18px 20px; }
.chart-card h3 { margin: 0 0 12px; font-size: .92rem; color: var(--text); }
.chart-wrap { position: relative; height: 280px; width: 100%; }

/* ============================= ROLE PERMISSION GRID ============================= */
.action-btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.perm-cb { width: 16px; height: 16px; accent-color: var(--accent); }
.h-5 { height: 1.25rem; } .w-5 { width: 1.25rem; }

/* ============================= LEGACY INVOICE BOX (kept, restyled to match) ============================= */
.invoice-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    color: var(--text);
}
.invoice-box h2, .invoice-box h3 { color: var(--text); }
.invoice-box table { width: 100%; border-collapse: collapse; }
.invoice-box th, .invoice-box td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.invoice-box th { background: var(--surface-sunken); color: var(--text); }

/* ============================= SITE FOOTER ============================= */
.site-footer {
    margin-left: var(--sidebar-width);
    padding: 16px 24px;
    text-align: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.site-footer-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.footer-logo { height: 28px; width: auto; margin-bottom: 4px; opacity: .85; }
.site-footer p { margin: 0; font-size: .76rem; color: var(--text-faint); }
.site-footer a { color: var(--accent); text-decoration: none; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }

/* ============================= MOBILE SIDEBAR BACKDROP ============================= */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11, 22, 38, .45);
    z-index: 45;
    opacity: 0;
    transition: opacity .2s var(--ease);
}
.sidebar-backdrop.show { display: block; opacity: 1; }

/* ============================= RESPONSIVE ============================= */
@media (max-width: 1024px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.show { transform: translateX(0); box-shadow: var(--shadow-pop); }
    .app-topbar { left: 0; }
    .app-main { margin-left: 0; }
    .site-footer { margin-left: 0; }
    .topbar-toggle { display: block; }
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .glass-card { padding: 16px; border-radius: var(--radius-md); }
    .ultra-glass { margin: 16px; padding: 1.75rem 1.5rem; }
    .stat-value { font-size: 1.3rem; }
    .topbar-title { font-size: .9rem; }
}

@media (max-width: 480px) {
    .app-main { padding-left: 12px; padding-right: 12px; }
    .glass-card { padding: 14px; }
    .toolbar-row { flex-direction: column; align-items: stretch; }
    .toolbar-row form { width: 100%; }
}

/* ============================= SCROLLBAR ============================= */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
.app-sidebar ::-webkit-scrollbar-thumb { background: var(--ink-border); }

/* =====================================================================
   PRINTABLE DOCUMENTS (invoices, receipts, diagnostic reports, P&L)
   Carried over from the previous system largely unchanged — these are
   letterhead documents with their own established print layout and
   clinic branding (the red accent below is the clinic's actual brand
   color from its letterhead/logo, not part of the app's UI palette).
   ===================================================================== */

/* === RECEIPT A4 SIZE === */
.receipt-box {
    background: #fff;
    border: 2px solid var(--doc-accent);
    border-radius: 0;
    padding: 0;
    color: #1e293b;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto 30px;
    overflow: hidden;
    font-size: .92rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
}

/* Header: logo + brand + barcode */
.receipt-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 18px 24px 10px;
}
.receipt-logo {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    flex: 1;
}
.receipt-logo-icon svg {
    display: block;
}
.receipt-brand-name {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--doc-accent);
    margin: 0;
    line-height: 1.2;
}
.receipt-brand-name span {
    font-weight: 400;
    font-size: .85rem;
    display: block;
    color: #555;
}
.receipt-brand-tagline {
    font-size: .62rem;
    color: #777;
    margin: 4px 0 0;
    line-height: 1.4;
    max-width: 380px;
}
.receipt-barcode {
    text-align: center;
    flex-shrink: 0;
}
.receipt-barcode canvas {
    display: block;
    max-width: 200px;
}
.barcode-label {
    display: block;
    font-size: .7rem;
    font-family: monospace;
    color: #333;
    margin-top: 2px;
}

/* Title banner */
.receipt-title-bar {
    background: var(--doc-accent);
    color: #fff;
    text-align: center;
    font-weight: 700;
    font-size: 1rem;
    padding: 6px 0;
    letter-spacing: 1px;
}

/* Patient info two-column */
.receipt-info {
    display: flex;
    justify-content: space-between;
    padding: 14px 24px;
    gap: 20px;
    border-bottom: 1px solid #ddd;
}
.receipt-info p {
    margin: 3px 0;
    font-size: .85rem;
    color: #333;
}
.receipt-info strong {
    color: #111;
}
.receipt-info-right {
    text-align: right;
    flex-shrink: 0;
}

/* Items table */
.receipt-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    flex: 1;
}
.receipt-table th {
    background: #f5f5f5;
    border: 1px solid #bbb;
    padding: 8px 12px;
    font-weight: 700;
    font-size: .85rem;
    color: #222;
}
.receipt-table td {
    border: 1px solid #bbb;
    padding: 8px 12px;
    font-size: .85rem;
    color: #333;
    min-height: 32px;
}

/* Summary box */
.receipt-summary {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    gap: 30px;
    padding: 16px 24px;
    border: 1px solid #bbb;
    margin: 16px 24px;
    position: relative;
}
.receipt-paid-stamp {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%) rotate(-18deg);
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--doc-accent);
    border: 4px solid var(--doc-accent);
    border-radius: 10px;
    padding: 2px 18px;
    opacity: .7;
}
.receipt-summary-table {
    text-align: right;
}
.receipt-summary-row {
    display: flex;
    justify-content: space-between;
    gap: 40px;
    padding: 3px 0;
    font-size: .88rem;
}
.receipt-net {
    font-weight: 700;
    border-top: 1px solid #999;
    padding-top: 6px;
    margin-top: 4px;
}

/* Bank info */
.receipt-bank {
    text-align: center;
    padding: 8px 24px;
    font-size: .82rem;
    color: #444;
    border-top: 1px solid #ddd;
}

/* Footer */
.receipt-footer {
    background: var(--doc-accent);
    color: #fff;
    text-align: center;
    padding: 10px 24px;
    font-size: .78rem;
}
.receipt-footer p {
    margin: 2px 0;
}
.receipt-footer strong {
    color: var(--doc-accent-tint);
}
.receipt-footer-tagline {
    font-style: italic;
    margin-top: 4px !important;
    font-size: .72rem;
    opacity: .85;
}

/* === PATIENT BILL (bill-box) === */
.bill-box {
    background: #fff;
    border: none;
    border-radius: 0;
    padding: 15mm 12mm;
    color: #1e293b;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto 30px;
    overflow: hidden;
    font-size: .92rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
    box-sizing: border-box;
}

/* Bill header: logo left, barcode right */
.bill-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 10px;
    border-bottom: 2px solid #888;
}
.bill-header-left { flex-shrink: 0; }
.bill-logo { height: 100px; width: auto; }
.bill-header-right {
    text-align: center;
    flex-shrink: 0;
}
.bill-header-right canvas {
    display: block;
    max-width: 200px;
    margin: 0 auto;
}
.bill-barcode-label {
    display: block;
    font-size: .7rem;
    font-family: monospace;
    color: #333;
    margin-top: 2px;
    letter-spacing: 1px;
    text-align: center;
}
.bill-barcode-billno {
    display: block;
    font-size: .85rem;
    font-weight: 800;
    color: #111;
    margin-top: 4px;
    text-align: center;
}
.bill-barcode-sub {
    display: block;
    font-size: .72rem;
    font-weight: 600;
    color: #666;
    margin-top: 2px;
    text-align: center;
}

/* ISO line under header */
.bill-iso-line {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    font-size: .75rem;
    font-weight: 700;
    color: var(--doc-accent);
    border-bottom: 1px solid #ccc;
}
.bill-iso-img {
    height: 32px;
    width: auto;
}

/* Bill info row */
.bill-info-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 0;
    gap: 20px;
    border-bottom: 1px solid #ccc;
}
.bill-info-left { flex: 1; padding: 14px 0; }
.bill-info-left p { margin: 3px 0; font-size: .85rem; color: #333; }
.bill-info-left strong { color: #111; }
.bill-info-right { flex-shrink: 0; padding-top: 14px; }

/* Service Date mini-table */
.bill-svc-date { border-collapse: collapse; font-size: .78rem; }
.bill-svc-date th,
.bill-svc-date td { border: 1px solid #999; padding: 3px 10px; text-align: center; color: #333; }
.bill-svc-date th { background: #e8e8e8; color: #333; font-weight: 700; }

/* Banner */
.bill-banner {
    background: #fff;
    color: #111;
    text-align: center;
    font-weight: 900;
    font-size: 1.2rem;
    padding: 10px 0 6px;
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 2px solid #333;
}

/* Bill items table */
.bill-table { width: 100%; border-collapse: collapse; }
.bill-table th {
    background: #e8e8e8;
    border: 1px solid #999;
    padding: 7px 12px;
    font-weight: 700;
    font-size: .85rem;
    color: #111;
}
.bill-table td {
    border: 1px solid #bbb;
    padding: 7px 12px;
    font-size: .85rem;
    color: #333;
}
.bill-table tbody tr:last-child td { border-bottom: 2px solid #333; }

/* Summary section (right-aligned) */
.bill-summary {
    display: flex;
    justify-content: flex-end;
    padding: 12px 0;
}
.bill-summary-table { min-width: 280px; }
.bill-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: .88rem;
    color: #333;
}
.bill-summary-row span:first-child { font-weight: 600; }
.bill-summary-sep {
    border-bottom: 1px solid #999;
    margin: 6px 0;
    padding: 0 !important;
}
.bill-summary-bold { font-weight: 800; color: #111; border-top: 1px solid #999; padding-top: 6px !important; }

/* Enter By */
.bill-entered-by {
    padding: 16px 0 10px;
    font-size: .88rem;
    color: #333;
}

/* Bank info */
.bill-bank {
    text-align: center;
    padding: 8px 0;
    font-size: .82rem;
    color: #444;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
}

/* Footer */
.bill-footer {
    background: var(--doc-accent);
    color: #fff;
    text-align: center;
    padding: 10px 16px;
    font-size: .78rem;
    margin-top: auto;
    margin-left: -12mm;
    margin-right: -12mm;
    margin-bottom: -15mm;
}
.bill-footer p { margin: 2px 0; color: #fff; }
.bill-footer strong { color: var(--doc-accent-tint); }

/* === LAB REPORT (Hum Lab style) additions on top of .bill-box === */
.lab-meta-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.lab-meta-table td { padding: 5px 0; vertical-align: baseline; }
.lab-meta-table td.lab-meta-label { width: 175px; padding-right: 20px; }
.lab-meta-table td.lab-meta-value { width: 205px; padding-right: 20px; }
.lab-meta-label { font-size: .95rem; font-weight: 700; color: #111; white-space: nowrap; }
.lab-meta-value { font-size: .95rem; font-weight: 400; color: #111; word-break: break-word; }
.lab-meta-value-wide { width: auto; word-break: normal; }

.bill-terms {
    text-align: center;
    padding: 6px 0 8px;
    font-size: .74rem;
    color: #555;
    border-bottom: 1px solid #ccc;
}
.bill-terms span { margin: 0 10px; }

.lab-signoff { padding: 18px 4px 4px; border-top: 1px solid #e5e7eb; margin-top: 10px; }
.lab-signoff-note { text-align: center; font-size: .78rem; font-weight: 700; color: #333; margin: 0 0 14px; }
.lab-signoff-row { display: flex; justify-content: space-between; gap: 20px; }
.lab-signoff-col { display: flex; flex-direction: column; gap: 2px; }
.lab-signoff-col strong { font-size: .88rem; color: #111; }
.lab-signoff-col span { font-size: .72rem; color: #666; }
.lab-signoff-right { align-items: flex-end; text-align: right; }

/* === P&L REPORT === */
.only-print { display: none; }

.pl-report {
    background: #fff;
    color: #1e293b;
    font-family: 'Segoe UI', Arial, sans-serif;
    width: 100%;
    margin: 0 auto 24px;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0,0,0,.12);
}
.pl-report-header {
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 3px solid var(--doc-accent);
    padding-bottom: 12px;
    margin-bottom: 18px;
}
.pl-report-logo {
    height: 55px;
    width: auto;
}
.pl-report-header h1 {
    font-size: 1.4rem;
    color: var(--doc-accent);
    margin: 0;
}
.pl-report-header p {
    margin: 2px 0;
    font-size: .88rem;
    color: #555;
}
.pl-period {
    font-weight: 700;
    color: #222 !important;
}

.pl-report-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}
.pl-section-head th {
    background: var(--doc-accent);
    color: #fff;
    padding: 7px 12px;
    font-size: .9rem;
    text-align: left;
}
.pl-report-table th {
    background: #f5f5f5;
    border: 1px solid #ccc;
    padding: 6px 10px;
    font-size: .82rem;
    color: #222;
}
.pl-report-table td {
    border: 1px solid #ccc;
    padding: 6px 10px;
    font-size: .82rem;
}
.pl-total-row td {
    background: var(--doc-accent-soft);
    border-top: 2px solid var(--doc-accent);
}

.pl-summary {
    margin-top: auto;
    border: 2px solid #333;
    padding: 14px 20px;
    max-width: 320px;
    margin-left: auto;
}
.pl-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: .9rem;
}
.pl-net {
    font-weight: 800;
    font-size: 1.05rem;
    border-top: 2px solid #333;
    padding-top: 8px;
    margin-top: 6px;
}
.pl-profit { color: #1b7a3e; }
.pl-loss { color: #c0392b; }

.pl-report-footer {
    margin-top: 20px;
    border-top: 1px solid #ccc;
    padding-top: 8px;
    text-align: center;
    font-size: .72rem;
    color: #888;
}

/* === PRINT === */
@page {
    size: A4 portrait;
    margin: 5mm;
}

@media print {
    *, *::before, *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    html, body {
        width: 210mm;
        height: 297mm;
        margin: 0 !important;
        padding: 0 !important;
    }

    .app-sidebar,
    .app-topbar,
    .sidebar-backdrop,
    .no-print,
    .toolbar-row,
    .glass-card.no-print {
        display: none !important;
    }

    .only-print,
    .print-only {
        display: block !important;
    }

    body, .dashboard-bg {
        background: #fff !important;
        animation: none !important;
    }

    .app-main {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .glass-card {
        background: #fff !important;
        backdrop-filter: none !important;
        box-shadow: none !important;
        border: 1px solid #e5e7eb !important;
        color: #000 !important;
    }

    .glass-card h2, .glass-card h3, .glass-card td, .glass-card th, .glass-card p, .glass-card label {
        color: #000 !important;
        -webkit-text-fill-color: #000 !important;
        background: none !important;
    }

    .invoice-box {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
    }

    .receipt-box,
    .bill-box {
        width: 100% !important;
        min-height: 100vh !important;
        border: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 10mm 12mm !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        box-sizing: border-box !important;
    }

    .receipt-table,
    .bill-table {
        flex: unset;
    }

    .receipt-footer,
    .bill-footer {
        margin-top: auto;
        margin-left: -12mm !important;
        margin-right: -12mm !important;
        margin-bottom: -10mm !important;
    }

    .bill-banner {
        color: #111 !important;
        border-bottom: 2px solid #333 !important;
    }
    .bill-table th {
        background: #e8e8e8 !important;
        color: #111 !important;
    }
    .bill-svc-date th {
        background: #e8e8e8 !important;
        color: #333 !important;
    }
    .bill-footer {
        background: var(--doc-accent) !important;
        color: #fff !important;
    }
    .lab-meta-label,
    .lab-signoff-col strong {
        color: #111 !important;
    }
    .lab-signoff {
        border-color: #999 !important;
    }

    /* P&L report print */
    .pl-report {
        width: 100% !important;
        min-height: auto !important;
        padding: 15mm !important;
        margin: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        page-break-inside: avoid;
    }
    .pl-section-head th {
        background: var(--doc-accent) !important;
        color: #fff !important;
    }
    .pl-total-row td {
        background: var(--doc-accent-soft) !important;
    }
}