:root {
    /* Warm-cream + terracotta + sage-teal palette (audits/color_palette_proposal.md, AA-passing) */
    --primary: #a8623a;
    --primary-hover: #8e5230;
    --primary-dark: #74411f;
    --primary-pressed: #74411f;
    --primary-light: #fbe9d8;
    --primary-50: #fdf3e8;
    --secondary: #8e5230;
    --secondary-hover: #74411f;
    --secondary-light: #fbe9d8;
    --bg: #fbf6ee;
    --bg-card: #ffffff;
    --bg-subtle: #f3ebde;
    --text: #231915;
    --text-secondary: #5a3f30;
    --text-muted: #7a5a48;
    /* Bumped from #e6d4bf (≈1.07:1 against bg) to #d4bfa3 (≈1.5:1) so cards
       have a visible edge instead of bleeding into the cream background. */
    --border: #d4bfa3;
    --border-hover: #b89876;
    --border-strong: #b89876;
    --danger: #c0392b;
    --danger-hover: #9c2d22;
    --danger-bg: #fbe7e3;
    --warning: #c8841a;
    --warning-bg: #faeed1;
    --success: #2f8f5e;
    --success-bg: #dff1e5;
    --success-border: #2f8f5e;
    --success-text: #1d6b46;
    --info: #2b6cb0;
    --info-bg: #e0ebf6;
    /* Field-state token triplet — AI-filled, human-edited, NHIS-confirmed are now visually distinct */
    --ai-fill: #f6ebd4;
    --ai-fill-border: #c89a3a;
    --human-fill: #e3efeb;
    --human-fill-border: #3d7a6e;
    --nhis-confirmed: #c8e0d2;
    --nhis-confirmed-border: #2f8f5e;
    --focus-ring: rgba(168, 98, 58, 0.35);
    --shadow-sm: 0 0.0625rem 0.125rem rgba(0, 0, 0, 0.05);
    --shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.1), 0 0.0625rem 0.125rem rgba(0, 0, 0, 0.06);
    --shadow-md: 0 0.25rem 0.375rem rgba(0, 0, 0, 0.07), 0 0.125rem 0.25rem rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 0.625rem 0.9375rem rgba(0, 0, 0, 0.1), 0 0.25rem 0.375rem rgba(0, 0, 0, 0.05);
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    /* ===== THEME TOKENS (overridden per theme) ===== */
    --sidebar-from: #a8623a;
    --sidebar-to: #74411f;
    --sidebar-text: #ffffff;
    --sidebar-text-muted: rgba(255,255,255,0.85); /* lifted from 0.65 → 0.85 to fix WCAG AA on subtitle */
    --header-pill-bg: rgba(255,255,255,0.15);
    --header-pill-hover-bg: rgba(255,255,255,0.28);
    --accent: #3d7a6e;
    --accent-hover: #2f6358;
    --accent-from: #3d7a6e;
    --accent-to: #2f6358;
    --accent-light: #e3efeb;
    --accent-border: rgba(61,122,110,0.4);
    --accent-text: #2f6358;
    --btn-primary-from: #a8623a;
    --btn-primary-to: #74411f;
}

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

/* Global UI scale — chair-side glance distance is ~70cm, doctors often
   wear gloves. 20px html base = ~25% upscale from the browser default.
   Every rem-based size in the app inherits this. Tap targets and text
   stay readable from a meter away.                                          */
html {
    font-size: 20px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    display: flex;
    height: 100vh;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 17rem;
    min-width: 17rem;
    background: var(--bg-card);
    border-right: 0.0625rem solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: all 0.3s ease;
}

.sidebar.collapsed {
    width: 4.5rem;
    min-width: 4.5rem;
}

.sidebar.collapsed .sidebar-header h2,
.sidebar.collapsed .sidebar-header .subtitle,
.sidebar.collapsed .sidebar-header .selected-counter,
.sidebar.collapsed .sidebar-header img,
.sidebar.collapsed .file-list {
    display: none;
    opacity: 0;
}

.sidebar-header {
    padding: 1.25rem;
    /* Flat sidebar header — gradient was visual noise in chair-side glance.
       --sidebar-from is the brand-side hue (theme overrides still drive it). */
    background: var(--sidebar-from);
    color: var(--sidebar-text);
    position: relative;
}

.sidebar-toggle-btn {
    position: absolute;
    top: 0.9375rem;
    right: 0.9375rem;
    background: rgba(0, 0, 0, 0.15);
    border: none;
    color: var(--sidebar-text);
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 0.375rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
    z-index: 20;
}

.sidebar-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.3);
}

.sidebar.collapsed .sidebar-toggle-btn {
    position: static;
    margin: 0 auto;
}

.sidebar-header h2 {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-header .subtitle {
    font-size: 0.6875rem;
    /* Was opacity:0.6 (≈2.7:1 on terracotta sidebar). Switched to the
       lifted --sidebar-text-muted token (rgba 0.85) which clears AA. */
    color: var(--sidebar-text-muted);
    margin-top: 0.25rem;
    font-weight: 400;
}

.selected-counter {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.625rem;
    padding: 0.375rem 0.625rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.selected-counter .count {
    background: var(--primary);
    color: white;
    width: 1.375rem;
    height: 1.375rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 700;
}

.file-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

/* Folder group */
.folder-group {
    margin-bottom: 0.25rem;
}

.folder-group.open {
    border: 0.09375rem solid var(--primary);
    border-radius: var(--radius);
    background: var(--primary-light);
    padding: 0.125rem;
}

.folder-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03125rem;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    border-radius: 0.375rem;
    transition: all 0.15s;
    user-select: none;
}

.folder-header:hover {
    background: var(--bg);
}

.folder-group.open .folder-header {
    color: var(--primary-dark);
}

.folder-header .folder-icon {
    font-size: 0.8125rem;
    transition: transform 0.2s;
}

.folder-files {
    overflow: hidden;
}

.folder-files.collapsed {
    display: none;
}

.file-item {
    /* Padding bumped from 0.625rem/0.75rem to 0.875rem so the row tap
       target clears the chair-side glove rule (~44px tall at 20px root). */
    padding: 0.875rem;
    margin: 0.125rem 0;
    background: transparent;
    border: 0.0625rem solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    transition: all 0.15s ease;
    font-size: 0.75rem;
}

.file-item:hover {
    background: var(--bg);
    border-color: var(--border);
}

.file-item.active {
    background: var(--primary-light);
    border-color: var(--primary);
}

.file-item.checked-file {
    /* Border tracks the human-fill mint so checked-state ≠ accidental
       hard-locked Tailwind green when themes flip. */
    background: var(--secondary-light);
    border-color: var(--human-fill-border);
}

.file-item.checked-file.active {
    background: var(--primary-50);
    border-color: var(--primary);
}

.file-checkbox {
    cursor: pointer;
    width: 1rem;
    height: 1rem;
    accent-color: var(--secondary);
    flex-shrink: 0;
}

.file-name {
    flex: 1;
    font-weight: 500;
    line-height: 1.4;
    word-break: break-word;
    color: var(--text);
}

.file-badge {
    background: var(--success-bg);
    color: var(--success-text);
    font-size: 0.5625rem;
    padding: 0.125rem 0.375rem;
    border-radius: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.01875rem;
    flex-shrink: 0;
}

/* Sidebar controls */
.sidebar-controls {
    padding: 0.75rem;
    border-top: 0.0625rem solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    background: var(--bg);
    transition: all 0.3s ease;
}

.sidebar.collapsed .sidebar-controls {
    flex: 1;
    justify-content: center;
    align-items: center;
    padding: 0;
    border-top: none;
    gap: 0.9375rem;
}

.btn {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    letter-spacing: 0.01em;
}

.sidebar.collapsed .btn {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    padding: 0;
}

.sidebar.collapsed .btn .btn-text {
    display: none;
}

.sidebar.collapsed .btn .btn-icon {
    font-size: 1.125rem;
    margin: 0;
}

.btn-primary {
    /* Solid primary — theme can still override --btn-primary-from to recolour. */
    background: var(--btn-primary-from);
    color: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.btn-primary:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.28);
}

.btn-primary:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-outline {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 0.0625rem solid var(--border);
}

.btn-outline:hover {
    background: var(--bg);
    border-color: var(--border-hover);
}

.btn-outline:disabled {
    color: var(--text-muted);
    border-color: var(--border);
    cursor: not-allowed;
    background: transparent;
}

/* Idle = brand primary (sienna); recording = red so the live state still
   reads as "hot mic". Keeping red for idle was alarming — doctors read it
   as "destructive" rather than "press to start". */
.btn-record {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-record:hover {
    background: var(--primary-hover, var(--primary-dark));
}

.btn-record.recording {
    background: var(--danger);
    animation: recordPulse 2s ease-in-out infinite;
}
.btn-record.recording:hover { background: var(--danger-hover); }

.mic-meter {
    /* Was margin-top:-0.25rem which pulled the meter flush against the
       record button and made the gap to "Запази всички" visually larger
       than the gap above. Sit on the parent's normal gap instead. */
    margin-top: 0;
    padding: 0.3rem 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.mic-meter-bars {
    display: flex;
    gap: 2px;
    height: 14px;
    align-items: flex-end;
}
.mic-bar {
    flex: 1;
    height: 30%;
    background: #e5e7eb;
    border-radius: 1px;
    transition: background 0.05s, height 0.05s;
}
.mic-bar.on { background: #10b981; height: 100%; }
.mic-bar.hot { background: #f59e0b; }
.mic-meter-hint {
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-align: center;
}
.sidebar.collapsed .mic-meter { display: none; }

@keyframes recordPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    50% {
        box-shadow: 0 0 0 0.5rem rgba(239, 68, 68, 0);
    }
}

.btn-sm {
    padding: 0.4375rem 0.75rem;
    font-size: 0.75rem;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Toolbar */
.toolbar {
    position: relative;
    padding: 0.5rem 1.25rem;
    background: var(--bg-card);
    border-bottom: 0.0625rem solid var(--border);
    display: flex;
    align-items: center;
    /* Was a fixed `height: 3.25rem` which clipped the top row when buttons
       wrapped to a second line (the top row got pushed above the clipped
       box). min-height grows the bar to fit instead. */
    min-height: 3.25rem;
    gap: 0.75rem;
    flex-shrink: 0;
}

.toolbar-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.toolbar-title .label {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.75rem;
    margin-right: 0.375rem;
}

.status-pill {
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    transition: opacity 0.2s, transform 0.25s;
    display: none;
}
/* Compact toast just below the toolbar, left-aligned to the main content
   column. Auto-grows to fit any message length (wraps when very long).
   Same 1rem inset from the toolbar above and from the sidebar to its left. */
.status-pill--floating {
    position: fixed;
    /* Toolbar min-height (3.25rem) + 1rem gap. */
    top: calc(3.25rem + 1rem);
    /* Sidebar width (17.5rem default) + matching 1rem gap. */
    left: calc(17.5rem + 1rem);
    transform: translateY(-0.4rem);
    z-index: 9998;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    pointer-events: none;
    opacity: 0;
    /* No nowrap / no truncation — long Bulgarian sentences wrap normally.
       Cap at the available main-column width so it never crosses the
       right edge of the viewport. */
    max-width: calc(100vw - 17.5rem - 2rem);
    width: max-content;
    line-height: 1.4;
    overflow-wrap: anywhere;
    transition: opacity 0.2s, transform 0.2s;
}
.status-pill--floating.visible {
    display: inline-flex;
    opacity: 1;
    transform: translateY(0);
}
/* Sidebar collapsed → main column starts ~4.5rem from left. */
@media (max-width: 1024px) {
    .status-pill--floating {
        left: calc(4.5rem + 1rem);
        max-width: calc(100vw - 4.5rem - 2rem);
    }
}
.status-pill--floating.success { border-color: var(--success); color: var(--success); }
.status-pill--floating.error,
.status-pill--floating.danger  { border-color: var(--danger);  color: var(--danger);  }
.status-pill--floating.warning { border-color: var(--warning); color: var(--warning); }
.status-pill--floating.info    { border-color: var(--accent);  color: var(--accent);  }

.status-pill.visible {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
}

.status-pill.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.status-pill.error {
    background: #fef2f2;
    color: #991b1b;
}

.status-pill.info {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* Preview */
.preview-area {
    flex: 1;
    overflow: auto;
    padding: 1.5rem;
    background: #e2e8f0;
    min-height: 0;
}

#previewContent {
    width: 100%;
}

.offline-banner[hidden] { display: none !important; }
.offline-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #fef3c7;
    border-bottom: 1px solid #f59e0b;
    color: #78350f;
    font-weight: 500;
    font-size: 0.8125rem;
    flex-shrink: 0;
}
.offline-banner-icon { font-size: 1rem; }

.btn.btn-disabled-offline {
    opacity: 0.55;
    cursor: not-allowed;
    filter: grayscale(0.4);
}

.allergy-banner[hidden] { display: none !important; }
.allergy-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: #fee2e2;
    border-bottom: 2px solid #dc2626;
    color: #7f1d1d;
    font-weight: 600;
    flex-shrink: 0;
}
.allergy-banner-icon { font-size: 1.25rem; }
.allergy-banner-label { letter-spacing: 0.05em; }
.allergy-banner-text { flex: 1; font-weight: 500; }

#docxContainer {
    width: 100%;
}

/* Minimal overrides — let docx-preview handle layout naturally */
.docx-wrapper {
    background: transparent !important;
}

/* Reset global box-sizing and margins for docx-preview so it renders exactly like Word */
.docx-wrapper * {
    box-sizing: content-box;
    margin: revert;
    padding: revert;
}

.docx-wrapper>section.docx {
    box-shadow: 0 0.125rem 0.75rem rgba(0, 0, 0, 0.15) !important;
    margin: 0 auto 1.875rem auto !important;
}

/* ===== Themed dropdown (replaces native <select> across the app) =====
   Used by /js/dropdown.js makeDropdown helper. Class names keep `.cal-`
   prefix so existing calendar markup continues to work unchanged. */
.cal-dropdown {
    position: relative;
    display: inline-block;
    min-width: 7rem;
    font-family: inherit;
}
.cal-dropdown-trigger {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.45rem 2rem 0.45rem 0.75rem;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    width: 100%;
    text-align: left;
    min-height: 2.5rem;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.cal-dropdown-trigger::after {
    content: '';
    position: absolute;
    right: 0.7rem;
    top: 50%;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: translateY(-65%) rotate(45deg);
    transition: transform 0.15s;
}
.cal-dropdown.open .cal-dropdown-trigger::after { transform: translateY(-25%) rotate(-135deg); }
.cal-dropdown-trigger:hover { border-color: var(--primary); }
.cal-dropdown.open .cal-dropdown-trigger {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus-ring, rgba(168,98,58,0.25));
}
.cal-dropdown-trigger-color {
    display: inline-block;
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.15);
}
.cal-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-strong, var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 100001;
    max-height: 18rem;
    overflow-y: auto;
}
.cal-dropdown.open .cal-dropdown-menu { display: block; }
.cal-dropdown-option {
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.55rem;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}
.cal-dropdown-option:hover { background: var(--primary-50); color: var(--primary-dark); }
.cal-dropdown-option.selected { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.cal-dropdown-option-meta {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Themed cancel/save buttons used by modals (sig-slot form, visual placer). */
.cal-btn {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.95rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.cal-btn:hover { border-color: var(--primary); background: var(--primary-50, var(--primary-light)); }
.cal-btn:active { transform: translateY(1px); }
.cal-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.cal-btn-primary {
    background: var(--primary);
    color: var(--white, #fff);
    border-color: var(--primary);
}
.cal-btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--white, #fff); }
.cal-btn-danger {
    background: var(--danger, #dc2626);
    color: #fff;
    border-color: var(--danger, #dc2626);
}
.cal-btn-danger:hover { background: var(--danger-dark, #b91c1c); border-color: var(--danger-dark, #b91c1c); }
.docx-wrapper {
    /* Apply zoom on the wrapper (not the section): a zoomed CONTAINER's
       layout box reliably reflects the scaled dimensions to ancestors in
       Chrome, while zoom on a leaf block does not. The wrapper's natural
       width is the section width (~595px); 1.25× ≈ 744px, so .preview-area's
       overflow:auto correctly sees the zoomed size and scrolls horizontally
       only when the viewport is narrower than 744 + padding. Section centers
       within the wrapper via margin:auto. */
    zoom: 1.25;
    margin: 0 auto;
    width: max-content;
}

.empty-state {
    text-align: center;
    padding: 5rem 1.25rem;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.8125rem;
}

/* ===== BOTTOM PANEL (Always visible when files selected) ===== */
.bottom-panel {
    background: var(--bg-card);
    border-top: 0.0625rem solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: height 0.25s ease;
    overflow: hidden;
}

.bottom-panel.closed {
    height: 2.5rem;
}

.bottom-panel.open {
    height: 17.5rem;
}

.panel-header {
    display: flex;
    align-items: center;
    border-bottom: 0.0625rem solid var(--border);
    flex-shrink: 0;
    height: 2.5rem;
    padding: 0 0.25rem;
    background: var(--bg);
}

.panel-tab {
    padding: 0 1rem;
    height: 100%;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--text-muted);
    border-bottom: 0.125rem solid transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    white-space: nowrap;
}

.panel-tab:hover {
    color: var(--text-secondary);
}

.panel-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.panel-tab .badge {
    background: var(--primary);
    color: white;
    font-size: 0.625rem;
    padding: 0.0625rem 0.375rem;
    border-radius: 0.625rem;
    min-width: 1.125rem;
    text-align: center;
    font-weight: 700;
}

.panel-tab .badge.green {
    background: var(--secondary);
}

.panel-toggle-btn {
    margin-left: auto;
    padding: 0.25rem 0.75rem;
    font-size: 0.6875rem;
    cursor: pointer;
    background: none;
    border: 0.0625rem solid var(--border);
    border-radius: 0.25rem;
    color: var(--text-muted);
    font-weight: 600;
    font-family: inherit;
    margin-right: 0.5rem;
    transition: all 0.15s;
}

.panel-toggle-btn:hover {
    background: var(--bg-card);
    color: var(--text-secondary);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.875rem 1.125rem;
    min-height: 0;
}

/* ===== FIELDS ===== */
.fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.625rem;
}

.field-card {
    background: var(--bg);
    border: 0.0625rem solid var(--border);
    border-radius: var(--radius);
    padding: 0.625rem 0.75rem;
    transition: all 0.15s;
}

.field-card:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.1875rem rgba(59, 130, 246, 0.1);
}

.field-card.filled {
    border-color: var(--success-border);
    background: var(--success-bg);
}

.field-card.warning {
    border-color: #fcd34d;
    background: #fef3c7;
}

.field-card.warning .field-dot {
    background: var(--warning);
}

.field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.375rem;
}

.field-name {
    font-size: 0.6875rem;
    font-weight: 700;
    /* Was --text-muted (≈2.95:1 on --bg-card) — bumped to --text-secondary
       (≈7:1) to clear WCAG AA for small bold uppercase. */
    color: var(--text-secondary);
    text-transform: uppercase;
    /* Cyrillic uppercase needs more open spacing than Latin (was 0.03125rem). */
    letter-spacing: 0.06em;
}

.field-dot {
    width: 0.4375rem;
    height: 0.4375rem;
    border-radius: 50%;
    background: var(--success);
    display: none;
}

.field-card.filled .field-dot {
    display: block;
}

.field-input {
    width: 100%;
    padding: 0.4375rem 0.625rem;
    border: 0.0625rem solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    background: var(--bg-card);
    color: var(--text);
}

.field-input:focus {
    border-color: var(--primary);
}

.field-input::placeholder {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.field-files {
    font-size: 0.625rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    line-height: 1.3;
}


/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 0.3125rem;
    height: 0.3125rem;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 0.625rem;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== TOOLBAR PRICE PILL + POPOVER ===== */
.price-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.7rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.price-pill:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.price-popover[hidden] { display: none !important; }
.price-popover {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 100;
    width: 17rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    overflow: hidden;
}
.price-popover-body {
    padding: 0.5rem 0.75rem;
    max-height: 16rem;
    overflow-y: auto;
}
.price-widget-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}
.price-widget-row:last-child { border-bottom: none; }
.price-label { font-weight: 500; }
.price-value { font-weight: 600; }
.price-value.has-price { color: var(--primary-dark); }

.price-widget-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-bottom: 0.0625rem solid var(--border);
}

.price-widget-row:last-child {
    border-bottom: none;
}

.price-label {
    font-weight: 500;
    color: var(--text-primary);
}

.price-value {
    font-weight: 600;
    color: var(--text-secondary);
}

.price-value.has-price {
    color: #0369a1;
}

/* Empty panel message */
.panel-empty {
    text-align: center;
    padding: 1.875rem 1.25rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.panel-empty .icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

/* ===== FIELD EDIT MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--bg-card);
    border-radius: 1.25rem;
    box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.25);
    width: 32.5rem;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
    from {
        transform: scale(0.95) translateY(0.625rem);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 0.0625rem solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-body {
    padding: 1.25rem;
    flex: 1;
    overflow: auto;
}

.modal-body textarea {
    width: 100%;
    min-height: 9.375rem;
    padding: 0.75rem;
    border: 0.0625rem solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
}

.modal-body textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.1875rem var(--primary-light);
}

/* ===== AUTOCOMPLETE ===== */
.autocomplete-list {
    margin-top: -0.25rem;
    background: var(--bg-card);
    border: 0.0625rem solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 9.375rem;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
}

.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    border-bottom: 0.0625rem solid var(--border);
    color: var(--text);
    transition: background 0.15s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: var(--bg);
}

.autocomplete-item strong {
    color: var(--primary-dark);
    margin-right: 0.25rem;
}

.modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 0.0625rem solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.modal-footer button {
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    border: 0.0625rem solid var(--border);
    background: white;
    color: var(--text);
    transition: all 0.15s;
}

.modal-footer button:hover {
    background: var(--bg);
}

.modal-footer .btn-save {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.modal-footer .btn-save:hover {
    background: var(--primary-dark);
}

/* ===== AMBULATORY SHEET BUTTON ===== */
.amb-list-btn {
    width: 100%;
    margin-top: 0.625rem;
    padding: 0.75rem 0.875rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius);
    color: var(--sidebar-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.amb-list-btn:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.1) 100%);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 0.75rem rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

/* Active = outline only, tinted with the theme's accent. Solid-green fill
   was overwhelming and ignored the active theme; an outline plus a tinted
   background is enough cue without the box screaming. */
.amb-list-btn.active {
    background: color-mix(in srgb, var(--accent) 12%, var(--bg-card));
    border-color: var(--accent);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.amb-list-btn.active:hover {
    background: color-mix(in srgb, var(--accent) 18%, var(--bg-card));
}
.amb-list-btn.active .amb-list-icon { color: var(--accent); }

.amb-list-icon {
    font-size: 1.125rem;
}

.amb-list-text {
    flex: 1;
    text-align: left;
}

/* Hide amb list button text when sidebar is collapsed */
.sidebar.collapsed .amb-list-btn {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
}

.sidebar.collapsed .amb-list-text {
    display: none;
}

.sidebar.collapsed .amb-list-icon {
    margin: 0;
}

/* ===== PATIENT RECORDS BUTTON ===== */
.patient-records-btn {
    background: linear-gradient(135deg, #4a6741 0%, #2d4a28 100%) !important;
    border-color: rgba(74, 103, 65, 0.3) !important;
}

.patient-records-btn:hover {
    background: linear-gradient(135deg, #5a7a50 0%, #3d5a38 100%) !important;
    transform: translateY(-0.0625rem);
}

/* ===== PATIENT MODAL OVERLAY ===== */
.patient-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.patient-modal-overlay.visible {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== PATIENT SEARCH BOX ===== */
.patient-search-box {
    width: min(95vw, 42rem);
    max-height: 85vh;
    background: var(--bg-card);
    border-radius: 1rem;
    box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(1.5rem); }
    to { opacity: 1; transform: translateY(0); }
}

.patient-search-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    /* Flat accent — theme overrides --accent-from for the brand hue. */
    background: var(--accent-from);
    color: white;
}

.patient-search-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.patient-search-input-wrap {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.patient-search-input-wrap input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg);
    color: var(--text);
}

.patient-search-input-wrap input:focus {
    border-color: #4a6741;
    box-shadow: 0 0 0 3px rgba(74, 103, 65, 0.12);
}

.patient-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1.5rem;
    max-height: 55vh;
    position: relative;
}

.patient-search-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 2.5rem 1rem;
}

/* ===== PATIENT CARDS ===== */
.patient-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
}

.patient-card:hover {
    border-color: #4a6741;
    background: #f0f7ee;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.patient-card-main {
    flex: 1;
    min-width: 0;
}

.patient-card-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.patient-card-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.patient-egn {
    font-family: 'JetBrains Mono', monospace;
    background: rgba(74, 103, 65, 0.1);
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
    font-weight: 500;
}

.patient-card-right {
    text-align: right;
    flex-shrink: 0;
    margin-left: 1rem;
}

.patient-card-visits {
    font-size: 1.1rem;
    font-weight: 700;
    color: #4a6741;
}

.patient-card-visits small {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-muted);
}

.patient-card-lastseen {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

/* ===== PATIENT PROFILE BOX ===== */
.patient-profile-box {
    width: min(95vw, 56rem);
    max-height: 90vh;
    background: var(--bg-card);
    border-radius: 1rem;
    box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.25s ease;
}

.patient-profile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.patient-back-btn {
    background: none;
    border: 1px solid var(--border);
    padding: 0.4rem 0.875rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.patient-back-btn:hover {
    background: var(--bg-card);
    border-color: var(--border-hover);
}

.patient-profile-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* ===== PATIENT PROFILE HEADER ===== */
.patient-profile-header {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
    padding-bottom: 1rem;
    margin-bottom: 0.75rem;
}

.patient-profile-avatar {
    font-size: 3rem;
    line-height: 1;
    flex-shrink: 0;
    width: 4rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: 50%;
    border: 2px solid var(--border);
}

.patient-profile-info {
    flex: 1;
    min-width: 0;
}

.patient-profile-info h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 0.375rem 0;
    color: var(--text);
}

.patient-profile-details {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.patient-profile-details strong {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text);
}

.patient-header-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 0.25rem 0 0.5rem 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.55rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge-insurance { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.badge-debt      { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.badge-clear     { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.badge-neutral   { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }

/* Allergy banner uses --warning so it visually pairs with the deferred-review
   warning toast; previous Tailwind amber clashed in dark-pro. */
.patient-allergy {
    margin-top: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--warning-bg);
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    color: var(--warning);
    font-weight: 500;
}

/* "Important note" pill must always read as destructive, in any theme — token-driven. */
.patient-important {
    margin-top: 0.375rem;
    padding: 0.4rem 0.75rem;
    background: var(--danger-bg);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    color: var(--danger-hover);
    font-weight: 500;
}

.patient-profile-stats {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.patient-profile-stats .stat {
    text-align: center;
    padding: 0.5rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex: 1;
    min-width: 5rem;
}

.patient-profile-stats .stat-value {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #4a6741;
}

.patient-profile-stats .stat-label {
    font-size: 0.625rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03rem;
    font-weight: 600;
    margin-top: 0.125rem;
}

/* ===== PATIENT PROFILE SECTIONS ===== */
.patient-profile-section {
    margin-bottom: 1.5rem;
}

.patient-profile-section h3 {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.75rem;
}

/* ===== TEETH GRID ===== */
.teeth-grid {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0.1875rem;
    margin-bottom: 0.5rem;
}

.tooth-cell {
    width: 2.5rem;
    height: 2.5rem;
    text-align: center;
    vertical-align: middle;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    position: relative;
    cursor: default;
    transition: all 0.15s;
}

.tooth-cell:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.tooth-cell.tooth-has-status {
    background: #e6f3e6;
    border-color: #86c486;
}

.tooth-num {
    font-size: 0.5625rem;
    color: var(--text-muted);
    font-weight: 600;
}

.tooth-code {
    font-size: 0.75rem;
    font-weight: 700;
    color: #4a6741;
    line-height: 1;
}

.teeth-divider {
    width: 0.5rem;
    border: none !important;
    background: transparent !important;
}

.teeth-legend {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.6875rem;
    color: var(--text-muted);
    padding: 0.5rem 0;
}

.teeth-legend b {
    color: #4a6741;
}

/* ===== TREATMENT HISTORY ===== */
.patient-treatments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.patient-treatments-header h3 {
    margin: 0;
}

.patient-treatments-filters {
    display: flex;
    gap: 0.5rem;
}

.patient-treatments-filters select {
    padding: 0.375rem 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.75rem;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    outline: none;
}

.patient-treatments-filters select:focus {
    border-color: #4a6741;
}

.treatments-timeline {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.treatments-date-group {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.treatments-date-header {
    padding: 0.5rem 0.875rem;
    background: var(--bg);
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.treatment-row {
    padding: 0.5rem 0.875rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    transition: background 0.1s;
}

.treatment-row:last-child {
    border-bottom: none;
}

.treatment-row:hover {
    background: var(--bg);
}

.treatment-main {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.treatment-desc {
    font-size: 0.8125rem;
    color: var(--text);
    flex: 1;
    line-height: 1.4;
}

.treatment-tooth {
    font-size: 0.75rem;
    font-weight: 600;
    color: #4a6741;
    background: #e6f3e6;
    padding: 0.1rem 0.375rem;
    border-radius: 0.25rem;
    flex-shrink: 0;
}

.treatment-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.treatment-price {
    font-weight: 600;
    color: #4a6741;
}

.treatment-insurance {
    background: #dbeafe;
    color: #1e40af;
    padding: 0.05rem 0.35rem;
    border-radius: 0.25rem;
    font-weight: 600;
    font-size: 0.625rem;
}

/* ===== PAGINATION ===== */
.treatments-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.875rem;
    margin-top: 0.5rem;
}

.treatments-pagination button {
    padding: 0.375rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.15s;
}

.treatments-pagination button:hover {
    background: var(--bg);
    border-color: #4a6741;
    color: #4a6741;
}

.pagination-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ===== LOAD PATIENT BUTTON ===== */
.patient-profile-actions {
    display: flex;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}

.btn-load-patient {
    flex: 1;
    padding: 0.8rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 700;
    background: var(--accent-from);
    color: white;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.btn-load-patient:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    filter: brightness(1.08);
}

.btn-load-patient.secondary {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    box-shadow: none;
    flex: 0;
    font-weight: 500;
    font-size: 0.8125rem;
}

.btn-load-patient.secondary:hover {
    background: var(--border);
    transform: none;
}

.btn-load-patient.danger {
    /* Replaced inline hex with --danger so the destructive-action red
       follows the active theme (was hard-locked to terracotta-red). */
    background: var(--bg-card);
    color: var(--danger);
    border: 1px solid var(--danger);
    box-shadow: none;
    flex: 0;
    font-weight: 500;
    font-size: 0.8125rem;
}

.btn-load-patient.danger:hover {
    background: var(--danger);
    color: var(--bg-card);
    transform: none;
}

/* ===== PATIENT MATCH TOAST ===== */
.patient-match-toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 20000;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--accent-from);
    color: white;
    border-radius: 1rem;
    box-shadow: 0 0.5rem 2rem rgba(0,0,0,0.25);
    animation: toastSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 22rem;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(2rem); }
    to { opacity: 1; transform: translateX(0); }
}

.toast-icon {
    font-size: 1.5rem;
    color: #fcd34d;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04rem;
    opacity: 0.8;
}

.toast-name {
    font-size: 0.9375rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toast-egn {
    font-size: 0.75rem;
    opacity: 0.7;
    font-family: monospace;
}

.toast-view {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.35rem 0.625rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.6875rem;
    font-weight: 600;
    flex-shrink: 0;
    transition: all 0.15s;
}

.toast-view:hover {
    background: rgba(255, 255, 255, 0.35);
}

.toast-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    flex-shrink: 0;
    transition: color 0.15s;
}

.toast-close:hover {
    color: white;
}

/* ===== MODAL CLOSE BUTTON ===== */
.modal-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== PATIENT STATS: DEBT & PAID ===== */
.patient-profile-stats .stat-debt {
    border-color: #fca5a5;
    background: #fef2f2;
}

.patient-profile-stats .stat-debt .stat-value {
    color: #dc2626;
}

.patient-profile-stats .stat-debt .stat-label {
    color: #991b1b;
}

.patient-profile-stats .stat-green {
    border-color: #86efac;
    background: #dcfce7;
}

.patient-profile-stats .stat-green .stat-value {
    color: #16a34a;
}

.patient-profile-stats .stat-green .stat-label {
    color: #166534;
}

/* ===== SETTINGS SIDE PANEL ===== */
.settings-side-panel {
    position: fixed;
    top: 3.25rem;
    right: 0;
    width: 26rem;          /* was 320px — fixed-px didn't scale with html font-size; rem follows */
    max-width: 95vw;
    height: calc(100vh - 3.25rem);
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 890;
    display: flex;
    flex-direction: column;
    box-shadow: -6px 0 32px rgba(0, 0, 0, 0.12);
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s;
    pointer-events: none;
    border-radius: 1rem 0 0 1rem;
}

.settings-side-panel.open {
    transform: translateX(0);
    pointer-events: all;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.16);
}

.settings-side-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    /* Flat header to match the (now-flat) sidebar. */
    background: var(--sidebar-from);
    color: var(--sidebar-text);
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
    border-radius: 1rem 0 0 0;
}

.settings-side-close {
    background: var(--header-pill-bg);
    border: none;
    color: var(--sidebar-text);
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    transition: background 0.15s;
}

.settings-side-close:hover { background: var(--header-pill-hover-bg); }


.settings-side-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.settings-side-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.875rem;
    line-height: 1.5;
}

/* ----- Settings panel reusable building blocks -----
   Extracted from ~150 inline style="" attributes. The aim is single source
   of truth for tap targets (≥40px), Cyrillic uppercase tracking, and section
   dividers — themes can override these once instead of per-input. */
.settings-section { border-top: 1px solid var(--border); padding: 1rem 0; }
.settings-section:first-child { border-top: 0; }
.settings-section-title {
    font-weight: 600; color: var(--accent-text); margin-bottom: 0.6rem;
    display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem;
    /* Cyrillic uppercase needs slightly more tracking than Latin. */
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.settings-label {
    font-size: 0.78rem; display: flex; flex-direction: column; gap: 0.2rem;
    color: var(--text-secondary);
}
/* Field with a tiny label above the input — used for clinic admin form so
   each input is no longer just an unlabeled placeholder. */
.settings-field { display: flex; flex-direction: column; gap: 0.2rem; }
.settings-field-label {
    font-size: 0.72rem; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.settings-input {
    width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg-card); color: var(--text);
    font-family: inherit; font-size: 0.85rem;
    /* Glove tap-target: 2.5rem ≈ 40px at default 16px root font-size. */
    min-height: 2.5rem;
}
.settings-input--mono { font-family: 'Courier New', monospace; font-size: 0.78rem; }
.settings-button {
    width: 100%; padding: 0.6rem; border: none; border-radius: var(--radius);
    background: var(--accent-from); color: #fff; cursor: pointer; font-family: inherit;
    font-size: 0.85rem; min-height: 2.5rem; font-weight: 600;
}
.settings-button:hover { filter: brightness(1.05); }
.settings-button--ghost {
    background: transparent; color: var(--text);
    border: 1px solid var(--border);
}
.settings-button--danger {
    background: transparent; color: var(--danger);
    border: 1px solid var(--danger);
}
.settings-row { display: grid; gap: 0.5rem; }
.settings-row--2 { grid-template-columns: 1fr 1fr; }
.settings-row--3 { grid-template-columns: 1fr 1fr 2fr; }
.settings-accordion {
    border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 0.5rem; overflow: hidden; background: var(--bg-card);
}
.settings-accordion summary {
    padding: 0.7rem 0.8rem; cursor: pointer; list-style: none;
    display: flex; align-items: center; justify-content: space-between;
    background: var(--bg-subtle, var(--bg)); font-weight: 600; font-size: 0.82rem;
    min-height: 2.5rem; user-select: none;
}
.settings-accordion summary::-webkit-details-marker { display: none; }
.settings-accordion summary .chev {
    transition: transform 0.18s; width: 0.85rem; height: 0.85rem;
}
.settings-accordion[open] summary .chev { transform: rotate(90deg); }
.settings-accordion-body { padding: 0.75rem; }


.btn-settings-save {
    flex: 1;
    padding: 0.6rem 1rem;
    border: none;
    border-radius: var(--radius);
    background: var(--btn-primary-from);
    color: white;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s, transform 0.15s, box-shadow 0.15s;
}

.btn-settings-save:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-settings-reset {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
}

.btn-settings-reset:hover { background: var(--border); }

/* Commands Editor */
.command-row {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 0.75rem;
}

.command-row label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
}

.command-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.8125rem;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color 0.15s;
}

.command-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(212, 160, 154, 0.15);
}

/* ===== TOOLBAR ACTIONS (top-right icon buttons) ===== */
.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    /* Was flex-shrink:0 — buttons fell off the right edge at laptop widths
       (1366/1440px). Wrap onto a second row instead so Бележки/Доктор/⚙
       remain reachable. */
    flex-wrap: wrap;
    justify-content: flex-end;
    flex-shrink: 1;
    margin-left: auto;
}

/* DEMO-mode badge — shown in the toolbar when DEMO_MODE=1, prevents
   accidentally screencasting demo data as if it were a real clinic. */
.demo-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--warning-bg);
    color: var(--warning);
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border: 1px solid var(--warning);
}
/* Floating variant — bottom-right of viewport, doesn't compete with the
   toolbar buttons. Used when a global demo-mode badge is needed. */
.demo-pill--floating {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 9990;
    box-shadow: var(--shadow-sm);
    pointer-events: none;
}
.demo-pill--floating[hidden] { display: none; }

.toolbar-icon-btn[hidden] { display: none !important; }
.toolbar-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.18s;
    white-space: nowrap;
    /* Was height: 2.1rem (~42px @20px root). Bumped to 2.5rem min so a
       gloved fingertip lands reliably; min-width matches for icon-only. */
    min-height: 2.5rem;
    min-width: 2.5rem;
}

.toolbar-icon-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.toolbar-icon-btn span {
    font-size: 0.8125rem;
}

/* Картотека / НЗИС default style — same outline as the other toolbar
   buttons, NOT filled by default. Two adjacent solid-green buttons before
   anything was clicked made them look pre-selected. The filled state is
   reserved for `.is-active` when the matching panel is open. */
.toolbar-icon-btn--green,
.toolbar-icon-btn--blue {
    background: var(--bg-card);
    color: var(--text-secondary);
    border-color: var(--border);
}
.toolbar-icon-btn--green:hover,
.toolbar-icon-btn--blue:hover {
    background: var(--primary-light, var(--bg));
    border-color: var(--accent, var(--primary));
    color: var(--accent, var(--primary-dark));
}
.toolbar-icon-btn--green.is-active,
.toolbar-icon-btn--blue.is-active,
.toolbar-icon-btn.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}
.toolbar-icon-btn--green.is-active:hover,
.toolbar-icon-btn--blue.is-active:hover,
.toolbar-icon-btn.is-active:hover {
    background: var(--accent);
    filter: brightness(1.08);
    color: white;
}

/* Logout — solid danger-tinted, no gradient, so it reads as "destructive
   session action" rather than a normal navigation pill. Sits next to Settings. */
.toolbar-icon-btn--danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.toolbar-icon-btn--danger:hover {
    background: var(--danger-bg, rgba(239,68,68,0.10));
    border-color: var(--danger);
    color: var(--danger-hover, var(--danger));
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ===== НЗИС panel — tabs, badges ===== */
.nhis-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 1rem 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.nhis-tab {
    padding: 0.55rem 0.85rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.nhis-tab:hover { color: var(--text); }
.nhis-tab.active {
    color: var(--accent-text, #5c3d1e);
    border-bottom-color: var(--accent-from, #5c3d1e);
    font-weight: 600;
}
.nhis-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}
.nhis-tab-pane[hidden] { display: none; }
.nhis-section-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent-text, #5c3d1e);
    margin: 0 0 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.nhis-action-btn {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius, 8px);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}
.nhis-action-btn:hover {
    border-color: var(--accent-from, #5c3d1e);
    background: var(--surface);
}
.nhis-action-btn:disabled,
.nhis-action-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    background: var(--bg-card);
    color: var(--text-muted);
}
.nhis-action-btn:disabled:hover,
.nhis-action-btn[disabled]:hover {
    border-color: var(--border);
    background: var(--bg-card);
}
/* Recolour the primary submit button from corporate blue to the accent
   teal — kills the third unrelated colour family in the toolbar. */
.nhis-action-btn--primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: 600;
}
.nhis-action-btn--primary:hover {
    filter: brightness(1.08);
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.nhis-action-btn--danger {
    color: var(--danger, #ef4444);
    border-color: rgba(239, 68, 68, 0.3);
}
.nhis-action-btn--danger:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: var(--danger, #ef4444);
    color: var(--danger, #ef4444);
}
.nhis-status {
    font-size: 0.8rem;
    margin: 0.75rem 0 0;
    min-height: 1.1em;
}
.nhis-placeholder {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.85rem;
    text-align: center;
    padding: 2rem 1rem;
}
.nrn-badge {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.nrn-badge--empty {
    background: var(--surface, #f3f4f6);
    color: var(--text-secondary, #6b7280);
    border: 1px dashed var(--border, #e5e7eb);
}
.nrn-badge--ok {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}
.insurance-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
}
/* Insurance pill — uses success/danger tokens so dark-pro and clean-medical
   themes don't surface fluorescent Tailwind green/red against their bg. */
.insurance-badge--insured     { background: var(--success-bg); color: var(--success-text); }
.insurance-badge--not-insured { background: var(--danger-bg); color: var(--danger-hover); }

.patient-search-loading {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-size: 0.875rem;
    opacity: 0.5;
    pointer-events: none;
}

/* ===== NOTES PANEL ===== */
.notes-panel {
    position: fixed;
    top: 3.25rem;
    right: 0;
    width: 340px;
    max-width: 92vw;
    height: calc(100vh - 3.25rem);
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 900;
    display: flex;
    flex-direction: column;
    box-shadow: -6px 0 32px rgba(0,0,0,0.12);
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s;
    pointer-events: none;
    border-radius: 1rem 0 0 1rem;
}

.notes-panel.open {
    transform: translateX(0);
    pointer-events: all;
    box-shadow: -8px 0 40px rgba(0,0,0,0.16);
}

.notes-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    /* Matches the now-flat sidebar/settings header. */
    background: var(--sidebar-from);
    color: var(--sidebar-text);
    flex-shrink: 0;
    border-radius: 1rem 0 0 0;
}

.notes-panel-title {
    font-weight: 600;
    font-size: 0.9375rem;
}

.notes-panel-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.notes-clear-btn {
    background: var(--header-pill-bg);
    border: none;
    color: var(--sidebar-text);
    font-size: 0.75rem;
    font-family: inherit;
    padding: 0.3rem 0.7rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background 0.15s;
}

.notes-clear-btn:hover {
    background: var(--header-pill-hover-bg);
}

.notes-close-btn {
    background: var(--header-pill-bg);
    border: none;
    color: var(--sidebar-text);
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    transition: background 0.15s;
}

.notes-close-btn:hover {
    background: var(--header-pill-hover-bg);
}

.notes-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    background: var(--bg);
}

.notes-placeholder {
    color: var(--text-muted);
    font-size: 0.8125rem;
    text-align: center;
    margin-top: 2rem;
    line-height: 1.6;
}

/* News modal — centered dialog (not a sidebar) because the content
   surface is substantial: multiple sources, sort controls, dates, item
   rows. Backdrop dims everything else and closes the modal on click. */
.news-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 950;
    backdrop-filter: blur(2px);
}
.news-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(900px, 92vw);
    height: min(82vh, 900px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    z-index: 960;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
    overflow: hidden;
}
/* The explicit display:flex above overrides the user-agent
   `[hidden] { display: none }` default, so the bare `hidden` attribute
   doesn't hide the modal on its own. These rules restore it. */
.news-modal[hidden],
.news-backdrop[hidden] {
    display: none !important;
}
.news-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.1rem;
    background: var(--sidebar-from, var(--bg-card));
    color: var(--sidebar-text, var(--text));
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.news-modal-title {
    font-weight: 600;
    font-size: 1rem;
    display: inline-flex; align-items: center; gap: 0.5rem;
}
.news-modal-actions { display: flex; align-items: center; gap: 0.35rem; }
.news-modal-iconbtn {
    background: transparent; border: none; cursor: pointer;
    color: var(--sidebar-text, var(--text));
    width: 2rem; height: 2rem;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 0.4rem;
    transition: background 0.15s ease;
}
.news-modal-iconbtn svg { width: 1.05rem; height: 1.05rem; }
.news-modal-iconbtn:hover { background: rgba(255, 255, 255, 0.12); }
.news-modal-close { font-size: 1.35rem; font-weight: 500; }
.news-modal-filters {
    display: flex;
    gap: 0.85rem;
    align-items: flex-end;
    padding: 0.65rem 1.1rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.news-filter { display: flex; flex-direction: column; gap: 0.25rem; min-width: 8rem; }
.news-filter--push { margin-left: auto; }
.news-filter label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
}
.news-modal-body {
    flex: 1;
    overflow-y: auto;
    background: var(--bg);
    padding: 0.85rem 1rem 1rem;
}

/* News bell + count badge — escalates color by unread count.
   Driven by `data-level="0|1|2|3"` set in JS: 0=hidden, 1=grey,
   2=blue (2-4 items), 3=orange (5+). */
.news-badge {
    position: absolute;
    top: -0.25rem;
    right: -0.25rem;
    min-width: 1.05rem;
    height: 1.05rem;
    padding: 0 0.32rem;
    border-radius: 999px;
    background: var(--text-muted);
    color: white;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1.05rem;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bg, #fff);
    pointer-events: none;
    transition: background 0.2s ease;
}
.news-badge[data-level="2"] { background: #2563eb; }
.news-badge[data-level="3"] { background: #f59e0b; }

.news-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.45rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    transition: background 0.15s ease;
}
.news-item:hover { background: var(--bg-card-hover, var(--bg-card)); border-color: var(--accent, #2563eb); }
.news-item.unread { border-left: 3px solid #2563eb; }
.news-item-body { flex: 1; cursor: pointer; min-width: 0; }
.news-item-fav {
    flex-shrink: 0;
    width: 1.75rem; height: 1.75rem;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 0.35rem;
    padding: 0;
    transition: color 0.15s ease, background 0.15s ease;
}
.news-item-fav svg { width: 1.05rem; height: 1.05rem; }
.news-item-fav:hover { background: rgba(0, 0, 0, 0.05); color: #f59e0b; }
.news-item-fav.on { color: #f59e0b; }
.news-item-source {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}
.news-item-title { font-weight: 600; font-size: 0.875rem; line-height: 1.3; color: var(--text); }
.news-item-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.35rem; }

.note-item {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0.5rem;
    transition: background 0.15s;
}
.note-item:hover { background: rgba(0,0,0,0.02); }

.note-check {
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.125rem;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.note-body { flex: 1; min-width: 0; }

.note-text {
    font-size: 0.9375rem;
    color: var(--text);
    line-height: 1.4;
    word-wrap: break-word;
}

.note-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.note-item--done .note-text {
    text-decoration: line-through;
    color: var(--text-muted);
}

.note-del {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.25rem;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.note-item:hover .note-del { opacity: 1; }
.note-del:hover { color: #dc2626; }

/* Action buttons (Settings → Лекари + patient documents/transcripts panels) —
   bumped from 0.75rem → 0.85rem font-size and from 0.25rem padding → 0.4rem
   so they're tappable on a kiosk and don't feel like microscopic chrome. */
.doc-action-btn {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem 0.85rem;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-height: 2rem;
}
.doc-action-btn:hover { background: var(--primary-50); border-color: var(--primary); }
.doc-action-btn--danger { color: var(--danger); border-color: var(--danger); }
.doc-action-btn--danger:hover { background: var(--danger-bg); color: var(--danger-hover); }

/* ===== INLINE DOCUMENT FIELD EDITING ===== */
.docx-inline-field {
    display: inline;
    cursor: pointer;
    border-radius: 2px;
    padding: 0 2px;
    transition: background 0.15s, outline 0.15s;
    position: relative;
}

/* Default filled field = AI fill (warm wheat). JS toggles .human-edit / .nhis-confirmed
   for the other two states so origin is visually obvious without reading the field. */
.docx-inline-field.filled {
    background: var(--ai-fill);
    border-bottom: 1.5px solid var(--ai-fill-border);
    color: inherit;
    font-weight: inherit;
}

.docx-inline-field.filled:hover {
    filter: brightness(0.96);
    outline: 1px solid var(--ai-fill-border);
}

.docx-inline-field.filled.human-edit {
    background: var(--human-fill);
    border-bottom-color: var(--human-fill-border);
}

.docx-inline-field.filled.human-edit:hover {
    outline: 1px solid var(--human-fill-border);
}

.docx-inline-field.filled.nhis-confirmed {
    background: var(--nhis-confirmed);
    border-bottom-color: var(--nhis-confirmed-border);
}

/* Mandatory NHIS-confirmed marker — Lucide "check" rendered via mask-image so the
   tick inherits --nhis-confirmed-border under any theme override (no inline SVG
   in CSS content possible without burning a hex into a data: URL — but mask
   recolours cleanly via background). Per persona: no emoji glyphs. */
.docx-inline-field.filled.nhis-confirmed::before {
    content: '';
    display: inline-block;
    width: 0.95em;
    height: 0.95em;
    margin-right: 0.25em;
    vertical-align: -0.15em;
    background-color: var(--nhis-confirmed-border);
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>") center/contain no-repeat;
            mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>") center/contain no-repeat;
}

/* Empty placeholder — context-aware sizing.
   Standalone fields (name, EGN, free-text headers — anything NOT inside a table
   cell) need a ≥40px-wide tap target so a gloved fingertip lands reliably.
   Table-cell fields (oral status grid, amb-list procedure rows) must stay
   compact, otherwise a 7-row × 6-col procedures table won't fit the page. */
.docx-inline-field.empty {
    display: inline-block;
    min-width: 2.5rem;     /* ~40px @ 16px root, glove-finger friendly */
    min-height: 1.4em;
    padding: 0 0.4rem;
    border-bottom: 1.5px dashed var(--border-strong);
    vertical-align: baseline;
}

/* Inside table cells, revert to the original tight geometry so dense grids
   (oral status, amb-list procedure rows) still fit the printed page width. */
td .docx-inline-field.empty {
    min-width: 1.5rem;
    min-height: 1em;
    padding: 0;
}

.docx-inline-field.empty:hover {
    background: var(--primary-50);
    border-bottom-color: var(--primary);
}

.docx-inline-field.empty::after {
    content: '+';
    font-size: 0.85em;
    color: var(--text-muted);
    vertical-align: super;
}

/* Smaller "+" inside table cells — matches the tighter target. */
td .docx-inline-field.empty::after {
    font-size: 0.65em;
}

.docx-inline-field.empty:hover::after {
    color: var(--primary);
}

/* Price widget empty state */
.price-widget-empty-row {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.25rem 0;
    text-align: center;
}

/* ===== SMOOTH PATIENT SEARCH (no jumping) ===== */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(0.5rem); }
    to { opacity: 1; transform: translateY(0); }
}

/* ================================================================
   THEMES — applied via data-theme attribute on <body>
   Default (no attribute) = Warm Dental
   ================================================================ */

/* ── CLEAN MEDICAL ─────────────────────────────────────────────── */
[data-theme="clean-medical"] {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-50: #dbeafe;
    --secondary: #3b82f6;
    --secondary-hover: #2563eb;
    --secondary-light: #eff6ff;
    --bg: #f0f6ff;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    --danger: #e11d48;
    --sidebar-from: #1a4080;
    --sidebar-to: #0f2a5a;
    --sidebar-text: #ffffff;
    --header-pill-bg: rgba(255,255,255,0.15);
    --header-pill-hover-bg: rgba(255,255,255,0.28);
    --accent: #1a4080;
    --accent-from: #1a6fa8;
    --accent-to: #0f4070;
    --accent-light: #eff6ff;
    --accent-border: rgba(59, 130, 246, 0.35);
    --accent-text: #1d4ed8;
    --btn-primary-from: #2563eb;
    --btn-primary-to: #1d4ed8;
}

/* ── DARK PRO ───────────────────────────────────────────────────── */
[data-theme="dark-pro"] {
    --primary: #58a6ff;
    --primary-hover: #79b8ff;
    --primary-dark: #388bfd;
    --primary-light: #1c2d3f;
    --primary-50: #1c2d3f;
    --secondary: #58a6ff;
    --secondary-hover: #79b8ff;
    --secondary-light: #1c2d3f;
    --bg: #0d1117;
    --bg-card: #161b22;
    --text: #c9d1d9;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border: #30363d;
    --border-hover: #484f58;
    --danger: #f85149;
    --danger-hover: #ff7b72;
    --success: #3fb950;
    --success-bg: #1b3a23;
    --success-border: #2ea043;
    --success-text: #3fb950;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
    --shadow: 0 1px 4px rgba(0,0,0,0.6);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.6);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.7);
    --sidebar-from: #010409;
    --sidebar-to: #0d1117;
    --sidebar-text: #e6edf3;
    --header-pill-bg: rgba(255,255,255,0.12);
    --header-pill-hover-bg: rgba(255,255,255,0.22);
    --accent: #3fb950;
    --accent-from: #238636;
    --accent-to: #196127;
    --accent-light: #1b3a23;
    --accent-border: rgba(63, 185, 80, 0.3);
    --accent-text: #3fb950;
    --btn-primary-from: #238636;
    --btn-primary-to: #196127;
}

[data-theme="dark-pro"] body {
    background: #0d1117;
    color: #c9d1d9;
}

[data-theme="dark-pro"] .modal-overlay {
    background: rgba(0,0,0,0.7);
}

[data-theme="dark-pro"] .toolbar {
    background: #161b22;
    border-bottom-color: #30363d;
}

[data-theme="dark-pro"] .sidebar {
    background: #0d1117;
    border-right-color: #30363d;
}

[data-theme="dark-pro"] .sidebar-controls {
    background: #010409;
}

[data-theme="dark-pro"] .preview-area {
    background: #010409;
}

/* ── GLASS MINIMAL ─────────────────────────────────────────────── */
[data-theme="glass-minimal"] {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --primary-50: #e0e7ff;
    --secondary: #6366f1;
    --secondary-hover: #4f46e5;
    --secondary-light: #eef2ff;
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-hover: #c7d2fe;
    --danger: #e11d48;
    --radius: 0.75rem;
    --radius-lg: 1.125rem;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.1);
    --sidebar-from: #f8fafc;
    --sidebar-to: #eef2ff;
    --sidebar-text: #1e1b4b;
    --sidebar-text-muted: rgba(30,27,75,0.5);
    --header-pill-bg: rgba(99,102,241,0.1);
    --header-pill-hover-bg: rgba(99,102,241,0.2);
    --accent: #6366f1;
    --accent-from: #6366f1;
    --accent-to: #4f46e5;
    --accent-light: #eef2ff;
    --accent-border: rgba(99, 102, 241, 0.3);
    --accent-text: #4338ca;
    --btn-primary-from: #6366f1;
    --btn-primary-to: #4f46e5;
}

[data-theme="glass-minimal"] .sidebar-header img {
    filter: brightness(0) opacity(0.6) !important;
}

[data-theme="glass-minimal"] .sidebar-header h2,
[data-theme="glass-minimal"] .sidebar-header .subtitle,
[data-theme="glass-minimal"] .selected-counter {
    color: var(--sidebar-text);
}

[data-theme="glass-minimal"] .selected-counter {
    background: rgba(99,102,241,0.1);
}

[data-theme="glass-minimal"] .notes-panel,
[data-theme="glass-minimal"] .settings-side-panel,
[data-theme="glass-minimal"] .modal-box,
[data-theme="glass-minimal"] .patient-search-box,
[data-theme="glass-minimal"] .patient-profile-box {
    box-shadow: 0 8px 40px rgba(99,102,241,0.12), 0 2px 8px rgba(0,0,0,0.06);
}

/* ── WARM WALNUT (dark, brand-warm) ───────────────────────────── */
[data-theme="warm-walnut"] {
    --primary: #d68a5c;
    --primary-hover: #e29c70;
    --primary-dark: #bd744a;
    --primary-pressed: #bd744a;
    --primary-light: #3a2a1f;
    --primary-50: #2f2218;
    --secondary: #d68a5c;
    --secondary-hover: #e29c70;
    --secondary-light: #3a2a1f;
    --bg: #1c1612;
    --bg-card: #26201b;
    --bg-subtle: #2f2823;
    --text: #f4ead9;
    --text-secondary: #d6c4a8;
    --text-muted: #a08d72;
    --border: #3a3128;
    --border-hover: #544638;
    --border-strong: #544638;
    --danger: #e57364;
    --danger-hover: #ed8e80;
    --danger-bg: #3d201c;
    --warning: #e8a64a;
    --warning-bg: #3a2a14;
    --success: #5fb583;
    --success-bg: #1d3025;
    --success-border: #5fb583;
    --success-text: #5fb583;
    --info: #6aa3d6;
    --info-bg: #1d2a3a;
    --ai-fill: #3d3220;
    --ai-fill-border: #d6a854;
    --human-fill: #243632;
    --human-fill-border: #7ab5a5;
    --nhis-confirmed: #1d3025;
    --nhis-confirmed-border: #5fb583;
    --focus-ring: rgba(214, 138, 92, 0.45);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
    --shadow: 0 1px 4px rgba(0,0,0,0.6);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.6);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.7);
    --sidebar-from: #2a1f17;
    --sidebar-to: #1c1612;
    --sidebar-text: #f4ead9;
    --sidebar-text-muted: rgba(244,234,217,0.75);
    --header-pill-bg: rgba(244,234,217,0.10);
    --header-pill-hover-bg: rgba(244,234,217,0.20);
    --accent: #7ab5a5;
    --accent-hover: #90c7b7;
    --accent-from: #7ab5a5;
    --accent-to: #5a9484;
    --accent-light: #243632;
    --accent-border: rgba(122,181,165,0.4);
    --accent-text: #7ab5a5;
    --btn-primary-from: #d68a5c;
    --btn-primary-to: #bd744a;
}

[data-theme="warm-walnut"] body {
    background: var(--bg);
    color: var(--text);
}

[data-theme="warm-walnut"] .modal-overlay {
    background: rgba(0,0,0,0.7);
}

[data-theme="warm-walnut"] .toolbar {
    background: var(--bg-card);
    border-bottom-color: var(--border);
}

[data-theme="warm-walnut"] .sidebar {
    background: var(--bg);
    border-right-color: var(--border);
}

[data-theme="warm-walnut"] .preview-area {
    background: #100c0a;
}

/* ── CLINICAL TEAL (cool light alternative) ───────────────────── */
[data-theme="clinical-teal"] {
    --primary: #2c6e7a;
    --primary-hover: #1f5560;
    --primary-dark: #163e47;
    --primary-pressed: #163e47;
    --primary-light: #d8eaee;
    --primary-50: #ecf4f6;
    --secondary: #2c6e7a;
    --secondary-hover: #1f5560;
    --secondary-light: #d8eaee;
    --bg: #f4f8f9;
    --bg-card: #ffffff;
    --bg-subtle: #e7eef0;
    --text: #15262a;
    --text-secondary: #34555c;
    --text-muted: #5a7a82;
    --border: #cfdee2;
    --border-hover: #a8c1c8;
    --border-strong: #a8c1c8;
    --danger: #c0392b;
    --danger-hover: #9c2d22;
    --danger-bg: #fbe7e3;
    --warning: #b8842a;
    --warning-bg: #f7ecd3;
    --success: #2f8f5e;
    --success-bg: #dff1e5;
    --success-border: #2f8f5e;
    --success-text: #1d6b46;
    --info: #2b6cb0;
    --info-bg: #e0ebf6;
    --ai-fill: #f3e8c8;
    --ai-fill-border: #b8842a;
    --human-fill: #d9e8eb;
    --human-fill-border: #2c6e7a;
    --nhis-confirmed: #c8e0d2;
    --nhis-confirmed-border: #2f8f5e;
    --focus-ring: rgba(44, 110, 122, 0.35);
    --sidebar-from: #2c6e7a;
    --sidebar-to: #163e47;
    --sidebar-text: #ffffff;
    --sidebar-text-muted: rgba(255,255,255,0.85);
    --header-pill-bg: rgba(255,255,255,0.15);
    --header-pill-hover-bg: rgba(255,255,255,0.28);
    --accent: #b8842a;
    --accent-hover: #9c6e1e;
    --accent-from: #b8842a;
    --accent-to: #9c6e1e;
    --accent-light: #f7ecd3;
    --accent-border: rgba(184,132,42,0.4);
    --accent-text: #9c6e1e;
    --btn-primary-from: #2c6e7a;
    --btn-primary-to: #1f5560;
}

/* ── ALL THEMES: treatments panel ─────────────────────────────── */
.treatmentsPanel.notes-panel .notes-panel-header {
    border-radius: 1rem 0 0 0;
}


/* Price widget empty state */
.price-widget-empty-row {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.25rem 0;
    text-align: center;
}

/* ===== SMOOTH PATIENT SEARCH (no jumping) ===== */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(0.5rem); }
    to { opacity: 1; transform: translateY(0); }
}


/* ===== RESPONSIVE: tablet + small-laptop sizing =====
   The chair-side product targets desktop + iPad-landscape; phones are out of
   scope. Three breakpoints cover what we care about:
   - ≤1280px (small laptops / iPad landscape): tighter toolbar buttons so all
     fit one row, doctor name compact, tighter sidebar spacing.
   - ≤1024px (iPad landscape): sidebar collapses to icon strip.
   -  ≤780px  (iPad portrait): toolbar wraps cleanly, modals fill width. */

@media (max-width: 1280px) {
    .toolbar-icon-btn { padding: 0.4rem 0.7rem; font-size: 0.78rem; }
    .toolbar-icon-btn span { font-size: 0.78rem; }
    .toolbar { padding: 0.5rem 0.85rem; gap: 0.5rem; }
    /* Doctor's full name eats a lot of horizontal space at this width.
       Show "Лекар" + initials if the chip would overflow. */
    #switchDoctorBtn span { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 1024px) {
    .sidebar:not(.collapsed) {
        width: 4.5rem;
        min-width: 4.5rem;
    }
    .sidebar:not(.collapsed) .sidebar-header h2,
    .sidebar:not(.collapsed) .sidebar-header .subtitle,
    .sidebar:not(.collapsed) .sidebar-header .selected-counter,
    .sidebar:not(.collapsed) .sidebar-header img,
    .sidebar:not(.collapsed) .file-list {
        display: none;
    }
    /* Bottom-sidebar buttons (Амб. лист, Старт Запис, Запази всички,
       Нулиране на попълнените) need their text labels hidden too —
       otherwise the text bleeds outside the 4.5rem column. */
    .sidebar:not(.collapsed) .amb-list-text,
    .sidebar:not(.collapsed) .selected-counter,
    .sidebar:not(.collapsed) .btn-text {
        display: none;
    }
    .sidebar:not(.collapsed) .btn,
    .sidebar:not(.collapsed) .amb-list-btn {
        justify-content: center;
        padding: 0.6rem 0;
    }
    .sidebar:not(.collapsed) .sidebar-controls,
    .sidebar:not(.collapsed) .sidebar-header {
        padding-left: 0.4rem;
        padding-right: 0.4rem;
    }
    /* Hide button labels in toolbar to fit; icons + tooltips keep meaning. */
    .toolbar-icon-btn span { display: none; }
    .toolbar-icon-btn { padding: 0.45rem 0.55rem; min-width: 2.4rem; }
}

@media (max-width: 780px) {
    /* iPad portrait. Modals should grab full width; preview must scroll. */
    .transcript-review-card,
    .modal-card,
    .patient-search-modal-content {
        width: 96vw !important;
        max-width: 96vw !important;
    }
    .preview-area { padding: 0.75rem 0.5rem; }
    .toolbar { gap: 0.35rem; padding: 0.5rem; }
    .toolbar-icon-btn { padding: 0.4rem 0.5rem; min-height: 2.25rem; min-width: 2.25rem; }
    .price-pill { font-size: 0.78rem; }
}
