:root {
  --bg: #fbf8f1;
  --panel: #ffffff;
  --ink: #18201c;
  --muted: #5d6a63;
  --line: #e4ded0;
  --side: #0f3b35;
  --side-ink: #e8f1ec;
  --side-muted: #9fbcb1;
  --tag: #f2b705;
  --tag-ink: #3a2c00;
  --profit: #13753a;
  --profit-bg: #e3f4e8;
  --warn: #9a5b00;
  --warn-bg: #fff2d6;
  --bad: #b3261e;
  --chip: #f1ede3;
  --focus: #1b6fd1;
  --shadow: 0 1px 2px rgb(20 30 25 / 6%), 0 4px 14px rgb(20 30 25 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --panel: #1a201d;
    --ink: #e7ece9;
    --muted: #9aa8a1;
    --line: #2b3430;
    --side: #0b1f1b;
    --side-ink: #e2ede8;
    --side-muted: #86a69a;
    --tag: #f2b705;
    --tag-ink: #2a2000;
    --profit: #5fd18b;
    --profit-bg: #173524;
    --warn: #f0b85a;
    --warn-bg: #3a2c12;
    --bad: #ff8a80;
    --chip: #232b27;
    --focus: #7cb4ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.shell > * { min-width: 0; }
.side {
  background: var(--side);
  color: var(--side-ink);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; align-items: center; min-height: 44px; gap: 10px; text-decoration: none; font-weight: 750; font-size: 19px; padding: 0 8px; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand svg path { fill: var(--tag); }
.brand svg circle { fill: var(--side); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: block; text-decoration: none; padding: 9px 10px; border-radius: 8px; min-height: 44px; }
.nav a b { display: block; font-weight: 650; }
.nav a span { display: block; font-size: 13px; color: var(--side-muted); }
.nav a:hover { background: rgb(255 255 255 / 6%); }
.nav a[aria-current="page"] { background: rgb(242 183 5 / 16%); box-shadow: inset 3px 0 0 var(--tag); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; font-size: 13px; color: var(--side-muted); padding: 0 8px; }
.side .ghost { color: var(--side-ink); border-color: rgb(255 255 255 / 20%); }

main { padding: 26px clamp(16px, 3vw, 36px) 80px; min-width: 0; }
main:focus { outline: none; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 19px; margin: 28px 0 10px; }
h3 { font-size: 16px; margin: 0; }
.lede { color: var(--muted); margin: 0 0 18px; max-width: 70ch; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid transparent; background: var(--side); color: #fff;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: default; }
.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.ghost.small, button.small { min-height: 44px; padding: 5px 10px; font-size: 14px; }
.tagbtn { background: var(--tag); color: var(--tag-ink); }
.danger { color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 18px 0 8px; }
.stat { background: transparent; border-top: 3px solid var(--line); padding: 10px 2px 4px; }
.stat.money { border-top-color: var(--profit); }
.stat b { display: block; font-size: 26px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 14px; }
.stat.money b { color: var(--profit); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0 16px; }
.filters input[type="search"] { flex: 1 1 220px; }
input, select, textarea {
  min-height: 44px; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel); max-width: 100%;
}
textarea { min-height: 70px; width: 100%; }
label { font-weight: 600; font-size: 14px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.deal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); min-width: 0;
}
.deal .pic { position: relative; flex: none; aspect-ratio: 4 / 3; background: var(--chip); display: block; }
.deal .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.deal .pic .nopic { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.pricetag {
  position: absolute; left: 10px; bottom: 10px; background: var(--tag); color: var(--tag-ink);
  font-weight: 800; padding: 4px 10px 4px 14px; border-radius: 4px 6px 6px 4px;
  clip-path: polygon(8px 0, 100% 0, 100% 100%, 8px 100%, 0 50%); font-variant-numeric: tabular-nums;
}
.deal .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.deal h3 { font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.deal h3 a { text-decoration: none; }
.deal h3 a:hover { text-decoration: underline; }
.math { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.profit { background: var(--profit-bg); color: var(--profit); font-weight: 800; font-size: 20px; padding: 2px 10px; border-radius: 8px; }
.math .resale { color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); border-radius: 4px; padding: 2px 9px; font-size: 13px; color: var(--muted); }
.chip.conf-high { color: var(--profit); }
.chip.conf-low, .chip.conf-none { color: var(--warn); }
.flags { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.flags li { background: var(--warn-bg); color: var(--warn); font-size: 13px; padding: 4px 8px; border-radius: 6px; }
.basis { font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.actions .btn, .actions button { min-height: 44px; padding: 6px 11px; font-size: 14px; }
.status-pill { font-size: 13px; font-weight: 700; color: var(--profit); }

.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; color: var(--muted); }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.err { color: var(--bad); min-height: 1.2em; }

.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--chip); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; border-radius: 10px; }

.fam { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; align-items: center; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.fam + .fam { margin-top: 8px; }
.fam .meta { font-size: 14px; color: var(--muted); }
.fam .right { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.fam.off { opacity: 0.6; }
.cat { font-size: 17px; color: var(--ink); margin: 24px 0 8px; font-weight: 700; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.switch { min-height: 44px; }
.switch input { width: 22px; height: 22px; min-height: 0; accent-color: var(--side); }

.form { display: grid; gap: 14px; max-width: 640px; }
.form .row { display: grid; gap: 5px; align-content: start; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .hint { font-size: 13px; color: var(--muted); font-weight: 400; }

.fb { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.fb a { display: flex; justify-content: space-between; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; text-decoration: none; min-height: 52px; }
.fb a:hover { border-color: var(--side); }
.fb a span { color: var(--muted); font-size: 13px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 40px); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); }
dialog::backdrop { background: rgb(10 20 15 / 45%); }
#dlgBody { padding: 20px; }
.dlg-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 12px; }

.login { position: fixed; inset: 0; background: var(--side); display: grid; place-items: center; padding: 16px; z-index: 10; }
.login-card { background: var(--panel); border-radius: 16px; padding: 28px; width: min(380px, 100%); display: grid; gap: 10px; }
.login-card svg { width: 44px; height: 44px; }
.login-card svg path { fill: var(--tag); }
.login-card svg circle { fill: var(--panel); }
.login-card h1 { margin: 0; }
.login-card p { margin: 0 0 6px; color: var(--muted); }
.login-card input { font-size: 18px; }
.login-card button { min-height: 46px; }

.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--profit); }
.loading { color: var(--muted); padding: 30px 0; }
.more { display: flex; justify-content: center; margin-top: 18px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; height: auto; z-index: 5; padding: 10px 12px 0; gap: 8px; }
  .brand { font-size: 17px; padding: 0 4px; width: max-content; }
  .brand svg { width: 26px; height: 26px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 8px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; padding: 11px 12px; }
  .nav a span { display: none; }
  .nav a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--tag); }
  .side-foot { position: absolute; right: 12px; top: 6px; margin: 0; flex-direction: row; align-items: center; padding: 0; }
  .side-foot .scan { display: none; }
  main { padding: 18px 16px 60px; }
  .grid { grid-template-columns: 1fr; }
  .form .two { grid-template-columns: 1fr; }
  .fam { grid-template-columns: 1fr; }
  .fam .right { justify-content: flex-start; }
}
