/* eAukcije — one stylesheet, no build step. Tokens first; dark mode is its own
   set of steps (dataviz reference palette), not an inversion. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --good: #006300;
  --warn: #8a5a00;
  --bad: #b32d2d;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-muted: #c3c2b7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a3a198;
    --line: #2c2c2a;
    --line-strong: #383835;
    --accent: #6da7ec;
    --accent-ink: #0b0b0b;
    --accent-soft: #184f95;
    --good: #0ca30c;
    --warn: #fab219;
    --bad: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-muted: #52514e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 0.75rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
p { margin: 0.4rem 0; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── layout ── */
.top {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.top .inner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: 0.6rem 16px; max-width: 1200px; margin: 0 auto; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--ink-2); text-decoration: none; padding: 0.35rem 0.6rem; border-radius: 6px; font-size: 0.95rem;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.who { color: var(--muted); font-size: 0.85rem; }
main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
footer { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 2rem; color: var(--muted); font-size: 0.85rem; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.tiles { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 0.5rem 0 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 0.9rem; }
.tile .v { font-size: 1.5rem; font-weight: 650; line-height: 1.2; }
.tile .k { color: var(--muted); font-size: 0.85rem; }

/* ── forms ── */
label { display: block; font-size: 0.85rem; color: var(--ink-2); margin-bottom: 0.2rem; }
input, select, button, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 0.45rem 0.55rem; width: 100%;
  min-height: 40px;
}
select[multiple] { min-height: 7.5rem; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .btn {
  width: auto; cursor: pointer; background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600; padding: 0.45rem 0.9rem; text-decoration: none; display: inline-flex; align-items: center; gap: 0.35rem;
  border-radius: 6px; border: 1px solid var(--accent); min-height: 40px;
}
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button.small, .btn.small { min-height: 32px; padding: 0.2rem 0.6rem; font-size: 0.9rem; }
.row { display: flex; gap: 0.5rem; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.row > .shrink { flex: 0 0 auto; }

.filters { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.filters .wide { grid-column: 1 / -1; }
.pair { display: flex; gap: 0.35rem; }
.pair input { min-width: 0; }
.checks { border: 1px solid var(--line); border-radius: 8px; margin: 0; padding: 0.4rem 0.6rem; max-height: 16rem; overflow-y: auto; }
.checks legend { color: var(--muted); padding: 0 0.25rem; }
.checks label { display: flex; gap: 0.4rem; align-items: center; margin: 0.15rem 0; color: var(--ink); }
.checks input { width: auto; min-height: 0; }
details.filterbox > summary { cursor: pointer; font-weight: 600; padding: 0.25rem 0; }
details.filterbox[open] > summary { margin-bottom: 0.75rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.85rem; color: var(--ink-2); }

/* ── results ── */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin: 1rem 0 0.5rem; }
.results { display: grid; gap: 0.6rem; }
.item {
  display: grid; grid-template-columns: 96px 1fr auto; gap: 0.85rem; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem;
  color: inherit; text-decoration: none;
}
.item:hover { border-color: var(--line-strong); }
.thumb {
  width: 96px; height: 72px; border-radius: 6px; background: var(--surface-2); object-fit: cover;
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.75rem; text-align: center;
}
.item > * { min-width: 0; }
.item .title { font-weight: 600; color: var(--ink); line-height: 1.3; }
.item .meta { color: var(--muted); font-size: 0.875rem; margin-top: 0.2rem; }
.item .price { text-align: right; }
.item .price .p { font-weight: 650; }
.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.05rem 0.45rem; border-radius: 4px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap; vertical-align: 1px;
}
.badge.good { color: var(--good); }
.badge.bad { color: var(--bad); }
.badge.warn { color: var(--warn); }
.pager { display: flex; gap: 0.35rem; align-items: center; justify-content: center; margin: 1.25rem 0; flex-wrap: wrap; }
.pager a, .pager span { padding: 0.3rem 0.65rem; border-radius: 6px; border: 1px solid var(--line); text-decoration: none; }
.pager .cur { background: var(--accent-soft); color: var(--ink); font-weight: 600; }

/* ── detail ── */
.kv { display: grid; grid-template-columns: minmax(130px, 34%) 1fr; gap: 0.35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv dd.num { white-space: normal; }
.parcels { list-style: none; margin: 0 0 0.25rem; padding: 0; }
.parcels li { margin: 0.1rem 0; }
.gallery { display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.gallery img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; display: block; }
.desc { white-space: pre-line; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 0.9rem 1rem; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 0.45rem; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--page);
}
.timeline time { color: var(--muted); font-size: 0.85rem; display: block; }
.copy { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── tables ── */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.bar { width: 22%; min-width: 80px; }
.cellbar { display: block; height: 10px; background: var(--series-1); border-radius: 0 4px 4px 0; margin-top: 0.35rem; }

/* ── charts ── */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; }
.chart .col:hover .hit { fill: var(--surface-2); }
.legend { display: flex; flex-wrap: wrap; gap: 0.9rem; font-size: 0.85rem; color: var(--ink-2); margin: 0.25rem 0 0.5rem; }
.legend .key { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ── map ── */
#map { width: 100%; height: min(72vh, 720px); border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); }
.maplibregl-popup-content { background: var(--surface); color: var(--ink); border-radius: 8px; font: 14px/1.4 var(--font); }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; }
.notice { background: var(--surface-2); border-radius: var(--radius); padding: 0.75rem 1rem; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 0.55rem 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 0.75rem; }
.feed li:last-child { border-bottom: 0; }
.feed .what { min-width: 0; }
.feed .what a { font-weight: 600; }
.feed .change { text-align: right; white-space: nowrap; font-size: 0.9rem; }
.periods { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.periods a { padding: 0.3rem 0.7rem; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--ink-2); font-size: 0.9rem; }
.periods a.on { background: var(--accent-soft); color: var(--ink); border-color: transparent; font-weight: 600; }
.periods form { display: inline-flex; gap: 0.35rem; }
.periods form input { width: auto; min-height: 32px; padding: 0.15rem 0.4rem; }

@media (max-width: 640px) {
  h1 { font-size: 1.3rem; }
  .top .inner { gap: 0.25rem 0.75rem; padding: 0.5rem 16px 0.35rem; }
  .nav { flex: 1 0 100%; order: 3; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 12px; }
  .nav a { white-space: nowrap; }
  .toolbar .row { flex: 1 1 100%; }
  .item { grid-template-columns: 72px 1fr; }
  .thumb { width: 72px; height: 56px; }
  .item .price { grid-column: 2; text-align: left; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv dt { margin-top: 0.5rem; }
  .feed li { flex-direction: column; gap: 0.15rem; }
  .feed .change { text-align: left; }
  .who > a, .who > .badge { display: none; }
}

.htmx-request .spinner, .htmx-request.spinner { opacity: 1; }
.spinner { opacity: 0; transition: opacity 0.2s; color: var(--muted); font-size: 0.85rem; }

/* ── accounts ── */
.narrow { max-width: 440px; margin: 2rem auto; }
.stack { display: grid; gap: 0.85rem; }
.alert { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--ink); border-left: 3px solid var(--bad); padding: 0.6rem 0.8rem; border-radius: 6px; }
.issued { border-left: 3px solid var(--good); margin-bottom: 1rem; }
.secret { font: 600 1.25rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.04em; background: var(--surface-2); padding: 0.2rem 0.5rem; border-radius: 6px; }
form.inline { display: inline; }
td.actions { white-space: nowrap; }
.who { display: flex; align-items: center; gap: 0.4rem; }
.who a { color: var(--ink-2); }
