:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-muted: #f1f2f4;
  --border: #e2e4e8;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --accent: #3461eb;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --success: #1f8a4c;
  --warning: #b8860b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #15171c;
  --surface: #1c1f26;
  --surface-muted: #23262e;
  --border: #30343d;
  --text: #e6e8eb;
  --text-muted: #9aa0ab;
  --accent: #6d8bff;
  --accent-text: #0d1117;
  --danger: #e0695e;
  --success: #3fbf79;
  --warning: #d4a72c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c;
    --surface: #1c1f26;
    --surface-muted: #23262e;
    --border: #30343d;
    --text: #e6e8eb;
    --text-muted: #9aa0ab;
    --accent: #6d8bff;
    --accent-text: #0d1117;
    --danger: #e0695e;
    --success: #3fbf79;
    --warning: #d4a72c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.topbar-nav {
  display: flex;
  gap: 4px;
}

.topbar-nav a {
  display: inline-block;
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13.5px;
}

.topbar-nav a:hover {
  background: var(--surface-muted);
  text-decoration: none;
  color: var(--text);
}

.topbar-nav a.active {
  background: var(--accent);
  color: var(--accent-text);
}

.nav-logout button {
  background: none;
  border: 0;
  padding: 8px 14px;
  color: var(--text-muted);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}

.nav-logout button:hover {
  color: var(--text);
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius);
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { background: var(--surface-muted); }

main {
  flex: 1;
  padding: 28px 32px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.page-header .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: var(--surface-muted); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  font-family: var(--font);
  font-size: 13.5px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.field-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  min-width: 140px;
}
.stat-tile .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.stat-tile .value { font-size: 20px; font-weight: 600; }
.stat-tile .value.positive { color: var(--success); }
.stat-tile .value.negative { color: var(--danger); }

.sync-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: -8px;
  margin-bottom: 16px;
}
.sync-progress-track {
  flex: 1;
  max-width: 320px;
  height: 8px;
  background: var(--surface-muted);
  border-radius: 4px;
  overflow: hidden;
}
.sync-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.2s ease;
}
.sync-progress-label {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Indeterminate variant - for a one-shot request with no real percentage to
   report, rather than leaving the track empty or faking a fill amount. */
.sync-progress-fill.indeterminate {
  width: 40% !important;
  animation: sync-progress-slide 1.1s ease-in-out infinite;
}
@keyframes sync-progress-slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .sync-progress-fill.indeterminate { animation: none; width: 100% !important; }
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-muted);
  color: var(--text-muted);
}
.badge.hot { background: rgba(31, 138, 76, 0.15); color: var(--success); }
.badge.dead { background: rgba(192, 57, 43, 0.12); color: var(--danger); }
.badge.type-single { background: rgba(59, 130, 246, 0.14); color: #3b82f6; }
.badge.type-sealed { background: rgba(168, 85, 247, 0.14); color: #a855f7; }
.badge.status-open { background: rgba(184, 134, 11, 0.15); color: var(--warning); }
.badge.status-shipped { background: rgba(31, 138, 76, 0.15); color: var(--success); }
.badge.status-closed { background: rgba(192, 57, 43, 0.12); color: var(--danger); }

.subtabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.subtab-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subtab-btn:hover { color: var(--text); }
.subtab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 1000;
}
.toast.error { background: var(--danger); color: #fff; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h2 { margin-top: 0; }

/* Tabulator theme overrides to match the design system */
.tabulator {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
}
.tabulator-header {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
}
.tabulator-col {
  background: var(--surface-muted) !important;
  color: var(--text) !important;
  border-right: none !important;
}
.tabulator-row {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--border);
}
.tabulator-row.tabulator-row-even { background: var(--surface) !important; }
.tabulator-row:hover { background: var(--surface-muted) !important; }
.tabulator-footer {
  background: var(--surface-muted);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.tabulator-cell { border-right: none !important; }

#card-preview {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  display: none;
}
#card-preview.visible { display: block; }
#card-preview img {
  width: 220px;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: block;
}
