:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5f6673;
  --line: #e1e4ea;
  --accent: #1f3864;
  --accent-soft: #e6ebf5;
  --ok: #1e7f3c;
  --warn: #b26a00;
  --danger: #b3261e;
  --row-green: #d9f2c4;
  --row-red: #ffd6d6;
  --row-magenta: #f3c6dc;
  --row-grey: #e3e5e8;
  --row-amber: #fff0c2;
  --row-ok: #eaf5e4;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
small, .muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .92em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* layout */
.topbar { background: var(--accent); color: #fff; display: flex; align-items: center; gap: 1rem; padding: .45rem 1rem; flex-wrap: wrap; }
.topbar .brand { font-weight: 700; letter-spacing: .3px; color: #fff; }
.topbar nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.topbar nav a { color: #e9eefb; padding: .35rem .6rem; border-radius: 6px; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.14); text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar form.search { display: flex; }
.topbar form.search input { width: 220px; border-radius: 6px; border: 0; padding: .35rem .6rem; }
.topbar .user { font-size: .9rem; color: #e9eefb; display: flex; gap: .5rem; align-items: center; }
.topbar .user button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 5px; padding: .15rem .45rem; cursor: pointer; }
main { max-width: 1500px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head .actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.kpi .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: .85rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: .4rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
th { background: #f7f8fa; font-weight: 600; color: #333; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
th a { color: inherit; }
tbody tr:hover { filter: brightness(.97); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-soft); }
tr.row-green td { background: var(--row-green); }
tr.row-red td { background: var(--row-red); }
tr.row-magenta td { background: var(--row-magenta); }
tr.row-grey td { background: var(--row-grey); color: var(--muted); }
tr.row-amber td { background: var(--row-amber); }
tr.row-ok td { background: var(--row-ok); }
tr.total td { font-weight: 700; background: #e9eef7; border-top: 2px solid var(--accent); }
td.desc { max-width: 520px; }
td.desc .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.compact td, .compact th { padding: .25rem .45rem; }

/* forms */
input, select, textarea, button { font: inherit; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=file], select, textarea {
  width: 100%; padding: .45rem .55rem; border: 1px solid #c9ced6; border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9db2d9; outline-offset: 0; border-color: var(--accent); }
.form-row { margin-bottom: .75rem; }
.form-row label { display: block; font-weight: 600; margin-bottom: .2rem; font-size: .9rem; }
.form-row .help { color: var(--muted); font-size: .8rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem 1rem; }
.errorlist { color: var(--danger); margin: .2rem 0 0; padding-left: 1.1rem; font-size: .85rem; }
.inline-form { display: inline; }
.btn { display: inline-block; padding: .45rem .8rem; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; font-weight: 600; font-size: .9rem; line-height: 1.2; }
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.sm { padding: .25rem .55rem; font-size: .82rem; }
.btn.lg { padding: .7rem 1.2rem; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
select.status-select { width: auto; padding: .15rem .3rem; font-size: .82rem; }

/* badges */
.badge { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.green { background: var(--row-green); color: #1e5a12; }
.badge.red { background: var(--row-red); color: #7a1414; }
.badge.magenta { background: var(--row-magenta); color: #6b0f3a; }
.badge.grey { background: var(--row-grey); color: #444; }
.badge.amber { background: var(--row-amber); color: #6b4a00; }
.badge.ok { background: var(--row-ok); color: #1e5a12; }

/* messages */
.messages { list-style: none; margin: 0 0 1rem; padding: 0; }
.messages li { padding: .55rem .8rem; border-radius: 6px; margin-bottom: .4rem; background: #e7f1ff; border: 1px solid #b9d4fb; }
.messages li.success { background: #e3f6e8; border-color: #a9dfb8; }
.messages li.error { background: #fde8e7; border-color: #f3b6b2; }
.messages li.warning { background: #fff4d6; border-color: #f0d48a; }

/* filters */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: .6rem; }
.filters label { font-size: .8rem; color: var(--muted); display: block; }
.filters input, .filters select { width: auto; min-width: 120px; padding: .3rem .45rem; }
.legend { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin: .4rem 0; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; border: 1px solid rgba(0,0,0,.1); }
.legend .lg-green::before { background: var(--row-green); } .legend .lg-red::before { background: var(--row-red); }
.legend .lg-magenta::before { background: var(--row-magenta); } .legend .lg-grey::before { background: var(--row-grey); }
.legend .lg-amber::before { background: var(--row-amber); } .legend .lg-ok::before { background: var(--row-ok); }
.legend .lg-white::before { background: #fff; }

/* live screen */
.live { max-width: 900px; margin: 0 auto; }
.live .scan { display: flex; gap: .5rem; }
.live .scan input { font-size: 1.4rem; padding: .7rem .9rem; border: 2px solid var(--accent); border-radius: 10px; }
.unit-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; margin-top: 1rem; }
.unit-card .title { font-size: 1.15rem; font-weight: 600; margin: .2rem 0 .4rem; }
.unit-card .prices { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin: .7rem 0; }
.unit-card .price { background: var(--bg); border-radius: 8px; padding: .5rem .7rem; }
.unit-card .price .l { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.unit-card .price .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.unit-card .price.big .v { font-size: 1.8rem; color: var(--accent); }
.sell-form { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; align-items: end; margin-top: .6rem; }
.sell-form .price-in input { font-size: 1.6rem; padding: .5rem .7rem; }
.sell-form .full { grid-column: 1 / -1; }
.radio-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.radio-row label { flex: 1; border: 1px solid #c9ced6; border-radius: 8px; padding: .55rem .6rem; cursor: pointer; text-align: center; font-weight: 600; background: #fff; }
.radio-row input { display: none; }
.radio-row input:checked + span { color: var(--accent); }
.radio-row label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.quick-status { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .8rem; }
.sold-banner { background: var(--row-green); border: 1px solid #a9dfb8; color: #1e5a12; padding: .8rem 1rem; border-radius: 10px; font-size: 1.2rem; font-weight: 700; margin-bottom: .6rem; }
.error-banner { background: var(--row-red); border: 1px solid #f3b6b2; color: #7a1414; padding: .6rem .9rem; border-radius: 8px; margin-bottom: .6rem; }
.result-list .item { display: flex; gap: .8rem; padding: .55rem .2rem; border-bottom: 1px solid var(--line); align-items: center; }
.result-list .item:hover { background: #fafbfd; }
.result-list .item .t { flex: 1; }

/* timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .4rem 0 .4rem 1rem; border-left: 2px solid var(--line); margin-left: .3rem; font-size: .9rem; }
.timeline li time { color: var(--muted); font-size: .8rem; margin-right: .5rem; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: .92rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
pre.notes { white-space: pre-wrap; font-family: inherit; background: var(--bg); padding: .6rem; border-radius: 6px; margin: 0; }
.login { max-width: 380px; margin: 8vh auto; }
@media (max-width: 700px) {
  html { font-size: 14px; }
  main { padding: .6rem; }
  .sell-form { grid-template-columns: 1fr; }
  .topbar form.search input { width: 140px; }
}
@media print { .topbar, .filters, .actions, .btn { display: none !important; } }
