:root {
  --bg: #f6f4ee; --panel: #ffffff; --panel2: #faf8f3; --fg: #1f1d18; --muted: #6d675b; --line: #e6e1d4;
  --gold: #a87b12; --gold-soft: #f6ecd2; --accent: #1f5f8b; --accent-soft: #e3eef6;
  --ok: #24753e; --ok-soft: #e1f2e6; --warn: #a15c00; --warn-soft: #fbecd6; --bad: #b3261e; --bad-soft: #fbe2df;
  --info: #3b5bab; --info-soft: #e5ebf8; --shadow: 0 1px 2px rgba(30,25,10,.06), 0 4px 16px rgba(30,25,10,.05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15140f; --panel: #1f1d17; --panel2: #24221b; --fg: #f0ece2; --muted: #a59f90; --line: #36322a;
    --gold: #e0b44a; --gold-soft: #3a3020; --accent: #7db7e0; --accent-soft: #1e2d38;
    --ok: #6bcf8b; --ok-soft: #1c3324; --warn: #f0b060; --warn-soft: #3a2c18; --bad: #ff8a80; --bad-soft: #3d1f1c;
    --info: #9db4ff; --info-soft: #222b44; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }
.hide { display: none !important; }
.stack > * + * { margin-top: 12px; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 4px 10px 16px; }
.brand .dot { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #e7c25b, #a87b12); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--fg); margin-bottom: 2px; }
.nav a:hover { background: var(--panel2); text-decoration: none; }
.nav a.on { background: var(--gold-soft); color: var(--fg); font-weight: 600; }
.nav .count { font-size: 12px; background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; }
.side .me { border-top: 1px solid var(--line); margin-top: 14px; padding: 12px 10px 0; font-size: 13px; }
.main { padding: 22px 26px 60px; min-width: 0; }
.top { display: none; }
.pagehead { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.pagehead .sub { color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-105%); transition: transform .2s; height: 100%; box-shadow: var(--shadow); }
  .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: 16px 16px 60px; }
}

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--fg); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button:disabled { opacity: .5; 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 { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--panel2); }
button.sm { padding: 4px 9px; font-size: 13px; }
input, select, textarea { font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--fg); font-size: 15px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.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: 700px) { .grid3, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 460px) { .grid2 { grid-template-columns: 1fr; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); flex-wrap: wrap; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--fg); color: var(--bg); }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel.flat { box-shadow: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.alert { padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* 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: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--panel2); 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); }

/* decision card */
.deck-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.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: 260px 1fr; }
.card-photo { background: var(--panel2); display: flex; align-items: center; justify-content: center; border-right: 1px solid var(--line); min-height: 280px; cursor: zoom-in; }
.card-photo img { width: 100%; height: 100%; max-height: 400px; object-fit: contain; }
.noimg { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }
.card-main { padding: 18px 20px; min-width: 0; }
.card-title { display: flex; gap: 10px; align-items: flex-start; }
.card-title h2 { margin: 0; font-size: 19px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
.stat { background: var(--panel2); border-radius: 10px; padding: 9px 11px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }
.suggest { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 12px; background: var(--panel2); flex-wrap: wrap; }
.suggest .big { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; }
.suggest.urgent { background: var(--bad-soft); }
.suggest.order { background: var(--gold-soft); }
.suggest.follow_up { background: var(--info-soft); }
.suggest.ok { background: var(--ok-soft); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel2); }
.actions button { padding: 9px 14px; }
.actions kbd { font: 11px ui-monospace, monospace; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; opacity: .6; }
@media (max-width: 760px) {
  .card-body { grid-template-columns: 1fr; }
  .card-photo { border-right: 0; border-bottom: 1px solid var(--line); min-height: 200px; max-height: 260px; }
  .card-photo img { max-height: 260px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions kbd { display: none; }
}
.spark { display: flex; align-items: flex-end; gap: 3px; height: 46px; }
.spark div { flex: 1; background: var(--gold); opacity: .75; border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.spark-l { display: flex; gap: 3px; font-size: 10px; color: var(--muted); }
.spark-l span { flex: 1; text-align: center; overflow: hidden; }

/* list cards (tasks, compact products) */
.tlist { display: grid; gap: 10px; }
.tcard { display: grid; grid-template-columns: 64px 1fr; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tcard.sel { outline: 2px solid var(--accent); }
.thumb { width: 64px; height: 64px; border-radius: 8px; background: var(--panel2); object-fit: cover; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.steps button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.days { font-weight: 650; font-variant-numeric: tabular-nums; }
.days.late { color: var(--bad); }
.days.soon { color: var(--warn); }

/* dialog */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--panel); color: var(--fg); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 18, 12, .45); }
dialog .dh { padding: 16px 18px 6px; display: flex; align-items: center; }
dialog .db { padding: 8px 18px 6px; max-height: 70vh; overflow-y: auto; }
dialog .df { padding: 12px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
dialog.wide { width: min(900px, calc(100vw - 24px)); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.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; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .panel { width: min(400px, 100%); }
.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: 8px; max-height: 260px; overflow-y: auto; box-shadow: var(--shadow); }
.typeahead .menu div { padding: 7px 10px; cursor: pointer; font-size: 14px; }
.typeahead .menu div:hover, .typeahead .menu div.hl { background: var(--panel2); }
.perm-grid td { padding: 4px 8px; }
.code { font: 13px ui-monospace, Menlo, monospace; }
.sec-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }
