:root {
  --ink: #1a1a1a;
  --muted: #5a5a5a;
  --line: #d8d8d8;
  --bg: #f6f7f9;
  --card: #fff;
  --accent: #2f7ab8;
  --accent-hover: #256596;
  --accent-soft: #e8f0f7;
  --ok: #1f6b3a;
  --ok-bg: #e7f5ec;
  --warn: #8a5a00;
  --warn-bg: #fff4db;
  --bad: #9b1c1c;
  --bad-bg: #fde8e8;
  --touch: 44px;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .04);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8e6e1;
    --muted: #a8a39a;
    --line: #2a2f38;
    --bg: #0c0e12;
    --card: #14171d;
    --accent: #5a9ecf;
    --accent-hover: #7ab4db;
    --accent-soft: #152230;
    --ok: #22c55e;
    --ok-bg: rgba(34, 197, 94, .12);
    --warn: #f59e0b;
    --warn-bg: #1a1710;
    --bad: #ff5a4d;
    --bad-bg: rgba(255, 90, 77, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.app-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.app-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: -0.02em;
  color: inherit; text-decoration: none; border-radius: 8px;
}
.brand:hover { color: var(--accent); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(145deg, var(--accent), #1d4f78);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15);
  flex-shrink: 0;
}
.brand-sub { color: var(--muted); font-weight: 500; font-size: 0.78rem; margin-left: 6px; }

.nav { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.nav button {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: var(--touch);
  cursor: pointer;
  transition: transform .06s, border-color .15s, background .15s;
}
.nav button:active { transform: translateY(1px); }
.nav button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
.nav button:hover { border-color: var(--accent); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 18px 56px;
}
@media (min-width: 1100px) {
  main:has(#panel-matches.active) { max-width: 1280px; }
}
.panel { display: none; }
.panel.active { display: block; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 14px;
}
.toolbar-flush { margin-bottom: 0; }
.toolbar-center { justify-content: center; margin-top: 12px; }
.select-rule { min-width: 9rem; }

.meta-bar {
  display: flex; flex-wrap: wrap; gap: 10px 16px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
}
.meta-bar strong { color: var(--ink); font-weight: 600; }
.meta-bar a { font-weight: 600; text-decoration: none; }
.meta-bar a:hover { text-decoration: underline; }
.running-tag { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 14px;
  min-height: var(--touch);
  cursor: pointer;
  color: var(--ink);
  transition: transform .06s, border-color .15s, background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn.is-busy { opacity: 0.6; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 40%, var(--line));
}

.spinner {
  width: 14px; height: 14px;
  border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  display: inline-block;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.run-banner {
  position: sticky; top: 60px; z-index: 18;
  background: var(--accent-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
}
.run-banner-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 18px;
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  font-size: 0.88rem;
}
.run-banner-title { font-weight: 700; color: var(--accent); }
.run-banner-detail { color: var(--muted); flex: 1; min-width: 8rem; }
.run-banner .btn { min-height: 36px; padding: 6px 12px; }

.seg {
  display: inline-flex; flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
}
.seg-btn {
  border: none; border-right: 1px solid var(--line);
  background: transparent; color: var(--muted);
  padding: 8px 12px; min-height: var(--touch);
  cursor: pointer; font-size: 0.88rem;
  transition: background .12s, color .12s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { color: var(--ink); background: var(--bg); }
.seg-btn:active { background: var(--accent-soft); }
.seg-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.seg-n {
  display: inline-block; min-width: 1.1em; margin-left: 3px;
  font-variant-numeric: tabular-nums; opacity: 0.85;
}

.nav-pill {
  display: inline-block; margin-left: 4px;
  padding: 1px 7px; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700;
  background: var(--ok-bg); color: var(--ok);
  vertical-align: middle;
}

.bulk-bar {
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.chk {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.88rem; color: var(--muted);
  min-height: var(--touch); cursor: pointer; user-select: none;
}

.matches-toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 12px; font-size: 0.88rem; color: var(--muted);
}
.matches-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 14px;
}
.match-card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.match-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.match-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent), var(--shadow);
}
.match-card.is-saved { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
.match-card.is-skipped { opacity: 0.72; }
.match-card.is-focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent), var(--shadow);
}

.match-check {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  border: 1px solid var(--line); cursor: pointer;
}
.match-check input { margin: 0; cursor: pointer; width: 16px; height: 16px; }

.match-media {
  display: block; aspect-ratio: 1;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.match-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.match-media.empty-thumb {
  background: linear-gradient(145deg, color-mix(in srgb, var(--line) 55%, var(--bg)), var(--bg));
}

.match-body {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 12px 14px; flex: 1;
}
.match-title {
  font-weight: 600; font-size: 0.92rem; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.match-title a { color: inherit; text-decoration: none; }
.match-title a:hover { color: var(--accent); text-decoration: underline; }

.match-stats {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline;
  font-size: 0.86rem;
}
.match-price { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.match-bp { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.match-bids { font-size: 0.78rem; color: var(--muted); }
.match-ends { font-size: 0.82rem; color: var(--muted); }
.match-ends.ends-soon { color: var(--warn); font-weight: 600; }
.match-ends.ends-urgent { color: var(--bad); font-weight: 700; }

.match-house {
  display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline;
  font-size: 0.8rem; line-height: 1.3; color: var(--muted);
}
.match-auctioneer { font-weight: 600; color: var(--ink); font-size: 0.84rem; }
.match-auctioneer.is-missing { font-weight: 500; color: var(--muted); font-style: italic; }
.match-loc::before { content: "·"; margin-right: 8px; opacity: 0.5; }

.lot-details {
  font-size: 0.78rem; color: var(--muted);
  border-top: 1px dashed var(--line); padding-top: 4px;
}
.lot-details summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.lot-details p { margin: 4px 0 0; white-space: pre-line; word-break: break-word; }

.why-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.chip {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.match-card .row-actions { margin-top: auto; padding-top: 6px; }
.match-card .row-actions .btn { padding: 6px 10px; min-height: 36px; font-size: 0.82rem; }
.match-card .row-actions .btn-save { flex: 1.2; font-weight: 600; }
.match-card .row-actions .btn-skip { flex: 1; color: var(--muted); background: transparent; }
.match-card .row-actions .btn-skip.primary { color: #fff; background: var(--accent); }
.btn-more { padding: 6px 10px; min-height: 36px; min-width: 36px; }

.menu-wrap { position: relative; display: inline-flex; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  min-width: 11.5rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow), 0 12px 32px rgba(0, 0, 0, .14);
  padding: 4px;
}
.menu.is-open { position: fixed; z-index: 100; right: auto; bottom: auto; }
.menu-item {
  display: block; width: 100%; text-align: left;
  border: none; background: transparent; color: var(--ink);
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 0.88rem; text-decoration: none;
}
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--bad); }

.layout-split {
  display: grid; grid-template-columns: 260px 1fr; gap: 14px; align-items: start;
}
@media (max-width: 820px) { .layout-split { grid-template-columns: 1fr; } }

.sidebar {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px;
  box-shadow: var(--shadow);
  max-height: min(70vh, 640px); overflow: auto;
}
.side-item {
  display: block; width: 100%; text-align: left;
  border: none; background: transparent;
  padding: 10px 12px; border-radius: 8px;
  color: var(--muted); cursor: pointer;
}
.side-item:hover { background: var(--bg); }
.side-item.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-item .sub { display: block; font-size: 0.75rem; font-weight: 500; color: var(--muted); margin-top: 2px; }
.side-row { display: flex; align-items: stretch; gap: 2px; border-radius: 8px; }
.side-row.sel { background: var(--accent-soft); }
.side-row .side-main { flex: 1; min-width: 0; }
.side-row.sel .side-main { background: transparent; color: var(--accent); font-weight: 600; }
.side-toggle {
  flex-shrink: 0; border: none; background: transparent; color: var(--muted);
  font-size: 0.68rem; font-weight: 700; padding: 4px 8px; border-radius: 6px;
  cursor: pointer; align-self: center; margin-right: 4px;
}
.side-toggle.on { color: var(--ok); }
.side-toggle:hover { background: var(--bg); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card-gap { margin-top: 14px; }
.settings-title { margin: 0 0 12px; font-size: 1rem; font-weight: 600; }

.field { margin-bottom: 12px; }
.field label {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; background: var(--bg); min-height: var(--touch);
}
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: var(--accent);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.flag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.flag.on { background: var(--ok-bg); color: var(--ok); }
.flag.off { background: var(--bg); color: var(--muted); }
.flag.warn { background: var(--warn-bg); color: var(--warn); }
.flag.bad { background: var(--bad-bg); color: var(--bad); }

.empty {
  text-align: center; padding: 2.5rem 1.25rem;
  border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--muted);
}
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 0.35rem; }

.table-wrap {
  overflow-x: auto; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--accent-soft); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }

.muted { color: var(--muted); font-size: 0.85rem; }
.help { font-size: 0.84rem; color: var(--muted); margin: 0.25rem 0 0; }
.keys-hint { margin-top: 16px; font-size: 0.78rem; }
.keys-hint kbd {
  display: inline-block; padding: 1px 5px;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--card); font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.note-banner {
  background: var(--warn-bg);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line));
  color: var(--warn);
  border-radius: 8px; padding: 10px 12px; font-size: 0.88rem; margin-bottom: 12px;
}
.note-banner.is-ok {
  background: var(--ok-bg);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--line));
  color: var(--ok);
}
.note-banner.is-bad {
  background: var(--bad-bg);
  border-color: color-mix(in srgb, var(--bad) 35%, var(--line));
  color: var(--bad);
}

.email-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px;
}
.email-stat {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg);
}
.email-stat-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.email-stat-val { margin-top: 4px; font-size: 0.88rem; }

.toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  background: var(--ink); color: var(--bg);
  padding: 12px 16px; border-radius: 10px;
  box-shadow: var(--shadow); max-width: min(380px, 92vw);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast.err { background: var(--bad); color: #fff; }
.toast-action {
  border: 1px solid color-mix(in srgb, #fff 40%, transparent);
  background: transparent; color: inherit;
  border-radius: 6px; padding: 4px 10px;
  font-size: 0.85rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.toast-action:hover { background: color-mix(in srgb, #fff 15%, transparent); }

/* Auth pages */
.auth-body {
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-main { width: 100%; max-width: 420px; padding: 0; }
.auth-card { padding: 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-weight: 700; font-size: 1.1rem; }
.auth-card h1 { margin: 0 0 8px; font-size: 1.25rem; }
.auth-submit { width: 100%; margin-top: 4px; }
