/* ==========================================================================
   CareNexa design tokens — white / teal / blue, light + dark (Bootstrap 5.3 data-bs-theme)
   ========================================================================== */
:root,
[data-bs-theme="light"] {
    --cf-teal: #0d9488;
    --cf-teal-dark: #0f766e;
    --cf-blue: #2563eb;
    --cf-surface: #ffffff;
    --cf-canvas: #f4f8fb;
    --cf-border: #e2e8f0;
    --cf-sidebar-bg: #ffffff;
    --cf-sidebar-active: #e6f6f4;
    --cf-text-muted: #64748b;

    --bs-primary: var(--cf-teal);
    --bs-primary-rgb: 13, 148, 136;
    --bs-link-color: var(--cf-blue);
    --bs-link-color-rgb: 37, 99, 235;
    --bs-link-hover-color: #1d4ed8;
    --bs-body-bg: var(--cf-canvas);
    --bs-border-color: var(--cf-border);
    --bs-font-sans-serif: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-bs-theme="dark"] {
    --cf-teal: #2dd4bf;
    --cf-teal-dark: #14b8a6;
    --cf-blue: #60a5fa;
    --cf-surface: #111827;
    --cf-canvas: #0b1220;
    --cf-border: #1f2937;
    --cf-sidebar-bg: #0f172a;
    --cf-sidebar-active: #134e4a;
    --cf-text-muted: #94a3b8;

    --bs-primary: var(--cf-teal);
    --bs-primary-rgb: 45, 212, 191;
    --bs-link-color: var(--cf-blue);
    --bs-link-color-rgb: 96, 165, 250;
    --bs-body-bg: var(--cf-canvas);
    --bs-border-color: var(--cf-border);
}

body { background: var(--cf-canvas); }

.btn-primary {
    --bs-btn-bg: var(--cf-teal);
    --bs-btn-border-color: var(--cf-teal);
    --bs-btn-hover-bg: var(--cf-teal-dark);
    --bs-btn-hover-border-color: var(--cf-teal-dark);
    --bs-btn-active-bg: var(--cf-teal-dark);
    --bs-btn-disabled-bg: var(--cf-teal);
    --bs-btn-color: #fff;
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #04201d; --bs-btn-hover-color: #04201d; }
.btn-outline-primary {
    --bs-btn-color: var(--cf-teal);
    --bs-btn-border-color: var(--cf-teal);
    --bs-btn-hover-bg: var(--cf-teal);
    --bs-btn-hover-border-color: var(--cf-teal);
}
.text-primary { color: var(--cf-teal) !important; }
.text-bg-primary { background-color: var(--cf-teal) !important; color: #fff !important; }

.card { background: var(--cf-surface); border-color: var(--cf-border); border-radius: .75rem; }
.card-header { border-color: var(--cf-border); }
.x-small { font-size: .75rem; }

/* Accessible focus ring */
.btn:focus-visible, .form-control:focus, .form-select:focus, .form-check-input:focus, .nav-link:focus-visible, .page-link:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 .2rem rgba(var(--bs-primary-rgb), .35);
}
h1:focus { outline: none; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; }
.brand-mark {
    display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: .6rem;
    background: linear-gradient(135deg, var(--cf-teal), var(--cf-blue)); color: #fff; font-size: .8rem; letter-spacing: .02em;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    width: 250px; flex-shrink: 0; background: var(--cf-sidebar-bg); border-right: 1px solid var(--cf-border);
    padding-top: 1rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 1040;
}
.app-sidebar .brand { height: 2.5rem; margin-bottom: 1rem; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
    height: 60px; display: flex; align-items: center; gap: .5rem; padding: 0 1.25rem;
    background: var(--cf-surface); border-bottom: 1px solid var(--cf-border); position: sticky; top: 0; z-index: 1030;
}
.app-content { padding: 1.5rem; max-width: 1400px; width: 100%; }
.app-backdrop { display: none; }

.btn-icon { border: 0; background: transparent; color: inherit; padding: .4rem; border-radius: .5rem; line-height: 0; }
.btn-icon:hover { background: rgba(var(--bs-primary-rgb), .1); }
.avatar {
    width: 2.1rem; height: 2.1rem; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 600;
    background: rgba(var(--bs-primary-rgb), .15); color: var(--cf-teal);
}

@media (max-width: 991.98px) {
    .app-sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 2rem rgba(0,0,0,.15); }
    .sidebar-open .app-sidebar { transform: translateX(0); }
    .sidebar-open .app-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 1035; }
    .app-content { padding: 1rem; }
}

/* ---------- Navigation ---------- */
.app-nav { display: flex; flex-direction: column; padding: 0 .75rem 1rem; gap: .15rem; }
.app-nav .nav-section {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--cf-text-muted);
    margin: 1rem .5rem .35rem;
}
.app-nav .nav-link {
    display: flex; align-items: center; gap: .65rem; padding: .55rem .75rem; border-radius: .5rem;
    color: var(--bs-body-color); font-weight: 500;
}
.app-nav .nav-link:hover { background: rgba(var(--bs-primary-rgb), .08); }
.app-nav .nav-link.active { background: var(--cf-sidebar-active); color: var(--cf-teal); }

/* ---------- Page elements ---------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.stat-card .stat-icon {
    width: 2.75rem; height: 2.75rem; border-radius: .75rem; display: grid; place-items: center;
    background: rgba(var(--bs-primary-rgb), .12); color: var(--cf-teal);
}
.stat-label { font-size: .8rem; color: var(--cf-text-muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-hint { font-size: .75rem; color: var(--cf-text-muted); }

.table > :not(caption) > * > * { background-color: transparent; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--cf-text-muted); font-weight: 600; }

/* ---------- Auth pages ---------- */
.auth-shell {
    min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1rem;
    background: radial-gradient(circle at 20% 20%, rgba(13,148,136,.12), transparent 40%),
                radial-gradient(circle at 80% 80%, rgba(37,99,235,.12), transparent 40%), var(--cf-canvas);
}
.auth-card { width: 100%; max-width: 440px; }
.auth-footer { margin-top: 1rem; }

/* ---------- Validation / Blazor ---------- */
.valid.modified:not([type=checkbox]) { outline: 1px solid #16a34a; }
.invalid { outline: 1px solid #dc2626; }
.validation-message { color: #dc2626; font-size: .85rem; }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "An error has occurred." }

#blazor-error-ui {
    background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none;
    left: 0; padding: .6rem 1.25rem .7rem 1.25rem; position: fixed; width: 100%; z-index: 2000; color: #111;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color); text-align: end;
}
.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder { text-align: start; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; right: 1rem; bottom: 1rem; z-index: 2100; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.cn-toast { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-radius: .6rem; box-shadow: 0 .5rem 1.5rem rgba(0,0,0,.15); background: var(--cf-surface); border-left: 4px solid var(--cf-teal); }
.cn-toast-error { border-left-color: #dc2626; }
.cn-toast-info { border-left-color: var(--cf-blue); }

/* ---------- Tables / timeline ---------- */
.row-link { cursor: pointer; }
.timeline { position: relative; }
.timeline-item { position: relative; padding: 0 0 1rem 1.25rem; border-left: 2px solid var(--cf-border); margin-left: .35rem; }
.timeline-item::before { content: ""; position: absolute; left: -.42rem; top: .2rem; width: .75rem; height: .75rem; border-radius: 50%; background: var(--cf-teal); }
.timeline-item:last-child { padding-bottom: 0; }
.nav-tabs .nav-link { color: var(--bs-body-color); }
.nav-tabs .nav-link.active { color: var(--cf-teal); font-weight: 600; }
.modal { background: transparent; }

/* ---------- Scheduling / queue ---------- */
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
.appt { border-left: 4px solid transparent; }
.appt-confirmed { border-left-color: #0ea5e9; }
.appt-checkedin, .appt-inprogress { border-left-color: var(--cf-teal); }
.appt-completed { border-left-color: #16a34a; }
.appt-cancelled, .appt-noshow, .appt-rescheduled { opacity: .6; }
.token-label { font-weight: 700; font-size: 1.1rem; color: var(--cf-teal); letter-spacing: .03em; }
.picker-results { z-index: 1050; max-height: 320px; overflow-y: auto; }

/* ---------- Waiting-room display ---------- */
.display-shell { min-height: 100vh; background: #0b1f2a; color: #fff; padding: 2rem 3rem; font-size: 1.4rem; }
.display-header { display: flex; justify-content: space-between; font-size: 2rem; font-weight: 700; margin-bottom: 2rem; }
.display-branch { color: #5eead4; }
.display-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 3rem; }
.display-grid h1, .display-grid h2 { text-transform: uppercase; letter-spacing: .1em; font-size: 1.2rem; color: #94a3b8; }
.display-token { display: flex; align-items: baseline; gap: 2rem; padding: 1rem 0; border-bottom: 1px solid #1e3a4a; }
.display-number { font-size: 4.5rem; font-weight: 800; color: #5eead4; }
.display-detail { font-size: 1.6rem; }
.display-waiting { display: flex; flex-wrap: wrap; gap: 1rem; font-size: 2rem; font-weight: 700; }
.display-message { display: grid; place-items: center; min-height: 80vh; font-size: 2rem; }
@media (max-width: 991.98px) { .display-grid { grid-template-columns: 1fr; } .display-shell { padding: 1rem; } }

/* ---------- Clinical ---------- */
.note { border-left: 3px solid var(--cf-teal); padding-left: .75rem; }
.note-amended { opacity: .55; border-left-color: #94a3b8; text-decoration: none; }
.preserve-lines { white-space: pre-line; }

/* ---------- Print ---------- */
.print-shell { background: #fff; color: #111; min-height: 100vh; padding: 2rem; }
.rx-sheet { max-width: 800px; margin: 0 auto; }
.rx-head { display: flex; justify-content: space-between; border-bottom: 3px solid #0d9488; padding-bottom: .75rem; margin-bottom: .75rem; }
.rx-clinic { font-size: 1.5rem; font-weight: 700; color: #0f766e; }
.rx-patient { border-bottom: 1px solid #ddd; padding-bottom: .5rem; margin-bottom: .5rem; }
.rx-symbol { font-size: 2rem; font-weight: 700; color: #0f766e; }
.rx-foot { border-top: 1px solid #ddd; margin-top: 2rem; padding-top: .5rem; color: #555; }
@media print { .no-print, #blazor-error-ui { display: none !important; } .print-shell { padding: 0; } }

/* ---------- Notifications ---------- */
.notification-panel { position: absolute; right: 0; top: 2.75rem; width: min(360px, 90vw); z-index: 1060; max-height: 70vh; overflow-y: auto; }

/* ---------- Charts (single validated hue: #0d9488 light / #119e91 dark) ---------- */
:root, [data-bs-theme="light"] { --cn-chart-mark: #0d9488; --cn-chart-grid: #e7ecf0; --cn-chart-ink: #475569; }
[data-bs-theme="dark"] { --cn-chart-mark: #119e91; --cn-chart-grid: #243041; --cn-chart-ink: #94a3b8; }
.cn-chart { margin: 0; }
.cn-chart-svg { overflow: visible; }
.cn-mark { fill: var(--cn-chart-mark); }
.cn-hit { fill: transparent; }
.cn-mark-group:hover .cn-mark { opacity: .8; }
.cn-grid { stroke: var(--cn-chart-grid); stroke-width: 1; }
.cn-baseline { stroke: var(--cn-chart-ink); stroke-width: 1; opacity: .5; }
.cn-axis { fill: var(--cn-chart-ink); font-size: 11px; }
.cn-value { fill: var(--bs-body-color); font-size: 11px; font-weight: 600; }
.cn-barlist li { margin-bottom: .6rem; }
.cn-bar-track { height: 8px; border-radius: 4px; background: var(--cn-chart-grid); }
.cn-bar { height: 8px; border-radius: 4px; background: var(--cn-chart-mark); min-width: 2px; }
.audit-json { white-space: pre-wrap; word-break: break-all; max-width: 520px; background: var(--cf-canvas); padding: .5rem; border-radius: .375rem; }

/* ---------- Accessibility ---------- */
.skip-link { position: absolute; left: -999px; top: .5rem; z-index: 3000; background: var(--cf-surface); padding: .5rem 1rem; border-radius: .5rem; box-shadow: 0 0 0 2px var(--cf-teal); }
.skip-link:focus { left: .5rem; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (forced-colors: active) { .cn-bar, .cn-mark { forced-color-adjust: none; fill: CanvasText; background: CanvasText; } }
