/* Tagebuch — warm, personal, minimal. Custom line icons, no libraries.
   Light and dark follow the system preference. */

:root {
    --bg: #faf6ef;
    --surface: #fffdf9;
    --text: #262219;
    --muted: #7d766a;
    --line: #eae2d4;
    --accent: #3d7a58;
    --accent-soft: #e6f1e9;
    --poop: #b06b3b;
    --poop-soft: #f6e9dc;
    --warn: #9a6700;
    --warn-soft: #fdf3dc;
    --error: #b3261e;
    --error-soft: #fbeae9;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171410;
        --surface: #211d17;
        --text: #efeae0;
        --muted: #a29a8a;
        --line: #332d23;
        --accent: #7cc39a;
        --accent-soft: #22392c;
        --poop: #d99a66;
        --poop-soft: #3a2a1b;
        --warn: #dcae4a;
        --warn-soft: #33290f;
        --error: #e08a84;
        --error-soft: #381c1a;
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    /* Same color as the body so overscroll and the strip behind the browser
       toolbar never flash a mismatched gray. */
    background: var(--bg);
}

/* Cross-document view transitions (Chromium/Safari): page changes cross-fade
   instead of flashing white. The tab bar keeps its own name so it stays
   perfectly still while the content fades. */
@view-transition {
    navigation: auto;
}

@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }
}

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

.page {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}

/* --- Top bar ------------------------------------------------------------ */

.topbar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 22px 0 18px;
}

.topbar h1 {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.topbar-link {
    color: var(--muted);
    font-size: 0.8125rem;
    text-decoration: none;
}

.topbar-links {
    display: flex;
    gap: 16px;
}

/* --- Bottom tab bar ------------------------------------------------------ */

/* A floating pill instead of an edge-to-edge bar: no cut-off sides on wide
   screens, and when a mobile browser's toolbar collapses on scroll the bar
   drifts over the page background instead of revealing a mismatched strip. */
.tabbar {
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: 16px;
    right: 16px;
    display: flex;
    max-width: 400px;
    margin: 0 auto;
    padding: 5px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: 0 10px 30px -12px rgba(38, 34, 25, 0.3);
    view-transition-name: tabbar;
}

@supports (backdrop-filter: blur(1px)) {
    .tabbar {
        background: color-mix(in srgb, var(--surface) 80%, transparent);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
}

@media (prefers-color-scheme: dark) {
    .tabbar {
        box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
    }
}

.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 0 7px;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.6875rem;
    font-weight: 550;
    letter-spacing: 0.02em;
}

.tabbar a.active {
    color: var(--accent);
    background: var(--accent-soft);
}

/* --- Cards & timeline ----------------------------------------------------- */

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

.card h2 {
    font-size: 1.125rem;
    margin-bottom: 8px;
}

.card h3 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.timeline {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.entry-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 0;
}

.entry-icon {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 13px;
    display: grid;
    place-items: center;
}

.entry-icon-food {
    background: var(--accent-soft);
    color: var(--accent);
}

.entry-icon-poop {
    background: var(--poop-soft);
    color: var(--poop);
}

.entry-body {
    flex: 1;
    min-width: 0;
}

.entry-title {
    font-weight: 600;
}

.entry-meta {
    color: var(--muted);
    font-size: 0.8125rem;
    margin-top: 2px;
}

.entry-note {
    font-size: 0.875rem;
    margin-top: 6px;
}

.entry-time {
    color: var(--muted);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    padding-top: 2px;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 56px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    opacity: 0.8;
}

/* --- Quick-add buttons (Heute page) ---------------------------------------- */

.quickadd {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
}

.quickadd a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
}

.quickadd-icon {
    position: relative;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    display: grid;
    place-items: center;
}

.quickadd-icon-food {
    background: var(--accent-soft);
    color: var(--accent);
}

.quickadd-icon-poop {
    background: var(--poop-soft);
    color: var(--poop);
}

.quickadd-plus {
    position: absolute;
    right: -5px;
    bottom: -5px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--surface);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 12px;
    text-align: center;
}

.quickadd-icon-food .quickadd-plus {
    background: var(--accent);
}

.quickadd-icon-poop .quickadd-plus {
    background: var(--poop);
}

@media (prefers-color-scheme: dark) {
    .quickadd-plus {
        color: #171410;
    }
}

/* --- Date navigation --------------------------------------------------------- */

.datenav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 0.9375rem;
    font-weight: 550;
}

.datenav a {
    color: var(--accent);
    text-decoration: none;
    font-size: 1.5rem;
    line-height: 1;
    padding: 4px 14px;
}

/* --- Forms --------------------------------------------------------------------- */

.field {
    margin-bottom: 16px;
}

.label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 550;
    color: var(--muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="search"],
input[type="password"],
input[type="datetime-local"] {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    appearance: none;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn {
    display: block;
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 650;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    margin-top: 8px;
}

@media (prefers-color-scheme: dark) {
    .btn {
        color: #10241a;
    }
}

.btn-ghost {
    background: none;
    border: none;
    color: var(--accent);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 0 0;
}

/* Segmented controls: hidden radios, pill labels. */

.segmented {
    display: flex;
    gap: 8px;
}

.segmented label {
    flex: 1;
    position: relative;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: block;
    text-align: center;
    padding: 11px 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
}

.segmented input:checked + span {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 650;
}

/* Bristol scale: one tappable row per type, with a small shape glyph. */

.bristol {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bristol label {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    cursor: pointer;
    user-select: none;
}

.bristol input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.bristol-glyph {
    flex: none;
    color: var(--muted);
}

.bristol-num {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    min-width: 16px;
}

.bristol label:has(input:checked) {
    border-color: var(--poop);
    background: var(--poop-soft);
}

.bristol label:has(input:checked) .bristol-glyph,
.bristol label:has(input:checked) .bristol-num {
    color: var(--poop);
}

/* --- Barcode scanning -------------------------------------------------------------- */

.searchrow {
    display: flex;
    gap: 8px;
}

.searchrow input {
    flex: 1;
    min-width: 0;
}

.scanbtn {
    flex: none;
    width: 50px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.scan-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
}

.scan-overlay video {
    width: 100%;
    max-width: 480px;
    border-radius: 16px;
}

.scan-hint {
    color: #fff;
    opacity: 0.8;
    font-size: 0.875rem;
}

.scan-cancel {
    max-width: 480px;
}

/* --- Check page --------------------------------------------------------------------- */

.checkintro {
    margin-bottom: 14px;
}

.checkcaveat {
    margin: 6px 0 14px;
}

.verdict {
    margin-top: 18px;
}

.verdict-headline {
    font-size: 1.0625rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.verdict-error .verdict-headline { color: var(--error); }
.verdict-warn .verdict-headline { color: var(--warn); }
.verdict-ok .verdict-headline { color: var(--accent); }
.verdict-unsure .verdict-headline { color: var(--muted); }

.nutable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.nutable td {
    padding: 6px 0;
    border-bottom: 1px solid var(--line);
}

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

.nutable td:last-child {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.nutable-kind {
    color: var(--muted);
    text-align: right;
}

/* --- Daily nutrient balance (Heute) -------------------------------------------------- */

.nutbalance .muted {
    margin-top: 10px;
}

.nutrow {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 10px;
    margin-bottom: 9px;
    font-size: 0.8125rem;
}

.nutrow-label {
    font-weight: 550;
}

.nutrow-value {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.nutrow-over {
    color: var(--warn);
    font-weight: 600;
}

.nutbar {
    grid-column: 1 / -1;
    height: 5px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}

.nutbar-fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
}

.nutbar-over {
    background: var(--warn);
}

/* --- Search results ---------------------------------------------------------------- */

.results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.result {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
    text-align: left;
    padding: 13px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.result-create {
    color: var(--accent);
    font-weight: 600;
    border-style: dashed;
}

/* --- Pills & banners ------------------------------------------------------------------ */

.pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 550;
    vertical-align: middle;
}

.pill-warn {
    background: var(--warn-soft);
    color: var(--warn);
}

.pill-unsure {
    background: var(--line);
    color: var(--muted);
}

.banner {
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 0.875rem;
    margin-bottom: 14px;
}

.banner-ok {
    background: var(--accent-soft);
    color: var(--accent);
}

.banner-warn {
    background: var(--warn-soft);
    color: var(--warn);
}

.banner-error {
    background: var(--error-soft);
    color: var(--error);
}

.muted {
    color: var(--muted);
    font-size: 0.875rem;
}

/* --- Login ------------------------------------------------------------------------------ */

.login-wrap {
    padding-top: 16vh;
}

.logo-mark {
    width: 64px;
    height: 64px;
    border-radius: 21px;
    background: var(--accent-soft);
    color: var(--accent);
    display: grid;
    place-items: center;
    margin: 0 auto 16px;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 28px;
    letter-spacing: -0.02em;
}
