/* ==========================================================================
   KartQuiz design system – "Outdoor & fresh"
   Mobile-first. Light/dark follow the system setting.
   ========================================================================== */

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

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */
:root {
    color-scheme: light dark;

    /* Surfaces & text */
    --bg: #F5F7F2;
    --surface: #FFFFFF;
    --surface-2: #EEF3EB;
    --surface-3: #E3EBDF;
    --ink: #13241A;
    --muted: #55665C;
    --line: #DCE5D8;
    --line-strong: #C4D1BF;

    /* Brand */
    --brand: #1F7A4D;
    --brand-hover: #18653F;
    --brand-ink: #FFFFFF;
    --brand-soft: #DDEFE4;
    --brand-text: #1A6942;
    --accent: #F2A541;
    --accent-hover: #E4952C;
    --accent-ink: #3A2500;
    --accent-soft: #FDEFD9;

    /* Status */
    --danger: #B4382A;
    --danger-hover: #9A2E22;
    --danger-ink: #FFFFFF;
    --danger-soft: #F9E3DF;
    --warning: #B26A00;
    --warning-soft: #FFF1D6;
    --info: #2F6FB8;
    --info-soft: #E1ECF8;
    --success: var(--brand);
    --success-soft: var(--brand-soft);
    --location: #2F7DE1;

    /* Map */
    --map: #E3ECDD;

    /* Shape & depth */
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-pill: 999px;
    --shadow-sm: 0 1px 3px rgba(19, 36, 26, 0.08);
    --shadow: 0 2px 10px rgba(19, 36, 26, 0.08);
    --shadow-lg: 0 10px 30px rgba(19, 36, 26, 0.16);
    --scrim: rgba(10, 20, 14, 0.45);
    --focus: 0 0 0 3px rgba(31, 122, 77, 0.35);

    /* Type */
    --font-display: 'Bricolage Grotesque', 'DM Sans', system-ui, sans-serif;
    --font-body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    /* Layout */
    --header-h: 60px;
    --tabbar-h: 68px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --tap: 44px;

    /* Legacy aliases – page styles written against the old palette keep working */
    --primary: var(--brand);
    --primary-dark: var(--brand-hover);
    --danger-dark: var(--danger-hover);
    --white: var(--surface);
    --gray-100: var(--bg);
    --gray-200: var(--surface-2);
    --gray-300: var(--line);
    --gray-400: var(--line-strong);
    --gray-500: var(--muted);
    --gray-600: var(--muted);
    --gray-700: var(--ink);
    --gray-800: var(--ink);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0E1712;
        --surface: #16231B;
        --surface-2: #1F2F26;
        --surface-3: #283A30;
        --ink: #E7F0EA;
        --muted: #9BB0A3;
        --line: #2A3B31;
        --line-strong: #3A4E42;

        --brand: #3DBB7E;
        --brand-hover: #52C98F;
        --brand-ink: #06140C;
        --brand-soft: #173A29;
        --brand-text: #6FD4A2;
        --accent: #F2A541;
        --accent-hover: #F5B562;
        --accent-ink: #3A2500;
        --accent-soft: #3A2A12;

        --danger: #FF8A7A;
        --danger-hover: #FFA394;
        --danger-ink: #2A0B06;
        --danger-soft: #3A1D19;
        --warning: #F2B35B;
        --warning-soft: #3A2A12;
        --info: #7FB2EE;
        --info-soft: #172B42;

        --map: #18241D;

        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
        --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.55);
        --scrim: rgba(0, 0, 0, 0.6);
        --focus: 0 0 0 3px rgba(61, 187, 126, 0.45);
    }
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    min-height: 100dvh;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: var(--ink);
}

h1 { font-size: clamp(1.75rem, 5vw, 2.25rem); font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.375rem; font-weight: 700; }
h3 { font-size: 1.125rem; font-weight: 700; }

a {
    color: var(--brand-text);
}

img {
    max-width: 100%;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.text-muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }

/* --------------------------------------------------------------------------
   App header (top bar)
   -------------------------------------------------------------------------- */
.header {
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    /* Above in-page overlays (map chips, FABs, tab bar) so the profile dropdown
       isn't covered; below modals (1000+), toasts and the offline banner */
    z-index: 950;
    padding-top: env(safe-area-inset-top, 0px);
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--header-h);
    padding: 0 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.logo {
    text-decoration: none;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.logo img {
    width: 116px;
    height: auto;
    display: block;
}

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

.nav-links {
    display: none;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: var(--tap);
    padding: 0 0.85rem;
    border-radius: var(--radius-pill);
    color: var(--muted);
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    color: var(--ink);
    background: var(--surface-2);
}

.nav-link.active {
    color: var(--brand-text);
    background: var(--brand-soft);
}

@media (min-width: 768px) {
    .nav-links { display: flex; }
}

/* Profile dropdown */
.profile-dropdown-container {
    position: relative;
    margin-left: 0.25rem;
}

.profile-trigger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    width: var(--tap);
    height: var(--tap);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-avatar,
.nav-avatar-initials {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--line);
    transition: border-color 0.15s, transform 0.15s;
}

.nav-avatar-initials {
    background: var(--brand-soft);
    color: var(--brand-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
}

.profile-trigger:hover .nav-avatar,
.profile-trigger:hover .nav-avatar-initials {
    border-color: var(--brand);
}

.profile-chevron { display: none; }

.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    min-width: 240px;
    padding: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: dropdownFadeIn 0.15s ease;
}

.profile-dropdown.open { display: block; }

@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.profile-dropdown-header {
    padding: 10px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.profile-dropdown-name {
    font-weight: 700;
    font-size: 0.95rem;
}

.profile-dropdown-email {
    font-size: 0.8rem;
    color: var(--muted);
    word-break: break-all;
    line-height: 1.3;
}

.profile-dropdown-divider {
    height: 1px;
    background: var(--line);
    margin: 6px 4px;
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    padding: 0 12px;
    border-radius: var(--radius-sm);
    color: var(--ink);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.15s;
}

.profile-dropdown-item:hover { background: var(--surface-2); }
.profile-dropdown-item .icon { color: var(--muted); }
.profile-dropdown-logout,
.profile-dropdown-logout .icon { color: var(--danger); }

/* Logout is a POST form button styled like the surrounding links */
button.profile-dropdown-item,
button.profile-link {
    width: 100%;
    background: none;
    border: 0;
    font-family: inherit;
    font-size: inherit;
    text-align: left;
    cursor: pointer;
}
.profile-dropdown-logout:hover { background: var(--danger-soft); }

/* Acting profile: organization badge, switcher and banner */
.nav-avatar-org { border-radius: var(--radius-sm); border-color: var(--brand); }
.profile-dropdown-badge {
    align-self: flex-start;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--brand-text);
    background: var(--brand-soft);
    border-radius: 999px;
    padding: 2px 8px;
    margin-bottom: 4px;
}
.profile-dropdown-label {
    display: block;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}
.profile-switch.current { font-weight: 700; cursor: default; }
.profile-switch-check { margin-left: auto; color: var(--brand) !important; }
.acting-banner {
    background: var(--brand-soft);
    color: var(--brand-text);
    font-size: 0.875rem;
    border-bottom: 1px solid var(--line);
}
.acting-banner .container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 6px;
    padding-bottom: 6px;
}
.acting-banner-switch {
    margin-left: auto;
    background: none;
    border: 0;
    padding: 4px 0;
    font: inherit;
    font-weight: 600;
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   Bottom tab bar (mobile)
   -------------------------------------------------------------------------- */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 6px 4px calc(8px + var(--safe-bottom));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--line);
}

.tabbar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 52px;
    justify-content: center;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
}

.tabbar-icon {
    width: 60px;
    height: 32px;
    border-radius: var(--radius-pill);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.tabbar-icon .icon { width: 22px; height: 22px; }

.tabbar-item.active {
    color: var(--brand-text);
    font-weight: 700;
}

.tabbar-item.active .tabbar-icon { background: var(--brand-soft); }

body.has-tabbar .main {
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
}

@media (min-width: 768px) {
    .tabbar { display: none; }
    body.has-tabbar .main { padding-bottom: 0; }
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.main {
    min-height: calc(100vh - var(--header-h));
    min-height: calc(100dvh - var(--header-h));
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem 1rem;
}

@media (min-width: 768px) {
    .container { padding: 2rem 1.5rem; }
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.page-header h1 { font-size: clamp(1.75rem, 6vw, 2.25rem); }

.page-subtitle {
    color: var(--muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: var(--tap);
    color: var(--muted);
    font-weight: 600;
    text-decoration: none;
    margin-bottom: 0.5rem;
}

.back-link:hover { color: var(--ink); }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.stat-tile {
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--muted);
}

/* Quiz grid & cards (rendered by JS in index.html etc.) */
.quiz-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    gap: 1rem;
}

.quiz-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1.1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.15s, transform 0.15s;
}

@media (hover: hover) {
    .quiz-card:hover { box-shadow: var(--shadow); }
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.quiz-card h3 {
    margin: 0;
    color: var(--ink);
    font-size: 1.15rem;
}

.quiz-org-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.quiz-org-logo {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--surface-2);
}

.quiz-org-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted);
}

.quiz-description {
    color: var(--muted);
    font-size: 0.95rem;
    margin-bottom: 0.85rem;
}

.quiz-meta {
    color: var(--muted);
    font-size: 0.875rem;
    margin-bottom: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.75rem;
}

.quiz-meta .status,
.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.6rem;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: 0;
}

.quiz-meta .status.active,
.status-pill.active { background: var(--brand-soft); color: var(--brand-text); }
.quiz-meta .status.inactive,
.status-pill.inactive { background: var(--danger-soft); color: var(--danger); }
.quiz-meta .status.scheduled,
.status-pill.scheduled { background: var(--warning-soft); color: var(--warning); }
.quiz-meta .status.closed,
.quiz-meta .status.ended,
.status-pill.ended,
.status-pill.closed { background: var(--surface-3); color: var(--muted); }

.quiz-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.5rem;
    margin-top: auto;
}

.preview-map {
    height: 150px;
    border-radius: var(--radius);
    margin-bottom: 0.85rem;
    background: var(--map);
    overflow: hidden;
}

.no-questions-preview {
    height: 80px;
    background: var(--surface-2);
    border-radius: var(--radius);
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.875rem;
    border: 1px dashed var(--line-strong);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--tap);
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active { transform: scale(0.98); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); }

.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--surface-2); color: var(--ink); }
.btn-secondary:hover { background: var(--surface-3); }

.btn-outline {
    background: transparent;
    color: var(--ink);
    box-shadow: inset 0 0 0 2px var(--line);
}
.btn-outline:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--brand-text); }
.btn-ghost:hover { background: var(--brand-soft); }

.btn-danger { background: var(--danger); color: var(--danger-ink); }
.btn-danger:hover { background: var(--danger-hover); }

.btn-success { background: var(--brand); color: var(--brand-ink); }
.btn-success:hover { background: var(--brand-hover); }

.btn-sm {
    min-height: 36px;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    min-height: 56px;
    padding: 0.75rem 1.5rem;
    font-size: 1.05rem;
    border-radius: 18px;
}

.btn-block { display: flex; width: 100%; }

.btn-icon {
    width: var(--tap);
    padding: 0;
    border-radius: 50%;
}

.fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
    z-index: 800;
    min-height: 56px;
    padding: 0 1.4rem 0 1.1rem;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
}

@media (min-width: 768px) {
    .fab { bottom: 24px; right: 24px; }
}

/* --------------------------------------------------------------------------
   Chips, badges, segmented control
   -------------------------------------------------------------------------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: var(--tap);
    padding: 0 1rem;
    border-radius: var(--radius-pill);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.chip.active,
.chip[aria-pressed="true"] {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-ink);
}

.chip-row {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.chip-row::-webkit-scrollbar { display: none; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--ink);
    margin-right: 0.25rem;
    white-space: nowrap;
}

.badge-age-adult { background: var(--surface-2); color: var(--ink); }
.badge-age-children { background: var(--info-soft); color: var(--info); }
.badge-difficulty-easy { background: var(--brand-soft); color: var(--brand-text); }
.badge-difficulty-normal { background: var(--accent-soft); color: var(--warning); }
.badge-difficulty-hard { background: var(--danger-soft); color: var(--danger); }
.badge-difficulty-very_hard { background: #EDE3F7; color: #6B2FA3; }
.badge-price { background: var(--accent); color: var(--accent-ink); }
.badge-success { background: var(--brand-soft); color: var(--brand-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

@media (prefers-color-scheme: dark) {
    .badge-difficulty-very_hard { background: #2E1F40; color: #C9A2EE; }
}

.segmented {
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    gap: 4px;
    padding: 4px;
    border-radius: 16px;
    background: var(--surface-2);
}

.segmented > button,
.segmented > a {
    min-height: var(--tap);
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.segmented > .active,
.segmented > [aria-selected="true"] {
    background: var(--surface);
    color: var(--ink);
    font-weight: 700;
    box-shadow: var(--shadow-sm);
}

/* --------------------------------------------------------------------------
   Modals – bottom sheet on phones, dialog on larger screens
   -------------------------------------------------------------------------- */
.modal {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    padding: 0;
    animation: modalFadeIn 0.2s ease;
}

.modal-content {
    background: var(--surface);
    color: var(--ink);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    max-height: 92dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: var(--safe-bottom);
    box-shadow: var(--shadow-lg);
    animation: sheetUp 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-content::before {
    content: '';
    display: block;
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: var(--line-strong);
    margin: 10px auto 0;
}

.modal-large { max-width: 680px; }

@media (min-width: 640px) {
    .modal { align-items: center; padding: 1.5rem; }
    .modal-content {
        border-radius: var(--radius-xl);
        padding-bottom: 0;
        animation: modalSlideIn 0.2s ease;
    }
    .modal-content::before { display: none; }
}

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

@keyframes sheetUp {
    from { transform: translateY(40px); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes modalSlideIn {
    from { transform: translateY(-12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

.modal-header h2 { font-size: 1.3rem; }

.modal-body { padding: 1.25rem; }

.close-btn {
    background: var(--surface-2);
    border: none;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover { color: var(--ink); background: var(--surface-3); }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
form { padding: 1.25rem; }

.form-group { margin-bottom: 1rem; }

.form-group label,
.form-label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ink);
}

.form-group input,
.form-group textarea,
.form-group select,
.input {
    width: 100%;
    min-height: 48px;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: 16px; /* prevents iOS zoom on focus */
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input[type="checkbox"],
.form-group input[type="radio"] {
    width: 20px;
    height: 20px;
    min-height: 0;
    padding: 0;
    accent-color: var(--brand);
}

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

.form-group input::placeholder,
.form-group textarea::placeholder,
.input::placeholder { color: var(--muted); opacity: 0.8; }

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
.input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: var(--focus);
}

.form-help,
.form-group small {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.form-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 1rem;
}

@media (min-width: 600px) {
    .form-row { grid-template-columns: 1fr 1fr; }
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}

@media (max-width: 599px) {
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; min-height: 52px; }
}

.location-display {
    background: var(--surface-2);
    padding: 0.75rem;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

.alert-error,
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--brand-soft); color: var(--brand-text); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* Auth pages (login, signup, password reset) */
.auth-wrap {
    max-width: 440px;
    margin: 0 auto;
    padding: 1.5rem 1rem 2.5rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    padding: 1.5rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.auth-card form { padding: 0; }

.auth-title { margin-bottom: 0.35rem; }
.auth-subtitle { color: var(--muted); margin-bottom: 1.25rem; }

.auth-card.centered { text-align: center; }
.auth-card .highlight { font-weight: 700; color: var(--ink); word-break: break-all; }

.auth-footer { margin-top: 1.25rem; text-align: center; color: var(--muted); }
.auth-footer a { font-weight: 700; display: inline-flex; align-items: center; min-height: var(--tap); }

.status-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand-text);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.status-icon .icon { width: 30px; height: 30px; }
.status-icon.danger { background: var(--danger-soft); color: var(--danger); }

.error-list { list-style: none; }
.error-list li + li { margin-top: 0.25rem; }

.divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.85rem;
    margin: 1.25rem 0;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    background: var(--surface-2);
}

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

/* --------------------------------------------------------------------------
   States
   -------------------------------------------------------------------------- */
.loading,
.empty-state,
.error {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
}

.error { color: var(--danger); }

.empty-state h3 { margin-bottom: 0.35rem; }

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--line);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 0.75rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Global modal & toasts (base.html)
   -------------------------------------------------------------------------- */
.global-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: modalFadeIn 0.2s ease;
}

.global-modal.open { display: flex; }

.global-modal-content {
    background: var(--surface);
    border-radius: var(--radius-xl);
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.2s ease;
    overflow: hidden;
}

.global-modal-header { padding: 1.4rem 1.5rem 0.5rem; }
.global-modal-header h3 { margin: 0; font-size: 1.2rem; }
.global-modal-header.danger h3 { color: var(--danger); }
.global-modal-header.warning h3 { color: var(--warning); }
.global-modal-header.success h3 { color: var(--brand-text); }

.global-modal-body { padding: 0.25rem 1.5rem 1.25rem; }
.global-modal-body p { margin: 0; color: var(--muted); line-height: 1.5; }

.global-modal-footer {
    padding: 0 1.5rem 1.5rem;
    display: flex;
    gap: 0.75rem;
}

.global-modal-footer .btn { flex: 1; min-height: 48px; }
.global-modal-footer.alert-mode #global-modal-cancel { display: none; }

#toast-container {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    width: max-content;
    max-width: calc(100vw - 32px);
}

body.has-tabbar #toast-container {
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
}

@media (min-width: 768px) {
    body.has-tabbar #toast-container { bottom: 24px; }
}

.toast {
    background: var(--ink);
    color: var(--bg);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-pill);
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    pointer-events: auto;
}

.toast.success { background: var(--brand); color: var(--brand-ink); }
.toast.error { background: var(--danger); color: var(--danger-ink); }
.toast.warning { background: var(--accent); color: var(--accent-ink); }
.toast.hiding { animation: toastOut 0.3s ease forwards; }

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

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

.offline-indicator {
    display: none;
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    background: var(--accent);
    color: var(--accent-ink);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 700;
    box-shadow: var(--shadow);
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Full-screen map pages
   -------------------------------------------------------------------------- */
body.map-page .main { min-height: 0; }

.map-fab {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    color: var(--brand-text);
    box-shadow: var(--shadow-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.sheet {
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
}

.sheet-grabber {
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: var(--line-strong);
    margin: 10px auto 6px;
}

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