*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e2e8f0;
  --muted: #8892a4;
  --accent: #6366f1;
  --accent-hover: #4f52d8;
  --danger: #ef4444;
  --success: #22c55e;
  --removed-bg: #1e1010;
  --removed-text: #f87171;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Login ──────────────────────────────────── */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-box h1 { font-size: 20px; font-weight: 600; margin-bottom: 28px; color: var(--text); }

.field { margin-bottom: 12px; }
.field input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--muted); }

#login-form button[type="submit"] {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
#login-form button[type="submit"]:hover { background: var(--accent-hover); }
#login-form button[type="submit"]:disabled { opacity: .6; cursor: not-allowed; }

.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ── App layout ────────────────────────────── */

#main-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────── */

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 0;
}

.sidebar-label {
  padding: 8px 16px 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.game-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.game-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background .12s, color .12s;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}

.game-item:hover { background: rgba(255,255,255,.04); color: var(--text); }
.game-item.active {
  background: rgba(99,102,241,.15);
  color: var(--text);
  font-weight: 600;
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.game-icon { font-size: 18px; line-height: 1; }
.game-name  { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Content area ───────────────────────────── */

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title { font-size: 16px; font-weight: 600; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-primary {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary.btn-stop {
  background: var(--danger);
}
.btn-primary.btn-stop:hover {
  background: #dc2626;
}

.btn-ghost {
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.toggle-label input { cursor: pointer; accent-color: var(--accent); }

/* ── Status bar ─────────────────────────────── */

.status-bar {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--muted);
  min-height: 32px;
  flex-shrink: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
}
.status-bar.loading { color: var(--accent); }
.status-bar.ok     { color: var(--success); }
.status-bar.err    { color: var(--danger); }

/* ── Search + filter bar ─────────────────────── */

.search-filter-bar {
  padding: 6px 20px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: none;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 1 340px;
  min-width: 180px;
}
.search-icon {
  position: absolute;
  left: 8px;
  font-size: 13px;
  pointer-events: none;
  opacity: .5;
}
.search-box input {
  width: 100%;
  padding: 5px 28px 5px 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
}
.search-box input:focus {
  border-color: var(--accent);
}
.search-box input::placeholder {
  color: var(--muted);
  opacity: .7;
}
.search-clear {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  display: none;
}
.search-clear:hover { color: var(--text); }
.search-count {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.category-filter-bar {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.active-only-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 12px;
}
.active-only-toggle input { cursor: pointer; }

/* ── Table ──────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
  padding: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:hover { background: var(--surface); }
tbody tr.removed { background: var(--removed-bg); }
tbody tr.removed td { color: var(--removed-text); opacity: .8; }

tbody td {
  padding: 10px 12px;
  vertical-align: middle;
  line-height: 1.4;
}

.col-photo { width: 80px; }
.col-name  { min-width: 160px; font-weight: 500; }
.col-desc  { min-width: 200px; max-width: 340px; color: var(--muted); font-size: 13px; }
.col-price { width: 90px; font-weight: 600; white-space: nowrap; }
.col-date  { width: 130px; font-size: 12px; color: var(--muted); white-space: nowrap; }

.offer-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border);
  display: block;
}
/* FC Mobile tile images are 300×476 (portrait) — show them taller */
.offer-thumb.tile-img {
  width: 52px;
  height: 82px;
  object-fit: cover;
  border-radius: 4px;
}
.no-thumb {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.price-estimated {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}
.price-source {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
  opacity: 0.7;
}

/* ── Inline price editing ───────────────────── */

.price-editable {
  cursor: pointer;
  border-bottom: 1px dashed var(--muted);
  padding: 2px 4px;
  border-radius: 3px;
  transition: background .15s;
  display: inline-block;
  min-width: 40px;
}
.price-editable:hover {
  background: rgba(99, 102, 241, 0.12);
  border-bottom-color: var(--accent);
}
.price-input {
  width: 90px;
  padding: 3px 6px;
  font-size: 13px;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 4px;
  outline: none;
}
.price-input:focus {
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}
.price-manual {
  font-size: 10px;
  color: var(--accent);
  margin-left: 3px;
  opacity: 0.7;
}

/* ── Bundle group header ────────────────────── */

tr.group-header td {
  padding: 8px 12px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
}

tr.group-header:hover td { background: rgba(255,255,255,.03); }

tr.group-misc td { color: var(--muted); }

.chevron {
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  color: var(--muted);
  transition: transform .18s ease;
  vertical-align: middle;
}
tr.group-header.collapsed .chevron { transform: rotate(-90deg); }

.group-misc-label { color: var(--muted); text-transform: none; letter-spacing: 0; }

tr.row-hidden { display: none; }

/* ── Chain path rows ────────────────────────── */

tr.chain-row td { background: rgba(99,102,241,.04); }
tr.chain-row:hover td { background: rgba(99,102,241,.09); }

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  background: rgba(99,102,241,.3);
  color: #c7d2fe;
  margin-right: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

.step-arrow {
  color: var(--muted);
  font-size: 10px;
  margin-right: 6px;
  vertical-align: middle;
  opacity: .6;
}

.group-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(99,102,241,.2);
  color: #a5b4fc;
  text-transform: none;
  letter-spacing: 0;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: #2d2360;
  color: #a5b4fc;
}

.tag-removed {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  background: #3b1010;
  color: var(--danger);
}

.tag-active {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  background: rgba(34,197,94,.12);
  color: var(--success);
}

.badge-new {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(34,197,94,.18);
  color: #4ade80;
  vertical-align: middle;
  margin-right: 4px;
  animation: badge-pulse 2s ease-in-out 3;
}
.badge-gone {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(239,68,68,.18);
  color: #f87171;
  vertical-align: middle;
  margin-right: 4px;
}
@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.empty-msg {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 15px;
}

/* ── Sidebar footer ─────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.btn-cookies {
  width: 100%;
  padding: 8px 12px;
  background: rgba(99,102,241,.12);
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,.3);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  text-align: left;
}
.btn-cookies:hover { background: rgba(99,102,241,.25); }

/* ── Cookies modal ──────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: rgba(255,255,255,.07); }

/* Tech tabs */
.tech-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}
.tech-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 16px;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.tech-tab:hover { color: var(--text); }
.tech-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-description {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 8px;
}

.modal-body { display: flex; flex-direction: column; gap: 10px; }
.modal-hint { font-size: 12px; color: var(--muted); margin: 0; }
.modal-hint code {
  font-family: monospace;
  background: rgba(255,255,255,.06);
  padding: 1px 4px;
  border-radius: 3px;
}
.cookies-textarea {
  width: 100%;
  height: 150px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-family: monospace;
  padding: 10px;
  resize: vertical;
  outline: none;
  box-sizing: border-box;
}
.cookies-textarea:focus { border-color: var(--accent); }
.cookies-status { font-size: 13px; min-height: 18px; }
.cookies-status.ok   { color: var(--success); }
.cookies-status.warn { color: #f59e0b; }
.cookies-status.err  { color: var(--danger); }
.modal-footer { display: flex; gap: 10px; }
.btn-primary {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-ghost {
  padding: 8px 18px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-ghost:hover { background: rgba(255,255,255,.06); color: var(--text); }
.error { font-size: 12px; color: var(--danger); min-height: 16px; margin: 0; }

/* ── Expand toggle column ───────────────────── */

.col-expand {
  width: 32px;
  padding: 0 4px !important;
  text-align: center;
}

.expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 10px;
  line-height: 1;
  transition: color .12s, background .12s;
  flex-shrink: 0;
}
.expand-btn:hover { color: var(--accent); background: rgba(99,102,241,.12); }
.expand-btn.open  { color: var(--accent); }

/* ── JSON expand row ────────────────────────── */

tr.json-row td {
  padding: 0 !important;
  background: #0c0e16;
  border-bottom: 2px solid var(--accent) !important;
}

.json-viewer {
  margin: 0;
  padding: 14px 20px;
  font-family: "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #c9d1d9;
  overflow-x: auto;
  white-space: pre;
  max-height: 520px;
  overflow-y: auto;
}

/* JSON syntax highlighting */
.json-viewer .jk  { color: #7dd3fc; }   /* key   — light blue  */
.json-viewer .js  { color: #86efac; }   /* str   — light green */
.json-viewer .jn  { color: #fca5a5; }   /* num   — light red   */
.json-viewer .jb  { color: #fdba74; }   /* bool  — orange      */
.json-viewer .jnu { color: #c084fc; }   /* null  — purple      */

/* ── Tech section button ──────────────────────────────────────── */
.btn-tech {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin: 0;
  background: var(--bg-dark, #1a1a2e);
  color: #a5b4fc;
  border: 1px solid #334155;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  transition: background .15s;
}
.btn-tech:hover { background: #334155; }

/* ── Tech modal (user management) ─────────────────────────────── */
.modal-wide { max-width: 900px; width: 95%; }

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 16px;
}
.users-table th,
.users-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border, #334155);
  vertical-align: middle;
}
.users-table th {
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.role-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-admin { background: #7c3aed33; color: #a78bfa; }
.role-user  { background: #0ea5e933; color: #67e8f9; }

.fp-chip {
  display: inline-block;
  background: #1e293b;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: #94a3b8;
  margin: 1px 2px;
  cursor: help;
}
.fp-none { color: #64748b; font-style: italic; font-size: 12px; }
.fp-counter { display: inline-block; font-size: 10px; color: #64748b; margin-left: 4px; vertical-align: middle; }

.user-actions { white-space: nowrap; }
.btn-sm {
  padding: 3px 8px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  margin-right: 4px;
}
.btn-warn { background: #92400e44; color: #fbbf24; }
.btn-warn:hover { background: #92400e88; }
.btn-danger { background: #7f1d1d44; color: #f87171; }
.btn-danger:hover { background: #7f1d1d88; }

.add-user-form {
  border-top: 1px solid var(--border, #334155);
  padding-top: 12px;
  margin-top: 4px;
}
.add-user-form h3 {
  font-size: 14px;
  margin: 0 0 8px;
  color: var(--text-secondary, #94a3b8);
}
.add-user-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.add-user-row input,
.add-user-row select {
  padding: 6px 10px;
  border: 1px solid var(--border, #334155);
  border-radius: 6px;
  background: var(--bg, #0f172a);
  color: var(--text, #e2e8f0);
  font-size: 13px;
}
.add-user-row input { flex: 1; }

/* Autoscan tab */
.autoscan-status-card {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
}
.autoscan-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.autoscan-label {
  font-size: 13px;
  color: var(--muted);
  min-width: 140px;
}
.autoscan-badge {
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
}
.autoscan-on {
  color: #22c55e;
  background: rgba(34,197,94,.12);
}
.autoscan-off {
  color: #ef4444;
  background: rgba(239,68,68,.12);
}
.autoscan-controls {
  display: flex;
  align-items: center;
}
.add-user-row select { width: 100px; }
