:root {
  --ink: #1b1714;
  --muted: #6b6258;
  --paper: #f3eee4;
  --card: #fffaf2;
  --line: #ddd3c4;
  --accent: #b8431f;
  --accent-2: #2f5d4a;
  --hot: #9a3412;
  --ok: #2d6a4f;
  --shadow: 0 12px 40px rgba(27, 23, 20, 0.08);
  --serif: "Literata", "Times New Roman", serif;
  --sans: "Manrope", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 10% -10%, #f7d9c6 0%, transparent 50%),
    var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

a { color: inherit; }
.skip { display: none; }

.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.side {
  background: var(--ink);
  color: #f6efe4;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand { display: flex; flex-direction: column; gap: 4px; }
.mark {
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: -0.03em;
}
.brand small { color: #c9b8a2; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-label {
  color: #8f7f6c;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 14px 12px 4px;
}
.nav-label:first-child { padding-top: 0; }
.nav a {
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  color: #eadfce;
}
.nav a.active, .nav a:hover { background: #2a241f; color: #fff; }
.side-add { justify-content: center; }
.side-foot { margin-top: auto; color: #b5a38d; font-size: 12px; display: flex; flex-direction: column; gap: 8px; }
.side-foot a { color: #f0d2b8; }

.main { padding: 32px 40px 60px; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 28px;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 560; letter-spacing: -0.03em; margin: 0; }
h1 { font-size: 36px; line-height: 1.12; }
.lead { color: var(--muted); margin-top: 8px; max-width: 640px; }
.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.status p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.status.run {
  background: #2a241f;
  color: #fff8ee;
  border-color: #2a241f;
}
.status.run span { color: #d7c7b4; }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.crumb { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.crumb a { color: var(--ink); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat, .card, .table-wrap, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.stat { padding: 18px 20px; }
.stat b { display: block; font-family: var(--serif); font-size: 30px; margin-top: 6px; }
.stat span { color: var(--muted); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; }
.panel { padding: 22px; margin-bottom: 18px; }
.panel.slim { padding: 16px 22px; }
.panel h2 { margin-bottom: 8px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 14px;
}

.steps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0;
  margin: 0 0 22px;
}
.steps li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.steps li b { font-size: 15px; }
.steps li span { color: var(--muted); font-size: 13px; }
.steps li.done { border-color: #beddc6; background: #f3faf4; }
.steps li.now { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(184, 67, 31, 0.12); }

.next {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  background: #2a241f;
  color: #fff8ee;
  border-radius: 18px;
  padding: 22px 24px;
  margin-bottom: 22px;
}
.next h2 { color: #fff8ee; margin-bottom: 6px; }
.next p { margin: 0; color: #d7c7b4; max-width: 560px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.tiles.compact { grid-template-columns: repeat(3, 1fr); }
.tile {
  display: block;
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
a.tile:hover { border-color: #c9b8a2; }
.tile span { color: var(--muted); font-size: 13px; }
.tile b { display: block; font-family: var(--serif); font-size: 32px; margin: 4px 0; }
.tile em { font-style: normal; color: var(--muted); font-size: 12px; }
.tile.cut b { color: var(--hot); }
.tile.raise b { color: var(--ok); }

.empty {
  text-align: left;
  padding: 8px 0 4px;
}
.empty h3 { font-size: 22px; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 0 0 14px; max-width: 520px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters a {
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
  font-weight: 600;
}
.filters a.on { background: var(--ink); color: #fff8ee; border-color: var(--ink); }

.job { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.job:last-child { border-bottom: 0; }

.table-wrap { overflow-x: auto; }
table.cmp th.num, table.cmp td.num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions.tight { gap: 6px; justify-content: flex-end; }
.row-actions.tight form { display: inline; }

.btn, button.btn {
  appearance: none;
  border: 0;
  background: var(--ink);
  color: #fff8ee;
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.accent { background: var(--accent); }
.btn.ok { background: var(--accent-2); }
.btn.small { padding: 7px 10px; font-size: 13px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
}
textarea { min-height: 140px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.choices { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.choice {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.choice h3 { font-size: 20px; margin-bottom: 6px; }
.choice p { color: var(--muted); font-size: 14px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.delta.down { color: var(--accent); font-weight: 800; }
.delta.up { color: var(--ok); font-weight: 800; }
.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #efe4d3;
}
.pill.hot { background: #f4d0c0; color: var(--hot); }
.pill.ok { background: #d7eadc; color: var(--ok); }
.pill.cut { background: #fde8dc; color: var(--hot); }
.pill.raise { background: #dceee4; color: var(--ok); }
.pill.hold { background: #eee8df; color: var(--muted); }
.pill.wait { background: #efe6d4; color: #7a5c2e; }
.pill.floor { background: #f4e4c8; color: #7a5c2e; }
.pill.new { background: #e4ecf4; color: #34506e; }

.brief { display: grid; gap: 10px; margin-bottom: 22px; }
.brief-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-decoration: none;
}
.brief-item.cut { border-color: #efc2b3; }
.brief-item.raise { border-color: #beddc6; }
.brief-item.floor { border-color: #e4d0a8; }
.brief-item.dump { border-color: #e4d0a8; }
.path { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.path-step {
  min-width: 110px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.path-step b { display: block; font-family: var(--serif); font-size: 18px; }
.path-step span { color: var(--muted); font-size: 12px; }
.path-step.down { border-color: #efc2b3; }
.path-step.up { border-color: #beddc6; }
.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 28px;
  margin: 8px 0 22px;
}
.facts div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.facts span { color: var(--muted); }
.facts b { font-weight: 700; text-align: right; }
.wb-price { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; line-height: 1.15; }
.wb-price b { font-family: var(--serif); font-weight: 600; }
.wb-price s { color: var(--muted); font-size: 13px; text-decoration: line-through; }
.wb-price em { font-style: normal; color: var(--hot); font-size: 12px; }
.tile .wb-price { align-items: flex-start; }
.tile .wb-price b { font-size: inherit; }
.num .wb-price { align-items: flex-end; }

.flash { background: #e8f3ea; border: 1px solid #beddc6; padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; }
.error { background: #fbe4dc; border: 1px solid #efc2b3; padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.login h1 { font-size: 42px; }
.login p { color: var(--muted); margin: 8px 0 22px; }

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.pair .panel h2 { margin-bottom: 8px; }
.pair select[name="cat_key"], #cat-select {
  min-height: 48px;
}
.pair .btn { width: 100%; justify-content: center; }
.goods { display: flex; gap: 12px; align-items: center; }
.goods img { width: 48px; height: 64px; object-fit: cover; border-radius: 8px; background: #eee; }
.goods.big img { width: 96px; height: 128px; border-radius: 12px; }
.mine {
  display: flex;
  gap: 16px;
  align-items: center;
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid #c9dccf;
  background: #f3f8f4;
  border-radius: 16px;
}
.mine img { width: 72px; height: 96px; object-fit: cover; border-radius: 10px; background: #fff; }
.mine strong { display: block; font-size: 18px; font-family: var(--serif); margin: 2px 0 4px; }
.mine-price { margin-top: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input { max-width: 280px; }

.pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.pick input { width: auto; margin: 0; }
table.cmp tr.hit td { background: #fde8dc; }
table.cmp tr.win td { background: #f7efe4; }
.versus {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.face {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.face.ours { border-color: #c9dccf; }
.face.theirs { border-color: #efc2b3; }
.face img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: #fff;
  border-radius: 12px;
  margin: 8px 0 12px;
}
.face h2 { font-size: 24px; margin: 0 0 6px; }
.face-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.face-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.face-grid b { font-size: 22px; font-family: var(--serif); }
.note { margin-top: 16px; }

.mob-bar, .tabs, .more-backdrop, .more-sheet { display: none; }

@media (max-width: 860px) {
  html, body { overflow-x: hidden; }
  .shell {
    display: block;
    min-height: 100vh;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }
  .side { display: none; }
  .mob-bar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 56px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: #1b1714;
    color: #fff8ee;
  }
  .mob-bar .mark { font-size: 24px; color: #fff8ee; text-decoration: none; }
  .main { padding: 16px 16px 28px; }
  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 18px;
  }
  .top .row-actions, .top .btn, .top form { width: 100%; }
  .top .btn, .top button.btn { justify-content: center; width: 100%; }
  h1 { font-size: 28px; }
  .lead { font-size: 15px; }
  .panel { padding: 16px; border-radius: 16px; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .stats, .grid-2, .choices, .pair, .versus, .steps { grid-template-columns: 1fr; }
  table.cmp tr.hit {
    background: #fde8dc;
    border-color: #efc2b3;
  }
  table.cmp tr.win { background: #f7efe4; }
  table.cmp tr.hit td,
  table.cmp tr.win td { background: transparent; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tiles.compact { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .tile b { font-size: 26px; }
  .status { flex-direction: column; align-items: stretch; }
  .status form, .status .btn { width: 100%; }
  .status .btn { justify-content: center; }
  .next {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
  }
  .next .btn, .next button { width: 100%; justify-content: center; }
  .empty .btn, .empty button { width: 100%; justify-content: center; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input, .toolbar select { max-width: none; }
  .filters { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .filters a { flex: 0 0 auto; min-height: 40px; display: inline-flex; align-items: center; }
  .btn, button.btn { min-height: 44px; }
  .goods { align-items: flex-start; }
  .goods img { width: 40px; height: 52px; flex: 0 0 auto; }
  .goods.big img { width: 72px; height: 96px; }
  .mine { align-items: flex-start; }
  .mine img { width: 56px; height: 74px; flex: 0 0 auto; }

  .table-wrap {
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }
  table.cmp thead,
  table.cmp tr:has(th) { display: none; }
  table.cmp, table.cmp tbody { display: block; width: 100%; }
  table.cmp tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
  }
  table.cmp td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    border: 0;
    padding: 8px 0;
    text-align: right;
  }
  table.cmp td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-align: left;
    flex: 0 0 38%;
  }
  table.cmp td:first-child {
    display: block;
    text-align: left;
    padding-top: 0;
  }
  table.cmp td:first-child::before { display: none; }
  table.cmp td[data-label=""]::before { display: none; }
  table.cmp td.num { text-align: right; }
  table.cmp td:last-child {
    justify-content: flex-start;
    flex-wrap: wrap;
    padding-bottom: 0;
  }
  table.cmp .row-actions { width: 100%; }
  table.cmp .row-actions .btn,
  table.cmp .row-actions button { flex: 1; justify-content: center; }

  .tabs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: #fffaf2;
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
  }
  .tabs a, .tabs label {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    border-radius: 10px;
    cursor: pointer;
  }
  .tabs a.active, .tabs label.active { color: var(--ink); background: #efe4d3; }

  .more-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(27, 23, 20, 0.45);
    z-index: 40;
  }
  .more-sheet {
    display: none;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    z-index: 50;
    background: #fffaf2;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    box-shadow: var(--shadow);
  }
  .more-title { margin: 0 0 10px; font-weight: 800; }
  .more-sheet a {
    display: flex;
    align-items: center;
    min-height: 48px;
    text-decoration: none;
    border-bottom: 1px solid var(--line);
    font-weight: 700;
  }
  .more-sheet a:last-of-type { border-bottom: 0; }
  .more-toggle:checked ~ .shell .more-backdrop,
  .more-toggle:checked ~ .more-backdrop { display: block; }
  .more-toggle:checked ~ .shell .more-sheet,
  .more-toggle:checked ~ .more-sheet { display: block; }

  .login { padding: 24px 20px; }
  .login h1 { font-size: 32px; }
}

@media (max-width: 420px) {
  .tiles { grid-template-columns: 1fr; }
}
