.hidden { display: none !important; }
.drawer.hidden { display: none !important; transform: translateX(-100%); }
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:        #0057a8;
    --blue-dark:   #003d7a;
    --blue-light:  #e6f1fb;
    --blue-mid:    #378add;
    --green:       #059669;
    --green-light: #d1fae5;
    --red:         #dc2626;
    --red-light:   #fee2e2;
    --amber:       #d97706;
    --amber-light: #fef3c7;
    --gray-50:     #f8fafc;
    --gray-100:    #f1f5f9;
    --gray-200:    #e2e8f0;
    --gray-300:    #cbd5e1;
    --gray-400:    #6b7280;   /* raised from #94a3b8 (2.56:1) to 4.83:1 on #fff — WCAG AA */
    --gray-500:    #64748b;
    --gray-600:    #475569;
    --gray-700:    #334155;
    --gray-800:    #1e293b;
    --gray-900:    #0f172a;
    --white:       #ffffff;
    --shadow-sm:   0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:   0 4px 12px rgba(0,0,0,0.10);
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Dark mode (Item 18) ─────────────────────────────────────────
   Overrides the colour custom properties; component rules keep using
   var(--…) so they adapt automatically. Status colours stay recognisable
   but are slightly brightened/desaturated for a dark background. */
:root[data-theme="dark"] {
    --blue:        #3b82f6;
    --blue-dark:   #2563eb;
    --blue-light:  #1e3a5f;
    --blue-mid:    #60a5fa;
    --green:       #34d399;
    --green-light: #0f3d30;
    --red:         #f87171;
    --red-light:   #3f1d1d;
    --amber:       #fbbf24;
    --amber-light: #3d2f0f;
    --gray-50:     #1a1a2e;
    --gray-100:    #1f2740;
    --gray-200:    #2c3654;
    --gray-300:    #384463;
    --gray-400:    #aab4cf;   /* raised from #7681a3 (3.24:1 on card) to 6.03:1 — WCAG AA */
    --gray-500:    #9aa3bd;
    --gray-600:    #b6bdd4;
    --gray-700:    #cbd2e4;
    --gray-800:    #dfe4ef;
    --gray-900:    #eef1f7;
    --white:       #16213e;
    --shadow-sm:   0 1px 3px rgba(0,0,0,0.5);
    --shadow-md:   0 4px 12px rgba(0,0,0,0.55);
}
/* Cards sit slightly lighter than the page background in dark mode */
:root[data-theme="dark"] .card { background: #0f3460; border-color: #1c4a7a; }
:root[data-theme="dark"] .form-input,
:root[data-theme="dark"] select.form-input,
:root[data-theme="dark"] textarea.form-input { background: #0f1b33; color: var(--gray-900); border-color: var(--gray-300); }
:root[data-theme="dark"] .form-input::placeholder { color: var(--gray-400); }
:root[data-theme="dark"] img { opacity: 0.95; }
/* Theme toggle button in the topnav */
.theme-toggle { background: none; border: none; cursor: pointer; color: #fff; padding: 4px 6px; margin-left: 4px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }
body { font-family: var(--font); background: var(--gray-50); color: var(--gray-900); line-height: 1.5; min-height: 100vh; margin: 0; overflow-x: hidden; max-width: 100vw; }

/* ── Typography ─────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 600; color: var(--gray-900); }
h2 { font-size: 1.25rem; font-weight: 600; color: var(--gray-900); }
h3 { font-size: 1rem; font-weight: 600; color: var(--gray-900); }
p  { color: var(--gray-600); }

/* ── Layout ─────────────────────────────────────────────── */
.app         { display: flex; flex-direction: column; min-height: 100vh; width: 100%; max-width: 100vw; overflow-x: hidden; }
.page        { display: none !important; }
.page.active { display: flex !important; flex-direction: column; min-height: 100vh; width: 100%; max-width: 100vw; overflow-x: hidden; }

@media (min-width: 768px) {
    .app { flex-direction: row; align-items: flex-start; }
    .page.active { flex: 1; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
    .hamburger { display: none !important; }
    .drawer-overlay { display: none !important; }
    .topnav { position: sticky; top: 0; z-index: 10; }
    .main { padding: 1.5rem 2rem; max-width: 860px; margin: 0 auto; width: 100%; }
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1100px) {
    .main { padding: 2rem 3rem; }
    .stat-grid { grid-template-columns: repeat(6, 1fr); }
}

/* ── Top nav ────────────────────────────────────────────── */
.topnav {
    background: var(--blue);
    padding: 0 1rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topnav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}
.topnav-logo {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}
.topnav-logo svg { width: 18px; height: 18px; fill: white; }
.topnav-name { color: white; font-weight: 600; font-size: 1.1rem; }
.topnav-right { display: flex; align-items: center; gap: 8px; }
.topnav-user { color: rgba(255,255,255,0.85); font-size: 0.875rem; }
.topnav-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    cursor: pointer;
}
.topnav-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Drawer navigation ──────────────────────────────────── */
.drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
}
.drawer-overlay.open { display: block; }

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    background: var(--gray-900);
    z-index: 201;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

@media (min-width: 768px) {
    .drawer {
        position: sticky;
        top: 0;
        height: 100vh;
        transform: translateX(0);
        flex-shrink: 0;
    }
}

.drawer-header {
    padding: 1.25rem 1rem 1rem;
    border-bottom: 0.5px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}
.drawer-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.drawer-logo-mark {
    width: 32px;
    height: 32px;
    background: var(--blue);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}
.drawer-logo-mark svg { width: 18px; height: 18px; fill: white; }
.drawer-app-name { color: white; font-size: 1rem; font-weight: 600; }
.drawer-user-name { font-size: 0.8rem; color: rgba(255,255,255,0.45); }

.drawer-section-label {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.3);
    letter-spacing: 0.08em;
    font-weight: 500;
    padding: 10px 12px 4px;
    text-transform: uppercase;
}
.drawer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    min-height: 44px;
    box-sizing: border-box;
    border-radius: var(--radius-sm);
    margin: 1px 8px;
    cursor: pointer;
    color: rgba(255,255,255,0.65);
    font-size: 0.875rem;
    border: none;
    background: none;
    width: calc(100% - 16px);
    text-align: left;
    transition: background 0.12s;
}
.drawer-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.9); }
.drawer-item.active { background: rgba(255,255,255,0.1); color: white; font-weight: 500; }
.drawer-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.7; }
.drawer-item.active svg { opacity: 1; }
.drawer-item-label { flex: 1; }
.drawer-badge {
    background: var(--red);
    color: white;
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 99px;
    flex-shrink: 0;
}
.drawer-divider { height: 0.5px; background: rgba(255,255,255,0.08); margin: 6px 8px; }

/* Toast notifications */
#toast-wrap {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    width: max-content;
    max-width: 92vw;
}
.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--gray-800, #1f2937);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius-md, 8px);
    font-size: 0.875rem;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s, transform 0.25s;
}
.toast.toast-in { opacity: 1; transform: translateY(0); }
.toast-error   { background: var(--red, #e24b4a); }
.toast-info    { background: var(--blue, #378add); }
.toast-action {
    background: rgba(255,255,255,0.18);
    border: none;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}
.toast-action:hover { background: rgba(255,255,255,0.3); }

/* Settings tabs */
.settings-tabs {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
}
.settings-tab {
    flex-shrink: 0;
    padding: 10px 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}
.settings-tab:hover { color: var(--gray-700); }
.settings-tab.active {
    color: var(--primary-color, var(--blue, #378add));
    border-bottom-color: var(--primary-color, var(--blue, #378add));
    font-weight: 600;
}

.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 20px;
    height: 15px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    flex-shrink: 0;
}
.hamburger span { display: block; height: 2px; background: white; border-radius: 1px; transition: all 0.2s; }



/* ── Cards ──────────────────────────────────────────────── */
.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.125rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    margin-bottom: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-bottom: 0.625rem;
    border-bottom: 1px solid var(--gray-100);
}

/* ── Stat grid ──────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 1rem; }
.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 1rem 1.125rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s;
}
.stat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.stat-label { font-size: 0.7rem; color: var(--gray-500); font-weight: 600; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--gray-900); line-height: 1; }
.stat-value.blue   { color: var(--blue); }
.stat-value.green  { color: var(--green); }
.stat-value.red    { color: var(--red); }
.stat-value.amber  { color: var(--amber); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    text-decoration: none;
    letter-spacing: 0.01em;
    white-space: nowrap;
    min-height: 44px;
}
.btn:hover { filter: brightness(0.92); transform: translateY(-1px); }
.btn:active { filter: brightness(0.85); transform: translateY(0); }
.btn-primary   { background: var(--blue); color: white; }
.btn-success   { background: var(--green); color: white; }
.btn-danger    { background: var(--red); color: white; }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-sm        { padding: 6px 12px; font-size: 0.8rem; min-height: 36px; }
.btn-full      { width: 100%; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group   { margin-bottom: 1rem; }
.form-label   { display: block; font-size: 0.875rem; font-weight: 500; color: var(--gray-800); margin-bottom: 5px; }
.required-star { color: var(--red); margin-left: 2px; }
.field-hint { font-size: 0.75rem; color: var(--gray-500); margin-top: 4px; }

/* ── Household member switcher ──────────────────────────────── */
.member-switcher { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 0.75rem; }
.member-switcher-drawer { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.member-chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 12px 6px 6px; border-radius: 999px;
    background: var(--white); border: 1px solid var(--gray-300);
    color: var(--gray-800); font-size: 0.82rem; font-weight: 500;
    cursor: pointer; min-height: 44px; box-sizing: border-box;
}
.member-chip:hover { border-color: var(--theme-primary, var(--blue)); }
.member-chip.active {
    border-color: var(--theme-primary, var(--blue));
    background: var(--blue-light, #e8f0fb);
    color: var(--theme-primary, var(--blue));
}
.member-chip .member-chip-avatar {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--gray-200); color: var(--gray-700);
    font-size: 0.72rem; font-weight: 700; object-fit: cover;
}
.member-chip.active .member-chip-avatar { background: var(--theme-primary, var(--blue)); color: #fff; }
.member-chip .junior-tag {
    font-size: 0.6rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
    background: var(--amber, #b8860b); color: #fff; border-radius: 4px; padding: 1px 5px;
}
/* On the dark drawer, chips invert for contrast */
.member-switcher-drawer .member-chip { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.18); color: rgba(255,255,255,0.9); }
.member-switcher-drawer .member-chip.active { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.5); color: #fff; }
.member-switcher-drawer .member-chip .member-chip-avatar { background: rgba(255,255,255,0.2); color: #fff; }
.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    color: var(--gray-900);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: none;
}
.form-input:focus { outline: none; border-color: var(--theme-primary, var(--blue)); box-shadow: 0 0 0 3px rgba(0,87,168,0.12); }
.form-input::placeholder { color: var(--gray-500); }
.form-error { font-size: 0.8rem; color: var(--red); margin-top: 4px; }

/* ── Public-form privacy / data notice (shared component) ──── */
.privacy-note {
    background: var(--blue-light);
    border-left: 3px solid var(--blue);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--gray-700);
    margin-bottom: 1rem;
}
.privacy-note strong { color: var(--gray-900); display: block; margin-bottom: 2px; }

/* ── Public-page network failure / retry state (shared) ────── */
.net-error { text-align: center; padding: 1rem; }
.net-error p { color: var(--gray-600); font-size: 0.875rem; margin-bottom: 0.75rem; }

/* ── Badges ─────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 0.75rem; font-weight: 500; }
/* Glyph inside a status badge — carries the meaning when colour can't be seen. */
.badge-glyph { font-size: 0.85em; line-height: 1; }
/* Non-badge status dot must always sit beside a text label, never alone. */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.badge-green  { background: var(--green-light); color: #065f46; }
.badge-red    { background: var(--red-light); color: #991b1b; }
.badge-blue   { background: var(--blue-light); color: #1e40af; }
.badge-amber  { background: var(--amber-light); color: #92400e; }
.badge-gray   { background: var(--gray-100); color: var(--gray-600); }

/* ── List rows ──────────────────────────────────────────── */
.list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.1s;
}
.list-row:last-child { border-bottom: none; }
.list-row[onclick]:hover, .list-row[style*="cursor:pointer"]:hover {
    background: var(--gray-50);
    margin: 0 -8px;
    padding-left: 8px;
    padding-right: 8px;
    border-radius: var(--radius-sm);
}
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--blue-light);
    color: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}
.list-name  { font-size: 0.9rem; font-weight: 500; color: var(--gray-900); }
.list-sub   { font-size: 0.78rem; color: var(--gray-500); }
.list-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

/* ── Alerts ─────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius-md); font-size: 0.875rem; margin-bottom: 1rem; }
.alert-error   { background: var(--red-light); color: #991b1b; }
.alert-success { background: var(--green-light); color: #065f46; }
.alert-info    { background: var(--blue-light); color: #1e40af; }

/* ── Login page ─────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    background: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
}
.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 1.75rem;
}
.login-logo-mark {
    width: 44px;
    height: 44px;
    background: var(--blue);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-logo-mark svg { width: 24px; height: 24px; fill: white; }
.login-title { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.login-subtitle { font-size: 0.875rem; color: var(--gray-500); text-align: center; margin-top: 2px; }

/* ── Section header ─────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-title  { font-size: 1.1rem; font-weight: 600; color: var(--gray-900); }

/* ── Loading ────────────────────────────────────────────── */
.spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--blue);
}
.loading-logo { color: white; font-size: 1.5rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }

/* ── Register ───────────────────────────────────────────────── */
.register-row {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    gap: 10px;
}
.register-row:last-child { border-bottom: none; }
.register-info { flex: 1; min-width: 0; }
.register-actions { display: flex; gap: 8px; flex-shrink: 0; }
.register-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    border: 2px solid var(--gray-200);
    background: var(--white);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    color: var(--gray-400);
}
.register-btn:active { transform: scale(0.92); }
.register-btn.present {
    background: var(--green);
    border-color: var(--green);
    color: white;
}
.register-btn.absent {
    background: var(--red);
    border-color: var(--red);
    color: white;
}
.register-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 8px;
}

/* ── Events ─────────────────────────────────────────────────── */
.event-date-block {
    width: 44px;
    height: 44px;
    background: var(--blue-light);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.event-day   { font-size: 1.1rem; font-weight: 700; color: var(--blue); line-height: 1; }
.event-month { font-size: 0.65rem; color: var(--blue); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Messages ───────────────────────────────────────────────── */
.message-bubble {
    max-width: 80%;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
}
.message-bubble.mine {
    align-self: flex-end;
    align-items: flex-end;
    margin-left: auto;
}
.message-bubble.theirs {
    align-self: flex-start;
    align-items: flex-start;
}
.bubble-body {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}
.mine .bubble-body {
    background: var(--blue);
    color: white;
    border-bottom-right-radius: 4px;
}
.theirs .bubble-body {
    background: var(--gray-100);
    color: var(--gray-900);
    border-bottom-left-radius: 4px;
}
.bubble-time {
    font-size: 0.7rem;
    color: var(--gray-400);
    margin-top: 3px;
    padding: 0 4px;
}
.conversation-list {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.message-compose {
    position: sticky;
    bottom: 0;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 10px 1rem;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    z-index: 10;
}
.message-compose textarea {
    flex: 1;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: var(--font);
}
.message-compose textarea:focus {
    outline: none;
    border-color: var(--blue);
}
.messages-badge {
    background: var(--red);
    color: white;
    border-radius: 99px;
    font-size: 0.65rem;
    padding: 1px 5px;
    margin-left: 3px;
    display: none;
}

/* ── Mobile UX improvements ─────────────────────────────── */

/* Smoother page transitions */
.page.active {
    animation: fadeIn 0.15s ease-in;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Loading skeleton */
.skeleton {
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
    border-radius: var(--radius-md);
    height: 16px;
    margin-bottom: 8px;
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Touch targets (X9): accessible checkboxes/radios everywhere */
input[type=checkbox], input[type=radio] {
    width: 20px;
    height: 20px;
    accent-color: var(--theme-primary, var(--blue));
    cursor: pointer;
    flex-shrink: 0;
}

/* Better tap targets on mobile */
@media (max-width: 600px) {
    .form-input { min-height: 44px; font-size: 16px; }
    .list-row { min-height: 52px; }
    .register-btn { width: 52px; height: 52px; font-size: 1.3rem; }
    .bottomnav-item { font-size: 0.65rem; padding: 6px 2px; }
    .topnav-name { font-size: 0.95rem; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .main { padding: 0.75rem; padding-bottom: 80px; }
}

/* PWA install banner */
.install-banner {
    position: fixed;
    bottom: 70px;
    left: 1rem;
    right: 1rem;
    background: var(--blue);
    color: white;
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0,87,168,0.4);
    animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.install-banner-text { flex: 1; font-size: 0.875rem; }
.install-banner-btn {
    background: white;
    color: var(--blue);
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.install-banner-dismiss {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Loading spinner overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.8);
    z-index: 50;
}

/* Better card spacing on mobile */
@media (max-width: 600px) {
    .card { padding: 0.875rem 1rem; margin-bottom: 0.75rem; }
    h1 { font-size: 1.25rem; }
    .stat-value { font-size: 1.5rem; }
}

/* Prevent zoom on input focus iOS */
input, select, textarea {
    font-size: 16px !important;
}

/* Safe area for iPhone notch */
.bottomnav {
    padding-bottom: max(env(safe-area-inset-bottom), 8px);
}
.topnav {
    padding-top: env(safe-area-inset-top);
}

/* ── Bottom nav overflow handling ───────────────────────────── */
@media (max-width: 400px) {
    .bottomnav-item:nth-child(n+6) {
        display: none;
    }
}

/* ── Theme definitions ──────────────────────────────────── */
:root {
    --theme-primary:      #0057a8;
    --theme-primary-dark: #003d75;
    --theme-primary-text: white;
    --theme-drawer-bg:    #0f172a;
    --theme-drawer-text:  rgba(255,255,255,0.65);
    --theme-drawer-active:rgba(255,255,255,0.1);
    --theme-accent:       #059669;
    --theme-name:         'clean-sport';
}

[data-theme="carbon-steel"] {
    --theme-primary:      #c9323c;
    --theme-primary-dark: #a01f28;
    --theme-primary-text: white;
    --theme-drawer-bg:    #0f1219;
    --theme-drawer-text:  rgba(255,255,255,0.65);
    --theme-drawer-active:rgba(255,255,255,0.08);
    --theme-accent:       #3a7bd5;
    --theme-name:         'carbon-steel';
}

[data-theme="parchment"] {
    --theme-primary:      #2c1810;
    --theme-primary-dark: #1a0e09;
    --theme-primary-text: #f5f0e8;
    --theme-drawer-bg:    #1e120a;
    --theme-drawer-text:  rgba(245,240,232,0.65);
    --theme-drawer-active:rgba(200,169,106,0.15);
    --theme-accent:       #c8a96a;
    --theme-name:         'parchment';
}

[data-theme="forest"] {
    --theme-primary:      #1a5c2a;
    --theme-primary-dark: #0d3317;
    --theme-primary-text: white;
    --theme-drawer-bg:    #0d2e16;
    --theme-drawer-text:  rgba(255,255,255,0.65);
    --theme-drawer-active:rgba(74,196,106,0.12);
    --theme-accent:       #4ac46a;
    --theme-name:         'forest';
}

/* ── Apply theme variables ───────────────────────────────── */
.topnav          { background: var(--theme-primary) !important; }
.drawer          { background: var(--theme-drawer-bg) !important; }
.drawer-item     { color: var(--theme-drawer-text) !important; }
.drawer-item.active,
.drawer-item:hover { background: var(--theme-drawer-active) !important; }
.drawer-app-name { color: var(--theme-primary-text) !important; }
.btn-primary     { background: var(--theme-primary) !important; border-color: var(--theme-primary) !important; }
.btn-primary:hover { background: var(--theme-primary-dark) !important; }
.stat-value.blue { color: var(--theme-primary) !important; }
.badge-green     { background: var(--theme-accent); }
.login-page      { background: var(--theme-primary) !important; }

/* ── Typography polish ──────────────────────────────────── */
h1 { font-size: 1.375rem; font-weight: 600; color: var(--gray-900); margin-bottom: 1rem; line-height: 1.3; }
h2 { font-size: 1.125rem; font-weight: 600; color: var(--gray-900); margin-bottom: 0.75rem; }
h3 { font-size: 0.975rem; font-weight: 600; color: var(--gray-800); margin-bottom: 0.5rem; }

.list-name { font-size: 0.9rem; font-weight: 500; color: var(--gray-900); line-height: 1.3; }
.list-sub  { font-size: 0.775rem; color: var(--gray-500); margin-top: 2px; }
.list-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }

.text-muted  { color: var(--gray-500); font-size: 0.875rem; }
.text-center { text-align: center; }
.mt-2 { margin-top: 0.75rem; }

/* ── Section header ─────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

/* ── Empty states ───────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--gray-500);
}
.empty-state-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    background: var(--gray-100);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.empty-state-icon svg { width: 24px; height: 24px; stroke: var(--gray-400); }
.empty-state-title { font-size: 0.975rem; font-weight: 500; color: var(--gray-600); margin-bottom: 4px; }
.empty-state-desc  { font-size: 0.825rem; color: var(--gray-500); }

/* ── Alert improvements ─────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    border-left: 3px solid transparent;
}
.alert-success { background: var(--green-light); color: #065f46; border-left-color: var(--green); }
.alert-error   { background: var(--red-light); color: #991b1b; border-left-color: var(--red); }
.alert-info    { background: var(--blue-light); color: #1e40af; border-left-color: var(--blue); }

/* ── Form label polish ──────────────────────────────────── */
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; letter-spacing: 0.01em; }

/* ── Topnav title ───────────────────────────────────────── */
.topnav-name { color: white; font-weight: 600; font-size: 1rem; flex: 1; }

/* ── Avatar improvements ────────────────────────────────── */
.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--blue-light);
    color: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}

/* ── Desktop table layout ───────────────────────────────── */
@media (min-width: 768px) {
    .desktop-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 0.875rem;
    }
    .desktop-table th {
        text-align: left;
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--gray-500);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        padding: 0 12px 10px;
        border-bottom: 1px solid var(--gray-200);
    }
    .desktop-table td {
        padding: 11px 12px;
        border-bottom: 1px solid var(--gray-100);
        color: var(--gray-800);
        vertical-align: middle;
    }
    .desktop-table tr:last-child td { border-bottom: none; }
    .desktop-table tr:hover td { background: var(--gray-50); }
    .desktop-table .td-name { font-weight: 500; color: var(--gray-900); }
    .desktop-table .td-muted { color: var(--gray-500); font-size: 0.8rem; }
    .desktop-table .td-actions { text-align: right; white-space: nowrap; }
}

/* ── Desktop dashboard two-column ───────────────────────── */
@media (min-width: 768px) {
    .dashboard-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
    .dashboard-grid .card-full { grid-column: 1 / -1; }
}

/* ── Dashboard priority alert cards ─────────────────────── */
.dashboard-alerts {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 1rem;
}
@media (min-width: 768px) {
    .dashboard-alerts { grid-template-columns: repeat(3, 1fr); }
}
.alert-card .alert-all-good {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--green, #3aa655);
    font-size: 0.85rem;
    padding: 4px 0;
}
.alert-card .alert-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 0;
    border-top: 1px solid var(--gray-100);
}
.alert-card .alert-row:first-of-type { border-top: none; }
.alert-card .alert-row-main { flex: 1; min-width: 0; }
.alert-card .alert-viewall { display: inline-block; margin-top: 8px; font-size: 0.8rem; color: var(--theme-primary, var(--blue, #378add)); cursor: pointer; }

/* ── Mobile dashboard: single column, alerts stack first ── */
@media (max-width: 640px) {
    .dashboard-alerts { grid-template-columns: 1fr; }
    #page-dashboard .dashboard-grid { grid-template-columns: 1fr; display: block; }
    #page-dashboard .dashboard-grid .card { margin-bottom: 1rem; }
}

/* ── Keyboard / focus improvements ─────────────────────── */
:focus-visible {
    outline: 2px solid var(--theme-primary, var(--blue));
    outline-offset: 2px;
}
button:focus:not(:focus-visible) { outline: none; }

/* ── Smooth page transitions ────────────────────────────── */
.page.active {
    animation: pageIn 0.18s ease-out;
}
@keyframes pageIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Desktop topnav improvements ───────────────────────── */
@media (min-width: 768px) {
    .topnav {
        height: 60px;
        padding: 0 1.5rem;
        gap: 14px;
    }
    .topnav-btn {
        font-size: 0.825rem;
        padding: 6px 12px;
    }
    .topnav-name {
        font-size: 1.05rem;
    }
}

/* ── Drawer width on large screens ─────────────────────── */
@media (min-width: 1200px) {
    .drawer { width: 240px; }
}

/* ── Scrollbar styling ──────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ── Card hover on desktop ──────────────────────────────── */
@media (min-width: 768px) {
    .card-clickable {
        cursor: pointer;
        transition: box-shadow 0.15s, transform 0.15s;
    }
    .card-clickable:hover {
        box-shadow: 0 4px 16px rgba(0,0,0,0.08);
        transform: translateY(-1px);
    }
}

/* ── CSV Import ─────────────────────────────────────────────── */
#import-dropzone:hover {
    border-color: var(--blue) !important;
    background: var(--blue-light);
}

/* ── Register tap-anywhere ──────────────────────────────────── */
.register-row { transition: background 0.15s; border-radius: var(--radius-md); }
.register-row:active { opacity: 0.8; }
.register-row-present { background: rgba(34, 197, 94, 0.08) !important; border-left: 3px solid var(--green); }
.register-row-absent  { background: rgba(239, 68, 68, 0.08) !important; border-left: 3px solid var(--red); }

/* ── iOS PWA safe area insets ─────────────────────────────── */
/* Push topnav down below status bar / dynamic island */
.topnav {
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
}

/* Drawer needs same top offset */
.drawer {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Bottom padding for home indicator */
.main {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* ── Print-friendly register (Item 19) ─────────────────────────── */
#print-register { display: none; }
.print-reg-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.print-reg-table th, .print-reg-table td { border: 1px solid #333; padding: 6px 8px; text-align: left; font-size: 12px; }
.print-reg-table th { background: #eee; }
.print-reg-check { width: 28px; text-align: center; }
@media print {
    .app, #drawer, #drawer-overlay, #toast-wrap, #notif-panel, #notif-overlay,
    .topnav, .theme-toggle, .notif-bell { display: none !important; }
    #print-register { display: block !important; padding: 16px; color: #000; }
    #print-register h1 { font-size: 20px; margin-bottom: 2px; }
    #print-register .print-meta { font-size: 13px; color: #333; margin-bottom: 4px; }
    #print-sign { margin-top: 28px; font-size: 13px; }
}
