/* Nozomi: hand-written CSS, no build step. */

:root {
    --bg: #f7f4ee;
    --surface: #ffffff;
    --ink: #1d1b19;
    --muted: #6b655d;
    --line: #e4ddd2;
    --accent: #594822;      /* Nozomi logo brown */
    --accent-ink: #fff8e6;
    --gold: #a08745;        /* logo fish */
    --danger: #b8322a;
    --ok: #2f6b4f;
    --radius: 10px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #161514;
        --surface: #201e1c;
        --ink: #eeeae4;
        --muted: #a39c92;
        --line: #34312d;
        --accent: #c2a65c;  /* lighter logo gold reads on dark */
        --accent-ink: #1d1a12;
        --gold: #c2a65c;
        --danger: #e0574c;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: inherit; }

/* Top bar */
.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 32px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-logo { display: block; width: 44px; height: 44px; border-radius: 50%; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.brand-name small { font-weight: 400; color: var(--muted); font-size: 14px; }

.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav-link {
    padding: 6px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 15px;
}
.nav-link:hover { background: var(--bg); }
.nav-link.is-active { background: var(--ink); color: var(--surface); }
.nav-link.is-disabled { color: var(--muted); opacity: .6; cursor: default; }
.nav-link.is-disabled:hover { background: none; }

/* Page */
.page { max-width: 1100px; margin: 0 auto; padding: 32px 24px 48px; }

.flash {
    margin-bottom: 20px; padding: 10px 14px;
    border-left: 4px solid var(--ok);
    background: var(--surface); border-radius: 6px;
}

.hero h1 { margin: 0 0 8px; font-size: 30px; }
.lead { margin: 0 0 28px; max-width: 720px; color: var(--muted); font-size: 17px; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}
.card {
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.card h2 { margin: 0 0 6px; font-size: 18px; }
.card h2 a { text-decoration: none; }
.card h2 a:hover { color: var(--accent); }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.card.is-pending h2 { color: var(--muted); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px; color: var(--muted);
}

/* Section tabs (Ingredients / Suppliers / Categories) */
.tabs { display: flex; gap: 4px; margin: -8px 0 24px; border-bottom: 1px solid var(--line); }
.tab { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--gold); font-weight: 600; }

/* Page heading with actions */
h1 { font-size: 26px; margin: 0 0 6px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px 24px; margin-bottom: 20px; }
.page-head p { margin: 0; }
.muted { color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.pre { white-space: pre-line; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons */
.btn {
    display: inline-block; padding: 7px 14px;
    border: 1px solid var(--line); border-radius: 6px;
    background: var(--surface); color: var(--ink);
    font: inherit; font-size: 14px; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.inline-form { display: inline; margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table td.actions { display: table-cell; text-align: right; white-space: nowrap; }
.table td.actions > * { margin-left: 4px; }
.table .group-row th { background: var(--bg); font-size: 14px; color: var(--ink); text-transform: none; letter-spacing: 0; }
.table tbody tr:last-child td { border-bottom: none; }
.table-compact { width: auto; min-width: 320px; margin-bottom: 14px; }
.badge-sample { margin-left: 6px; border-color: var(--gold); color: var(--gold); }

.filter { margin-bottom: 16px; color: var(--muted); font-size: 14px; }
.filter select { margin-left: 6px; }

/* Forms */
.form { max-width: 820px; }
.form-section { margin: 0 0 20px; padding: 16px 20px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.form-section legend { padding: 0 6px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px 20px; }
.form > .form-grid { padding: 16px 20px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.field > span:first-child { font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); }
.field-wide { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 12px; }
.field-error { color: var(--danger); font-size: 13px; }
input, select, textarea {
    font: inherit; font-size: 15px; color: var(--ink);
    padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-actions { display: flex; gap: 8px; }
.flash.is-error { border-left-color: var(--danger); }

/* Ingredient detail */
.panel { margin-bottom: 20px; padding: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2 { margin: 0 0 12px; font-size: 18px; }
.cost-steps { margin: 0; display: grid; gap: 8px; }
.cost-steps > div { display: grid; grid-template-columns: 200px 1fr; gap: 12px; }
.cost-steps dt { color: var(--muted); }
.cost-steps dd { margin: 0; font-variant-numeric: tabular-nums; }
.cost-steps .is-result { padding-top: 8px; border-top: 1px solid var(--line); font-size: 17px; }
.cost-steps .is-result dt { color: var(--ink); font-weight: 600; }
.inline-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-add input[type=text] { width: 130px; }
.inline-add input[type=number] { width: 120px; }

/* Invoices (S2.1) */
.form-wide { max-width: none; }
.line-entry th, .line-entry td { padding: 6px 6px; }
.line-entry input, .line-entry select { width: 100%; }
.line-entry .in-desc { min-width: 220px; }
.line-entry .in-num { min-width: 80px; text-align: right; }
.line-entry .in-unit { min-width: 70px; }
.line-entry .in-match { min-width: 200px; }
.line-entry .field-error { display: block; }
.badge-ok { border-color: var(--ok); color: var(--ok); }
.badge-draft { border-color: var(--gold); color: var(--gold); }
.ok { color: var(--ok); }
.table tfoot th { border-top: 1px solid var(--line); border-bottom: none; }
.table tr.has-problem td { background: color-mix(in srgb, var(--danger) 7%, transparent); }
.problem-list { margin: 6px 0 0; padding-left: 20px; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 16px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Invoice upload (S2.2) */
.upload-box { border: 1px dashed var(--line); border-radius: 8px; padding: 14px 16px; margin: 0 0 20px;
    display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.upload-box .field { margin: 0; }
.upload-box .hint { flex-basis: 100%; margin: 0; }
.line-entry tr.is-unmatched td { background: color-mix(in srgb, var(--gold) 10%, transparent); }
.flag { display: block; font-size: 12px; color: var(--gold); margin-top: 2px; }

/* Purchases (S2.3) */
.report-filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; margin: 0 0 12px; }
.report-filters .presets { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; padding-bottom: 8px; }
.report-range { margin: 0 0 12px; font-size: 14px; }
.table.report th, .table.report td { padding: 8px 10px; }
.table.report td { white-space: nowrap; }
.table.report tr.is-other td { color: var(--muted); font-style: italic; }
.table.report tfoot th { font-variant-numeric: tabular-nums; }
.report-check { margin: 12px 0 20px; font-size: 14px; }
.report-check p { margin: 0 0 6px; }
.price-changes { margin-top: 24px; }
.price-changes .page-head { margin-bottom: 8px; align-items: center; }
.price-changes .page-head h2 { margin: 0; }
.price-up { color: var(--danger); font-weight: 600; }
.price-down { color: var(--ok); font-weight: 600; }

/* Menus and dishes (S3.1) */
.dish-lines { font-size: 13px; max-width: 420px; }
.menu-totals { max-width: 520px; }

/* Portions from covers vs ingredients bought (S3.1b) */
.btn-small { padding: 3px 10px; font-size: 13px; }
.covers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px 20px; margin-top: 8px; }
.covers-grid input { max-width: 140px; }
.portion-table .group-row th { white-space: normal; }
.portion-table .group-detail { display: block; margin-top: 2px; font-weight: 400; font-size: 13px; color: var(--muted); }
.portion-table td.actions { vertical-align: middle; }
.unused-list { margin: 8px 0 0; padding-left: 20px; columns: 2 220px; }

/* Covers: services per menu per day (S3.2) */
.week-nav { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; margin: 0 0 14px; font-size: 14px; }
.services-week th.col-group { text-align: center; border-bottom: 1px solid var(--line); }
.services-week tr.is-empty td { color: var(--muted); }
.services-week tr.is-today td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.services-week tbody th { font-weight: 600; }
.service-menu legend small { font-weight: 400; margin-left: 6px; }
.service-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px 20px; }
.service-fields input { max-width: 150px; }
.service-dishes { margin-top: 12px; }
.service-dishes summary { cursor: pointer; font-size: 14px; }
.service-dishes .table { max-width: 560px; }

/* Covers: Resy import (S3.3) */
.check { display: flex; gap: 8px; align-items: baseline; margin: 0 0 16px; font-size: 14px; }
.check small { display: inline; }
.resy-mapping { min-width: 0; } /* a fieldset grows to its table by default: let the table scroll inside it on a phone */

/* Usage: stock counts and actual usage (S4.1) */
.count-sheet { max-width: 640px; }
.count-sheet .in-num { max-width: 110px; }
.count-sheet .in-unit { max-width: 110px; }
.count-sheet tr.is-counted td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.count-sheet .group-row th { background: color-mix(in srgb, var(--line) 35%, transparent); }
.usage-table tr.is-not-counted td { color: var(--muted); }
.usage-table tr.is-negative td { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.usage-table td .flag { white-space: normal; }
.usage-table .op { color: var(--muted); font-weight: 400; }
.count-list { max-width: 560px; margin-top: 24px; }

/* Usage: expected vs actual (S4.2) */
.variance-table tr.is-not-counted td { color: var(--muted); }
.variance-table tr.is-over td:last-child { color: var(--danger); }
.variance-table td .flag { white-space: normal; }

/* Dashboard (S4.3) */
.target-form .field { margin: 0; }
.target-input { display: flex; gap: 6px; }
.target-input input { max-width: 90px; }
.answer { border-left: 4px solid var(--gold); }
.menu-picks { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; font-size: 14px; }
.menu-picks a { padding: 3px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); text-decoration: none; }
.menu-picks a:hover { border-color: var(--muted); }
.menu-picks a.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.answer-lead { margin: 0 0 8px; font-size: 18px; line-height: 1.45; }
.answer-why { margin: 0; padding-left: 20px; font-size: 15px; }
.answer-why li { margin-bottom: 4px; }
.is-over { color: var(--danger); }
.is-within { color: var(--ok); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 8px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 26px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile-note { font-size: 12px; color: var(--muted); }
.tile.is-over { border-color: var(--danger); }
.tile.is-over .tile-value { color: var(--danger); }
.tile.is-within .tile-value { color: var(--ok); }
.trend-table td small, .trend-table th small { display: block; font-weight: 400; }
.trend-table th small { color: var(--muted); }
.trend-table .pct { color: var(--muted); }
.trend-table .pct.is-over { color: var(--danger); font-weight: 600; }
.trend-table .pct.is-within { color: var(--ok); }
.trend-table .is-chosen { background: color-mix(in srgb, var(--gold) 12%, transparent); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 0 20px; }
.drivers-table td.is-up { color: var(--danger); }
.drivers-table td.is-down { color: var(--ok); }
.drivers-table td .flag, .alerts-table td .flag { white-space: normal; }
.variance-table tr.is-under td:last-child { color: var(--ok); }

/* Reorder (S4.4) */
.badge-late { border-color: var(--danger); color: var(--danger); }
.reorder-flag { margin: 0 0 16px; padding: 10px 14px; border-left: 4px solid var(--gold); background: var(--surface); font-size: 14px; }
.order-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; margin-bottom: 8px; }
.order-card h3 { margin: 0 0 4px; font-size: 18px; }
.order-card .badge { margin-left: 6px; }
.order-card details { margin-top: 10px; font-size: 14px; }
.order-text { display: block; width: 100%; box-sizing: border-box; margin: 8px 0; font: 13px/1.4 ui-monospace, Consolas, monospace; }
.reorder-table td small { white-space: normal; }
.reorder-table td:last-child { min-width: 180px; }
/* Mark as ordered (S4.5) */
.badge-ordered { border-color: var(--muted); color: var(--muted); }
.order-mark { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 12px; }
.order-mark .hint { font-size: 13px; color: var(--muted); }
.order-card.is-overdue { border-color: var(--danger); }
.order-card .reorder-flag { border-left-color: var(--danger); margin: 8px 0; }
.day-picks { display: flex; flex-direction: row; flex-wrap: wrap; gap: 4px 14px; border: 0; padding: 0; margin: 0; }
.day-picks legend { width: 100%; padding: 0; margin-bottom: 6px; }
.day-picks .check { margin: 0; }

.footer { padding: 16px 24px 32px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 600px) {
    .topbar { padding: 12px 16px; }
    .page { padding: 24px 16px 40px; }
    .hero h1 { font-size: 24px; }
    .cost-steps > div { grid-template-columns: 1fr; gap: 0; }
}

/* O2: sign-in, password page and the signed-in user in the top bar */
.userbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-left: auto; font-size: 14px; color: var(--muted); }
.userbar a { color: var(--muted); }
.userbar .inline-form button { font: inherit; }
.auth-box { max-width: 420px; margin: 24px auto 0; }
.auth-box .form-section { display: grid; gap: 0; }
.auth-field { margin-top: 14px; }
.auth-box .check { margin: 14px 0 18px; }

/* O3: Feedback link and list, invoice reading off, "How to start" on Menus */
.userbar .btn-feedback { color: var(--ink); }
.feedback-heading { display: flex; align-items: center; gap: 8px; margin: 24px 0 10px; font-size: 18px; }
.feedback-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.feedback-item { padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: var(--radius); }
.feedback-item.is-done { border-left-color: var(--ok); opacity: .8; }
.feedback-meta { margin: 0 0 6px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.feedback-meta strong { color: var(--ink); }
.feedback-body { margin: 0 0 10px; overflow-wrap: anywhere; }
.upload-off { margin: 0 0 20px; padding: 12px 16px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); }
.howto { margin: 0 0 20px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: var(--radius); }
.howto summary { font-weight: 600; cursor: pointer; }
.howto ol { margin: 10px 0 8px; padding-left: 22px; display: grid; gap: 6px; }
.howto .hint { margin: 0; font-size: 13px; }
