:root {
    color-scheme: light;
    --bg: #f6f7f5;
    --surface: #ffffff;
    --ink: #17211f;
    --muted: #5b6763;
    --line: #d9dfdc;
    --accent: #0f766e;
    --accent-ink: #ffffff;
    --warn: #b45309;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 20px;
    min-height: 64px;
    padding: 12px 24px;
    /* Opaque: scrolled content must never ghost through the sticky header. */
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.brand {
    flex: 0 0 auto;
    color: var(--accent);
    font-weight: 800;
    text-decoration: none;
}

.session-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.session-user {
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 700;
}

/* Collapsible global menu (spec 4.c.5 per 14.b.40): the nav lives behind a
   hamburger toggle at every screen size so it never occupies the page. */
.menu {
    position: relative;
    flex: 0 0 auto;
}

.menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    list-style: none;
    font-weight: 700;
    color: var(--ink);
    user-select: none;
}

.menu-toggle::-webkit-details-marker {
    display: none;
}

.menu-toggle:hover,
.menu-toggle:focus-visible,
.menu[open] .menu-toggle {
    background: #dff3ef;
    outline: none;
}

.menu-icon {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 18px;
}

.menu-icon span {
    height: 2px;
    border-radius: 1px;
    background: currentColor;
}

.menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    width: min(320px, calc(100vw - 24px));
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    padding: 10px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 45, 42, 0.16);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav a {
    min-height: 38px;
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
}

.nav a.active,
.nav a:focus-visible,
.nav a:hover {
    background: #dff3ef;
    color: var(--ink);
    outline: none;
}

.menu-sub summary {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

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

.menu-sub summary::after {
    content: "▾";
    font-size: 0.8rem;
}

.menu-sub[open] summary::after {
    content: "▴";
}

.menu-sub summary.active,
.menu-sub summary:focus-visible,
.menu-sub summary:hover {
    background: #dff3ef;
    color: var(--ink);
    outline: none;
}

.menu-sub-links {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 2px 0 4px;
    padding-left: 14px;
    border-left: 2px solid var(--line);
    margin-left: 10px;
}

.menu-session {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
    padding: 10px 10px 4px;
    border-top: 1px solid var(--line);
}

.page {
    width: min(1120px, calc(100% - 32px));
    margin: 24px auto 48px;
}

.panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 420px);
    gap: 24px;
    align-items: end;
    padding: 24px 0;
    border-bottom: 1px solid var(--line);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    line-height: 1.15;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.1rem;
    margin-bottom: 14px;
}

.lede {
    margin: 0;
    color: var(--muted);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.card,
.metric {
    margin-top: 20px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metric {
    min-height: 112px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-weight: 700;
}

.metric strong {
    display: block;
    margin-top: 8px;
    color: var(--accent);
    font-size: 2rem;
}

.stage-list {
    display: grid;
    gap: 10px;
    padding-left: 0;
    list-style: none;
}

.stage-list li {
    display: flex;
    gap: 10px;
    align-items: center;
}

.stage-list span,
.status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #dff3ef;
    color: var(--accent);
    font-weight: 800;
}

.stage-list strong {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.9rem;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.86rem;
}

.auth-shell {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 24px;
}

.auth-card {
    margin-top: 0;
}

.form-stack {
    display: grid;
    gap: 14px;
}

.field {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 700;
}

.field input {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    color: var(--ink);
    background: #fff;
}

.field select {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    color: var(--ink);
    background: #fff;
}

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.checkbox-row input {
    flex: 0 0 auto;
    margin-top: 3px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 14px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-ink);
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button-secondary {
    background: #dff3ef;
    color: var(--ink);
}

.button-danger {
    background: #a61b1b;
    color: #fff;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.notice {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 6px;
    font-weight: 700;
}

.notice-error {
    background: #fff3e8;
    color: var(--warn);
}

.notice-ok {
    background: #e7f8f0;
    color: #146c43;
}

.copy-notice {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.copy-notice a {
    overflow-wrap: anywhere;
}

.danger-zone {
    min-width: 280px;
}

.danger-zone summary {
    width: max-content;
    list-style: none;
}

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

.danger-panel {
    margin-top: 10px;
    padding: 14px;
    border: 2px solid #a61b1b;
    border-radius: 6px;
    background: #ffe5e5;
    color: #651313;
}

.danger-panel h3 {
    margin-top: 0;
}

@media (max-width: 720px) {
    /* The topbar stays a single row at every width now that the nav is
       collapsed behind the menu toggle (spec 4.c.5 per 14.b.40). */
    .topbar {
        gap: 10px;
        padding: 12px 16px;
    }

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

.admin-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 20px;
}

.admin-tabs a {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    border: 1px solid transparent;
}

.admin-tabs a.active,
.admin-tabs a:focus-visible,
.admin-tabs a:hover {
    background: #dff3ef;
    color: var(--ink);
    outline: none;
}

.form-inline {
    /* flex-wrap keeps filter forms inside the viewport on phones (issue #13);
       .availability-toolbar/.admin-tabs/.inline-form already wrap the same way. */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 2px 4px 2px 0;
}

.availability-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

.availability-toolbar fieldset {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0;
    border: 0;
}

.availability-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 16px;
}

@media (min-width: 640px) {
    .availability-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .availability-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.availability-month {
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.availability-month h3 {
    margin: 0 0 10px;
    font-size: 1rem;
}

.availability-weekdays,
.availability-week {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
}

.availability-weekdays {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.availability-week {
    margin-bottom: 4px;
}

.availability-day {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border-radius: 4px;
    font-size: 0.85rem;
    user-select: none;
    cursor: pointer;
    /* Drag-to-select must not scroll the page on touch (issue #22). */
    touch-action: none;
}

.availability-day:has(input:checked) {
    background: #fde7e0;
    color: var(--warn);
    font-weight: 700;
}

.availability-day.empty {
    cursor: default;
}

.availability-day.blocked {
    background: #fde7e0;
    color: var(--warn);
    font-weight: 700;
    border-radius: 4px;
}

.availability-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.density-glyph {
    display: inline-block;
    width: 1.2em;
    color: var(--accent, #2c6e49);
    font-weight: 700;
}

.warning-icon {
    color: var(--warn, #b3541e);
    cursor: help;
}

.histogram {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.histogram li {
    display: grid;
    grid-template-columns: 90px 1fr 40px;
    align-items: center;
    gap: 10px;
}

.histogram-bar-wrap {
    background: #eee;
    border-radius: 4px;
    overflow: hidden;
    height: 14px;
}

.histogram-bar {
    display: block;
    height: 100%;
    background: var(--accent, #2c6e49);
}

.histogram-count {
    text-align: right;
}

/* Stage 5 Grocery Planning */
.inline-form {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-right: 1rem;
}
.grocery-progress {
    font-weight: 600;
}
.grocery-item-layout {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}
@media (min-width: 720px) {
    .grocery-item-layout {
        grid-template-columns: 3fr 2fr;
    }
}
.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-right: 0.75rem;
}

/* Stage 7 attendance banner (spec 7.g.12.b) */
.attendance-banner {
    background: #fef3c7;
    border-bottom: 2px solid #f59e0b;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
}
.attendance-banner-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.4rem;
}
.attendance-banner-name {
    font-weight: 600;
    min-width: 10rem;
}
.attendance-banner details,
.attendance-review-row details {
    display: inline-block;
}

/* Header notification bell (spec 8.c.9) */
.notification-bell { position: relative; text-decoration: none; font-size: 1.1rem; padding: 0.25rem 0.4rem; border-radius: 6px; }
.notification-bell:focus-visible { outline: 3px solid #0f766e; outline-offset: 2px; }
.notification-bell .badge {
    position: absolute; top: -0.3rem; right: -0.4rem;
    background: #b91c1c; color: #fff; font-size: 0.7rem; font-weight: 700;
    border-radius: 999px; padding: 0 0.35rem; min-width: 1.1rem; text-align: center; line-height: 1.1rem;
}
.notification-inbox li.unread { font-weight: 600; }
.notification-inbox li { display: flex; gap: 0.6rem; align-items: baseline; padding: 0.35rem 0; }
.notification-inbox time { color: #6b7280; font-size: 0.85rem; white-space: nowrap; }

/* Accessibility: keyboard skip link (spec 3.f) */
.skip-link { position: absolute; left: -9999px; top: 0; background: #0f766e; color: #fff; padding: 0.5rem 1rem; z-index: 100; border-radius: 0 0 6px 0; }
.skip-link:focus { left: 0; }

/* Readable forms (issue #4, spec 14.b.16.c): one field per line; option
   groups vertically aligned with the control and label on the same row. */
form > label {
    display: block;
    margin: 0 0 14px;
    font-weight: 600;
    color: var(--ink);
}
form > label > input:not([type="checkbox"]):not([type="radio"]),
form > label > select,
form > label > textarea {
    display: block;
    width: 100%;
    max-width: 30rem;
    margin-top: 6px;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-weight: 400;
    color: var(--ink);
    background: #fff;
}
form > label > textarea { min-height: 90px; }
form fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 14px 12px;
    margin: 0 0 14px;
    max-width: 34rem;
}
form fieldset legend {
    font-weight: 700;
    padding: 0 6px;
}
form fieldset > label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 8px 0;
    font-weight: 400;
    color: var(--ink);
}
form fieldset > label input[type="radio"],
form fieldset > label input[type="checkbox"] {
    flex: none;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: #0f766e;
}
/* Compact forms (table actions, filter rows) keep their inline layout. */
form.inline-form > label,
form.form-inline > label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-weight: 400;
}
form.inline-form > label > input,
form.inline-form > label > select,
form.form-inline > label > input,
form.form-inline > label > select {
    display: inline-block;
    width: auto;
    margin-top: 0;
}

/* House thumbnails (issue #17) */
.house-thumbnail { max-width: 120px; max-height: 90px; border-radius: 6px; object-fit: cover; display: inline-block; }
.house-thumbnail-large { max-width: 320px; max-height: 220px; }

/* Family Tree dependents (issue #47): guardian self-service edits presented as
   touch-friendly cards with obvious, full-width edit affordances instead of
   tiny nested collapsibles buried under bulleted names. */
.dependent-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.dependent-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 16px;
    background: #fff;
}
.dependent-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.dependent-name {
    font-weight: 700;
    font-size: 1.05rem;
}
.dependent-age {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--accent);
    background: #dff3ef;
    border-radius: 999px;
    padding: 3px 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.dependent-guardians {
    margin: 8px 0 0;
    color: var(--muted);
}
.dependent-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}
/* Each disclosure grows to fill the row; on narrow screens they wrap to
   full-width taps. The summary reuses the .button look and toggles the form. */
.disclosure {
    flex: 1 1 14rem;
}
.disclosure > summary {
    width: 100%;
    list-style: none;
    user-select: none;
}
.disclosure > summary::-webkit-details-marker {
    display: none;
}
.disclosure[open] > summary {
    margin-bottom: 12px;
}
.disclosure-form {
    padding-top: 4px;
}
/* The readable one-field-per-line form rules already apply; keep the last
   control snug against the submit button. */
.disclosure-form > label {
    max-width: 100%;
}
.dependent-subhead {
    margin: 0 0 6px;
    font-weight: 700;
    color: var(--muted);
}
.guardian-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 16px;
}
.guardian-chips form {
    margin: 0;
}
.guardian-chip {
    gap: 8px;
}
.app-footer {
    padding: 16px;
    text-align: center;
}
.app-footer-version {
    font-size: 0.75rem;
    color: var(--muted);
}
