/* Оформление «Нарцисса». Цвета заданы токенами, тёмная тема переопределяет их. */
:root {
    --bg: #faf8f3;
    --surface: #ffffff;
    --surface-2: #f3efe6;
    --text: #2a2620;
    --muted: #7a7266;
    --line: #e4ddd0;
    --accent: #c98a12;
    --accent-ink: #ffffff;
    --ok: #2f8a4c;
    --warn: #b7791f;
    --bad: #c0392b;
    --radius: 10px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17150f;
        --surface: #211e17;
        --surface-2: #2a261d;
        --text: #eee8dc;
        --muted: #a69d8e;
        --line: #3a3428;
        --accent: #e0a73a;
        --accent-ink: #1b1508;
        --ok: #5cc27e;
        --warn: #e0a73a;
        --bad: #ec6b5e;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 var(--font);
}

button, .button {
    font: inherit;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.link { border: 0; background: none; color: var(--muted); padding: 2px 6px; }
button.link:hover { color: var(--bad); }

input, select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 6px;
    width: 100%;
    min-width: 0;
}
input[type="number"] { text-align: right; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Шапка */
.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; }
.logo { font-size: 28px; color: var(--accent); }
.brand-name { font-weight: 700; font-size: 18px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Сводка */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    padding: 12px 16px;
}
.kpi {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
}
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.kpi.bad .value { color: var(--bad); }
.kpi.ok .value { color: var(--ok); }

/* Раскладка */
.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    padding: 0 16px 24px;
}
.steps { display: flex; flex-direction: column; gap: 2px; }
.steps button {
    text-align: left;
    border: 0;
    background: none;
    padding: 8px 10px;
    border-radius: 8px;
    display: flex;
    gap: 8px;
}
.steps button .n {
    width: 22px; height: 22px; border-radius: 50%;
    display: inline-grid; place-items: center;
    background: var(--surface-2); color: var(--muted); font-size: 12px; flex: none;
}
.steps button.active { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.steps button.active .n { background: var(--accent); color: var(--accent-ink); }

.view, .steps, .layout > * { min-width: 0; }
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.lead { color: var(--muted); margin: 0 0 12px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px 16px;
}
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }

/* Таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 700; border-bottom: 0; }
tr.sub td { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); }

.tips { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.tips li { display: flex; gap: 8px; align-items: baseline; }
.tips .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; transform: translateY(1px); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* Техкарта внутри позиции меню */
details.recipe { margin: 6px 0 0; }
details.recipe summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.recipe table { margin-top: 6px; background: var(--surface-2); border-radius: 8px; }

/* Чек-лист */
.check-stage { margin-bottom: 12px; }
.check-stage h3 { display: flex; justify-content: space-between; }
.check-item { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.check-item input { width: auto; margin-top: 3px; }
.check-item.done span { color: var(--muted); text-decoration: line-through; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 6px 0 12px; }
.progress > div { height: 100%; background: var(--accent); }

/* График денежного потока */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart .bar-pos { fill: var(--ok); }
.chart .bar-neg { fill: var(--bad); }
.chart .cum { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.nav-bottom { display: flex; justify-content: space-between; margin-top: 4px; }

/* Телефон: шаги лентой, сводка в две колонки, строки таблиц — карточками с подписями полей */
@media (max-width: 760px) {
    body { font-size: 15px; }
    input, select { font-size: 16px; padding: 7px 8px; } /* 16px — чтобы iOS не увеличивал страницу при вводе */
    .topbar { padding: 8px 12px; }
    .actions { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .actions button, .actions .button { white-space: nowrap; }
    .kpis { grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 12px; }
    .kpi { padding: 8px 10px; }
    .kpi .value { font-size: 17px; }
    .layout { grid-template-columns: 1fr; padding: 0 12px 20px; gap: 10px; }
    .steps {
        flex-direction: row; overflow-x: auto; position: sticky; top: 0; z-index: 5;
        background: var(--bg); padding: 6px 0; scrollbar-width: none;
    }
    .steps button { white-space: nowrap; }
    .card { padding: 12px; }

    table.editable thead { display: none; }
    table.editable tbody tr {
        display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px;
        padding: 12px 0; border-bottom: 1px solid var(--line); position: relative;
    }
    table.editable td { border: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; text-align: left; }
    table.editable td.num { text-align: left; }
    table.editable td::before { content: attr(data-label); font-size: 12px; color: var(--muted); }
    table.editable td:first-child { grid-column: 1 / -1; padding-right: 32px; }
    table.editable td.row-del { position: absolute; top: 8px; right: 0; }
    table.editable td.row-del::before { content: none; }
    table.editable tfoot tr { display: flex; flex-wrap: wrap; gap: 4px 14px; padding-top: 10px; }
    table.editable tfoot td { border: 0; padding: 0; }
    table.editable tfoot td:empty { display: none; }
    input[type="number"] { text-align: left; }
    .nav-bottom button { padding: 10px 14px; }
    .chart text { font-size: 22px; } /* график масштабируется по ширине — на телефоне подписи увеличиваем */
}

/* Печать: только содержимое, весь план подряд */
@media print {
    .topbar .actions, .steps, .nav-bottom, .row-actions, button.link { display: none !important; }
    .layout { display: block; padding: 0; }
    body { background: #fff; color: #000; }
    .card { break-inside: avoid; border-color: #ccc; }
    input, select { border: 0; padding: 0; background: none; }
}

/* Отрицательная сумма (убыток) */
.neg { color: var(--bad); }
