:root {
    --color-bg: #f6f8f7;
    --color-surface: #ffffff;
    --color-text: #1d2939;
    --color-muted: #667085;
    --color-border: #d0d5dd;
    --color-primary: #157f66;
    --color-primary-dark: #0f604d;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 8px 24px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}
main { flex: 1; }
a { color: var(--color-primary); }
.container { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; }
.narrow-page { max-width: 640px; }
.app-page { padding-bottom: 3rem; }
.text-center { text-align: center; }
.muted { color: var(--color-muted); }

.navbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem max(1rem, calc((100vw - 1180px) / 2));
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.nav-brand {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: var(--color-text);
    font-weight: 800;
    text-decoration: none;
}
.nav-links { display: flex; align-items: center; gap: .65rem; }
.nav-links a {
    color: var(--color-text);
    text-decoration: none;
    padding: .45rem .6rem;
    border-radius: var(--radius-sm);
}
.nav-links a.active { background: #e6f4ef; color: var(--color-primary-dark); }
.nav-toggle { display: none; }

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin: 2rem 0 1.25rem;
}
.page-header h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.subtitle { margin: .25rem 0 0; color: var(--color-muted); }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel { padding: 1.25rem; margin-bottom: 1.25rem; }
.panel h1, .panel h2 { margin-top: 0; }
.panel h2 { font-size: 1.15rem; }
.notice { padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; align-items: start; }

.btn, button, input[type="submit"] {
    border: 0;
    border-radius: var(--radius-sm);
    padding: .62rem .9rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.btn-sm { padding: .42rem .65rem; font-size: .88rem; }
.btn-primary, button[type="submit"], input[type="submit"] { background: var(--color-primary); color: #fff; }
.btn-primary:hover, button[type="submit"]:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #eef2f6; color: var(--color-text); }
.btn-danger { background: #b42318; color: #fff; }
.btn:disabled, button:disabled { opacity: .6; cursor: wait; }

.form-block {
    width: min(420px, calc(100% - 2rem));
    margin: 2rem auto;
    padding: 1.5rem;
    display: grid;
    gap: .85rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.form-block h1 { margin: 0 0 .5rem; }
.form-message { max-width: 420px; margin: 1rem auto; }
.stack { display: grid; gap: .75rem; }
.inline-form { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.input-row { display: flex; gap: .5rem; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
.input-row .btn { flex-shrink: 0; }
.honeypot {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

label { display: block; font-weight: 700; margin-bottom: .35rem; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: .65rem .75rem;
    font: inherit;
    background: #fff;
    color: var(--color-text);
}
.checkbox-label { display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; margin: 0; }
.checkbox-label input { width: auto; }
.form-note { color: var(--color-muted); font-size: .92rem; }
.error-message { background: #fde2e1; color: #9f1d20; border-radius: var(--radius-sm); padding: .65rem .8rem; }
.success-message { background: #d8f3dc; color: #1b6b3a; border-radius: var(--radius-sm); padding: .65rem .8rem; }

.key-value-list { display: grid; gap: .75rem; margin: 0; }
.key-value-list div { display: grid; grid-template-columns: minmax(120px, 35%) 1fr; gap: .75rem; }
.key-value-list dt { color: var(--color-muted); font-size: .85rem; font-weight: 700; }
.key-value-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th, .data-table td {
    padding: .65rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}
.data-table th { background: var(--color-bg); font-weight: 700; }
.action-row { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; }

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .18rem .55rem;
    font-size: .78rem;
    font-weight: 700;
    white-space: nowrap;
}
.badge-active { background: #d8f3dc; color: #1b6b3a; }
.badge-inactive { background: #fde2e1; color: #9f1d20; }
.badge-admin { background: #fff3cd; color: #856404; }
.badge-global { background: #cff4fc; color: #055160; }

.site-footer {
    margin-top: 2.5rem;
    padding: 1rem max(1rem, calc((100vw - 1180px) / 2));
    background: rgba(255, 255, 255, .82);
    border-top: 1px solid var(--color-border);
    backdrop-filter: blur(10px);
}
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.footer-account { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.footer-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #e6f4ef;
    color: var(--color-primary-dark);
    font-weight: 800;
}
.footer-label {
    display: block;
    margin-bottom: .1rem;
    color: var(--color-muted);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
}
.footer-user { display: block; overflow: hidden; color: var(--color-text); text-overflow: ellipsis; white-space: nowrap; }
.footer-links { display: flex; align-items: center; justify-content: flex-end; gap: .35rem; flex-wrap: wrap; }
.footer-links a {
    color: var(--color-text);
    text-decoration: none;
    padding: .45rem .65rem;
    border-radius: var(--radius-sm);
    font-size: .92rem;
    font-weight: 700;
}
.footer-links a:hover, .footer-links a.active { background: #e6f4ef; color: var(--color-primary-dark); }
.footer-links .footer-logout { color: #9f1d20; }
.footer-links .footer-logout:hover { background: #fde2e1; color: #9f1d20; }

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .inline-form { align-items: stretch; }
}

@media (max-width: 720px) {
    .nav-toggle { display: inline-flex; background: #eef2f6; }
    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        right: 1rem;
        left: 1rem;
        flex-direction: column;
        align-items: stretch;
        padding: .75rem;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }
    .nav-links.open { display: flex; }
    .page-header { display: block; }
    .key-value-list div { grid-template-columns: 1fr; gap: .15rem; }
    .input-row { flex-direction: column; }
    .site-footer { padding-block: .85rem; }
    .footer-inner { align-items: stretch; flex-direction: column; }
    .footer-links { justify-content: stretch; }
    .footer-links a { flex: 1; text-align: center; }
}

.vita-page { max-width: 920px; }
.vita-header { margin-bottom: 1rem; }
.day-actions { display: flex; gap: .45rem; }
.week-strip-wrap { display: flex; align-items: stretch; gap: .5rem; margin-bottom: .75rem; }
.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); flex: 1; gap: .4rem; }
.week-nav { display: grid; place-items: center; min-width: 2.5rem; color: var(--color-text); font-size: 1.5rem; text-decoration: none; }
.day-chip { display: grid; gap: .1rem; place-items: center; padding: .55rem .25rem; color: var(--color-text); text-decoration: none; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); }
.day-chip span, .day-chip small { color: var(--color-muted); font-size: .75rem; }
.day-chip strong { font-size: 1.05rem; }
.day-chip.active { border-color: var(--color-primary); background: var(--color-primary); color: #fff; }
.day-chip.active span, .day-chip.active small { color: #d9f4ea; }
.day-chip.today:not(.active) { border-color: var(--color-primary); }
.day-chip.illness-day:not(.active) { background-color: #fff6ee; background-image: repeating-linear-gradient(135deg, transparent 0 5px, rgba(180, 82, 49, .13) 5px 7px); border-color: #e9b89e; }
.day-chip.illness-day:not(.active) small { color: #9a4a2e; }
.date-jump { display: flex; align-items: center; justify-content: flex-end; gap: .6rem; margin: 0 0 1rem; }
.date-jump label { margin: 0; font-size: .85rem; }
.date-jump input { width: auto; }
.timeline-card { overflow: hidden; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); }
.timeline-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.15rem; border-bottom: 1px solid var(--color-border); }
.timeline-heading h2 { margin: 0; font-size: 1.1rem; }
.timeline-heading p { margin: .2rem 0 0; color: var(--color-muted); font-size: .9rem; }
.day-timeline { max-height: min(66vh, 620px); overflow-y: auto; overscroll-behavior: contain; }
.timeline-grid-wrap { position: relative; display: flex; height: calc(var(--hour-height) * 24); }
.hour-labels { position: relative; width: 3.25rem; flex-shrink: 0; }
.hour-label { position: absolute; left: 0; right: .5rem; transform: translateY(-.6em); text-align: right; font-size: .75rem; color: var(--color-muted); font-variant-numeric: tabular-nums; }
.timeline-track {
    position: relative;
    flex: 1;
    min-width: 0;
    cursor: pointer;
    background-image:
        repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-height) * .25 - 1px), #f1f3f4 calc(var(--hour-height) * .25 - 1px), #f1f3f4 calc(var(--hour-height) * .25)),
        repeating-linear-gradient(to bottom, #e2e6e9 0, #e2e6e9 1px, transparent 1px, transparent var(--hour-height));
}
.hour-add-fallback { position: absolute; left: 0; right: 0; height: var(--hour-height); margin: 0; padding: 0; border: 0; background: transparent; opacity: 0; cursor: pointer; pointer-events: none; }
.hour-add-fallback:focus-visible { opacity: 1; outline: 2px solid var(--color-primary); outline-offset: -2px; background: #d9f1e7; pointer-events: auto; }
.timeline-hover-indicator { position: absolute; left: 0; right: 0; height: 2px; background: var(--color-primary); pointer-events: none; display: none; z-index: 2; }
.timeline-hover-indicator::after { content: attr(data-time); position: absolute; right: .4rem; top: -.65rem; background: var(--color-primary); color: #fff; font-size: .7rem; line-height: 1.3; padding: .05rem .4rem; border-radius: 999px; white-space: nowrap; }
.timeline-event { position: absolute; display: flex; min-width: 0; justify-content: space-between; gap: .5rem; align-items: center; padding: .3rem .5rem; border-left: 3px solid; border-radius: var(--radius-sm); cursor: grab; box-shadow: 0 1px 3px rgba(16, 24, 40, .1); z-index: 1; touch-action: none; }
.timeline-event.dragging { cursor: grabbing; z-index: 3; box-shadow: 0 6px 18px rgba(16, 24, 40, .25); opacity: .95; }
.timeline-event > div { min-width: 0; }
.timeline-event strong, .timeline-event span { display: block; }
.timeline-event strong, .timeline-event span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-event strong { font-size: .82rem; }
.timeline-event span { color: var(--color-muted); font-size: .72rem; margin-top: .05rem; }
.event-edit:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.meal-event { border-color: var(--color-primary); background: #edf7f3; }
.toilet-event { border-color: #aa6b25; background: #fff5e7; }
.health-events { display: grid; gap: .4rem; margin: 0 0 1rem; padding: .75rem 1rem; border-left: 3px solid #b95d38; background: #fff6ee; }
.health-events h2 { margin: 0; font-size: .95rem; }
.health-events article { display: flex; justify-content: space-between; gap: .75rem; align-items: start; }
.health-events strong, .health-events span { display: block; }
.health-events span { color: var(--color-muted); font-size: .85rem; }
.entry-delete, .icon-button { width: 1.8rem; height: 1.8rem; padding: 0; background: transparent; color: var(--color-muted); font-size: 1.25rem; line-height: 1; }
.entry-delete:hover, .icon-button:hover { background: #eef2f6; color: var(--color-text); }
.entry-dialog { width: min(520px, calc(100% - 2rem)); border: 0; border-radius: var(--radius); box-shadow: 0 20px 60px rgba(16, 24, 40, .25); }
.entry-dialog::backdrop { background: rgba(16, 24, 40, .45); }
.entry-dialog form { display: grid; gap: .85rem; }
.entry-choice-dialog { padding: 1.25rem; }
.entry-choice-actions { display: grid; gap: .6rem; }
.entry-choice { display: grid; gap: .15rem; padding: .85rem 1rem; text-align: left; background: #edf7f3; color: var(--color-text); border: 1px solid #b8dfd0; }
.entry-choice:hover { background: #d9f1e7; }
.entry-choice span { color: var(--color-muted); font-size: .82rem; font-weight: 500; }
.entry-choice.toilet-choice { background: #fff5e7; border-color: #ecd0a8; }
.entry-choice.toilet-choice:hover { background: #ffead0; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; }
.dialog-heading h2 { margin: 0; font-size: 1.2rem; }
.choice-fieldset { margin: 0; padding: .75rem; border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
.choice-fieldset legend { padding: 0 .25rem; font-weight: 700; font-size: .9rem; }
.choice-fieldset > label { display: inline-flex; align-items: center; gap: .35rem; margin: 0 .9rem 0 0; font-weight: 500; }
.choice-fieldset input { width: auto; }
.ingredient-buttons { display: flex; flex-wrap: wrap; gap: .45rem; }
.ingredient-buttons label { margin: 0; cursor: pointer; }
.ingredient-buttons input { position: absolute; opacity: 0; }
.ingredient-buttons span { display: block; padding: .4rem .6rem; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: .85rem; }
.ingredient-buttons input:checked + span { border-color: var(--color-primary); background: #e6f4ef; color: var(--color-primary-dark); }
.form-status { min-height: 1.2rem; margin: 0; color: #9f1d20; font-size: .88rem; }
.suggestion-status { min-height: 1.2rem; margin: -.2rem 0 0; color: var(--color-primary-dark); font-size: .82rem; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
.detail-grid label, .urine-details label { font-size: .85rem; }
.urine-details { margin-top: .75rem; }
.detail-button-group { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.detail-button-group + .detail-button-group { margin-top: .75rem; }
.detail-button-group > span { width: 100%; font-size: .85rem; font-weight: 700; }
.detail-button-group button { padding: .45rem .65rem; background: #f5f7f8; color: var(--color-text); border: 1px solid var(--color-border); font-size: .86rem; }
.detail-button-group button:hover { background: #e8f3ee; border-color: var(--color-primary); }
.detail-button-group button.selected { background: #e6f4ef; border-color: var(--color-primary); color: var(--color-primary-dark); }
.analysis-filter { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: .75rem; align-items: end; }
.analysis-filter button { align-self: end; }
.catalog-seed-control { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; padding: .75rem; border: 1px solid #b8dfd0; border-radius: var(--radius-sm); background: #edf7f3; }
.catalog-seed-control strong, .catalog-seed-control span { display: block; }
.catalog-seed-control span { margin-top: .15rem; color: var(--color-muted); font-size: .85rem; }

@media (max-width: 720px) {
    .timeline-heading { align-items: start; flex-direction: column; }
    .timeline-heading .btn { width: 100%; }
    .analysis-filter { grid-template-columns: 1fr 1fr; }
    .analysis-filter button { grid-column: span 2; }
    .catalog-seed-control { align-items: stretch; flex-direction: column; }
    .catalog-seed-control .btn { width: 100%; }
    .day-timeline { max-height: 62vh; }
    .hour-labels { width: 2.75rem; }
    .hour-label { font-size: .68rem; right: .3rem; }
    .timeline-event strong { font-size: .76rem; }
    .timeline-event span { font-size: .68rem; }
    .detail-grid { grid-template-columns: 1fr; }
}
