/* ═══════════════════════════════════════════════════════════════════════════
   Active Aging System — Modernized Stylesheet v3
   Design tokens from DASHBOARD.md §3, refined for a warm, accessible,
   health-app aesthetic.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ────────────────────────────────────────────────────── */
:root {
    /* Primary palette */
    --ink: #16241F;
    --ink-80: rgba(22, 36, 31, 0.80);
    --ink-60: rgba(22, 36, 31, 0.60);
    --ink-40: rgba(22, 36, 31, 0.40);
    --ink-12: rgba(22, 36, 31, 0.12);
    --ink-08: rgba(22, 36, 31, 0.08);
    --ink-04: rgba(22, 36, 31, 0.04);

    --paper: #FBFAF6;
    --paper-60: rgba(251, 250, 246, 0.60);

    --white: #FFFFFF;

    /* Jade — action / success / brand */
    --jade: #2E7D64;
    --jade-hover: #256B54;
    --jade-light: #E8F5EE;
    --jade-16: rgba(46, 125, 100, 0.16);
    --jade-08: rgba(46, 125, 100, 0.08);

    /* Clay — attention / error / warmth */
    --clay: #B4552F;
    --clay-light: #FDF0EB;
    --clay-16: rgba(180, 85, 47, 0.16);

    /* Mustard — highlight / warning */
    --mustard: #D9A521;
    --mustard-light: #FDF6E3;
    --mustard-16: rgba(217, 165, 33, 0.16);

    /* Slate — secondary text / borders */
    --slate: #5B6B66;
    --slate-light: #EEF0EF;

    /* Surface / elevation tokens */
    --surface: #FFFFFF;
    --surface-hover: rgba(22, 36, 31, 0.02);
    --border-default: rgba(22, 36, 31, 0.10);
    --border-field: rgba(22, 36, 31, 0.20);

    /* Typography */
    --font-display: 'Bricolage Grotesque', 'Instrument Serif', Georgia, serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;

    /* Type scale */
    --text-xs: 13px;
    --text-sm: 14px;
    --text-base: 16px;
    --text-lg: 18px;
    --text-xl: 20px;
    --text-2xl: 22px;
    --text-3xl: 30px;
    --text-4xl: 36px;
    --text-5xl: 48px;
    --text-6xl: 64px;

    /* Spacing scale (4px grid) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Border radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 999px;

    /* Shadow elevations */
    --shadow-sm: 0 1px 2px rgba(22, 36, 31, 0.06);
    --shadow-md: 0 2px 8px rgba(22, 36, 31, 0.08);
    --shadow-lg: 0 4px 16px rgba(22, 36, 31, 0.10);
    --shadow-xl: 0 8px 32px rgba(22, 36, 31, 0.12);

    /* Motion */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --duration-fast: 150ms;
    --duration-base: 200ms;
    --duration-slow: 300ms;
}

/* ── Reset ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

/* ── Base ─────────────────────────────────────────────────────────────── */
body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper);
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
}

footer {
    text-align: center;
    padding: var(--space-8);
    color: var(--slate);
    font-size: var(--text-sm);
}

/* ── Typography ───────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin-bottom: 0.4em;
    color: var(--ink);
}

h1 { font-size: var(--text-3xl); font-weight: 700; }
h2 { font-size: var(--text-2xl); font-weight: 700; }
h3 { font-size: var(--text-lg); font-weight: 600; }

p { margin-bottom: 0.5em; }

a {
    color: var(--jade);
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color var(--duration-fast) var(--ease-out);
}

a:hover { color: var(--jade-hover); }

/* ── Skip Link ────────────────────────────────────────────────────────── */
.skip-link {
    position: absolute;
    left: -9999px;
    top: var(--space-2);
    z-index: 200;
    background: var(--jade);
    color: var(--white);
    padding: var(--space-3) var(--space-6);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-weight: 600;
    text-decoration: none;
    transition: left 0s;
}
.skip-link:focus { left: 0; }

/* ── Tables ───────────────────────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-4) 0;
}
th, td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--ink-08);
}
th {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--slate);
    font-weight: 600;
}
td[class*="number"],
td[class*="metric"] {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 var(--space-6);
    font-size: var(--text-base);
    font-family: var(--font-body);
    font-weight: 600;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--jade);
    color: var(--white);
    cursor: pointer;
    min-width: 200px;
    min-height: 60px;
    transition: background var(--duration-fast) var(--ease-out),
                transform var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
    text-decoration: none;
}

button:hover, .btn:hover {
    background: var(--jade-hover);
    box-shadow: var(--shadow-md);
}
button:active, .btn:active { transform: scale(0.98); }
button:focus-visible, .btn:focus-visible {
    outline: 3px solid var(--jade);
    outline-offset: 2px;
}

/* Semantics */
.positive { color: var(--jade); }
.attention { color: var(--clay); }
.highlight { color: var(--mustard); }

/* ── Primary Button ───────────────────────────────────────────────────── */
.btn-primary {
    height: 60px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    background: var(--jade);
    color: var(--white);
    font-size: var(--text-lg);
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--duration-fast) var(--ease-out),
                transform var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}
.btn-primary:hover {
    background: var(--jade-hover);
    box-shadow: var(--shadow-md);
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:focus-visible {
    outline: 3px solid var(--jade);
    outline-offset: 3px;
}

/* ── Secondary Button ─────────────────────────────────────────────────── */
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    min-width: 160px;
    padding: 0 var(--space-6);
    border-radius: var(--radius-md);
    border: 2px solid var(--ink-40);
    background: transparent;
    color: var(--ink);
    font-size: var(--text-base);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: border-color var(--duration-fast) var(--ease-out),
                background var(--duration-fast) var(--ease-out);
}
.btn-secondary:hover {
    border-color: var(--ink);
    background: var(--ink-04);
}
.btn-secondary:active { transform: scale(0.98); }

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: var(--radius-full);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: var(--ink-08);
    color: var(--slate);
}
.badge--jade { background: var(--jade-16); color: var(--jade); }
.badge--clay { background: var(--clay-16); color: var(--clay); }
.badge--mustard { background: var(--mustard-16); color: var(--mustard); }
.badge--slate { background: var(--ink-08); color: var(--ink-60); }

/* ── Flash Messages (Toast-style) ─────────────────────────────────────── */
.flash {
    border-radius: var(--radius-md);
    padding: var(--space-5) var(--space-6);
    margin-bottom: var(--space-6);
    font-size: var(--text-base);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    animation: flashIn var(--duration-slow) var(--ease-out);
    border: 1px solid transparent;
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.flash--success {
    background: var(--jade-16);
    color: var(--jade);
    border-color: var(--jade);
}
.flash--error {
    background: var(--clay-16);
    color: var(--clay);
    border-color: var(--clay);
}

/* ── Error Box ────────────────────────────────────────────────────────── */
.error-box {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    background: var(--clay-16);
    border: 1px solid var(--clay);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    font-size: var(--text-base);
    color: var(--ink);
}
.error-box ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* ── Inline errorlist ─────────────────────────────────────────────────── */
.errorlist {
    margin: var(--space-1) 0 0;
    padding: 0;
    list-style: none;
    color: var(--clay);
    font-size: var(--text-sm);
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════════════
   AUTH PAGES (login, logout, password reset)
   Single centred column, 480px max, paper background.
   ═══════════════════════════════════════════════════════════════════════════ */

.auth-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    background: linear-gradient(180deg, var(--jade-08) 0%, var(--paper) 40%);
}

.auth-container {
    width: 100%;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    animation: fadeUp var(--duration-slow) var(--ease-out);
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Brand zone — white card with partner logos */
.brand-zone {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-5) var(--space-8);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-8);
    transition: box-shadow var(--duration-base) var(--ease-out);
}
.brand-zone:hover { box-shadow: var(--shadow-lg); }

.brand-zone img {
    height: 64px;
    width: auto;
    object-fit: contain;
}
.brand-zone img.logo-ntu { min-width: 140px; }

.brand-zone .brand-divider {
    width: 1px;
    height: 52px;
    background: var(--ink-12);
    border-radius: 0;
}

.auth-title {
    text-align: center;
}
.auth-title h1 {
    font-size: var(--text-3xl);
    font-weight: 700;
    margin-bottom: var(--space-1);
    color: var(--ink);
}
.auth-title p {
    color: var(--ink-60);
    font-size: var(--text-base);
}

/* Auth card — refined white panel */
.auth-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-8);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    border: 1px solid var(--ink-04);
    transition: box-shadow var(--duration-base) var(--ease-out);
}
.auth-card:hover { box-shadow: var(--shadow-xl); }

.auth-card h2 {
    font-size: var(--text-2xl);
    font-weight: 700;
    text-align: center;
    margin: 0;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

/* Form fields */
.form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.form-field label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink-80);
}

.form-input,
.form-field input[type="text"],
.form-field input[type="password"],
.form-field input[type="email"] {
    height: 60px;
    width: 100%;
    padding: 0 var(--space-4);
    font-size: var(--text-lg);
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--white);
    border: 2px solid var(--border-field);
    border-radius: var(--radius-md);
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}
.form-field input:focus {
    outline: none;
    border-color: var(--jade);
    box-shadow: 0 0 0 4px var(--jade-16);
}

.form-help {
    font-size: var(--text-sm);
    color: var(--ink-60);
}

/* Password field with show/hide */
.input-wrap {
    position: relative;
}
.input-wrap input {
    padding-right: 5rem;
}
.show-toggle {
    position: absolute;
    right: var(--space-2);
    top: 50%;
    transform: translateY(-50%);
    min-width: 48px;
    min-height: 48px;
    padding: 0 var(--space-3);
    background: none;
    border: none;
    color: var(--jade);
    font-size: var(--text-base);
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--duration-fast) var(--ease-out);
}
.show-toggle:hover { background: var(--jade-08); }
.show-toggle:focus-visible {
    outline: 3px solid var(--jade);
    outline-offset: 2px;
}

/* Auth footer links */
.auth-link {
    text-align: center;
}
.auth-link a {
    color: var(--jade);
    font-size: var(--text-base);
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Success state */
.auth-success {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    text-align: center;
    padding: var(--space-4) 0;
}
.auth-success-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--jade-16);
    color: var(--jade);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    font-weight: 700;
    font-family: var(--font-display);
}
.auth-success p {
    font-size: var(--text-lg);
    color: var(--ink);
    margin: 0;
}
.auth-success .auth-subnote {
    font-size: var(--text-base);
    color: var(--ink-60);
}

.auth-footer {
    text-align: center;
    color: var(--ink-60);
    font-size: var(--text-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   APP SHELL — Sidebar + Main Area
   ═══════════════════════════════════════════════════════════════════════════ */

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
    width: 272px;
    flex-shrink: 0;
    background: var(--ink);
    color: var(--paper);
    display: flex;
    flex-direction: column;
    padding: var(--space-6) var(--space-4);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: 0 var(--space-3) var(--space-5);
    border-bottom: 1px solid var(--paper-60);
    margin-bottom: var(--space-3);
}
.sidebar-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: -0.01em;
}
.sidebar-subtitle {
    font-size: var(--text-sm);
    color: var(--paper-60);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3);
    min-height: 48px;
    border-radius: var(--radius-md);
    color: var(--paper-60);
    text-decoration: none;
    font-size: var(--text-base);
    font-weight: 500;
    transition: background var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
}
.nav-link:hover {
    background: rgba(251, 250, 246, 0.10);
    color: var(--paper);
}
.nav-link:focus-visible {
    outline: 2px solid var(--jade);
    outline-offset: -2px;
}

.nav-link--active {
    background: var(--jade);
    color: var(--white);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.nav-link--active:hover {
    background: var(--jade-hover);
}

.nav-icon {
    font-size: 20px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-user {
    border-top: 1px solid var(--paper-60);
    padding: var(--space-4) var(--space-3) 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
.sidebar-username {
    font-weight: 600;
    font-size: var(--text-base);
}

.btn-signout {
    background: none;
    border: 1px solid var(--paper-60);
    color: var(--paper);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-4);
    min-width: 0;
    min-height: 44px;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-out),
                border-color var(--duration-fast) var(--ease-out);
}
.btn-signout:hover {
    background: rgba(251, 250, 246, 0.10);
    border-color: var(--paper);
}

/* ── Main Content Area ────────────────────────────────────────────────── */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--paper);
}

.page-main {
    flex: 1;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
}

/* ── Footer ───────────────────────────────────────────────────────────── */
.page-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--ink-08);
    background: var(--white);
}

.partner-chips {
    display: flex;
    gap: var(--space-2);
}

.partner-chip {
    background: var(--white);
    border: 1px solid var(--ink-08);
    border-radius: var(--radius-sm);
    padding: var(--space-1) var(--space-3);
    display: inline-flex;
    align-items: center;
    transition: box-shadow var(--duration-fast) var(--ease-out);
}
.partner-chip:hover { box-shadow: var(--shadow-sm); }

.footer-note {
    margin: 0;
    color: var(--ink-60);
    font-size: var(--text-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   PAGE HEADER
   ═══════════════════════════════════════════════════════════════════════════ */

.page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}
.page-head h1,
.page-head h2 {
    margin: 0;
}

.page-date {
    color: var(--ink-60);
    font-size: var(--text-base);
}

/* ── Back link ────────────────────────────────────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 48px;
    margin-right: var(--space-1);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--ink-60);
    font-size: 22px;
    transition: background var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
}
.back-link:hover,
.back-link:focus-visible {
    background: var(--jade-08);
    color: var(--jade);
}

/* ═══════════════════════════════════════════════════════════════════════════
   DASHBOARD — KPI Cards, Station Status, Check-ins
   ═══════════════════════════════════════════════════════════════════════════ */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-4);
    margin: var(--space-6) 0;
}

.kpi-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--ink-04);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    transition: box-shadow var(--duration-base) var(--ease-out),
                transform var(--duration-base) var(--ease-out);
    position: relative;
    overflow: hidden;
}
.kpi-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--jade);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}
.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.kpi-card--attention::before { background: var(--clay); }
.kpi-card--highlight::before { background: var(--mustard); }

.kpi-card .kpi-value {
    font-family: var(--font-display);
    font-size: var(--text-5xl);
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
    letter-spacing: -0.02em;
}
.kpi-card .kpi-label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-60);
    font-weight: 600;
}
.kpi-card .kpi-delta {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    margin-top: var(--space-1);
    color: var(--ink-60);
}

.kpi-total {
    font-size: var(--text-xl);
    color: var(--ink-60);
    font-weight: 400;
}

/* ── Section Cards ────────────────────────────────────────────────────── */
.section-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--ink-04);
    margin: var(--space-6) 0;
    transition: box-shadow var(--duration-base) var(--ease-out);
}
.section-card:hover { box-shadow: var(--shadow-md); }

.section-card h2 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--ink-08);
}

/* ── Station Status ───────────────────────────────────────────────────── */
.station-strip {
    display: flex;
    gap: var(--space-3);
    margin: var(--space-4) 0;
    flex-wrap: wrap;
}

.station-chip {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--white);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--ink-04);
    font-size: var(--text-sm);
    transition: box-shadow var(--duration-fast) var(--ease-out);
}
.station-chip:hover { box-shadow: var(--shadow-md); }

.station-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--slate);
    box-shadow: 0 0 0 2px rgba(91, 107, 102, 0.2);
}
.station-dot--online {
    background: var(--jade);
    box-shadow: 0 0 0 2px var(--jade-16);
    animation: pulse 2s infinite;
}
.station-dot--busy {
    background: var(--mustard);
    box-shadow: 0 0 0 2px var(--mustard-16);
}
.station-dot--offline { background: var(--slate); }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 2px var(--jade-16); }
    50%      { box-shadow: 0 0 0 6px var(--jade-08); }
}

/* ── Check-in List ────────────────────────────────────────────────────── */
.checkin-list { list-style: none; }

.checkin-item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--ink-04);
    transition: background var(--duration-fast) var(--ease-out);
}
.checkin-item:last-child { border-bottom: none; }
.checkin-item:hover { background: var(--surface-hover); }

.checkin-name {
    font-weight: 600;
    font-size: var(--text-base);
    flex: 1;
}
.checkin-meta {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--ink-60);
}
.checkin-time {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: var(--text-base);
    color: var(--ink-60);
}
.checkin-action {
    min-width: auto;
    min-height: auto;
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    border-radius: var(--radius-sm);
}

/* ── Empty State ──────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--ink-40);
}
.empty-state p {
    font-size: var(--text-base);
    margin-bottom: var(--space-4);
}

/* ── Quick Actions ────────────────────────────────────────────────────── */
.quick-actions {
    display: flex;
    gap: var(--space-3);
    margin: var(--space-6) 0;
    flex-wrap: wrap;
}
.quick-actions .btn { min-width: auto; }

/* ═══════════════════════════════════════════════════════════════════════════
   SEARCH BAR (D2)
   ═══════════════════════════════════════════════════════════════════════════ */

.search-bar {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-6);
}
.search-bar input[type="search"],
.search-bar input[type="text"] {
    flex: 1;
    min-height: 60px;
    padding: 0 var(--space-4);
    font-size: var(--text-lg);
    border: 2px solid var(--border-field);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--ink);
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}
.search-bar input:focus {
    outline: none;
    border-color: var(--jade);
    box-shadow: 0 0 0 4px var(--jade-16);
}
.search-bar .btn-primary {
    width: auto;
    min-width: 140px;
    flex-shrink: 0;
    padding: 0 var(--space-6);
}

/* NRIC scan accent */
.search-bar--scan { margin-bottom: var(--space-2); }
.search-bar--scan input[type="text"] { border-color: var(--jade); }
.search-bar--scan + .help-text {
    margin-bottom: var(--space-6);
    color: var(--ink-60);
    font-size: var(--text-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   PARTICIPANT LIST (D2)
   ═══════════════════════════════════════════════════════════════════════════ */

.person-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.person-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: var(--white);
    border: 1px solid var(--ink-08);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-5);
    min-height: 72px;
    text-decoration: none;
    color: var(--ink);
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out),
                transform var(--duration-fast) var(--ease-out);
}
.person-row:hover {
    border-color: var(--jade);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.person-row:focus-visible {
    outline: 3px solid var(--jade);
    outline-offset: 2px;
}

.person-name { font-size: var(--text-lg); font-weight: 600; }
.person-meta { color: var(--ink-60); font-size: var(--text-sm); }
.person-last { margin-left: auto; text-align: right; }

/* ═══════════════════════════════════════════════════════════════════════════
   PARTICIPANT PROFILE (D3)
   ═══════════════════════════════════════════════════════════════════════════ */

.profile-head {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    background: var(--white);
    border: 1px solid var(--ink-08);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--duration-base) var(--ease-out);
}
.profile-head:hover { box-shadow: var(--shadow-md); }

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--jade), #1A5C47);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    font-family: var(--font-display);
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
}

.profile-facts {
    display: flex;
    gap: var(--space-5);
    flex-wrap: wrap;
    margin-top: var(--space-2);
    color: var(--ink-60);
    font-size: var(--text-sm);
}

/* Card grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

/* Panel */
.panel {
    background: var(--white);
    border: 1px solid var(--ink-08);
    border-radius: var(--radius-lg);
    padding: var(--space-5) var(--space-6);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--duration-base) var(--ease-out);
}
.panel:hover { box-shadow: var(--shadow-md); }
.panel h3 { margin: 0 0 var(--space-4); }

/* Stat line */
.stat-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--ink-04);
    font-size: var(--text-base);
}
.stat-line:last-child { border-bottom: none; }
.stat-line .num {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--ink-80);
}

/* Rhythm strip */
.rhythm-strip {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.rhythm-day {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-family: var(--font-mono);
    background: var(--ink-08);
    color: var(--ink-60);
    transition: transform var(--duration-fast) var(--ease-out);
}
.rhythm-day:hover { transform: scale(1.15); }
.rhythm-day--visited {
    background: var(--jade);
    color: var(--white);
    box-shadow: 0 2px 4px var(--jade-16);
}
.rhythm-day--today {
    outline: 2px solid var(--clay);
    outline-offset: 2px;
}

/* Note item */
.note-item {
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--ink-04);
}
.note-item:last-child { border-bottom: none; }
.note-meta { color: var(--ink-60); font-size: var(--text-sm); margin-top: var(--space-1); }

.kpi-note { font-size: var(--text-xs); color: var(--ink-60); margin-top: var(--space-1); }

/* ═══════════════════════════════════════════════════════════════════════════
   FORMS (D4/D5) — Modernized input styling
   ═══════════════════════════════════════════════════════════════════════════ */

.form-card {
    background: var(--white);
    border: 1px solid var(--ink-08);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    max-width: 680px;
    box-shadow: var(--shadow-sm);
}

.form-card .form-field { margin-bottom: var(--space-5); }

.form-card label {
    display: block;
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--ink-80);
    margin-bottom: var(--space-2);
}

.form-card input,
.form-card select,
.form-card textarea {
    width: 100%;
    min-height: 60px;
    padding: 0 var(--space-4);
    font-size: var(--text-lg);
    font-family: var(--font-body);
    border: 2px solid var(--border-field);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--ink);
    box-sizing: border-box;
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
    appearance: none;
}

.form-card textarea { padding: var(--space-4); min-height: 120px; }

.form-card select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235B6B66' stroke-width='2' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 48px;
}

.form-card input:focus,
.form-card select:focus,
.form-card textarea:focus {
    outline: none;
    border-color: var(--jade);
    box-shadow: 0 0 0 4px var(--jade-16);
}

.form-card .help-text {
    color: var(--ink-60);
    font-size: var(--text-sm);
    margin-top: var(--space-1);
}

.form-card .errorlist {
    color: var(--clay);
    font-weight: 600;
    margin: var(--space-2) 0 0;
    padding-left: var(--space-5);
}

/* Form actions */
.form-actions {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-8);
    flex-wrap: wrap;
}
.form-actions .btn-primary {
    width: auto;
    min-width: 220px;
    padding: 0 var(--space-8);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

/* Collapsible fold */
.form-fold {
    border: 2px solid var(--ink-12);
    border-radius: var(--radius-md);
    padding: 0 var(--space-5);
    background: var(--jade-08);
    margin-bottom: var(--space-6);
}
.form-fold summary {
    cursor: pointer;
    min-height: 48px;
    display: flex;
    align-items: center;
    padding: var(--space-3) 0;
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--jade);
    transition: color var(--duration-fast) var(--ease-out);
}
.form-fold summary:hover { color: var(--jade-hover); }
.form-fold summary:focus-visible {
    outline: 3px solid var(--jade);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
.form-fold[open] { padding-bottom: var(--space-5); }
.form-fold[open] summary {
    border-bottom: 1px solid var(--ink-12);
    margin-bottom: var(--space-4);
}
.form-fold .form-field { margin-top: var(--space-4); }

/* ── Autocomplete Combobox ──────────────────────────────────────────── */
.autocomplete { position: relative; }

.form-card .autocomplete-input {
    width: 100%;
    min-height: 60px;
    padding: 0 var(--space-4) 0 52px;
    font-size: var(--text-lg);
    font-family: var(--font-body);
    border: 2px solid var(--border-field);
    border-radius: var(--radius-md);
    background: var(--white);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235B6B66' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.35-4.35'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 16px center;
    color: var(--ink);
    box-sizing: border-box;
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
    appearance: none;
}

.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    background: var(--white);
    border: 2px solid var(--border-field);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    list-style: none;
    margin: var(--space-1) 0 0;
    padding: 0;
    z-index: 100;
}
.autocomplete-result {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--ink-04);
    transition: background var(--duration-fast) var(--ease-out);
}
.autocomplete-result:last-child { border-bottom: none; }
.autocomplete-result:hover,
.autocomplete-result.autocomplete-active {
    background: var(--jade-08);
}
.autocomplete-name { font-weight: 600; font-size: var(--text-base); }
.autocomplete-meta { font-size: var(--text-sm); color: var(--ink-60); }
.autocomplete-no-results {
    padding: var(--space-4);
    text-align: center;
    color: var(--ink-60);
    font-size: var(--text-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BROADCAST DISPLAY (B1)
   ═══════════════════════════════════════════════════════════════════════════ */

.broadcast-body {
    background: linear-gradient(160deg, #0E1A15 0%, var(--ink) 40%, #1A2E26 100%);
    color: var(--paper);
}

.broadcast-stage {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    padding: var(--space-8) var(--space-12);
    gap: var(--space-5);
    animation: fadeUp var(--duration-slow) var(--ease-out);
    overflow-y: auto;
}

/* Header */
.broadcast-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
}

.broadcast-heading {
    font-family: var(--font-display);
    font-size: clamp(36px, 6vw, 72px);
    font-weight: 700;
    line-height: 1.1;
    margin: 0;
    background: linear-gradient(180deg, var(--paper) 0%, rgba(251, 250, 246, 0.7) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.broadcast-date {
    font-size: clamp(18px, 2vw, 24px);
    color: var(--paper-60);
    margin: 0;
    font-weight: 400;
    letter-spacing: 0.04em;
}

.broadcast-sub {
    font-size: clamp(20px, 2.5vw, 28px);
    color: var(--paper-60);
    margin: 0;
    font-weight: 400;
}

/* Hero count zone */
.broadcast-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-4) 0;
}

.broadcast-hero-label {
    font-family: var(--font-body);
    font-size: clamp(16px, 1.8vw, 22px);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--paper-60);
    margin: 0 0 var(--space-1);
}

.broadcast-count {
    font-family: var(--font-display);
    font-size: clamp(96px, 18vw, 200px);
    font-weight: 700;
    color: var(--mustard);
    line-height: 1;
    text-shadow: 0 4px 32px rgba(217, 165, 33, 0.3);
    animation: countIn var(--duration-slow) var(--ease-out);
}

.broadcast-avg {
    font-size: clamp(18px, 2vw, 24px);
    color: var(--paper-60);
    margin: var(--space-2) 0 0;
}

.broadcast-avg strong {
    color: var(--paper);
    font-weight: 600;
}

/* KPI strip */
.broadcast-kpi-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-4);
    width: 100%;
    max-width: 900px;
}

.broadcast-kpi {
    flex: 1 1 180px;
    max-width: 220px;
    background: rgba(251, 250, 246, 0.05);
    border: 1px solid rgba(251, 250, 246, 0.10);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    backdrop-filter: blur(4px);
}

.broadcast-kpi-value {
    font-family: var(--font-display);
    font-size: clamp(48px, 6vw, 72px);
    font-weight: 700;
    line-height: 1;
}

.broadcast-kpi-value--jade  { color: var(--jade-light); text-shadow: 0 2px 16px rgba(46, 125, 100, 0.3); }
.broadcast-kpi-value--mustard { color: var(--mustard); text-shadow: 0 2px 16px rgba(217, 165, 33, 0.25); }

.broadcast-kpi-label {
    font-size: var(--text-sm);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--paper-60);
    font-weight: 500;
}

/* Weekly trend bar chart */
.broadcast-trend {
    width: 100%;
    max-width: 700px;
}

.broadcast-trend-heading {
    font-family: var(--font-display);
    font-size: clamp(20px, 2.5vw, 28px);
    font-weight: 600;
    color: var(--paper);
    margin: 0 0 var(--space-3);
    text-align: center;
}

.broadcast-trend-bars {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 160px;
    gap: var(--space-3);
    padding: 0 var(--space-2);
}

.broadcast-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-1);
    height: 100%;
}

.broadcast-bar-fill {
    width: 44px;
    border-radius: 6px 6px 2px 2px;
    background: var(--jade);
    box-shadow: 0 2px 10px rgba(46, 125, 100, 0.35);
    transition: height var(--duration-base) var(--ease-out);
}

.broadcast-bar-fill--today {
    background: var(--mustard);
    box-shadow: 0 2px 14px rgba(217, 165, 33, 0.45);
}

.broadcast-bar-label {
    font-size: var(--text-sm);
    color: var(--paper-60);
    font-weight: 500;
    letter-spacing: 0.04em;
}

.broadcast-bar-count {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--paper);
}

/* Check-in list */
.broadcast-checkins {
    width: 100%;
    max-width: 560px;
}

.broadcast-checkins-heading {
    font-family: var(--font-display);
    font-size: clamp(20px, 2.5vw, 28px);
    font-weight: 600;
    color: var(--paper);
    margin: 0 0 var(--space-3);
    text-align: center;
}

.broadcast-checkins-empty {
    font-size: clamp(18px, 2vw, 22px);
    color: var(--paper-60);
    margin: 0;
    text-align: center;
}

.broadcast-checkin-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 220px;
    overflow-y: auto;
}

.broadcast-checkin-item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-4);
    background: rgba(251, 250, 246, 0.04);
    border-radius: var(--radius-sm);
    font-size: clamp(18px, 2vw, 22px);
}

.broadcast-checkin-time {
    font-family: var(--font-mono);
    color: var(--mustard);
    font-weight: 500;
    min-width: 5ch;
}

.broadcast-checkin-name {
    color: var(--paper);
    font-weight: 500;
}

/* Footer */
.broadcast-footer {
    margin-top: auto;
    padding-top: var(--space-3);
}

.broadcast-footer p {
    font-size: var(--text-sm);
    color: rgba(251, 250, 246, 0.30);
    margin: 0;
}

@keyframes countIn {
    from { opacity: 0; transform: scale(0.8); }
    to   { opacity: 1; transform: scale(1); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   ERROR PAGES (404, 500)
   ═══════════════════════════════════════════════════════════════════════════ */

.error-stage {
    min-height: 70vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--space-4);
    animation: fadeUp var(--duration-slow) var(--ease-out);
}

.error-code {
    font-family: var(--font-display);
    font-size: 120px;
    font-weight: 700;
    color: var(--jade);
    margin: 0;
    line-height: 1;
    opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        padding: var(--space-4);
    }
    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: var(--space-2);
    }
    .nav-link {
        font-size: var(--text-sm);
        padding: var(--space-2) var(--space-3);
        min-height: 40px;
    }
    .page-main {
        padding: var(--space-4) var(--space-4);
    }
    .form-row { grid-template-columns: 1fr; }
    .card-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
    .kpi-card .kpi-value { font-size: var(--text-3xl); }
    .page-head { flex-direction: column; align-items: flex-start; }
    .profile-head { flex-direction: column; text-align: center; }
    .page-footer { flex-direction: column; text-align: center; }
    .search-bar { flex-direction: column; }
    .search-bar .btn-primary { width: 100% !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
