/* Строго — оформление.
   Тёмная тема основная: приложением пользуются рано утром и поздно вечером.
   Светлая полноценная, а не автоматически вывернутая. */

:root {
    color-scheme: dark light;

    --surface-1: #1a1a19;
    --surface-2: #202020;
    --plane: #0d0d0d;
    --ink-1: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --hairline: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;

    --good: #0ca30c;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #d03b3b;

    --seq-100: #cde2fb;
    --seq-250: #86b6ef;
    --seq-400: #3987e5;
    --seq-550: #1c5cab;
    --seq-700: #0d366b;

    --radius: 14px;
    --gap: 16px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: light) {
    :root:where(:not([data-theme="dark"])) {
        color-scheme: light;
        --surface-1: #fcfcfb;
        --surface-2: #f4f3f0;
        --plane: #f9f9f7;
        --ink-1: #0b0b0b;
        --ink-2: #52514e;
        --ink-muted: #898781;
        --grid: #e1e0d9;
        --axis: #c3c2b7;
        --hairline: rgba(11, 11, 11, 0.10);
        --series-1: #2a78d6;
        --series-2: #eb6834;
        --series-3: #1baf7a;
        --series-4: #eda100;
        --series-5: #e87ba4;
        --good: #006300;
    }
}

:root[data-theme="light"] {
    color-scheme: light;
    --surface-1: #fcfcfb;
    --surface-2: #f4f3f0;
    --plane: #f9f9f7;
    --ink-1: #0b0b0b;
    --ink-2: #52514e;
    --ink-muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --hairline: rgba(11, 11, 11, 0.10);
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --good: #006300;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--plane);
    color: var(--ink-1);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: contain;
}

body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
    min-height: 100vh;
}

/* --- каркас ------------------------------------------------------------- */

.app {
    max-width: 720px;
    margin: 0 auto;
    padding: calc(12px + env(safe-area-inset-top)) 14px 0;
}

.topbar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-2);
}

.topbar .clock {
    font-size: 13px;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}

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

.card h2 {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.card .sub {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--ink-2);
}

/* --- герой: главное число ----------------------------------------------- */

.hero { text-align: center; padding: 22px 16px 20px; }

.hero .value {
    font-size: 58px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
}

.hero .unit { font-size: 24px; font-weight: 500; color: var(--ink-2); }
.hero .caption { margin-top: 6px; font-size: 13px; color: var(--ink-muted); }

.hero .delta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.delta.down { color: var(--good); }
.delta.up { color: var(--critical); }
.delta.flat { color: var(--ink-2); }

/* --- плитки -------------------------------------------------------------- */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.tile {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 12px 14px;
}

.tile .label {
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.tile .value {
    margin-top: 4px;
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.tile .note { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }

/* --- список слотов ------------------------------------------------------- */

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

.slot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--surface-2);
}

.slot .mark {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--axis);
    flex: none;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
}

.slot.done .mark { border-color: var(--good); color: var(--good); }
.slot.late .mark { border-color: var(--critical); color: var(--critical); }
.slot .title { flex: 1; font-weight: 500; }
.slot .time { color: var(--ink-muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* --- элементы управления ------------------------------------------------- */

button, .btn {
    font: inherit;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    padding: 13px 18px;
    background: var(--series-1);
    color: #fff;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.08s ease, opacity 0.15s ease;
}

button:active { transform: scale(0.975); }
button:disabled { opacity: 0.5; cursor: default; }

button.ghost {
    background: var(--surface-2);
    color: var(--ink-1);
    border: 1px solid var(--hairline);
}

button.danger { background: var(--critical); }
button.wide { width: 100%; }
button.small { padding: 8px 12px; font-size: 14px; border-radius: 8px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }

input, select, textarea {
    font: inherit;
    width: 100%;
    padding: 13px 14px;
    border-radius: 10px;
    border: 1px solid var(--hairline);
    background: var(--surface-2);
    color: var(--ink-1);
    -webkit-appearance: none;
    appearance: none;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--series-1);
    outline-offset: 1px;
}

textarea { min-height: 84px; resize: vertical; }

label {
    display: block;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--ink-2);
}

label > span { display: block; margin-bottom: 6px; }

.checkline {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    font-size: 15px;
    color: var(--ink-1);
}

.checkline input { width: 22px; height: 22px; flex: none; accent-color: var(--critical); }

/* --- нижние вкладки ------------------------------------------------------ */

.tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    background: color-mix(in srgb, var(--surface-1) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--hairline);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 40;
}

.tabs button {
    flex: 1;
    background: none;
    color: var(--ink-muted);
    border-radius: 0;
    padding: 10px 4px 12px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.tabs button.active { color: var(--series-1); }
.tabs button svg { width: 22px; height: 22px; }

/* --- графики ------------------------------------------------------------- */

.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick {
    fill: var(--ink-muted);
    font-size: 11px;
    font-family: var(--font);
    font-variant-numeric: tabular-nums;
}

.chart .trend { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .raw-dot { stroke: var(--surface-1); stroke-width: 2; }
.chart .goal-line { stroke: var(--ink-muted); stroke-width: 1.5; stroke-dasharray: 5 4; fill: none; }
.chart .crosshair { stroke: var(--ink-muted); stroke-width: 1; stroke-dasharray: 3 3; }

.tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
    z-index: 10;
    transition: opacity 0.1s ease;
}

.tooltip .t-day { color: var(--ink-muted); font-size: 11px; margin-bottom: 3px; }
.tooltip .t-row { display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; }
.tooltip .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--ink-2);
}

.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .dash { width: 14px; height: 0; border-top: 2px dashed var(--ink-muted); }

.range {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    background: var(--surface-2);
    border-radius: 10px;
    padding: 3px;
}

.range button {
    flex: 1;
    background: none;
    color: var(--ink-2);
    padding: 8px 4px;
    font-size: 13px;
    border-radius: 8px;
}

.range button.active { background: var(--surface-1); color: var(--ink-1); }

/* --- теплокарта ---------------------------------------------------------- */

.heat { display: flex; gap: 3px; flex-wrap: wrap; }
.heat .cell { width: 15px; height: 15px; border-radius: 3px; background: var(--surface-2); }

/* --- лента и списки ------------------------------------------------------ */

.feed { display: flex; flex-direction: column; gap: 2px; }

.feed .entry {
    display: flex;
    gap: 11px;
    padding: 11px 0;
    border-bottom: 1px solid var(--hairline);
    font-size: 14px;
}

.feed .entry:last-child { border-bottom: none; }
.feed .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; }
.feed .who { font-weight: 600; }
.feed .when { color: var(--ink-muted); font-size: 12px; margin-left: auto; white-space: nowrap; }

.meal {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid var(--hairline);
}

.meal:last-child { border-bottom: none; }
.meal img { width: 54px; height: 54px; border-radius: 8px; object-fit: cover; flex: none; }
.meal .body { flex: 1; min-width: 0; }
.meal .title { font-weight: 500; word-break: break-word; }
.meal .meta { font-size: 12px; color: var(--ink-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.meal .verdict { font-size: 13px; color: var(--ink-2); margin-top: 6px; font-style: italic; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.badge.binge { background: color-mix(in srgb, var(--critical) 22%, transparent); color: var(--critical); }
.badge.ai { background: var(--surface-2); color: var(--ink-muted); }

/* --- всплывающее окно ---------------------------------------------------- */

.sheet-bg {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 50;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.sheet {
    background: var(--surface-1);
    width: 100%;
    max-width: 720px;
    border-radius: 18px 18px 0 0;
    padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
    max-height: 88vh;
    overflow-y: auto;
    animation: rise 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet h3 { margin: 0 0 16px; font-size: 19px; }

@media (prefers-reduced-motion: reduce) {
    .sheet { animation: none; }
    button:active { transform: none; }
}

/* --- прочее -------------------------------------------------------------- */

.empty { text-align: center; color: var(--ink-muted); padding: 26px 12px; font-size: 14px; }
.muted { color: var(--ink-muted); font-size: 13px; }
.hidden { display: none !important; }
.center { text-align: center; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(84px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    color: var(--ink-1);
    padding: 11px 18px;
    border-radius: 999px;
    font-size: 14px;
    z-index: 60;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    max-width: 88vw;
    text-align: center;
}

.toast.bad { border-color: var(--critical); color: var(--critical); }

.auth { max-width: 380px; margin: 12vh auto 0; padding: 0 18px; }
.auth h1 { font-size: 30px; letter-spacing: 0.16em; text-transform: uppercase; text-align: center; margin-bottom: 6px; }
.auth p.lead { text-align: center; color: var(--ink-muted); margin: 0 0 26px; font-size: 14px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: right; padding: 7px 6px; border-bottom: 1px solid var(--hairline); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--ink-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
table.data td { font-variant-numeric: tabular-nums; }
