:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --text: #18202b; --muted: #5f6b7a; --line: #e3e6eb;
  --accent: #2b59c3; --accent-ink: #ffffff; --accent-soft: #e8eefb;
  --down: #b42318; --down-soft: #fdecea; --up: #11743c; --up-soft: #e4f4ea;
  --warn: #8a5a00; --warn-soft: #fff3d6; --na: #9aa3af;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1217; --surface: #161b22; --surface-2: #1d232c; --text: #e6e9ee; --muted: #9aa4b2; --line: #2a313b;
    --accent: #7ea2ff; --accent-ink: #0e1217; --accent-soft: #1c2740;
    --down: #ff8b80; --down-soft: #3a1815; --up: #6fd39c; --up-soft: #12301f;
    --warn: #f2c14e; --warn-soft: #33290c; --na: #6b7480; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1440px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 22px; margin: 22px 0 4px; }
h2 { font-size: 16px; margin: 28px 0 10px; }
.sub, .muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { display: flex; align-items: center; gap: 24px; min-height: 52px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand span { color: var(--accent); }
.top nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.top nav a { color: var(--muted); padding: 8px 10px; border-radius: 8px; white-space: nowrap; }
.top nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.top nav a.on { color: var(--text); background: var(--surface-2); font-weight: 600; }
/* market switch: PL · zł | UK · £ */
.markets { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.markets a { padding: 5px 10px; color: var(--muted); white-space: nowrap; font-size: 13px; }
.markets a + a { border-left: 1px solid var(--line); }
.markets a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.markets a.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* job bar */
.jobbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.jobbar-in { display: flex; align-items: center; gap: 12px; padding-top: 8px; padding-bottom: 8px; flex-wrap: wrap; }
.jobbar .text { flex: 1 1 320px; color: var(--muted); }
.jobbar .text b { color: var(--text); }
.progress { flex: 0 0 160px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; display: none; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.jobbar.running .progress { display: block; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
form.inline { display: inline; margin: 0; }

button, .btn {
  font: inherit; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
button.secondary, .btn.secondary { background: transparent; color: var(--accent); }
button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
button.danger { background: transparent; border-color: var(--line); color: var(--down); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:hover, .btn:hover { filter: brightness(1.05); text-decoration: none; }
input[type=text], input[type=url], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px; min-width: 0;
}

/* flash messages */
.flash { margin: 14px 0 0; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.flash.ok { border-color: transparent; background: var(--up-soft); color: var(--up); }
.flash.error { border-color: transparent; background: var(--down-soft); color: var(--down); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 16px 0 4px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--text); box-shadow: var(--shadow); }
.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi .delta { display: inline-block; margin-top: 6px; padding: 0 7px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 11px; font-style: normal; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi .delta.bad { color: var(--down); border-color: var(--down); background: var(--down-soft); }
.kpi .delta.good { color: var(--up); border-color: var(--up); background: var(--up-soft); }
.kpi span + .delta { display: table; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; margin-top: 8px; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px 12px; box-shadow: var(--shadow); min-width: 0; }
.chart-card .head { flex-wrap: nowrap; align-items: center; }
.chart-card h2 { margin: 12px 0 8px; font-size: 15px; }
.chart-fit { position: relative; }
@media (max-width: 640px) { .charts { grid-template-columns: 1fr; } }
.grid2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
td.r, th.r { text-align: right; }
td.nowrap { white-space: nowrap; }
td.note { min-width: 240px; color: var(--muted); }
tbody tr:hover td { background: var(--surface-2); }
.group td { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

.min { background: var(--up-soft) !important; color: var(--up); font-weight: 600; }
.below { color: var(--down); font-weight: 600; }
.min.below { background: var(--down-soft) !important; }
.na { color: var(--na); text-decoration: line-through; }
.err { color: var(--warn); }
.down { color: var(--down); }
.up { color: var(--up); }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.t-first { background: var(--down-soft); color: var(--down); }
.t-follow { background: var(--warn-soft); color: var(--warn); }
.t-up { background: var(--up-soft); color: var(--up); }
.t-info { background: var(--surface-2); color: var(--muted); }
.t-ok { background: var(--up-soft); color: var(--up); }
.t-bad { background: var(--down-soft); color: var(--down); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.chip { padding: 5px 11px; border-radius: 16px; border: 1px solid var(--line); color: var(--text); background: var(--surface); }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.legend { color: var(--muted); font-size: 12px; margin: 8px 2px; }
.empty { color: var(--muted); padding: 18px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.facts { display: flex; gap: 24px; flex-wrap: wrap; margin: 10px 0; }
.facts > div > span:first-child { display: block; color: var(--muted); font-size: 12px; }
.facts div b { font-size: 18px; font-variant-numeric: tabular-nums; }
.facts div .stack { width: 140px; margin-top: 4px; }
.chart-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; height: 360px; }
details.tl { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0; }
details.tl summary { cursor: pointer; padding: 10px 14px; }
details.tl .card { border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; }
.override { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.override input[type=url] { flex: 1 1 260px; }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }   /* desktop: 3 columns */
.settings-grid > .panel { min-width: 0; overflow-x: auto; }
@media (max-width: 1100px) { .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .settings-grid { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.panel h2 { margin-top: 0; }
.panel label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0; }
.panel label input { width: 130px; text-align: right; }
/* Products tab – accordion */
.products > tbody.product > tr.summary { cursor: pointer; }
.products > tbody.product > tr.summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.products > tbody.product > tr.summary td { vertical-align: middle; }
.products td.r, .products th.r { white-space: nowrap; }
.products th.exp, .products td.exp { width: 28px; padding-right: 0; }
.chev { display: inline-block; color: var(--muted); transition: transform .15s; }
tr.summary[aria-expanded="true"] .chev { transform: rotate(90deg); color: var(--accent); }
tr.summary[aria-expanded="true"] td { background: var(--accent-soft); }
.products tbody.product:not(:last-child) tr.detail td { border-bottom: 1px solid var(--line); }
.products tr.detail > td { background: var(--surface-2); padding: 10px 12px 14px 38px; }
.products tbody tr.detail:hover > td { background: var(--surface-2); }
.products tbody.product:target td { background: transparent !important; }
.products tbody.product:target tr.summary td { background: var(--accent-soft) !important; }
td.alerts { white-space: nowrap; }
.ico { display: inline-block; min-width: 38px; padding: 1px 7px; margin: 2px 3px 2px 0; border-radius: 10px; font-size: 12px;
  font-weight: 600; font-variant-numeric: tabular-nums; background: var(--surface-2); color: var(--muted); cursor: help; }
.i-up { background: var(--up-soft); color: var(--up); }
.i-down, .i-flash { background: var(--warn-soft); color: var(--warn); }
.rank { display: inline-block; min-width: 28px; padding: 1px 6px; border-radius: 6px; text-align: center; font-weight: 700; font-size: 12px; }
.rank-0 { background: var(--up-soft); color: var(--up); }
.rank-1 { background: var(--surface-2); color: var(--text); }
.rank-2 { background: var(--warn-soft); color: var(--warn); }
.rank-3 { background: var(--down-soft); color: var(--down); }
.spread { display: block; height: 4px; margin-top: 3px; margin-left: auto; width: 56px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.spread i { display: block; height: 100%; background: var(--accent); margin-left: auto; }
.i-promo, .t-promo { background: var(--accent-soft); color: var(--accent); }
.i-below, .i-new { background: var(--down-soft); color: var(--down); }
.products tbody.product > tr.summary > td { border-bottom: 1px solid var(--line); }
table.offers { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table.offers th { position: static; }
table.offers td { vertical-align: middle; }
table.offers td .tag + .tag { margin-left: 4px; }
.dbar { position: relative; display: block; width: 90px; height: 5px; margin: 3px 0 0 auto; background: var(--surface-2); border-radius: 3px; }
.dbar::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--muted); }
.dbar i { position: absolute; top: 0; bottom: 0; }
.dbar i.neg { right: 50%; background: var(--down); border-radius: 3px 0 0 3px; }
.dbar i.pos { left: 50%; background: var(--up); border-radius: 0 3px 3px 0; }
th[title] { text-decoration: underline dotted var(--line); text-underline-offset: 3px; cursor: help; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: " ↕"; opacity: .35; }
th[aria-sort="ascending"]::after { content: " ↑"; opacity: 1; color: var(--accent); }
th[aria-sort="descending"]::after { content: " ↓"; opacity: 1; color: var(--accent); }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.stack { display: flex; width: 120px; height: 8px; margin-top: 5px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.stack i { display: block; height: 100%; }
.st-below { background: var(--down); }
.st-at { background: var(--accent); }
.st-above { background: var(--up); }
.accent { color: var(--accent); }
.tabs { display: flex; gap: 4px; margin: 0 0 8px; }
.tab { background: transparent; border-color: var(--line); color: var(--muted); padding: 4px 12px; }
.tab.on { background: var(--surface); border-color: var(--accent); color: var(--text); font-weight: 600; }
.chart-box[hidden] { display: none; }
tr.more-row td { background: var(--surface); }
td.offer-name { min-width: 240px; max-width: 520px; }
.panel label input.short { width: 90px; }
.panel label.check { display: flex; justify-content: flex-start; margin: 2px 0; }
.panel label.check input { width: auto; }
.rrp-list { max-height: 360px; overflow: auto; margin: 6px 0 10px; padding-right: 4px; }

/* switched-off shops */
tr.off td { color: var(--na); }
tr.off td a { color: var(--muted); }
button.small-btn { padding: 2px 10px; font-size: 12px; }

/* login */
form.userbox { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.login { max-width: 380px; margin: 48px auto; }
.login .panel { display: flex; flex-direction: column; gap: 4px; }
.login .panel label { flex-direction: column; align-items: stretch; gap: 4px; }
.login .panel input { width: 100%; text-align: left; }
.login button { margin-top: 8px; }
input[type=email], input[type=password] {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}

footer { color: var(--muted); font-size: 12px; padding: 32px 16px; text-align: center; }
:target td { background: var(--accent-soft) !important; }

@media (max-width: 640px) {
  h1 { font-size: 19px; }
  .top-in { gap: 8px; padding-top: 6px; }
  .top nav { width: 100%; padding-bottom: 6px; }
  th, td { padding: 6px 8px; }
}
