:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --line: #e2e5ea;
    --text: #1a1d22;
    --muted: #6b7280;
    --accent: #2563eb;
    --gluten: #dc2626;
    --no-gluten: #16a34a;
    --mild: #d97706;
    --strong: #dc2626;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
    overscroll-behavior-y: contain;
}

body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ---------- Layout ---------- */
.app { max-width: 560px; margin: 0 auto; padding: 0 16px 80px; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    margin-bottom: 16px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}
.topbar a { color: var(--muted); font-size: 14px; }

.date-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}
.date-nav button {
    width: 36px; height: 36px;
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    font-size: 18px;
    display: grid; place-items: center;
    border: 1px solid var(--line);
}
.date-nav button:active { background: var(--surface-2); }
.date-nav button:disabled { opacity: 0.3; }
.date-label-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 140px;
    height: 36px;
    border-radius: 10px;
}
.date-label-wrap:active { background: var(--surface-2); }
.date-label-text {
    padding: 0 12px;
    font-weight: 600;
    font-size: 17px;
    color: var(--text);
    pointer-events: none; /* taps pass through to the input above */
    user-select: none;
}

/* Real date input sits invisibly on top — actual tap target on iOS. */
.date-picker-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    font: inherit;
    color: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}
.date-picker-input::-webkit-calendar-picker-indicator { opacity: 0; }
.date-picker-input::-webkit-date-and-time-value { text-align: center; }

.date-nav .today-btn {
    width: auto; padding: 0 10px; font-size: 13px; color: var(--accent);
    background: transparent; border: 0;
}
.date-nav .today-btn[hidden] { display: none; }

/* ---------- Section ---------- */
.section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin: 24px 4px 8px;
}

/* ---------- Sick buttons ---------- */
.sick-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.sick-buttons button {
    padding: 18px 12px;
    border-radius: 14px;
    background: var(--surface);
    font-size: 17px;
    font-weight: 600;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    transition: transform 0.06s, background 0.15s;
}
.sick-buttons button:active { transform: scale(0.97); }
.sick-buttons .mild { color: var(--mild); }
.sick-buttons .strong { color: var(--strong); }
.sick-buttons .mild:active { background: rgba(217, 119, 6, 0.08); }
.sick-buttons .strong:active { background: rgba(220, 38, 38, 0.08); }
.sick-buttons small {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    margin-top: 2px;
}

/* ---------- Sick list ---------- */
.sick-list { list-style: none; margin: 12px 0 0; padding: 0; }
.sick-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}
.sick-list .time {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 92px;
    font-size: 14px;
}
.sick-list .sev { font-size: 12px; padding: 3px 8px; border-radius: 999px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.sick-list .sev.mild { background: rgba(217, 119, 6, 0.12); color: var(--mild); }
.sick-list .sev.strong { background: rgba(220, 38, 38, 0.12); color: var(--strong); }
.sick-list .note { color: var(--muted); font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sick-list .del {
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    padding: 6px 8px;
    border-radius: 8px;
}
.sick-list .del:active { background: var(--surface-2); color: var(--strong); }

.empty {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    padding: 16px;
    font-style: italic;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}

/* ---------- Meal rows ---------- */
.meal-row {
    background: var(--surface);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}
.meal-row .row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.meal-row .name {
    font-size: 16px;
    font-weight: 600;
}
.pills {
    display: inline-flex;
    background: var(--surface-2);
    padding: 3px;
    border-radius: 999px;
    gap: 2px;
}
.pills button {
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    transition: background 0.15s, color 0.15s;
    min-width: 72px;
}
.pills button.active[data-value="1"] { background: var(--gluten); color: #fff; }
.pills button.active[data-value="0"] { background: var(--no-gluten); color: #fff; }

.notes-wrap {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.2s ease, margin-top 0.2s ease;
}
.notes-wrap.open { max-height: 60px; margin-top: 10px; }
.notes-wrap input {
    width: 100%;
    box-sizing: border-box;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
}
.notes-wrap input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }

/* ---------- Login ---------- */
.login-body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
}
.login {
    width: 100%;
    max-width: 280px;
    box-sizing: border-box;
    text-align: center;
    margin: 0;
}
.login h1 {
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 14px;
    font-size: 22px;
}
.login form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
}
.login label {
    text-align: left;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0;
}
.login input {
    width: 100%;
    box-sizing: border-box;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    font-size: 18px;
    text-align: center;
    letter-spacing: 0.3em;
    box-shadow: var(--shadow);
    margin: 0;
    font-family: inherit;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login button {
    width: 100%;
    box-sizing: border-box;
    padding: 11px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    border: 0;
    margin: 4px 0 0;
    font-family: inherit;
}
.login .error { color: var(--strong); font-size: 13px; margin: 4px 0 0; text-align: center; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modal ---------- */
.modal-bg {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.35);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
}
.modal-bg.open { display: flex; }
.modal {
    background: var(--bg);
    width: min(560px, 100%);
    border-radius: 16px 16px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.modal h3 { margin: 0 0 12px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.modal input, .modal select, .modal textarea {
    width: 100%;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
}
.modal .seg {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    background: var(--surface-2);
    padding: 4px;
    border-radius: 12px;
}
.modal .seg button {
    padding: 10px;
    border-radius: 8px;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
}
.modal .seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.modal .actions { display: flex; gap: 8px; margin-top: 20px; }
.modal .actions button {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    font-weight: 600;
}
.modal .actions .primary { background: var(--accent); color: #fff; border-color: var(--accent); }
