:root {
  --bg: #f4f5f7; --surface: #ffffff; --text: #1d2330; --muted: #6b7385; --line: #d9dde5; --grid: #eceef2;
  --accent: #2f6fdf; --good: #1f9d6b; --bad: #d64545; --heat0: #f3f6fb;
  --c1: #2f6fdf; --c2: #e8833a; --c3: #1f9d6b; --c4: #9b59d0; --c5: #d64545; --c6: #2bb3c0; --c7: #c9a227; --c8: #7a8699;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1b1f27; --text: #e4e7ee; --muted: #949cad; --line: #2e3440; --grid: #262b35;
    --accent: #6a9cff; --good: #3cc68a; --bad: #ff6b6b; --heat0: #1f2530;
    --c1: #6a9cff; --c2: #f4a259; --c3: #3cc68a; --c4: #b98af0; --c5: #ff6b6b; --c6: #4fd1dc; --c7: #e3c053; --c8: #9aa5b8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[x-cloak] { display: none !important; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 6px 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 8px; }
.up { color: var(--good); }
.down { color: var(--bad); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

input, select, button { font: inherit; color: inherit; }
input[type=text], input[type=date], input[type=number], select {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0;
}
input.mini { width: 56px; padding: 2px 4px; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 6px 12px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
button.link.danger { color: var(--bad); }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; color: var(--muted); }
.tabs button.active { background: var(--bg); color: var(--text); font-weight: 600; }
.badge { background: var(--accent); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.dataset { color: var(--muted); font-size: 13px; }
.userbox { display: flex; align-items: center; gap: 4px; font-size: 13px; }

.wrap { max-width: 1500px; margin: 0 auto; padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.wrap > div { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.card.empty { text-align: center; padding: 40px; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.tight { gap: 6px; flex-wrap: wrap; }
.grow { flex: 1; }

.filters .frow { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filters label.grow { min-width: 240px; }
.filters label > * { color: var(--text); }
label.check { flex-direction: row; display: flex; align-items: center; gap: 4px; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 2px 4px 2px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
.chip b { font-weight: 600; color: var(--muted); }
.chip button { border: 0; background: none; padding: 0 6px; font-size: 15px; line-height: 1; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; transition: opacity .15s; }
.kpis.loading { opacity: .55; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; color: var(--muted); }
.kpi .delta.up { color: var(--good); } .kpi .delta.down { color: var(--bad); }

.chart { width: 100%; height: 320px; }
.chart.tall { height: 380px; }

.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 420px; overflow-y: auto; }
.table-wrap.short { max-height: 220px; margin-top: 8px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.grid td { padding: 5px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.grid .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.grid td.name { max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid td.path { max-width: 420px; overflow-wrap: anywhere; font-size: 12px; }
.grid tr.clickable { cursor: pointer; }
.grid tr.clickable:hover td { background: var(--bg); }
.grid tr.sel td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.spark { display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; }

.status { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--bg); white-space: nowrap; }
.status.done { color: var(--good); } .status.error { color: var(--bad); } .status.duplicate { color: var(--muted); }
.err { color: var(--bad); font-size: 12px; margin-top: 4px; white-space: pre-wrap; max-width: 520px; }
.progress { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; margin-top: 6px; width: 180px; }
.progress div { height: 100%; background: var(--accent); transition: width .3s; }
.msg { margin-top: 10px; padding: 8px 12px; border-radius: 6px; background: var(--bg); }
.msg.bad { color: var(--bad); } .msg.good { color: var(--good); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 10px; background: var(--surface); color: var(--muted); }
.seg button.active { background: var(--accent); color: #fff; }
.subtabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 0 12px; }
.subtabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 12px; color: var(--muted); }
.subtabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.subtabs .count { font-size: 11px; background: var(--bg); border-radius: 9px; padding: 0 6px; margin-left: 2px; font-variant-numeric: tabular-nums; }
.chip.filter { cursor: pointer; padding: 3px 10px; font: inherit; font-size: 12px; color: var(--text); }
.chip.filter.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.chip.stat { padding: 3px 10px; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px; margin: 1px 3px 1px 0; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.tag.no_sale, .tag.exceeds { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.tag.late { color: var(--c2); }
.table-wrap.short2 { max-height: 300px; overflow-y: auto; }
label.check.inline { display: inline-flex; margin-left: 8px; }
.cols > .table-wrap { min-width: 0; }

.dropzone { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px 16px; text-align: center; color: var(--muted); transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dropzone .row { text-align: left; color: var(--text); }
.dropzone .progress.wide { width: 100%; margin-top: 10px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
details.server-path { margin-top: 12px; font-size: 13px; }
details.server-path summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--bad); color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 480px; cursor: pointer; z-index: 20; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .wrap { padding: 12px 16px 32px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-right { margin-left: 0; width: 100%; justify-content: space-between; }
}
