/* TherapyNotes Custom Styles */

/* ===== Layout ===== */
.container-narrow {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 0.2em 0.6em;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge-green {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-yellow {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-blue {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-red {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-orange {
    background-color: #ffedd5;
    color: #9a3412;
}

.badge-purple {
    background-color: #ede9fe;
    color: #5b21b6;
}

.badge-grey {
    background-color: #f3f4f6;
    color: #6b7280;
}

/* ===== Stat Cards ===== */
.stat-grid {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.stat-card {
    flex: 1;
    min-width: 140px;
    background: #eff6ff;
    border: 1px solid #dbeafe;
    border-radius: 0.5rem;
    padding: 1rem;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #2563eb;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

/* ===== Progress Bar ===== */
.progress-container {
    width: 100%;
    background: #e5e7eb;
    border-radius: 0.5rem;
    overflow: hidden;
    height: 1.5rem;
    margin: 1rem 0;
}

.progress-fill {
    height: 100%;
    background: #2563eb;
    border-radius: 0.5rem;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
}

/* ===== Error Highlighting (Amber) ===== */
.field-error {
    border-color: #d97706 !important;
    background-color: #fffbeb !important;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15) !important;
}

.error-text {
    color: #92400e;
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.info-link {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 0.8rem;
    color: #b45309;
    text-decoration: underline;
    cursor: pointer;
}
.info-link:hover,
.info-link:focus {
    color: #92400e;
}

.info-popover-wrap {
    position: relative;
}
.info-popover {
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 0.25rem;
    max-width: 380px;
    padding: 0.65rem 0.85rem;
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: 0.375rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    font-size: 0.85rem;
    line-height: 1.4;
    color: #1f2937;
    z-index: 50;
}

/* ===== Toast Messages ===== */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: toastSlideIn 0.3s ease;
    max-width: 400px;
}

.toast-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.toast-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.toast-warning {
    background: #ffedd5;
    color: #9a3412;
    border: 1px solid #fdba74;
}

.toast-error {
    background: #ffedd5;
    color: #92400e;
    border: 1px solid #fdba74;
}

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

/* ===== Decrypt-Failure Banner ===== */
.decrypt-fail-banner {
    background: #fef2f2;
    color: #991b1b;
    border-bottom: 2px solid #b91c1c;
    padding: 0.85rem 1.25rem;
    font-size: 0.9rem;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 500;
    box-shadow: 0 2px 8px rgba(185, 28, 28, 0.15);
}

.decrypt-fail-banner a {
    color: #7f1d1d;
    text-decoration: underline;
    font-weight: 600;
}

.decrypt-fail-banner a:hover {
    color: #450a0a;
}

/* ===== Shared Confirm Dialog ===== */
.tn-confirm-article {
    max-width: 480px;
    margin: 0;
}

.tn-confirm-title {
    margin: 0;
}

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

.danger-btn:hover:not(:disabled) {
    background: #991b1b !important;
    border-color: #991b1b !important;
}

/* ===== Status Messages ===== */
.status-bar {
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.status-bar-blue {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.status-bar-orange {
    background: #ffedd5;
    color: #9a3412;
    border: 1px solid #fdba74;
}

.status-bar-green {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

/* ===== Tables ===== */
.table-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.table-actions button,
.table-actions a {
    font-size: 0.8rem;
    padding: 0.3em 0.6em;
    margin: 0;
}

/* ===== Header Gradient (Therapist) ===== */
.therapist-header {
    background: linear-gradient(135deg, #1e40af, #2563eb);
    color: white;
    padding: 1rem 0;
    margin-bottom: 1.5rem;
}

.therapist-header nav {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1rem;
}

.nav-tabs {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-tab {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav-tab:hover {
    color: white;
    background: rgba(255, 255, 255, 0.15);
}

.nav-tab-active {
    color: white;
    background: rgba(255, 255, 255, 0.2);
    font-weight: 600;
}

.nav-tab-logout {
    opacity: 0.7;
    font-size: 0.85rem;
}

.nav-tab-logout:hover {
    opacity: 1;
    background: rgba(255, 80, 80, 0.25);
}

.nav-divider {
    width: 1px;
    height: 1.2rem;
    background: rgba(255, 255, 255, 0.3);
    margin: 0 0.35rem;
}

/* ===== Nav Dropdowns ===== */
.nav-dropdown {
    position: relative;
    display: flex;
    align-items: center;
}

.nav-dropdown-toggle {
    color: rgba(255, 255, 255, 0.75) !important;
    text-decoration: none;
    padding: 0.4rem 0.75rem !important;
    border-radius: 0.375rem !important;
    font-size: 0.9rem !important;
    font-weight: 500;
    line-height: normal !important;
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    height: auto !important;
    --pico-background-color: transparent;
    -webkit-appearance: none;
}

.nav-dropdown-toggle:hover {
    color: white !important;
    background: rgba(255, 255, 255, 0.15) !important;
}

.nav-dropdown-toggle.nav-tab-active {
    color: white !important;
    background: rgba(255, 255, 255, 0.2) !important;
    font-weight: 600;
}

.nav-dropdown-toggle .caret {
    font-size: 0.6rem;
    transition: transform 0.2s;
}

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    min-width: 160px;
    padding: 0.35rem 0;
    z-index: 200;
    padding-top: 0.6rem;
}

/* Invisible bridge to prevent hover gap */
.nav-dropdown-menu::before {
    content: '';
    position: absolute;
    top: -0.5rem;
    left: 0;
    right: 0;
    height: 0.5rem;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-menu a {
    display: block;
    padding: 0.5rem 1rem;
    color: #374151;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 0.1s;
}

.nav-dropdown-menu a:hover {
    background: #eff6ff;
    color: #1e40af;
}

.nav-dropdown-menu a.active {
    background: #dbeafe;
    color: #1e40af;
    font-weight: 600;
}

/* ===== Admin Sticky Nav ===== */
.admin-nav {
    background: #1e293b;
    color: white;
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.admin-nav a {
    color: white;
    text-decoration: none;
}

.admin-nav-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.admin-nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.admin-nav-links form {
    margin: 0;
    display: flex;
    align-items: center;
}

.admin-logout-btn {
    background: transparent;
    color: #fff;
    border: 1px solid #fff;
    padding: 0.3rem 0.85rem;
    margin: 0;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: 4px;
    cursor: pointer;
}

.admin-logout-btn:hover {
    background: #fff;
    color: #1e293b;
}

.danger-zone {
    border: 2px solid #b91c1c;
    background: #fef2f2;
}

.delete-account-btn {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

.delete-account-btn:hover:not(:disabled) {
    background: #991b1b;
    border-color: #991b1b;
    color: #fff;
}

.delete-account-btn:disabled {
    background: #fca5a5;
    border-color: #fca5a5;
    color: #fff;
    cursor: not-allowed;
}

/* ===== Forms =====
   Each logical "row" of the form actually spans THREE CSS grid rows:
   label / input / hint. Every cell uses `grid-template-rows: subgrid`
   to inherit those rows from the outer grid, so all labels in a row
   share a sub-row, all inputs share a sub-row, and the hint sub-row
   expands to fit the tallest <small> in the row (or stays empty if
   no cell has one). This guarantees inputs on the same row align
   perfectly regardless of whether one cell has a multi-line helper. */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 1rem;
    row-gap: 1rem;
    margin-bottom: 1.5rem;
}

.form-grid > div {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    row-gap: 0.25rem;
}

.form-grid > div > label {
    grid-row: 1;
    align-self: end;
    margin-bottom: 0;
}

.form-grid > div > input,
.form-grid > div > select,
.form-grid > div > textarea {
    grid-row: 2;
    align-self: start;
    margin-bottom: 0;
}

.form-grid > div > small {
    grid-row: 3;
    align-self: start;
    line-height: 1.3;
    /* Pico applies a negative margin-top to small siblings of form
       elements to visually tighten helper text; undo it here because
       the subgrid already gives us proper spacing. */
    margin-top: 0;
}

.form-full {
    grid-column: 1 / -1;
}

.inner-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ===== Auth Card (Login/Setup) ===== */
.auth-card {
    max-width: 450px;
    margin: 4rem auto;
}

/* ===== Deactivated Client ===== */
.client-deactivated {
    opacity: 0.6;
    text-decoration: line-through;
}

/* ===== Notes List ===== */
.note-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
}

.note-item:hover {
    background: #f9fafb;
}

.note-tag {
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

/* ===== Autocomplete Dropdown ===== */
.autocomplete-dropdown {
    position: absolute;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    width: 100%;
}

.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #dbeafe;
    color: #1e40af;
}

/* ===== Autocomplete: caret-anchored popup (desktop) ===== */
.autocomplete-popup {
    position: fixed;
    z-index: 1000;
    min-width: 220px;
    max-width: 320px;
    max-height: 240px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 0.9rem;
    color: #111;
}
.autocomplete-popup .autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Autocomplete: pinned chip bar (mobile / soft keyboard) ===== */
.autocomplete-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: #f8fafc;
    border-top: 1px solid #cbd5e0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.autocomplete-bar .autocomplete-item {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0.6rem 0.9rem;
    border: 1px solid #cbd5e0;
    border-radius: 20px;
    background: #ffffff;
    white-space: nowrap;
    max-width: 75vw;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
}
@media (max-width: 600px) {
    .autocomplete-bar .autocomplete-item {
        font-size: 1rem;
    }
}

/* ===== Utility ===== */
.text-muted {
    color: #6b7280;
    font-size: 0.85rem;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

.flex { display: flex; }
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

.hidden { display: none !important; }

/* ===== Time Picker ===== */
.time-picker-row {
    display: flex !important;
    align-items: center;
    gap: 0.4rem;
}
.time-picker-row select {
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
    margin-bottom: 0 !important;
}
button.time-custom-btn {
    flex: 0 0 2.6rem;
    width: 2.6rem !important;
    height: 2.6rem;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    border: 1px solid var(--pico-form-element-border-color, #ccc) !important;
    border-radius: var(--pico-border-radius, 0.25rem);
    background-color: var(--pico-form-element-background-color, #fff) !important;
    color: var(--pico-form-element-color, #333);
    --pico-background-color: transparent;
}
button.time-custom-btn:hover {
    background-color: #e9ecef !important;
}
button.time-custom-btn.active {
    background-color: #1e88e5 !important;
    color: #fff;
    border-color: #1e88e5 !important;
}

/* ===== Responsive Tables ===== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== Settings Sub-tabs ===== */
.settings-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===== Tablet ===== */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .nav-tabs {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.2rem;
    }

    .nav-tab {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    .nav-dropdown-toggle {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    .nav-divider {
        display: none;
    }

    .flex-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .inner-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Mobile ===== */
@media (max-width: 480px) {
    .container-narrow {
        padding: 0 0.75rem;
    }

    .stat-grid {
        flex-direction: column;
    }

    .table-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .table-actions button,
    .table-actions a {
        width: 100%;
        text-align: center;
    }

    .flex-between {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .nav-tabs {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.15rem;
    }

    .nav-tab {
        font-size: 0.82rem;
        padding: 0.35rem 0.5rem;
        min-height: 2.2rem;
        display: inline-flex;
        align-items: center;
    }

    .nav-dropdown-toggle {
        font-size: 0.82rem;
        padding: 0.35rem 0.5rem;
        min-height: 2.2rem;
    }

    .nav-divider {
        display: none;
    }

    /* Therapist header */
    .therapist-header nav {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    /* Admin nav */
    .admin-nav-inner {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    /* Toast notifications */
    .toast {
        max-width: calc(100vw - 2rem);
    }

    .toast-container {
        left: 0.5rem;
        right: 0.5rem;
    }

    /* Login/setup top margin */
    .auth-card {
        margin-top: 1.5rem;
    }

    /* Time picker touch target */
    button.time-custom-btn {
        flex: 0 0 2.75rem;
        width: 2.75rem !important;
        height: 2.75rem;
    }

    /* Limit textarea height on mobile */
    textarea[rows="8"] {
        max-height: 8rem;
    }

    /* Dialog min-width */
    dialog article {
        min-width: auto !important;
        margin: 0.5rem;
    }

    /* Client filter select */
    #client-filter {
        min-width: 0 !important;
        width: 100%;
    }

    /* Pagination */
    #pagination {
        flex-direction: row !important;
        align-items: center !important;
    }
}

/* ------------------------------------------------------------------
   Spellcheck overlay (static/js/spellcheck.js)
   The overlay is a sibling sitting *behind* the textarea at the same
   coordinates. The textarea is made transparent-background so the
   overlay's wavy underlines show through beneath the real caret/text.
   ------------------------------------------------------------------ */
.spellcheck-overlay {
    position: absolute;
    pointer-events: none;
    overflow: hidden;
    color: transparent;
    background: transparent;
    border-color: transparent !important;
    margin: 0;
    z-index: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

textarea.spellcheckable {
    position: relative;
    background: transparent;
    z-index: 1;
}

.spellcheck-miss {
    text-decoration: underline wavy #d93025;
    text-decoration-skip-ink: none;
    -webkit-text-decoration: underline wavy #d93025;
}

.spellcheck-menu {
    position: absolute;
    z-index: 10000;
    min-width: 160px;
    max-width: 280px;
    background: #ffffff;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    font-size: 0.9rem;
    font-family: inherit;
}

.spellcheck-menu-item {
    padding: 6px 14px;
    cursor: pointer;
    color: #111;
    user-select: none;
}

.spellcheck-menu-item:hover {
    background: #eef2ff;
}

.spellcheck-menu-empty {
    padding: 6px 14px;
    color: #777;
    font-style: italic;
}

/* Google Drive sync banner — appears beneath the site header on any
 * authenticated page when DriveSync has something worth reporting
 * (saving, error, offline). Keep this rule block self-contained so it
 * can be edited without touching surrounding styles. */
.drive-sync-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0 1rem;
    font-size: 0.85rem;
    line-height: 1;
    margin-top: -1.5rem;
    margin-bottom: 1.5rem;
}
.drive-sync-banner__icon {
    font-size: 0.85rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}
.drive-sync-banner__action {
    appearance: none;
    border: 1px solid currentColor;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.75rem;
    line-height: 1;
    height: 18px;
    padding: 0 0.6rem;
    margin: 0;
    border-radius: 999px;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.15s, background 0.15s;
    display: inline-flex;
    align-items: center;
}
.drive-sync-banner__action:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}
.drive-sync-banner__action:disabled {
    opacity: 0.5;
    cursor: default;
}
.drive-sync-banner--info {
    background: #eff6ff;
    color: #1e40af;
}
.drive-sync-banner--error {
    background: #fef2f2;
    color: #991b1b;
}
.drive-sync-banner--warning {
    background: #fee2e2;
    color: #b91c1c;
}

/* Read-only lockdown when Drive sync is unreachable. sync_lockdown.js
 * sets `disabled` on every gated input/button, so the visual greying
 * here just reinforces that the controls aren't editable — and gives
 * the page a uniform muted feel so the banner is unmistakably the
 * source of truth. */
body.sync-locked input:disabled,
body.sync-locked textarea:disabled,
body.sync-locked select:disabled,
body.sync-locked button:disabled {
    background-color: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
    opacity: 0.85;
}
body.sync-locked [data-sync-gated]:disabled {
    background-color: #f3f4f6;
    color: #6b7280;
    border-color: #d1d5db;
    cursor: not-allowed;
    opacity: 0.7;
}
/* The banner's own Reconnect / Save now buttons live inside the banner
 * and must remain interactive even while body.sync-locked is set. They
 * carry the `.drive-sync-banner__action` class, so re-assert the lively
 * affordances here. */
body.sync-locked .drive-sync-banner__action:not(:disabled) {
    background-color: transparent;
    color: inherit;
    cursor: pointer;
    opacity: 0.85;
}

/* Drive Backup nag banner — separate concern from .drive-sync-banner.
 * Shown app-wide when the vault has notes but no recent off-site
 * disaster-recovery backup. Cannot be closed inline; the only dismiss
 * is "Snooze 30 days" inside Settings → Backup → Drive Backup. */
.backup-banner {
    display: block;
    background: #fff7ed;
    color: #9a3412;
    border-bottom: 1px solid #fed7aa;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    line-height: 1.35;
}
.backup-banner__inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.backup-banner__icon {
    font-size: 1.05rem;
    line-height: 1;
}
.backup-banner__text {
    flex: 1 1 auto;
    min-width: 200px;
}
.backup-banner__action {
    flex-shrink: 0;
    appearance: none;
    text-decoration: none;
    border: 1px solid currentColor;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.85rem;
    padding: 0.3rem 0.85rem;
    border-radius: 999px;
    cursor: pointer;
    transition: opacity 0.15s, background 0.15s;
}
.backup-banner__action:hover {
    background: rgba(154, 52, 18, 0.08);
}

/* ==================================================================
   Mobile & Tablet Responsiveness Pass
   ------------------------------------------------------------------
   All rules below exist to make the app usable on phones (375px+) and
   tablets (768px) without regressing desktop. They intentionally sit
   at the end of the file so later-wins cascade beats the 480px/768px
   rules above when selectors tie. Breakpoints: 768 (tablet), 640 (nav
   and settings-tabs transition), 480 (phone), 375 (narrow-phone edge
   cases — autocomplete popup, time picker).
   ================================================================== */

/* Dialog sizing system. Templates opt in via .tn-dialog on the
   <dialog> element; the <article> inside inherits a max-width that's
   sensible on desktop and clamped to viewport on phones. Replaces
   per-dialog inline style="max-width:…; margin:0" in setup.html,
   dashboard.html, settings.html, login.html. */
.tn-dialog article {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}
.tn-dialog-medium article { max-width: 520px; }
.tn-dialog-wide   article { max-width: 620px; }

/* Responsive tables: any JS-rendered <table> should be wrapped in
   .table-responsive (see clients.js, notes.js, supervisees.js) so it
   scrolls horizontally on phones rather than blowing out the layout. */
.table-responsive table {
    min-width: 100%;
}

/* Nav dropdown: click/tap toggle via aria-expanded, complementing the
   existing :hover / :focus-within rules. The JS shim in
   therapist/base.html sets aria-expanded on tap. */
.nav-dropdown-toggle[aria-expanded="true"] + .nav-dropdown-menu {
    display: block;
}

/* Right-anchor the rightmost/supervision dropdown so it never clips
   off-screen on narrow viewports. */
.nav-dropdown:last-of-type .nav-dropdown-menu,
.nav-supervision .nav-dropdown-menu {
    left: auto;
    right: 0;
}

/* ----- Tablet / mid-size (<=768) — existing block above handles most
   form-grid collapsing; keep additions minimal. ----- */

/* ----- Nav + settings-tabs transition (<=640) ----- */
@media (max-width: 640px) {
    /* Settings tabs turn into a horizontally scrolling snap strip.
       Activated by adding class="tabs settings-tabs" to the <nav> in
       settings.html. Preserves existing show/hide panel JS. */
    .settings-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        padding-bottom: 0.25rem;
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
        /* Fade hint at the right edge signals more tabs off-screen. */
        -webkit-mask-image: linear-gradient(to right, black calc(100% - 1.5rem), transparent);
        mask-image: linear-gradient(to right, black calc(100% - 1.5rem), transparent);
    }
    .settings-tabs .tab-link {
        flex: 0 0 auto;
        scroll-snap-align: start;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 0.5rem 0.9rem;
    }
}

/* ----- Phone (<=480) ----- */
@media (max-width: 480px) {
    /* Dialogs: beat any remaining inline max-width on migrated and
       un-migrated dialogs alike. !important is deliberate — inline
       style="max-width:…" has higher specificity than a class rule. */
    .tn-dialog article,
    .tn-dialog-medium article,
    .tn-dialog-wide article {
        max-width: calc(100vw - 1rem);
        margin: 0.5rem auto;
    }
    dialog article {
        min-width: 0;
        max-width: calc(100vw - 1rem) !important;
        margin: 0.5rem auto !important;
    }

    /* Filter selects — notes_list.html and supervision_notes_list.html
       wrap a <select> in a div with inline min-width/max-width. On
       narrow screens, let it span full width. */
    .flex > div[style*="min-width"] {
        min-width: 0 !important;
        max-width: none !important;
        width: 100%;
        flex-basis: 100%;
    }
    #client-filter,
    #supervisee-filter {
        min-width: 0 !important;
        width: 100%;
    }

    /* Textarea clamp — dashboard uses rows=6 (summary) and rows=3
       (risk/interventions/actions). Clamp the taller ones on phones
       so the form stays short enough to see Save without scrolling. */
    textarea[rows="6"] { max-height: 10rem; }
    textarea[rows="8"] { max-height: 12rem; }
    .spellcheckable {
        /* iOS Safari zooms on <16px input font-size. Keep 1rem so the
           viewport doesn't jump on focus. */
        font-size: 1rem;
    }

    /* Tables rendered by clients.js / notes.js / supervisees.js:
       tighten cells, allow first column (id/name) to wrap. */
    .table-responsive th,
    .table-responsive td {
        padding: 0.5rem 0.5rem;
        font-size: 0.88rem;
        white-space: nowrap;
    }
    .table-responsive td:first-child {
        white-space: normal;
        word-break: break-word;
    }
    /* clients.js inlines padding on row-action buttons — override. */
    .table-responsive .flex.gap-1 a[role="button"],
    .table-responsive .flex.gap-1 button {
        padding: 0.5rem 0.7rem !important;
        font-size: 0.85rem !important;
        min-height: 40px;
    }

    /* Navigation: override the existing column-stack rule at
       style.css:835-839 — keep the wordmark row, wrap the tabs below. */
    .therapist-header nav.flex-between {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }
    .therapist-header > nav > strong { flex: 0 0 auto; }
    .nav-tabs {
        flex: 1 1 100%;
        justify-content: flex-start;
        gap: 0.25rem;
    }
    .nav-dropdown-menu {
        min-width: 180px;
        max-width: calc(100vw - 2rem);
    }

    /* Dashboard summary header (label + checkbox + reason select):
       put the label on its own line so the row reads cleanly. */
    .summary-header {
        gap: 0.5rem !important;
    }
    .summary-header > label[for="note-summary"] {
        flex: 1 1 100%;
    }
    .summary-header > .inline-check,
    .summary-header > #note-no-session-reason {
        flex: 0 1 auto;
    }

    /* 44px touch targets (WCAG 2.5.5 / Apple HIG / Material). */
    button,
    a[role="button"],
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
    }
    /* Dense-UI exceptions: table rows already tight, drive-sync banner
       buttons are inline within a thin status strip. */
    .table-responsive button,
    .table-responsive a[role="button"] {
        min-height: 40px;
    }
    .drive-sync-banner button {
        min-height: 36px;
    }
}

/* ----- Narrow phone (<=375) — edge cases only ----- */
@media (max-width: 375px) {
    /* Autocomplete popup (desktop caret-anchored variant) — keep a
       breathing gap on narrow phones. Mobile usually uses the pinned
       .autocomplete-bar instead. Do NOT change position or transform;
       autocomplete.js:_reposition reads getBoundingClientRect(). */
    .autocomplete-popup {
        min-width: 180px;
        max-width: calc(100vw - 1rem);
    }

    /* Time picker button + paired <select>: pull button back slightly
       so both fit on one row. 2.5rem is still a 40px touch target. */
    button.time-custom-btn {
        flex: 0 0 2.5rem;
        width: 2.5rem !important;
        height: 2.5rem;
        font-size: 1.1rem;
    }
    .time-picker-row { gap: 0.3rem; }
}
