/* DieTrack styles. Colours are tokens on :root; dark mode follows the device setting. */
:root {
    color-scheme: light dark;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #1b2430;
    --muted: #5d6b7c;
    --border: #d9dfe6;
    --accent: #1f7a5c;
    --accent-text: #ffffff;
    --track: #e6eaee;
    --good: #1f7a5c;
    --near: #8f5600;
    --over: #c0392b;
    --error-bg: #fdecea;
    --info-bg: #e8f1fb;
    --radius: 12px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11161c;
        --surface: #1b232c;
        --text: #e8edf2;
        --muted: #9aa8b8;
        --border: #2d3844;
        --accent: #3fb68b;
        --accent-text: #08150f;
        --track: #2a3541;
        --good: #3fb68b;
        --near: #e0a030;
        --over: #ef6a5b;
        --error-bg: #3a1f1c;
        --info-bg: #1b2d42;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

h1 { font-size: 1.5rem; margin: 0.5rem 0; }
h1:focus { outline: none; } /* the router focuses the page heading on navigation */
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
a { color: var(--accent); }

.loading, #app > .loading { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.875rem; margin: 0.5rem 0; }

/* Layout */
.shell { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }
.bare { max-width: 480px; margin: 0 auto; padding: 24px 16px; }
.narrow { margin-top: 1rem; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a { text-decoration: none; color: var(--muted); padding: 4px 0; }
.topbar nav a.active { color: var(--text); font-weight: 600; border-bottom: 2px solid var(--accent); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head h2 { margin: 0; }

/* Forms */
label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 12px; }
input, select, textarea, button { font: inherit; }
/* iPhone Safari zooms the whole page in when a box with text under 16px is tapped, and never zooms back out.
   Boxes inside the smaller-text labels would inherit a smaller size, so they set their own. Keep this at 16px or more. */
input, select, textarea { font-size: 16px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    min-height: 44px;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 12px; margin-top: 12px; }
.pair { display: flex; gap: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); margin: 0; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }

@media (max-width: 480px) {
    .row { grid-template-columns: 1fr; }
}

/* Buttons */
button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 10px 16px; min-height: 44px; }
button:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; width: 100%; }
button.primary.small { width: auto; min-height: 40px; padding: 8px 16px; }
button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
button.link { background: none; border: none; color: var(--accent); padding: 10px 8px; min-height: 44px; text-decoration: underline; }
button.link.danger { color: var(--over); }
button.icon { background: var(--surface); border-color: var(--border); color: var(--text); width: 44px; font-size: 1.4rem; line-height: 1; padding: 0; }
.actions { display: flex; gap: 12px; margin-top: 8px; }
.actions .primary { width: auto; flex: 1; }

/* Messages */
.error, .info { padding: 10px 12px; border-radius: 8px; margin: 12px 0; }
.error { background: var(--error-bg); color: var(--over); }
.info { background: var(--info-bg); }
.stat { margin: 4px 0 0; }

/* Day bar */
.daybar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.daylabel { flex: 1; text-align: center; }
.daylabel h1 { margin: 0; }
.daylabel input[type="date"] { width: auto; min-height: 36px; margin: 4px auto 0; padding: 4px 8px; }

/* Nutrient bars */
.nutrient { margin-bottom: 14px; }
.nutrient-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.95rem; }
.nutrient-head span:first-child { font-weight: 600; }
.nutrient-head span:last-child { color: var(--muted); font-size: 0.85rem; }
.nutrient-head .over { color: var(--over); }
.nutrient-head .near { color: var(--near); }
.nutrient-head .good { color: var(--good); }
.bar { height: 10px; background: var(--track); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }
.fill.near { background: var(--near); }
.fill.over { background: var(--over); }
.fill.good { background: var(--good); }

/* Meals */
.meals { list-style: none; padding: 0; margin: 0; }
.meals li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.meals li:first-child { border-top: none; }
.meal-main { display: flex; flex-direction: column; min-width: 0; }
.meal-main strong { overflow-wrap: anywhere; }
.meal-main .muted { font-size: 0.85rem; }
.meal-actions { display: flex; flex: none; }
.mealform { border-bottom: 1px solid var(--border); margin-bottom: 8px; padding-bottom: 8px; }

.prose h2 { margin-top: 1.25rem; }
.switch { text-align: center; }

#blazor-error-ui {
    background: var(--error-bg);
    color: var(--over);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* AI meal analysis */
textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    resize: vertical;
}
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ai-box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 16px; }
.ai-box textarea { background: var(--surface); }
.ai-box .primary { margin-top: 4px; }

.photo-actions { display: flex; gap: 12px; margin-bottom: 12px; }
.photo-actions .button { flex: 1; text-align: center; margin: 0; }

/* A <label> styled like a button, so it opens the (hidden) file input on any device. */
label.button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    background: transparent;
    font-size: 1rem;
    cursor: pointer;
}
label.button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

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

.photo { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 12px; }
.photo img { max-width: 100%; max-height: 220px; border-radius: 8px; border: 1px solid var(--border); }

.item { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.item-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.item-head input { flex: 1 1 140px; margin-top: 0; }
.grid.compact { margin-top: 0; grid-template-columns: repeat(3, 1fr); gap: 0 8px; }
.grid.compact label { font-size: 0.75rem; margin-bottom: 6px; }
.grid.compact input { padding: 6px 8px; min-height: 40px; }
.mealform > button.secondary { width: 100%; margin: 4px 0 8px; }

/* Review fixes */
.topbar nav { flex-wrap: wrap; justify-content: flex-end; row-gap: 4px; }
.center { text-align: center; }
input.decimal { text-align: left; }
input.invalid, input.decimal.invalid { border-color: var(--over); }
button.secondary.full { width: 100%; margin: 4px 0 8px; }
button.primary.danger { background: var(--over); color: #fff; }
.meal-actions.confirm { align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; font-size: 0.9rem; }
.data-card .actions { margin-top: 8px; }
.danger-zone { border: 1px solid var(--over); border-radius: var(--radius); padding: 12px; margin-top: 12px; }
