:root {
  --bg: #f7f6f2; --panel: #ffffff; --panel2: #f3f1ec; --fg: #1c1b18; --muted: #77716a; --line: #e9e6df; --line2: #f0ede7;
  --gold: #9a6f0f; --gold-bg: #f7efd9; --accent: #2a5d86; --accent-bg: #e8f0f7;
  --ok: #22703c; --ok-bg: #e5f3ea; --warn: #94570a; --warn-bg: #fbf0dc; --bad: #b0281f; --bad-bg: #fbe7e4; --info: #375a9e; --info-bg: #e8eefa;
  --radius: 12px; --shadow: 0 1px 2px rgba(25, 20, 10, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141310; --panel: #1c1b17; --panel2: #23211c; --fg: #efebe2; --muted: #a29b8d; --line: #302d27; --line2: #27251f;
    --gold: #e2b54d; --gold-bg: #362c18; --accent: #8cbbe0; --accent-bg: #1d2a35;
    --ok: #6fcf8e; --ok-bg: #1a2e21; --warn: #eeb064; --warn-bg: #352816; --bad: #ff8d84; --bad-bg: #3a1d1a; --info: #a3b8ff; --info-bg: #202940;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h2 a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.hide { display: none !important; }
.stack > * + * { margin-top: 14px; }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad); }
.code { font: 13px ui-monospace, Menlo, monospace; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; padding: 2px 10px 18px; letter-spacing: -.01em; }
.brand .dot { width: 22px; height: 22px; border-radius: 7px; background: linear-gradient(135deg, #e6c25e, #9a6f0f); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 8px; color: var(--muted); margin-bottom: 1px; font-size: 14.5px; }
.nav a:hover { background: var(--panel2); color: var(--fg); text-decoration: none; }
.nav a.on { background: var(--panel2); color: var(--fg); font-weight: 600; }
.nav .count { font-size: 11.5px; background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-weight: 600; }
.side .me { margin-top: auto; border-top: 1px solid var(--line); padding: 14px 10px 0; font-size: 13px; }
.main { padding: 28px 36px 64px; min-width: 0; max-width: 1280px; }
.top { display: none; }
.pagehead { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.pagehead .sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 25% 0 0; z-index: 40; transform: translateX(-105%); transition: transform .2s; height: 100%; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .side.open { transform: none; }
  .top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .main { padding: 18px 16px 60px; }
}

/* ---------- controls ---------- */
button, .btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); padding: 7px 13px; border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transition: background .12s, border-color .12s; }
button:hover, .btn:hover { border-color: #cfc9be; text-decoration: none; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
button.gold { background: var(--gold); color: #fff; border-color: var(--gold); }
button.danger { color: var(--bad); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover, .btn.ghost:hover { background: var(--panel2); color: var(--fg); }
button.sm, .btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
button.icon { width: 32px; height: 32px; padding: 0; justify-content: center; font-size: 18px; border-radius: 50%; }
input, select, textarea { font: inherit; font-size: 14.5px; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { width: 100%; min-height: 72px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--fg); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .grid3, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid2 { grid-template-columns: 1fr; } }
.seg { display: inline-flex; background: var(--panel2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 8px; }
.seg button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.small-seg button { font-size: 13px; padding: 4px 10px; }

/* toolbar with tabs */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.tabs > button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 8px; }
.tabs > button:hover { background: var(--panel2); color: var(--fg); }
.tabs > button.on { background: var(--fg); color: var(--bg); }
.tabs > select { border: 0; background: transparent; color: var(--muted); }
.tabs > select.on { color: var(--fg); font-weight: 600; }
.count-pill { font-size: 11.5px; opacity: .7; margin-left: 2px; font-variant-numeric: tabular-nums; }
.deck-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }

/* ---------- panels, chips ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel.flat { box-shadow: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 9px; border-radius: 20px; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.chip.gold { background: var(--gold-bg); color: var(--gold); font-weight: 600; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--info); }
.dot-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot-label::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dot-label.bad::before { background: var(--bad); } .dot-label.gold::before { background: var(--gold); } .dot-label.info::before { background: var(--info); }
.dot-label.ok::before { background: var(--ok); } .dot-label.warn::before { background: var(--warn); }
.alert, .note { padding: 9px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-size: 13.5px; }
.alert.bad, .note.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info, .note.info { background: var(--info-bg); color: var(--info); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 44px 10px; }
.sec-title { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.eyebrow { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: 4px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; padding: 6px 0; border-bottom: 1px solid var(--line2); }
.kv:last-child { border-bottom: 0; }
.big-num { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.back { display: inline-block; margin-bottom: 14px; color: var(--muted); }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel2); }
table.clean td, table.clean th { padding: 7px 8px; }
.sub-line { font-size: 12px; color: var(--muted); }

/* ---------- decision card ---------- */
.pager { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.card-body { display: grid; grid-template-columns: 280px 1fr; }
.card-photo { background: var(--panel2); display: flex; align-items: center; justify-content: center; min-height: 300px; }
.card-photo img { width: 100%; height: 100%; max-height: 420px; object-fit: contain; cursor: zoom-in; }
.noimg { color: var(--muted); font-size: 13px; }
.card-main { padding: 22px 24px; min-width: 0; }
.card-head { display: flex; gap: 12px; align-items: flex-start; }
.card-head h2 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.status { font-size: 12.5px; font-weight: 600; padding: 4px 11px; border-radius: 20px; white-space: nowrap; }
.status.bad { background: var(--bad-bg); color: var(--bad); } .status.gold { background: var(--gold-bg); color: var(--gold); }
.status.info { background: var(--info-bg); color: var(--info); } .status.ok { background: var(--ok-bg); color: var(--ok); }
.suggest { display: flex; align-items: center; gap: 14px; margin: 18px 0 16px; padding: 14px 16px; border-radius: 12px; background: var(--panel2); }
.suggest .tiny { color: var(--muted); }
.suggest .big { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.suggest .unit { font-size: 15px; font-weight: 500; color: var(--muted); }
.suggest.urgent { background: var(--bad-bg); } .suggest.order { background: var(--gold-bg); } .suggest.ok { background: var(--ok-bg); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border: 1px solid var(--line2); border-radius: 12px; }
.metrics > div { padding: 11px 13px; display: flex; flex-direction: column; gap: 2px; min-width: 0; border-right: 1px solid var(--line2); }
.metrics > div:last-child { border-right: 0; }
.metrics .k { font-size: 12px; color: var(--muted); }
.metrics .v { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.metrics .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-main .note { margin-top: 12px; }
.how { margin-top: 12px; font-size: 13.5px; }
.how summary { cursor: pointer; color: var(--muted); }
.calc { margin-top: 8px; border-radius: 10px; background: var(--panel2); padding: 4px 12px; }
.calc-row { display: grid; grid-template-columns: 190px 1fr auto; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.calc-row:last-child { border-bottom: 0; }
.meta { margin-top: 12px; font-size: 13px; color: var(--muted); display: grid; gap: 3px; }
.meta b { color: var(--fg); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 14px 24px; border-top: 1px solid var(--line); }
.actions > button:not(.ghost) { padding: 8px 16px; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; min-width: 190px; box-shadow: 0 8px 30px rgba(0,0,0,.12); display: grid; }
.menu-list button { border: 0; justify-content: space-between; background: transparent; padding: 8px 10px; }
.menu-list button:hover { background: var(--panel2); }
.kbd { font: 11px ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
@media (max-width: 800px) {
  .card-body { grid-template-columns: 1fr; }
  .card-photo { min-height: 200px; max-height: 260px; }
  .card-photo img { max-height: 260px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics > div:nth-child(2) { border-right: 0; }
  .metrics > div:nth-child(-n+2) { border-bottom: 1px solid var(--line2); }
  .calc-row { grid-template-columns: 1fr auto; }
  .calc-row .muted { grid-column: 1 / -1; order: 3; }
  .card-main, .actions { padding-left: 16px; padding-right: 16px; }
}
.spark { display: flex; align-items: flex-end; gap: 3px; height: 54px; }
.spark.sm { height: 18px; width: 70px; margin-top: 2px; }
.spark div { flex: 1; background: var(--gold); opacity: .55; border-radius: 3px 3px 0 0; min-height: 2px; }
.spark div:last-child { opacity: .9; }
.spark-l { display: flex; gap: 3px; font-size: 10.5px; color: var(--muted); margin-top: 4px; }
.spark-l span { flex: 1; text-align: center; overflow: hidden; }

/* ---------- product page ---------- */
.product-hero { display: flex; gap: 24px; align-items: flex-start; margin-bottom: 22px; flex-wrap: wrap; }
.hero-photo { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.thumb.hero-thumb { width: 150px; height: 190px; border-radius: 12px; }
.thumb.hero-thumb img { object-fit: contain; background: var(--panel2); }
.upload { cursor: pointer; }
.hero-stats { display: flex; gap: 28px; margin-top: 14px; flex-wrap: wrap; }
.hero-stats .k { display: block; font-size: 12px; color: var(--muted); }
.hero-stats b { font-size: 20px; font-variant-numeric: tabular-nums; }
.product-grid { align-items: start; }
.step + .step { margin-top: 14px; }
.step-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.timeline > div { padding: 9px 0; border-bottom: 1px solid var(--line2); }
.timeline > div:last-child { border-bottom: 0; }

/* ---------- formula builder ---------- */
.fb-line { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; background: var(--panel2); min-height: 50px; }
.tok { position: relative; display: inline-flex; align-items: center; }
.tok.var { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 13.5px; font-weight: 500; }
.tok.var:hover { border-color: #cfc9be; }
.tok.var select { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; padding: 0; border: 0; }
.tok-label { white-space: nowrap; pointer-events: none; }
.tok.num input { width: auto; min-width: 46px; padding: 5px 8px; font-size: 13.5px; text-align: center; border-radius: 8px; font-variant-numeric: tabular-nums; }
.tok.op button { border: 0; background: transparent; color: var(--gold); font-weight: 700; width: 22px; height: 30px; padding: 0; justify-content: center; font-size: 19px; }
.tok.op button:hover { background: var(--gold-bg); border-radius: 6px; }
.tok.paren { font-size: 22px; color: var(--muted); padding: 0 2px; }
.tok-x { position: absolute; z-index: 2; top: -7px; right: -7px; width: 17px; height: 17px; padding: 0; border-radius: 50%; font-size: 11px; line-height: 1; justify-content: center; background: var(--fg); color: var(--bg); border: 0; opacity: 0; transition: opacity .1s; }
.tok:hover .tok-x, .tok:focus-within .tok-x { opacity: 1; }
@media (hover: none) { .tok-x { opacity: .7; } }
.fb-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.fb-add select { font-size: 13.5px; padding: 5px 8px; }
.fb-ops { display: inline-flex; gap: 4px; }
.fb-ops .op { width: 32px; justify-content: center; padding: 4px 0; font-weight: 700; font-size: 15px; }
.fb-msg { margin-top: 6px; }
.fb-msg.ok { color: var(--ok); }
.fb-msg.bad { color: var(--warn); }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 960px) { .settings-grid { grid-template-columns: 1fr; } }
.lead-grid { display: grid; grid-template-columns: 50px 1fr 1fr 70px; gap: 8px; align-items: center; }
.lead-grid input { width: 100%; }

/* ---------- task cards ---------- */
.tlist { display: grid; gap: 10px; }
.tcard { display: grid; grid-template-columns: 56px 1fr; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.thumb { width: 56px; height: 56px; border-radius: 9px; background: var(--panel2); display: flex; align-items: center; justify-content: center; font-size: 10.5px; color: var(--muted); overflow: hidden; text-align: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.steps button.on { background: var(--accent-bg); border-color: transparent; color: var(--accent); font-weight: 600; }
.days { font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.days.late { color: var(--bad); }
.days.soon { color: var(--warn); }

/* ---------- dialogs & overlays ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(540px, calc(100vw - 24px)); background: var(--panel); color: var(--fg); box-shadow: 0 24px 70px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 18, 12, .4); }
dialog .dh { padding: 18px 20px 6px; display: flex; align-items: center; }
dialog .db { padding: 8px 20px 6px; max-height: 70vh; overflow-y: auto; }
dialog .df { padding: 14px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog.wide { width: min(900px, calc(100vw - 24px)); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: calc(100vw - 32px); font-size: 14px; }
.toast.err { background: var(--bad); color: #fff; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 90; display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }
.lightbox::after { content: '✕'; position: fixed; top: 14px; right: 20px; color: #fff; font-size: 22px; }

/* ---------- misc ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .panel { width: min(400px, 100%); padding: 28px; }
.typeahead { position: relative; }
.typeahead .menu { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; max-height: 260px; overflow-y: auto; box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.typeahead .menu div { padding: 8px 10px; cursor: pointer; font-size: 14px; }
.typeahead .menu div:hover, .typeahead .menu div.hl { background: var(--panel2); }
.perm-grid td { padding: 5px 8px; }
