/* OP Patient Tasks - Styling with Theme Support */

/* Import fonts */
@import url('https://fonts.googleapis.com/css2?family=Italiana&family=Inter:wght@400;500;600;700&family=Instrument+Sans:wght@400;500;600;700&display=swap');

/* ── Design tokens ───────────────────────────────────────────────── */
:root {
    /* Palette */
    --cream: #FAF7F2;
    --soft-beige: #F5EDE3;
    --warm-sand: #E0D5C7;
    --golden-tan: #B0A08C;
    --deep-walnut: #5A3520;
    --near-black: #1A1208;
    --medium-forest: #4A7C59;
    --dark-forest: #3B6548;

    /* Border radii */
    --radius-xs:   4px;   /* badge, pill tag */
    --radius-sm:   6px;   /* small button, input tag */
    --radius-md:   8px;   /* input, small card */
    --radius-lg:  10px;   /* panel card */
    --radius-xl:  12px;   /* modal, large card */
    --radius-pill: 20px;  /* pill badge */

    /* Shadows */
    --shadow-card: 0 1px 3px rgba(90,53,32,0.07), 0 4px 14px rgba(90,53,32,0.05);
    --shadow-md:   0 2px 8px rgba(90,53,32,0.12);
    --shadow-lg:   0 4px 20px rgba(90,53,32,0.14);
}

/* Light Theme (Default) */
body {
    --bg-primary: #FAF7F2;
    --bg-secondary: #F5EDE3;
    --bg-card: #FFFDF9;
    --bg-hover: #F3EDE3;
    --text-primary: #3A2818;
    --text-secondary: #7A6048;
    --text-muted: #A08870;
    --border-color: #E0D5C7;
    --accent-primary: #5A3520;
    --accent-secondary: #4A7C59;
    --accent-tertiary: #3B6548;
    --button-primary: #5A3520;
    --button-primary-hover: #7A5540;
    --button-secondary: #5A3520;
    --button-secondary-hover: #7A5540;
    --button-color: #5A3520;
    --shadow-color: rgba(90, 53, 32, 0.06);
}

/* Dark Theme */
body.dark-theme {
    --bg-primary: #1A1410;
    --bg-secondary: #2A2118;
    --bg-card: #2A2118;
    --bg-hover: #3D3028;
    --text-primary: #F5EDE3;
    --text-secondary: #B0A08C;
    --text-on-card: #F5EDE3;
    --border-color: #3D3028;
    --accent-primary: #B0A08C;
    --accent-secondary: #6B9D7A;
    --accent-tertiary: #4A7C59;
    --button-primary: #4A7C59;
    --button-primary-hover: #6B9D7A;
    --button-secondary: #5A3520;
    --button-secondary-hover: #7A5540;
    --button-color: #6B9D7A;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

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

html {
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ── Type scale ──────────────────────────────────────────────────────
   h1  Page title        — Italiana, 34px, near-black
   h2  Section title     — Inter, 22px, near-black (e.g. "Prospect: MK-12-31")
   h3  Panel header      — Inter, 10px, 800, uppercase, tracked (e.g. "DAILY TASKS")
   h4  Sub-label         — Inter, 12px, 700, near-black
   h5  Micro-label       — Inter, 10px, 700, muted, uppercase, tracked
   ─────────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    color: var(--near-black);
    line-height: 1.2;
}

h1 {
    font-family: 'Italiana', serif;
    font-size: 34px;
    font-weight: 400;
    color: var(--near-black);
}

h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--near-black);
}

h3 {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--near-black);
}

h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--near-black);
}

h5 {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ── Body text ───────────────────────────────────────────────────── */
p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0 0 10px;
}

p:last-child { margin-bottom: 0; }

small {
    font-size: 11px;
    color: var(--text-muted);
}

/* Utility text sizes */
.text-xs  { font-size: 11px; }
.text-sm  { font-size: 12px; }
.text-md  { font-size: 13px; }
.text-muted-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ── Border & card system ────────────────────────────────────────────
   .card          Standard warm card (bg-card, border, radius-lg, shadow)
   .card-accent   Card with dark walnut top-border accent
   .card-header   Panel header row inside a card (h3 label + optional badge)
   .divider       Horizontal rule, 1px warm border
   .border        Just the border, no other styles
   ─────────────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.card-accent {
    border-top: 2px solid var(--deep-walnut);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border-color);
}

/* ── Dashboard panels ────────────────────────────────────────────────
   Each panel uses --panel-accent CSS var for its top border color.
   Colors are defined by ID below — zero hardcoding in JS.
   ─────────────────────────────────────────────────────────────────── */
.dash-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: 3px solid var(--panel-accent, var(--deep-walnut));
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

.dash-panel-header {
    padding: 11px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.dash-panel-header.clickable { cursor: pointer; }
.dash-panel-header.clickable:hover { background: rgba(90,53,32,0.02); }

.dash-panel-count {
    display: inline-block;
    padding: 1px 9px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
    background: var(--panel-accent, var(--deep-walnut));
    color: #fff;
}

.dash-panel-count.empty {
    background: rgba(0,0,0,0.07);
    color: var(--text-muted);
}

.dash-panel-arrow {
    font-size: 9px;
    color: var(--text-muted);
    transition: transform 0.2s;
    display: inline-block;
}

/* Per-panel accent colors — change here, applies everywhere */
#dailyPanel      { --panel-accent: #5A3520; }
#refillsPanel    { --panel-accent: #A84030; }
#tasksPanel      { --panel-accent: #8B6020; }
#newPatientPanel { --panel-accent: #8C4A38; }
#prospectsPanel  { --panel-accent: #7A6A1A; }

.card-body {
    padding: 16px;
}

.divider {
    border: none;
    border-bottom: 1px solid var(--border-color);
    margin: 0;
}

/* Radius utilities */
.rounded-xs  { border-radius: var(--radius-xs); }
.rounded-sm  { border-radius: var(--radius-sm); }
.rounded-md  { border-radius: var(--radius-md); }
.rounded-lg  { border-radius: var(--radius-lg); }
.rounded-xl  { border-radius: var(--radius-xl); }
.rounded-pill{ border-radius: var(--radius-pill); }

/* ═══════════════════════════════════════════════════════════════════
   COMPONENT LIBRARY
   All UI patterns defined once here. Use classes in HTML and JS —
   no inline styles, no hardcoded values in templates.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Badges & pills ─────────────────────────────────────────────────
   .badge          filled pill (use background/color per context)
   .badge-outline  stamp style — transparent, border:currentColor
   .badge-count    small number bubble (nav, panel headers)
   ─────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.6;
    white-space: nowrap;
}

.badge-outline {
    background: transparent;
    border: 1px solid currentColor;
    padding: 2px 7px;
    border-radius: var(--radius-xs);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    line-height: 1.6;
    white-space: nowrap;
}

.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
    background: var(--deep-walnut);
    color: #fff;
}

.badge-count.muted {
    background: rgba(0,0,0,0.07);
    color: var(--text-muted);
}

/* ── Forms ──────────────────────────────────────────────────────────
   Global input/select/textarea styling — apply to all form controls.
   .field-label    the uppercase muted label above every input
   .field-group    label + input wrapper (stacked)
   .field-value    read-only display value
   .form-row       two-column input grid
   ─────────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="password"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--deep-walnut);
    box-shadow: 0 0 0 3px rgba(90,53,32,0.08);
}

input[type="checkbox"],
input[type="radio"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--deep-walnut);
}

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235a3825' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
    cursor: pointer;
}

textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

.field-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.field-group:last-child { margin-bottom: 0; }

.field-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ── Button variants ────────────────────────────────────────────────
   .btn-icon     borderless icon/symbol button
   .btn-danger   destructive action
   .btn-pill     rounded filter toggle
   ─────────────────────────────────────────────────────────────────── */
.btn-icon {
    background: none;
    border: none;
    box-shadow: none;
    color: var(--text-muted);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: color 0.12s, background 0.12s;
}

.btn-icon:hover {
    background: rgba(90,53,32,0.07);
    color: var(--text-primary);
    transform: none;
    box-shadow: none;
}

.btn-danger {
    background: #A84030 !important;
    color: #fff !important;
    border-color: #A84030 !important;
}

.btn-danger:hover {
    background: #8a3026 !important;
    box-shadow: 0 2px 8px rgba(168,64,48,0.3) !important;
}

.btn-pill {
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    box-shadow: none;
}

.btn-pill:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
    transform: none;
    box-shadow: none;
}

.btn-pill.active {
    background: var(--deep-walnut);
    color: #F5EDE3;
    border-color: var(--deep-walnut);
}

/* ── Layout utilities ───────────────────────────────────────────────
   .stack        flex column with gap
   .cluster      flex row, wrapping, with gap
   .row-spread   flex row, space-between, centered
   .row          flex row, aligned center, gap
   .truncate     overflow ellipsis (requires width constraint)
   .empty-state  centered placeholder for empty lists
   ─────────────────────────────────────────────────────────────────── */
.stack   { display: flex; flex-direction: column; gap: 12px; }
.stack-sm{ display: flex; flex-direction: column; gap: 6px; }
.cluster { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row     { display: flex; align-items: center; gap: 10px; }
.row-spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

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

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    padding: 32px 16px;
}

/* ── Modals ─────────────────────────────────────────────────────────
   .modal          full-screen overlay (hidden by default via .hidden)
   .modal-box      the centered content box
   .modal-header   title row inside modal
   .modal-body     scrollable content area
   .modal-actions  button row at bottom
   ─────────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(26,18,8,0.45);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden { display: none; }

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border-color);
}

.modal-body { padding: 20px; }

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
}

/* ── Tabs & filter bars ─────────────────────────────────────────────
   .tab-bar    horizontal row of tab buttons
   .tab        individual tab (use .active for selected state)
   ─────────────────────────────────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.tab {
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    box-shadow: none;
    transition: color 0.12s, background 0.12s;
}

.tab:hover {
    color: var(--text-primary);
    background: rgba(90,53,32,0.05);
    transform: none;
    box-shadow: none;
}

.tab.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* ── Collapsible / accordion ────────────────────────────────────────
   Use <details> + <summary>. Styling below handles the disclosure
   triangle and header appearance consistently.
   ─────────────────────────────────────────────────────────────────── */
details.collapsible summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(90,53,32,0.04);
    border-radius: var(--radius-sm);
    cursor: pointer;
    list-style: none;
    font-size: 12px;
    font-weight: 700;
    color: var(--near-black);
    user-select: none;
}

details.collapsible summary::-webkit-details-marker { display: none; }

details.collapsible summary::after {
    content: '▼';
    font-size: 9px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

details.collapsible[open] summary::after {
    transform: rotate(180deg);
}

details.collapsible .collapsible-body {
    padding: 12px 14px;
    border-top: 1px solid var(--border-color);
}

/* ── Section label ──────────────────────────────────────────────────
   Uppercase muted divider label between groups of list items.
   ─────────────────────────────────────────────────────────────────── */
.section-label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--near-black);
    padding: 14px 0 6px;
}

.section-label.muted {
    color: var(--text-muted);
}

/* ── List rows ──────────────────────────────────────────────────────
   .list-row      standard bordered-bottom list item (flex)
   .list-row-card clickable card row with left accent
   ─────────────────────────────────────────────────────────────────── */
.list-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
}

.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--bg-hover); }

.list-row-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: 3px solid var(--deep-walnut);
    border-radius: var(--radius-md);
    margin-bottom: 5px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-width: 0;
    overflow: hidden;
}

/* Patient card name — truncates in narrow grid cells */
.patient-card-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-row-card:hover {
    border-color: var(--near-black);
    border-top-color: var(--near-black);
    box-shadow: var(--shadow-md);
}

/* ── Inline link style ──────────────────────────────────────────────
   For clickable IDs, patient names, and text links inside content.
   ─────────────────────────────────────────────────────────────────── */
a.link, .link {
    color: var(--deep-walnut);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.12s;
}

a.link:hover, .link:hover {
    border-bottom-color: var(--deep-walnut);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow-color);
    padding: 30px;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

/* Logo Styling */
.logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    line-height: 1;
    flex-shrink: 0;
}

.logo-ordinary {
    font-family: 'Italiana', serif;
    font-size: 48px;
    font-weight: 400;
    font-style: normal;
    color: var(--medium-forest);
    letter-spacing: normal;
    margin: 0;
    padding: 0;
}

.logo-psychiatry {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 16px;
    font-weight: 300;
    color: var(--medium-forest);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin: 0;
    padding: 0;
}

.page-title {
    flex: 1;
    text-align: center;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 20px;
    font-weight: 500;
    color: var(--text-primary);
    padding: 0 20px;
}

/* Fallback for old h1 headers */
header h1 {
    color: var(--accent-primary);
    font-size: 28px;
    font-weight: 600;
    transition: color 0.3s ease;
}

/* Theme Toggle Button */
.header-buttons {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.theme-toggle {
    padding: 10px 18px;
    background: var(--button-secondary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle:hover {
    background: var(--button-secondary-hover);
    transform: scale(1.05);
}

.theme-icon {
    font-size: 16px;
}

/* Search Section */
.search-section {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    position: relative;
}

/* Autocomplete input styling - reusable for patient/prospect search */
.autocomplete-input,
#patientSearch,
#prospectSearch {
    flex: 1;
    min-width: 200px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Inter', -apple-system, sans-serif;
    text-transform: uppercase;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Autocomplete dropdown for patient/prospect search */
#patientSuggestions,
#prospectSuggestions,
.autocomplete-dropdown {
    position: absolute !important;
    top: 52px !important;
    left: 0 !important;
    width: calc(100% - 280px) !important;
    max-width: 500px;
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    max-height: 280px !important;
    overflow-y: auto !important;
    z-index: 9999 !important;
    box-shadow: 0 4px 12px rgba(90,53,32,0.08) !important;
}

#patientSuggestions .suggestion-item,
#prospectSuggestions .suggestion-item {
    padding: 12px 16px !important;
    border-bottom: 1px solid var(--border-color) !important;
    cursor: pointer;
    font-size: 14px;
}

#patientSuggestions .suggestion-item:hover,
#prospectSuggestions .suggestion-item:hover {
    background: var(--bg-secondary) !important;
}

/* Add new button styling - walnut for adding prospects/patients */
.add-new-btn {
    background: #5A3520 !important;
    color: #F5EDE3 !important;
    font-weight: 600;
    transition: all 0.2s;
}

.add-new-btn:hover {
    background: #7A5540 !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(90,53,32,0.25) !important;
}

#patientSearch:focus {
    outline: none;
    border-color: var(--accent-primary);
}

body.dark-theme #patientSearch {
    color: var(--text-on-card);
}

button {
    padding: 7px 16px;
    background: var(--button-primary);
    color: white;
    border: none;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
    font-family: inherit;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

button:hover {
    background: var(--button-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(90,53,32,0.2);
}

button:active {
    transform: translateY(0);
    box-shadow: none;
    transition: transform 0.06s, box-shadow 0.06s;
}

/* Button size utilities */
.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 5px;
    letter-spacing: 0.01em;
}

.btn-md {
    padding: 7px 14px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-lg {
    padding: 10px 22px;
    font-size: 14px;
    border-radius: 8px;
}

/* Secondary / ghost button */
.btn-secondary {
    background: var(--bg-secondary) !important;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: none !important;
}

.btn-secondary:hover {
    background: var(--bg-hover) !important;
    border-color: var(--text-muted) !important;
    transform: none !important;
    box-shadow: none !important;
}

/* Outline button — border only, no fill. Used for secondary actions in page headers. */
.btn-outline {
    background: transparent !important;
    color: var(--accent-primary) !important;
    border: 1.5px solid #C4AB94 !important;
    box-shadow: none !important;
    text-decoration: none !important;
    display: inline-flex !important;
    align-items: center !important;
}

a.btn-outline, a.btn-primary {
    text-decoration: none !important;
    display: inline-flex !important;
    align-items: center !important;
}

.btn-outline:hover {
    background: var(--bg-secondary) !important;
    border-color: var(--deep-walnut) !important;
    transform: none !important;
    box-shadow: none !important;
}

/* Primary button — explicit class for walnut fill */
.btn-primary {
    background: var(--deep-walnut) !important;
    color: #F5EDE3 !important;
    border: 1.5px solid transparent !important;
}

.btn-primary:hover {
    background: #7A4A30 !important;
}

/* Workflow task action buttons */
.task-action-btn {
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: opacity 0.12s, transform 0.1s;
    font-family: inherit;
    background: var(--button-primary);
    color: #F5EDE3;
    width: 100%;
    text-align: left;
}

.task-action-btn:hover {
    opacity: 0.88;
    transform: none;
    box-shadow: none;
}

.task-action-btn.secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.task-action-btn.secondary:hover {
    border-color: var(--text-muted);
}

#addNewPatientBtn {
    background: var(--button-secondary);
}

#addNewPatientBtn:hover {
    background: var(--button-secondary-hover);
}

/* Patient View */
.patient-view {
    margin-top: 20px;
}

.patient-view.hidden {
    display: none;
}

.patient-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.patient-header h2 {
    color: var(--text-primary);
    font-size: 24px;
}

.patient-header h2 span {
    font-family: monospace;
    color: var(--accent-primary);
    font-weight: 700;
}

#backBtn {
    background: var(--golden-tan);
}

#backBtn:hover {
    background: var(--text-secondary);
}

/* Tasks Section */
.tasks-section h3 {
    margin-bottom: 20px;
    color: var(--accent-primary);
    font-size: 20px;
}

.add-task {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

#taskType {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    min-width: 200px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
}

body.dark-theme #taskType {
    color: var(--text-on-card);
}

#taskDescription {
    flex: 1;
    min-width: 250px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
}

body.dark-theme #taskDescription {
    color: var(--text-on-card);
}

#taskDueDate {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    min-width: 150px;
    background: var(--bg-card);
    color: var(--text-primary);
}

body.dark-theme #taskDueDate {
    color: var(--text-on-card);
}

#addTaskBtn {
    background: var(--button-secondary);
    padding: 10px 20px;
}

#addTaskBtn:hover {
    background: var(--button-secondary-hover);
}

/* Task Filters */
.task-filters {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.filter-btn {
    padding: 8px 16px;
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 14px;
    border: 1px solid var(--border-color);
}

.filter-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* Task List */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s;
}

body.dark-theme .task-item {
    color: var(--text-on-card);
}

.task-item:hover {
    box-shadow: 0 2px 8px var(--shadow-color);
    transform: translateY(-1px);
}

.task-item.completed {
    opacity: 0.6;
}

.task-item.overdue {
    border-left: 4px solid #ff3b30;
}

.task-main {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex: 1;
}

.task-main input[type="checkbox"] {
    margin-top: 4px;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.task-content {
    flex: 1;
}

.task-type-badge {
    display: inline-block;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid currentColor;
    color: var(--accent-primary);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 6px;
    line-height: 1.6;
}

.task-description {
    font-size: 15px;
    color: var(--text-primary);
    margin-bottom: 4px;
}

body.dark-theme .task-description {
    color: var(--text-on-card);
}

.task-item.completed .task-description {
    text-decoration: line-through;
}

.task-due-date {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

body.dark-theme .task-due-date {
    color: var(--text-on-card);
    opacity: 0.8;
}

.task-due-date.overdue-text {
    color: #ff3b30;
    font-weight: 600;
}

.delete-btn {
    padding: 8px 16px;
    background: #ff3b30;
    font-size: 13px;
}

.delete-btn:hover {
    background: #d32f2f;
}

.no-tasks {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* All Patients List */
.patients-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.patients-header h3 {
    color: var(--accent-primary);
    font-size: 20px;
    margin: 0;
}

.patient-filters {
    display: flex;
    gap: 10px;
}

.patient-filter-btn {
    padding: 8px 16px;
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 14px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
}

.patient-filter-btn:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.patient-filter-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* patientsContainer styling removed - layout now handled in app.js */

.patient-card {
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 4px rgba(90, 53, 32, 0.06);
}

body.dark-theme .patient-card {
    color: var(--text-on-card);
}

.patient-card:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 4px 12px var(--shadow-color);
    transform: translateY(-2px);
}

.patient-id {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: var(--deep-walnut);
    margin-bottom: 6px;
    text-transform: uppercase;
    border-bottom: 1px dotted #C4AB94;
    text-decoration: none;
    display: inline-block;
}

body.dark-theme .patient-id {
    color: var(--text-on-card);
}

.patient-age {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

body.dark-theme .patient-age {
    color: var(--text-on-card);
    opacity: 0.8;
}

.patient-stats {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.pending-count {
    display: inline-block;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid #8B6020;
    color: #8B6020;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.overdue-count {
    display: inline-block;
    padding: 4px 10px;
    background: #ff3b30;
    color: white;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.no-tasks-text {
    color: var(--text-secondary);
    font-size: 13px;
}

body.dark-theme .no-tasks-text {
    color: var(--text-on-card);
    opacity: 0.7;
}

.no-patients {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* Data Management */
.data-management {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: center;
}

#exportBtn, #importBtn {
    background: var(--golden-tan);
}

#exportBtn:hover, #importBtn:hover {
    background: var(--text-secondary);
}

#resetBtn {
    background: #C0392B;
}

#resetBtn:hover {
    background: #A93226;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-content h2 {
    color: var(--accent-primary);
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="color"],
.form-group input[type="date"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-weight: 400;
}

body.dark-theme .form-group input,
body.dark-theme .form-group select,
body.dark-theme .form-group textarea {
    color: var(--text-on-card);
}

.form-group input[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 25px;
}

.cancel-btn {
    background: var(--golden-tan) !important;
}

.modal-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
    font-size: 20px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.modal-close-btn:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
}

.cancel-btn:hover {
    background: var(--text-secondary) !important;
}

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.edit-patient-link {
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    margin-left: 10px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.edit-patient-link:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Inline editable fields */
.info-value[title="Double-click to edit"] {
    display: inline-block;
    transition: background 0.2s, transform 0.2s;
    border-radius: 4px;
    padding: 4px 6px;
    margin: -4px -6px;
}

.info-value[title="Double-click to edit"]:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.01);
}

/* ============================================
   APP LAYOUT - Sidebar Navigation
   ============================================ */

/* Patient card grid — 3 cols desktop, responsive on mobile */
.patient-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.app-layout {
    display: flex;
    min-height: 100vh;
    margin: -20px; /* Offset body padding */
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: #8C4A38;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    border-right: 1px solid rgba(0,0,0,0.15);
    box-shadow: 2px 0 14px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: width 0.25s ease, transform 0.3s ease;
    overflow: hidden;
}

/* Sidebar collapse toggle */
.sidebar-collapse-btn {
    position: absolute;
    top: 12px;
    right: 10px;
    width: 28px;
    height: 28px;
    background: none;
    border: 1px solid rgba(245, 237, 227, 0.2);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(245, 237, 227, 0.6);
    font-size: 16px;
    z-index: 10;
    transition: transform 0.25s ease;
    padding: 0;
}

.sidebar-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #F5EDE3;
}

/* Collapsed sidebar */
.sidebar.collapsed {
    width: 0;
}

.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .sidebar-search,
.sidebar.collapsed .sidebar-nav,
.sidebar.collapsed .sidebar-footer {
    opacity: 0;
    pointer-events: none;
}

.sidebar.collapsed .sidebar-collapse-btn {
    opacity: 0;
    pointer-events: none;
}

/* Expand button (visible when collapsed) */
.sidebar-expand-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 10px;
    width: 36px;
    height: 36px;
    background: var(--deep-walnut);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: #F5EDE3;
    font-size: 18px;
    z-index: 101;
    padding: 0;
}

.sidebar-expand-btn:hover {
    background: var(--button-secondary-hover);
    color: white;
}

.sidebar.collapsed ~ .sidebar-expand-btn {
    display: flex;
}

.sidebar-logo {
    height: 96px;
    box-sizing: border-box;
    padding: 0 20px;
    border-bottom: 1px solid rgba(245, 237, 227, 0.15);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.sidebar-logo .logo-ordinary {
    font-family: 'Italiana', serif;
    font-size: 32px;
    font-style: normal;
    color: #F5EDE3;
}

.sidebar-logo .logo-psychiatry {
    font-size: 11px;
    letter-spacing: 0.15em;
    color: rgba(245, 237, 227, 0.7);
}

/* Sidebar Quick Tiles */
.sidebar-tiles {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 10px 15px;
    border-bottom: 1px solid rgba(245, 237, 227, 0.15);
}

.sidebar-tile {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    font-size: 16px;
    text-decoration: none;
    color: rgba(245, 237, 227, 0.6);
    transition: all 0.15s;
}

.sidebar-tile:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(245, 237, 227, 0.9);
}

.sidebar-tile.active {
    background: rgba(255, 255, 255, 0.18);
    color: rgba(245, 237, 227, 1);
}

.sidebar.collapsed .sidebar-tiles {
    display: none;
}

.sidebar-search {
    padding: 15px 15px 10px;
    border-bottom: 1px solid rgba(245, 237, 227, 0.15);
}

.sidebar-search input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(245, 237, 227, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #F5EDE3;
    font-size: 13px;
    font-family: 'Inter', -apple-system, sans-serif;
}

.sidebar-search input:focus {
    outline: none;
    border-color: rgba(196,171,148,0.6);
    background: rgba(255, 255, 255, 0.15);
}

.sidebar-search input::placeholder {
    color: rgba(245, 237, 227, 0.5);
}

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

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    color: rgba(245, 237, 227, 0.8);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    border-left-color: rgba(245, 237, 227, 0.3);
    color: #F5EDE3;
}

.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.12);
    border-left-color: #C4AB94;
    color: #F5EDE3;
    font-weight: 600;
}

.sidebar-nav .nav-icon {
    display: none;
}

.sidebar-nav .nav-badge {
    margin-left: auto;
    background: rgba(196,171,148,0.25);
    color: #F5EDE3;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.sidebar-nav .nav-badge.urgent {
    background: #c62828;
}

/* Sidebar Today's Patients */
.sidebar-today {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(245, 237, 227, 0.15);
}

.sidebar-today-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 5px 6px;
}

.sidebar-today-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(245, 237, 227, 0.4);
}

.sidebar-today-add {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(245, 237, 227, 0.5);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.15s;
}

.sidebar-today-add:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(245, 237, 227, 0.9);
}

.sidebar-today-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-today-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: 5px;
    cursor: grab;
    transition: background 0.15s;
    text-decoration: none;
}

.sidebar-today-item:active {
    cursor: grabbing;
}

.sidebar-today-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-today-item-id {
    font-size: 12px;
    font-weight: 600;
    color: rgba(245, 237, 227, 0.8);
    letter-spacing: 0.5px;
}

.sidebar-today-item:hover .sidebar-today-item-id {
    color: #F5EDE3;
}

.sidebar-today-item-time {
    font-size: 10px;
    color: rgba(245, 237, 227, 0.35);
}

.sidebar-today-remove {
    width: 16px;
    height: 16px;
    border: none;
    background: none;
    color: rgba(245, 237, 227, 0.2);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    opacity: 0;
    transition: all 0.15s;
}

.sidebar-today-item:hover .sidebar-today-remove {
    opacity: 1;
}

.sidebar-today-remove:hover {
    color: #C0392B;
    background: rgba(192, 57, 43, 0.15);
}

.sidebar-today-empty {
    font-size: 11px;
    color: rgba(245, 237, 227, 0.25);
    padding: 4px 8px;
    font-style: italic;
}

.sidebar.collapsed .sidebar-today {
    display: none;
}

.sidebar-divider {
    height: 1px;
    background: var(--border-color);
    margin: 6px 16px;
    opacity: 0.3;
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: rgba(245, 237, 227, 0.35);
    background: none;
    padding: 10px 20px 4px;
    margin: 6px 0 0;
    border-radius: 4px;
}

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid rgba(245, 237, 227, 0.15);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer button {
    width: 100%;
    padding: 10px;
    font-size: 13px;
    border-radius: 6px;
}

.sidebar-footer .theme-toggle {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(245, 237, 227, 0.8);
    border: 1px solid rgba(245, 237, 227, 0.2);
    justify-content: center;
}

.sidebar-footer .sign-out-btn {
    background: rgba(255,255,255,0.12);
    color: rgba(245,237,227,0.85);
    text-align: center;
    border: 1px solid rgba(245,237,227,0.2);
}
.sidebar-footer .sign-out-btn:hover {
    background: rgba(255,255,255,0.2);
    color: #F5EDE3;
}

/* Main Content Area — fixed position, scrolls internally */
.main-content {
    position: fixed;
    left: 260px;
    right: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    background: var(--bg-primary);
    transition: left 0.25s ease;
}

.sidebar.collapsed ~ .main-content,
.sidebar.collapsed ~ .sidebar-expand-btn ~ .main-content {
    left: 0;
}

/* Sticky page header — stays at top as content scrolls */
.main-content .page-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #EDE5D8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 96px;
    box-sizing: border-box;
    padding: 0 60px;
    border-bottom: 1px solid #D4C4B0;
    margin-bottom: 0;
}

/* Content padding below the sticky header */
.main-content > *:not(.page-header):first-of-type {
    margin-top: 0;
}

/* Default inner content padding for direct children after header */
.main-content > .page-header + * {
    padding: 24px 60px 40px;
}

/* All non-header direct children get horizontal breathing room */
.main-content > :not(.page-header) {
    padding-left: 60px;
    padding-right: 60px;
    box-sizing: border-box;
}


/* Stats Row - Clean admin style */
.stats-row {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    align-items: stretch;
}

.stats-row > a {
    flex: 1;
    display: flex;
    text-decoration: none;
}

.stat-card {
    background: var(--bg-card);
    padding: 24px 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    min-width: 140px;
    flex: 1;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(90,53,32,0.07), 0 4px 14px rgba(90,53,32,0.05);
}

.stats-row > a > .stat-card {
    width: 100%;
}

.stat-card:hover {
    border-color: var(--button-primary);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--button-primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

/* Content Cards - Clean style */
.content-card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(90,53,32,0.07), 0 4px 14px rgba(90,53,32,0.05);
}

.content-card-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.content-card-header h2 {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.content-card-body {
    padding: 15px 20px;
}

/* Clean Table Style */
.clean-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

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

.clean-table th {
    background: rgba(90,53,32,0.05);
    font-weight: 700;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.clean-table tr:hover {
    background: var(--bg-hover);
}

.clean-table tr:last-child td {
    border-bottom: none;
}

/* Mobile Sidebar Toggle */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--deep-walnut);
    color: #F5EDE3;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* ── Task drag-and-drop ───────────────────────────────────────────── */
.task-drag-handle {
    cursor: grab;
    color: var(--border-color);
    font-size: 14px;
    flex-shrink: 0;
    padding: 0 4px 0 0;
    line-height: 1;
    transition: color 0.12s;
    user-select: none;
}
.task-row:hover .task-drag-handle { color: var(--text-muted); }
.task-drag-handle:active { cursor: grabbing; }

.task-drag-over {
    background: var(--bg-secondary) !important;
    border-top: 2px solid var(--deep-walnut) !important;
}

/* ── Dashboard 2-column grid ──────────────────────────────────────── */
.dash-main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
    padding: 4px 0;
}

.dash-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Mobile Layout — iPhone ───────────────────────────────────────── */
@media (max-width: 768px) {
    /* Prevent any horizontal overflow */
    body, .app-layout {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Remove the desktop negative margin that bleeds past the viewport */
    .app-layout {
        margin: 0;
    }

    /* Patient grid: 2 cols on tablet, 1 on phone */
    .patient-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Sidebar: off-canvas */
    .sidebar {
        width: 260px !important;
        transform: translateX(-100%);
        z-index: 200;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: flex;
    }
    .sidebar-collapse-btn,
    .sidebar-expand-btn {
        display: none !important;
    }
    .sidebar-overlay.open {
        display: block;
    }

    /* Main content: full width */
    .main-content {
        left: 0 !important;
        right: 0 !important;
        max-width: 100vw;
    }

    /* Tables: scroll horizontally within their container */
    .t-table,
    .clean-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    /* Collapsibles and cards: contain their content */
    details,
    .card {
        overflow-x: hidden;
        max-width: 100%;
    }

    /* Page header: smaller, space for hamburger */
    .main-content .page-header {
        height: auto !important;
        min-height: 60px;
        padding: 10px 12px 10px 62px !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .main-content .page-header h1 {
        font-size: 22px;
    }

    /* Content padding: replace 60px with 16px */
    .main-content > :not(.page-header) {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    .main-content > .page-header + * {
        padding-top: 16px !important;
        padding-bottom: 28px !important;
    }

    /* Dashboard: stack to single column */
    .dash-main-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    /* Panel bodies: allow horizontal scroll instead of overflowing viewport */
    .dash-panel {
        overflow: visible;
    }
    .dash-panel > div:last-child {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* Stats bars: 2-column */
    .op-stats-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .inbox-stats-bar {
        grid-template-columns: 1fr 1fr;
    }
    .stats-row {
        flex-wrap: wrap;
    }
    .stat-card {
        min-width: 0;
    }

    /* Tables: scroll horizontally */
    .card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modals: slide up from bottom */
    .modal {
        padding: 0;
        align-items: flex-end;
    }
    .modal-box,
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0;
        max-height: 88vh;
    }

    /* Forms: single column */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Slide panel: full width */
    .slide-panel {
        width: 100%;
        right: -100%;
    }

    /* Button rows: wrap */
    .page-header > div {
        flex-wrap: wrap;
        gap: 6px !important;
    }

    /* General text */
    h1 { font-size: 26px; }
}

@media (max-width: 430px) {
    /* Tighter on smaller iPhones */
    .main-content .page-header {
        padding: 10px 8px 10px 58px !important;
    }
    .op-stats-card {
        padding: 10px 12px;
    }
    .op-stats-card .stat-num {
        font-size: 18px;
    }
    .inbox-stat-value {
        font-size: 20px;
    }
    .dash-panel-header {
        padding: 10px 12px;
    }
}

/* ── Billing table: hide low-priority columns on mobile ───────────── */
@media (max-width: 768px) {
    /* Hide Session Type and Payment ID — keeps Time/Patient/Amount/Payment/Charged visible */
    .t-table th:nth-child(3),
    .t-table td:nth-child(3),
    .t-table th:nth-child(7),
    .t-table td:nth-child(7) {
        display: none;
    }
    .t-table th,
    .t-table td {
        padding: 8px 7px;
        font-size: 12px;
    }
}

@media (max-width: 430px) {
    /* Also hide Payment column on smaller phones — keeps Time/Patient/Amount/Charged */
    .t-table th:nth-child(5),
    .t-table td:nth-child(5) {
        display: none;
    }
}

/* ============================================
   END APP LAYOUT
   ============================================ */

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    header {
        padding-bottom: 60px;
    }

    header h1 {
        font-size: 22px;
        padding-right: 0;
    }

    .theme-toggle {
        position: absolute;
        top: 50px;
        right: 0;
        left: 0;
        margin: 0 auto;
        width: fit-content;
    }

    .search-section {
        flex-direction: column;
    }

    #patientSearch {
        width: 100%;
    }

    .add-task {
        flex-direction: column;
    }

    #taskType, #taskDescription, #taskDueDate {
        width: 100%;
    }

    .patient-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    #backBtn {
        width: 100%;
    }

    #patientsContainer {
        grid-template-columns: 1fr;
    }

    .task-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .delete-btn {
        width: 100%;
    }
}

/* ========== Diagnosis Picker Component ========== */

.diagnosis-input-container {
    position: relative;
}

.diagnosis-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    min-height: 28px;
}

.diagnosis-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--button-primary);
    color: white;
    border-radius: 16px;
    font-size: 13px;
}

.diagnosis-tag .remove-tag {
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: 0.8;
}

.diagnosis-tag .remove-tag:hover {
    opacity: 1;
}

.diagnosis-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    margin-top: 2px;
    box-shadow: 0 4px 12px rgba(90,53,32,0.08);
}

.diagnosis-dropdown.active {
    display: block;
}

.diagnosis-dropdown-section {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.diagnosis-dropdown-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

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

.diagnosis-dropdown-item:hover {
    background: var(--bg-secondary);
}

.diagnosis-dropdown-item .diagnosis-name {
    font-weight: 500;
    color: var(--text-primary);
}

.diagnosis-dropdown-item .diagnosis-code {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 8px;
}

/* ============================================
   INBOX DASHBOARD STYLES
   ============================================ */

/* Stats Bar */
.inbox-stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.inbox-stat-card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    text-align: center;
    transition: all 0.2s;
    box-shadow: 0 1px 4px rgba(90, 53, 32, 0.06);
}

.inbox-stat-card.clickable {
    cursor: pointer;
}

.inbox-stat-card.clickable:hover {
    border-color: var(--button-primary);
    transform: translateY(-2px);
}

.inbox-stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--button-primary);
    line-height: 1.2;
}

.inbox-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

.inbox-stat-detail {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Filter Bars */
.inbox-filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    padding: 12px 15px;
    background: var(--bg-card);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.inbox-filter-btn {
    padding: 8px 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.inbox-filter-btn:hover {
    background: var(--bg-hover);
    border-color: var(--button-primary);
}

.inbox-filter-btn.active {
    background: var(--button-primary);
    color: white;
    border-color: var(--button-primary);
}

.inbox-filter-btn.urgent {
    color: #c62828;
}

.inbox-filter-btn.urgent.active {
    background: #c62828;
    color: white;
    border-color: #c62828;
}

.filter-count {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.inbox-filter-btn.active .filter-count {
    background: rgba(255, 255, 255, 0.2);
}

/* Inbox Container */
.inbox-container {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    min-height: 400px;
    box-shadow: 0 1px 4px rgba(90, 53, 32, 0.06);
}

.inbox-loading {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
}

.inbox-empty {
    padding: 80px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 16px;
}

/* Day Groups */
.inbox-day-group {
    border-bottom: 1px solid var(--border-color);
}

.inbox-day-group:last-child {
    border-bottom: none;
}

.inbox-day-header {
    padding: 12px 20px;
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

/* Inbox Items - Email-style compact rows */
.inbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

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

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

.inbox-item.urgent {
    border-left: 3px solid #c62828;
}

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

.inbox-item-icon {
    display: none;
}

.inbox-inline-checkbox {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--button-primary, #4CAF50);
}

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

/* Compact row: type + patient + preview all on one line */
.inbox-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
}

.inbox-item-type {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

.inbox-item.urgent .inbox-item-type {
    background: #ffebee;
    color: #c62828;
}

.inbox-item-patient {
    font-weight: 800;
    color: var(--deep-walnut);
    text-decoration: none;
    font-size: 11px;
    letter-spacing: 0.05em;
    border-bottom: 1px dotted #C4AB94;
    flex-shrink: 0;
}

.inbox-item-patient:hover {
    border-bottom-color: var(--deep-walnut);
}

.unverified-badge {
    background: #ff9800;
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}

.inbox-item-summary {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.inbox-item-time {
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-left: auto;
    padding-left: 8px;
}

/* Expanded detail panel */
.inbox-item-body {
    display: none;
    margin-bottom: 0;
}

.inbox-item-expand {
    display: none;
    padding: 12px 16px 12px 50px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    animation: slideDown 0.15s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; max-height: 0; }
    to { opacity: 1; max-height: 300px; }
}

.inbox-item-expand.open {
    display: block;
}

.inbox-expand-subitem {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
}

.inbox-expand-subitem:last-of-type {
    border-bottom: none;
}

.inbox-expand-detail {
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 6px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
}

.inbox-expand-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    word-break: break-word;
    overflow-wrap: break-word;
}

.inbox-expand-meta.overdue {
    color: #c62828;
    font-weight: 600;
}

.inbox-expand-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
}

/* Keep old class names working for actions */
.inbox-item-actions {
    display: none;
}

.inbox-action-btn {
    padding: 5px 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.inbox-action-btn:hover {
    background: var(--bg-hover);
    border-color: var(--button-primary);
}

.inbox-action-btn.primary {
    background: var(--button-primary);
    color: white;
    border-color: var(--button-primary);
}

.inbox-action-btn.primary:hover {
    background: var(--button-primary-hover);
}

.inbox-task-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--button-primary);
}

/* Responsive Inbox */
@media (max-width: 1024px) {
    .inbox-stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .inbox-stats-bar {
        grid-template-columns: 1fr 1fr;
    }

    .inbox-stat-card {
        padding: 15px;
    }

    .inbox-stat-value {
        font-size: 22px;
    }

    .inbox-filter-bar {
        padding: 10px;
    }

    .inbox-filter-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .inbox-item {
        padding: 8px 12px;
    }

    .inbox-item-expand {
        padding-left: 12px;
    }

    .inbox-item-summary {
        display: none;
    }
}

@media (max-width: 480px) {
    .inbox-stats-bar {
        grid-template-columns: 1fr;
    }

    .inbox-filter-bar {
        justify-content: center;
    }
}

/* ============================================
   END INBOX DASHBOARD STYLES
   ============================================ */

/* ============================================
   SLIDE PANEL (Overlays)
   ============================================ */

.slide-panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
}

.slide-panel-overlay.open {
    display: block;
}

.slide-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    z-index: 1000;
    transition: right 0.25s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(90, 53, 32, 0.1);
}

.slide-panel.open {
    right: 0;
}

.slide-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.slide-panel-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.slide-panel-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 5px;
}

.slide-panel-close:hover {
    color: var(--text-primary);
}

.slide-panel-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.saved-calc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 13px;
}

.saved-calc-item .calc-amount {
    font-weight: 700;
    font-size: 15px;
}

.saved-calc-item .calc-date {
    color: var(--text-secondary);
    font-size: 12px;
}

.saved-calc-item .calc-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
}

.saved-calc-item .calc-delete:hover {
    color: #c62828;
}

@media (max-width: 480px) {
    .slide-panel {
        width: 100%;
        right: -100%;
    }
}

/* ── Shared stats bar (billing, prospects, etc.) ─────────────────── */
.op-stats-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.op-stats-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 18px;
    text-align: center;
    flex: 1;
    min-width: 100px;
}

.op-stats-card .stat-num {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.op-stats-card .stat-lbl {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
