/* One stylesheet. Phone first; light and dark follow the system. Calm on
   purpose: no colours that judge a number. */

:root {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --text: #1e2321;
    --muted: #67706c;
    --line: #e1dfd8;
    --accent: #2e6a5c;
    --accent-text: #ffffff;
    --accent-soft: #e2eeea;
    --danger: #b3261e;
    --warn: #8a5a00;
    --radius: 12px;
    --nav-height: 58px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #141716;
        --surface: #1e2321;
        --text: #e8ecea;
        --muted: #9aa49f;
        --line: #333a37;
        --accent: #74c2ad;
        --accent-text: #0e1a16;
        --accent-soft: #22342f;
        --danger: #f2a39c;
        --warn: #f0c46b;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 72px);
}

body.plain {
    padding-bottom: 0;
}

a {
    color: var(--accent);
}

h1 {
    font-size: 1.35rem;
    margin: 0 0 8px;
}

h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 20px 0 6px;
    font-weight: 600;
}

[hidden] {
    display: none !important;
}

.top {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.top__brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.top__status {
    flex: 1;
    text-align: right;
    font-size: 0.8rem;
    color: var(--warn);
    overflow-wrap: anywhere;
}

.top__status a {
    color: inherit;
}

.main {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px;
}

.footer {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 16px 16px;
    font-size: 0.75rem;
    color: var(--muted);
}

.footer a {
    color: inherit;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.muted {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 4px 0;
}

.empty {
    color: var(--muted);
    text-align: center;
    margin: 24px 0;
}

.error {
    color: var(--danger);
    margin: 8px 0;
}

.warn {
    color: var(--warn);
    margin: 8px 0;
}

/* Day */

.daynav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.daynav__title {
    margin: 0;
}

.daynav__step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    font-size: 1.6rem;
    text-decoration: none;
    border-radius: 50%;
}

.daynav__step--off {
    visibility: hidden;
}

.summary {
    padding: 14px 16px;
}

.summary__big {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.summary__unit {
    font-size: 1rem;
    font-weight: 400;
    color: var(--muted);
}

.group__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.list > li + li {
    border-top: 1px solid var(--line);
}

.row-wrap {
    display: flex;
}

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 52px;
    padding: 8px 16px;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.row:active {
    background: var(--accent-soft);
}

.row__main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.row__name {
    overflow-wrap: anywhere;
}

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

.row__kcal {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.row__plus {
    flex: none;
    width: 56px;
    border: 0;
    border-left: 1px solid var(--line);
    background: none;
    color: var(--accent);
    font-size: 1.6rem;
    cursor: pointer;
}

.row__plus:active {
    background: var(--accent-soft);
}

.fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px);
    z-index: 15;
    padding: 14px 22px;
    border-radius: 28px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

/* Add */

.addhead {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.addhead h1 {
    margin: 0;
}

.search {
    width: 100%;
    padding: 12px 14px;
    font: inherit;
    font-size: 1.05rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

.added {
    color: var(--accent);
    font-size: 0.9rem;
    margin: 8px 0;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.chip {
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
}

.chip--on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

/* Forms */

.form {
    padding: 14px 16px;
}

.form.inline {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 12px;
}

.form.inline .field {
    flex: 1;
    margin: 0;
}

.field {
    display: block;
    margin: 0 0 12px;
}

.field__label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 4px;
}

input,
select {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}

.row2,
.row3 {
    display: grid;
    gap: 10px;
}

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

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

.btn {
    display: inline-block;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.btn--danger {
    color: var(--danger);
}

.btn--wide {
    width: 100%;
    margin: 10px 0 0;
    text-align: left;
    font-weight: 400;
}

.link {
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-size: 0.9rem;
    padding: 4px 0;
    cursor: pointer;
}

.actions {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin-top: 12px;
}

.calc {
    margin: 0 0 14px;
    padding: 10px 12px;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.calc summary {
    cursor: pointer;
    color: var(--accent);
    margin-bottom: 4px;
}

.calc[open] summary {
    margin-bottom: 12px;
}

.login {
    max-width: 360px;
    margin: 12vh auto 0;
}

/* Sheet */

.backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.sheet {
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}

.sheet__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.sheet__title {
    font-size: 1.1rem;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
    margin: 4px 0 12px;
}

.sheet__result {
    font-variant-numeric: tabular-nums;
    margin: 4px 0 10px;
}

/* Barcode */

.scan__video {
    display: block;
    width: 100%;
    max-height: 45vh;
    object-fit: cover;
    border-radius: 8px;
    background: #000;
}

.scan__manual {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.scan__manual input {
    flex: 1;
}

/* Photo and text logging */

.textarea {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    margin-bottom: 10px;
    resize: vertical;
}

.previews {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
}

.preview {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.preview__top,
.preview__bottom {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview__bottom {
    margin-top: 6px;
    justify-content: space-between;
}

.preview__choice {
    flex: 1;
    min-width: 0;
}

.preview__remove {
    flex: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: none;
    color: var(--muted);
    font-size: 1.3rem;
    cursor: pointer;
}

.preview__amount {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
}

.preview__qty {
    width: 90px;
}

.preview__result {
    font-variant-numeric: tabular-nums;
}

.preview__note {
    margin: 4px 0 0;
    font-size: 0.8rem;
    color: var(--warn);
}

.preview__note:empty {
    display: none;
}

/* Toast, nav */

.toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 76px);
    z-index: 50;
    max-width: 608px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--text);
    color: var(--bg);
}

.toast__action {
    border: 0;
    background: none;
    color: var(--bg);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    height: calc(var(--nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.nav a {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.nav a.active {
    color: var(--accent);
    font-weight: 600;
}

/* Weight chart */

.chart {
    display: block;
    width: 100%;
    height: auto;
    margin-top: 10px;
}

.chart__dot {
    fill: var(--muted);
    opacity: 0.6;
}

.chart__trend {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
}

.chart__label {
    fill: var(--muted);
    font-size: 10px;
}
