/* Resale Profit. System fonts, no external assets. Light + dark, reduced motion, 320-430 px first. */
:root {
  --bg: #f5f7f6; --surface: #ffffff; --surface-2: #eef2f0; --text: #14201c; --muted: #52615b; --line: #d6dfdb;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #d7f0ec; --pos: #15803d; --neg: #b42318; --warn-bg: #fff4e0; --warn: #8a4b00;
  --focus: #2563eb; --radius: 14px; --shadow: 0 1px 2px rgb(16 24 20 / .06), 0 4px 16px rgb(16 24 20 / .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1513; --surface: #131e1b; --surface-2: #1a2824; --text: #e6eeeb; --muted: #9db0a9; --line: #2a3b36;
    --brand: #2dd4bf; --brand-ink: #062b27; --brand-soft: #123b35; --pos: #4ade80; --neg: #f87171; --warn-bg: #3a2a0c; --warn: #fcd38a;
    --focus: #93c5fd; --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.has-bar { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--surface); padding: 10px 14px; border-radius: 8px; z-index: 30; }
.skip:focus { top: 8px; }

.top {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  max-width: 680px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; min-height: 44px; flex: 1 1 auto; }
.brand img { display: block; border-radius: 7px; }
.brand span { white-space: nowrap; }
.nav { display: flex; gap: 2px; }
.nav a { white-space: nowrap; display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; color: var(--muted); text-decoration: none; font-size: 14px; }
.lang {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; border-radius: 10px;
  border: 1px solid var(--line); color: var(--text); text-decoration: none; font-weight: 700; font-size: 14px; background: var(--surface);
}
@media (max-width: 359px) { .nav { display: none; } }

main { max-width: 680px; margin: 0 auto; padding: 0 16px; }
.intro h1 { font-size: 1.45rem; line-height: 1.2; margin: 6px 0 6px; letter-spacing: -0.01em; }
.intro p { margin: 0 0 8px; color: var(--muted); font-size: 15px; }
.intro .src { font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; box-shadow: var(--shadow); }
.card h2 { font-size: 1.1rem; margin: 0 0 6px; }
.sub { font-size: .95rem; margin: 14px 0 6px; }
.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.hint, .note { font-size: 13px; color: var(--muted); margin: 6px 0; }
.note { background: var(--warn-bg); color: var(--warn); padding: 8px 10px; border-radius: 10px; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.chips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span {
  display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 600; font-size: 14px; padding: 0 2px; text-align: center;
}
.chip input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (max-width: 359px) { .chip span { font-size: 12.5px; } }

.selrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-top: 10px; }
.selrow .fld#catWrap { grid-column: 1 / -1; }
select, input[type=text], input:not([type]), input[inputmode] {
  width: 100%; min-height: 48px; font: inherit; font-size: 17px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 0 12px;
}
select { padding-right: 28px; font-size: 15px; }
input[aria-invalid=true] { border-color: var(--neg); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-top: 10px; align-items: end; }
.inp { position: relative; display: block; }
.inp input { padding-right: 30px; font-variant-numeric: tabular-nums; }
.inp .cur { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: 15px; }
.fld { display: block; min-width: 0; }
.fld.small { max-width: 160px; }

.more { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 4px; }
.more summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--brand); }
.vat { margin-top: 10px; display: grid; gap: 8px; }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 15px; }
.switch input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; margin: 0; }
.opts { margin-top: 8px; }

.result .empty { margin: 4px 0; color: var(--muted); }
.kpis { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.kpi output { display: block; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi.big { grid-column: 1 / -1; background: var(--brand-soft); }
.kpi.big output { font-size: 2rem; line-height: 1.1; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .zero { color: var(--text); }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li { border-bottom: 1px solid var(--line); padding: 8px 0; }
.lines li.off, .lines li.excl { opacity: .8; }
.lines li.off .lamt, .lines li.excl .lamt { color: var(--muted); font-weight: 500; }
.lrow { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.lname { font-size: 14.5px; min-width: 0; }
.lamt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; font-size: 14.5px; }
.lines li.excl .lamt { white-space: normal; }
.lmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 3px; font-size: 12px; }
.srcl { color: var(--muted); display: inline-flex; align-items: center; min-height: 24px; }
.tag { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.tag.ver { background: var(--brand-soft); color: var(--text); }
.tag.unv { background: var(--warn-bg); color: var(--warn); }
.tag.buyer { background: var(--surface-2); }
.lines li.costs .lname, .lines li.buyerline .lname { font-weight: 600; }

.solve { margin-top: 10px; display: grid; gap: 6px; }
.srow { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 44px; font-size: 14.5px; }
.srow strong { font-variant-numeric: tabular-nums; }
.tgt { width: 120px; flex: none; }
.flags { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.flags li { font-size: 13px; color: var(--muted); padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.flags li.warn { background: var(--warn-bg); color: var(--warn); }
.save { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; margin-top: 12px; }
.save .ok { grid-column: 1 / -1; font-size: 13px; color: var(--pos); min-height: 1em; }

.btn {
  min-height: 48px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.tblwrap { overflow-x: auto; }
.cmp { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.cmp th, .cmp td { text-align: right; padding: 4px 4px; border-bottom: 1px solid var(--line); }
.cmp thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
.cmp th[scope=row], .cmp thead th:first-child { text-align: left; }
.cmp tr.cur { background: var(--brand-soft); }
.cmp tr.fx td { color: var(--muted); }
.rowbtn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-height: 44px; width: 100%; background: none; border: 0;
  padding: 4px 0; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.rowbtn small { color: var(--muted); font-size: 11.5px; font-weight: 400; }

.itemlist { list-style: none; padding: 0; margin: 6px 0; }
.itemlist li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.iname { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.iname strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iname small { color: var(--muted); font-size: 12px; }
.iprofit { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.del { min-width: 44px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 20px; cursor: pointer; }
.totals p { font-size: 14px; margin: 8px 0; }
.count { color: var(--muted); font-weight: 500; font-size: .9rem; }

.about .links { padding-left: 18px; margin: 4px 0; }
.about .links li { margin: 2px 0; }
.about .links a { display: inline-block; min-height: 32px; padding: 6px 0; }
.foot { max-width: 680px; margin: 8px auto 24px; padding: 0 16px; font-size: 13px; color: var(--muted); }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: 1.3fr 1fr 1.2fr; gap: 6px;
  padding: 8px 16px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgb(0 0 0 / .08);
}
.bar[hidden] { display: none; }
.bar div { min-width: 0; }
.bar .lbl { margin: 0; font-size: 11.5px; }
.bar strong { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar div:first-child strong { font-size: 1.25rem; }

@media (min-width: 560px) { .kpis { grid-template-columns: 1.4fr 1fr 1fr 1fr; } .kpi.big { grid-column: auto; } }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; animation: none !important; } }
