:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel2: #f0f2f5; --line: #e1e4ea;
  --fg: #16181d; --muted: #6b7280; --accent: #2563eb; --accent-fg: #ffffff;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --info: #0891b2;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
    --fg: #e6e8ee; --muted: #8b93a3; --accent: #3b82f6; --accent-fg: #ffffff;
    --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --info: #22d3ee;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --fg: #e6e8ee; --muted: #8b93a3; --accent: #3b82f6; --accent-fg: #ffffff;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --info: #22d3ee;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
button, input, select { font: inherit; color: inherit; }

/* ── login ─────────────────────────────────────────────────────────── */
.screen { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
        padding: 28px 28px 20px; width: min(360px, 100%); box-shadow: var(--shadow); }
.card h1 { margin: 0 0 2px; font-size: 22px; letter-spacing: .01em; }
.card p { margin: 0 0 18px; }
.card input { width: 100%; margin-bottom: 10px; }
.card button { width: 100%; }

/* ── controls ──────────────────────────────────────────────────────── */
input[type=text], input[type=password], input[type=search], select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.btn, button.btn, .tab {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; line-height: 1.2; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.tab { background: transparent; border-color: transparent; color: var(--muted); }
.tab.active { color: var(--fg); background: var(--panel2); border-color: var(--line); }

/* ── shell ─────────────────────────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .02em; margin-right: 6px; }
nav { display: flex; gap: 4px; }
.stats { display: flex; gap: 6px; flex-wrap: wrap; margin-left: 8px; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; padding: 3px 9px; border-radius: 999px;
        background: var(--panel2); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.chip b { color: var(--fg); font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
main { padding: 16px; max-width: 1600px; margin: 0 auto; }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.split.with-detail { grid-template-columns: minmax(0, 1fr) minmax(0, 480px); }
@media (max-width: 1100px) { .split.with-detail { grid-template-columns: minmax(0, 1fr); } .detail { position: static; } .detail .body { max-height: none; } }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=search] { min-width: 220px; flex: 1; max-width: 420px; }

/* ── tables ────────────────────────────────────────────────────────── */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
         box-shadow: var(--shadow); overflow: hidden; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle;
         white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
     background: var(--panel2); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tbody tr.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.trunc { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
         letter-spacing: .03em; text-transform: uppercase; border: 1px solid transparent; }
.badge.queued    { color: var(--muted);  background: color-mix(in srgb, var(--muted) 14%, transparent); }
.badge.unpacking { color: var(--info);   background: color-mix(in srgb, var(--info) 14%, transparent); }
.badge.done, .badge.ok       { color: var(--ok);   background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.failed, .badge.miss   { color: var(--bad);  background: color-mix(in srgb, var(--bad) 14%, transparent); }
.badge.nopick, .badge.notrun { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

.bar { height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; min-width: 90px; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }
.anchors-cell { display: flex; align-items: center; gap: 8px; }

/* ── detail ────────────────────────────────────────────────────────── */
.detail { position: sticky; top: 64px; }
.detail .head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.detail .head h2 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.detail .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 140px); overflow: auto; }
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 5px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
pre.log { margin: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
          padding: 10px; max-height: 320px; overflow: auto; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.progress { display: flex; flex-direction: column; gap: 6px; }
.progress .bar { height: 8px; }
.filelist, .loglist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.filelist li, .loglist li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line);
                            border-radius: 6px; background: var(--panel2); }
.filelist li .name, .loglist li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.loglist li { cursor: pointer; }
.loglist li:hover { border-color: var(--accent); }
.copy { cursor: pointer; color: var(--muted); }
.copy:hover { color: var(--accent); }
.summary { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }

/* ── drop zone / upload ────────────────────────────────────────────── */
.dropping main::after {
  content: "Drop RainbowSix.exe to upload"; position: fixed; inset: 0; display: grid; place-items: center;
  font-size: 22px; color: var(--accent); background: color-mix(in srgb, var(--bg) 80%, transparent);
  border: 3px dashed var(--accent); z-index: 20; pointer-events: none;
}
.upload { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 12px; }
.upload .bar { flex: 1; height: 8px; }

/* ── toasts ────────────────────────────────────────────────────────── */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--info);
         border-radius: 6px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 380px; }
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }

@media (max-width: 640px) {
  header { padding: 8px 12px; }
  main { padding: 12px; }
  .stats { display: none; }
  th, td { padding: 8px 8px; }
  .kv { grid-template-columns: 100px minmax(0, 1fr); }
}
