@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #0a0e17;
  --surface: #111827;
  --surface-2: #1a2235;
  --border: #1f2d3d;
  --border-2: #2a3a50;
  --text: #e2e8f4;
  --muted: #6b7fa3;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --sidebar-width: 220px;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 0.9rem;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: #60a5fa;
  text-decoration: underline;
}

/* ─── Layout ──────────────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  margin-bottom: 0.75rem;
}

.sidebar-brand .brand-name {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.sidebar-brand .brand-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 0.1rem;
}

.sidebar-db {
  margin-top: 0.5rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
}

.nav-section-label {
  padding: 0.5rem 1.25rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  opacity: 0.6;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: 0;
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: rgba(59, 130, 246, 0.08);
  text-decoration: none;
}

.sidebar-nav a.nav-active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.sidebar-nav a svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-nav a.nav-active svg {
  opacity: 1;
}

.sidebar-nav a:hover svg {
  opacity: 0.9;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.sidebar-footer form {
  margin: 0;
}

.sidebar-footer .btn-logout {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.sidebar-footer .btn-logout:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

/* ─── Hamburger (mobile) ──────────────────────────────────────── */

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  color: var(--text);
  line-height: 1;
}

/* ─── Main content ────────────────────────────────────────────── */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  flex: 1;
  padding: 2rem 2rem 3rem;
  max-width: 1200px;
}

/* ─── Page header ─────────────────────────────────────────────── */

.page-header {
  margin-bottom: 1.75rem;
}

.page-header h1 {
  margin: 0 0 0.2rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

.page-header .page-sub {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ─── Badges ──────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.ok {
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.08);
}

.badge.ok::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* ─── Cards ───────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: all 0.15s ease;
}

.card:hover {
  border-color: var(--border-2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.card h3 {
  margin: 0 0 0.4rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}

.card .val {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.1;
}

.card .val.accent {
  color: var(--accent);
}

.card .hint {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.card .stat-change {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.card .stat-change.up {
  color: var(--success);
}

.card .stat-change.down {
  color: var(--danger);
}

.card-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease;
}

.card-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.card-link-subtle {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.card-link-subtle:hover {
  color: var(--accent);
  text-decoration: none;
}

.card .val.val-compact {
  font-size: 0.95rem;
  line-height: 1.35;
  font-weight: 600;
}

/* ─── KPI grid ────────────────────────────────────────────────── */

.grid-kpi {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}

/* ─── Sections ────────────────────────────────────────────────── */

section.block {
  margin-bottom: 2rem;
}

section.block h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

section.block h2::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 1em;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}

/* ─── Tables ──────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

table.data th,
table.data td {
  padding: 0.6rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.02);
}

table.data tr:last-child td {
  border-bottom: none;
}

table.data tbody tr:hover td {
  background: rgba(59, 130, 246, 0.05);
}

/* ─── Status styles ───────────────────────────────────────────── */

.status-running {
  color: var(--warning);
  font-weight: 600;
  animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.status-success {
  color: var(--success);
  font-weight: 600;
}

.status-failed {
  color: var(--danger);
  font-weight: 600;
}

/* ─── Buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(1.12);
  box-shadow: 0 0 0 3px var(--accent-glow);
  text-decoration: none;
  color: #fff;
}

.btn.btn-secondary,
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-2);
}

.btn.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  filter: none;
}

.btn.btn-danger,
.btn-danger {
  background: linear-gradient(135deg, var(--danger), #dc2626);
}

.btn.btn-danger:hover {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
  filter: brightness(1.1);
}

a.btn {
  text-decoration: none;
  color: #fff;
}

a.btn.btn-secondary {
  color: var(--text);
}

a.btn:hover {
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-2);
  background: rgba(255, 255, 255, 0.04);
}

/* ─── Flash messages ──────────────────────────────────────────── */

.flash {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.flash-error {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* ─── Progress bar ────────────────────────────────────────────── */

.scraper-progress-track {
  height: 8px;
  width: 100%;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.scraper-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 999px;
  transition: width 0.3s ease;
  position: relative;
  overflow: hidden;
}

.scraper-progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 200%; }
}

/* ─── Modal ───────────────────────────────────────────────────── */

.panel-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
}

.panel-modal[hidden] {
  display: none;
}

.panel-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.panel-modal__content {
  position: relative;
  width: min(860px, calc(100vw - 2rem));
  margin: 7vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 1.1rem;
  max-height: 86vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.panel-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.panel-modal__head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.panel-modal__body {
  margin: 0;
  max-height: 68vh;
  overflow: auto;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  font-size: 0.82rem;
}

/* ─── Forms ───────────────────────────────────────────────────── */

.form-export .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem 1rem;
  margin-bottom: 1.25rem;
}

.form-export .form-grid .span-2 {
  grid-column: 1 / -1;
}

.form-export label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.form-export input,
.form-export select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.form-export input:focus,
.form-export select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-export h3 {
  margin: 1.25rem 0 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-export h3:first-of-type {
  margin-top: 0;
}

.form-panel {
  display: grid;
  gap: 0.75rem;
  max-width: 520px;
}

.form-panel label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.form-panel input,
.form-panel select,
.form-panel textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s ease;
}

.form-panel input:focus,
.form-panel select:focus,
.form-panel textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-panel textarea {
  min-height: 100px;
  resize: vertical;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.75rem;
  align-items: end;
}

.form-inline label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.form-inline input,
.form-inline select {
  min-width: 10rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.form-inline input:focus,
.form-inline select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Records filter grid ─────────────────────────────────────────── */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem 0.6rem;
}

.filter-cell label {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.filter-cell input,
.filter-cell select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  color-scheme: dark;
  font-size: 0.84rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.filter-cell select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%236b7fa3' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.8rem;
}

.filter-cell input:focus,
.filter-cell select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-cell input::placeholder {
  color: var(--muted);
  opacity: 0.45;
}

/* KPI strip for records page */
.records-kpi {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.records-kpi .kpi-item {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.records-kpi .kpi-val {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.records-kpi .kpi-label {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Responsive filter grid */
@media (max-width: 960px) {
  .filter-grid { grid-template-columns: repeat(3, 1fr) !important; }
}
@media (max-width: 600px) {
  .filter-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ─── Login ───────────────────────────────────────────────────── */

.login-body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  box-shadow: 0 0 0 1px var(--accent-glow), 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-brand .brand-mark {
  display: inline-block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.login-brand .brand-tagline {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}

.login-card h1 {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.login-form label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.login-form .password-field {
  position: relative;
}

.login-form input[type="password"],
.login-form input[type="text"] {
  width: 100%;
  padding: 0.6rem 2.5rem 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.password-toggle {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  transition: color 0.15s ease;
}

.password-toggle:hover {
  color: var(--text);
}

/* ─── Markdown docs ───────────────────────────────────────────── */

.lead {
  line-height: 1.6;
}

.markdown-doc {
  font-size: 0.92rem;
  line-height: 1.65;
  max-width: 52rem;
}

.markdown-doc h1,
.markdown-doc h2,
.markdown-doc h3 {
  margin: 1.5rem 0 0.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.markdown-doc h1 {
  font-size: 1.35rem;
  margin-top: 0;
}

.markdown-doc h2 {
  font-size: 1.05rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.markdown-doc h3 {
  font-size: 0.95rem;
  color: var(--muted);
}

.markdown-doc p {
  margin: 0.7rem 0;
}

.markdown-doc ul,
.markdown-doc ol {
  margin: 0.5rem 0 0.5rem 1.25rem;
  padding: 0;
}

.markdown-doc li {
  margin: 0.3rem 0;
}

.markdown-doc code {
  font-size: 0.86em;
  font-family: var(--mono);
  background: var(--bg);
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: #93c5fd;
}

.markdown-doc pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.82rem;
  font-family: var(--mono);
}

.markdown-doc pre code {
  border: none;
  padding: 0;
  background: none;
  color: var(--text);
}

.markdown-doc table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.75rem 0;
}

.markdown-doc th,
.markdown-doc td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

.markdown-doc th {
  color: var(--muted);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.02);
}

.markdown-doc hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.markdown-doc a {
  color: var(--accent);
}

/* ─── Monospace ───────────────────────────────────────────────── */

.mono {
  font-family: var(--mono);
  font-size: 0.8rem;
  word-break: break-word;
}

/* ─── Misc table helpers ──────────────────────────────────────── */

.cell-wrap {
  word-break: break-word;
  max-width: 28rem;
}

.run-id-pill {
  display: inline-block;
  min-width: 3.2rem;
  text-align: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.14);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--mono);
}

.run-job-cell {
  max-width: 18rem;
}

.run-job-main {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-job-sub {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.72rem;
  overflow-wrap: anywhere;
  font-family: var(--mono);
}

.run-details {
  max-width: 34rem;
}

.run-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.82rem;
}

.run-details summary:hover {
  color: #60a5fa;
}

.run-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.3rem 0.7rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
}

.run-details-block {
  margin-top: 0.5rem;
  font-size: 0.82rem;
}

.run-details pre {
  margin: 0.35rem 0 0;
  max-height: 14rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* ─── Level indicators ────────────────────────────────────────── */

.level-error {
  color: var(--danger);
  font-weight: 600;
}

.level-warning {
  color: var(--warning);
  font-weight: 600;
}

.level-info {
  color: var(--accent);
}

/* ─── Badge job ───────────────────────────────────────────────── */

.badge-job-scraper {
  display: inline-block;
  margin-right: 0.3rem;
  padding: 0.06rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent);
  vertical-align: middle;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

/* ─── Row highlight ───────────────────────────────────────────── */

tr.run-row-docker-scraper {
  background: rgba(59, 130, 246, 0.04);
}

tr.expandable-hidden-row {
  display: none;
}

.expand-toggle-btn {
  margin-top: 0.65rem;
}

/* ─── Bar chart ───────────────────────────────────────────────── */

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding: 0.5rem 0;
}

.bar-chart .bar {
  flex: 1;
  min-width: 0;
  background: linear-gradient(180deg, var(--accent), rgba(59, 130, 246, 0.25));
  border-radius: 4px 4px 0 0;
  position: relative;
  min-height: 2px;
  transition: filter 0.15s ease;
}

.bar-chart .bar:hover {
  filter: brightness(1.2);
}

.bar-chart .bar span {
  position: absolute;
  bottom: -1.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.63rem;
  color: var(--muted);
  white-space: nowrap;
  font-family: var(--mono);
}

.report-chart {
  height: 170px;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 1.5rem;
}

/* ─── Candidate grid ──────────────────────────────────────────── */

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.candidate-col {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  background: var(--surface);
}

.candidate-col h3 {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.candidate-col pre {
  margin-top: 0.5rem;
  max-height: 15rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* ─── Nav actions ─────────────────────────────────────────────── */

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  margin-top: 0.5rem;
}

.nav-actions form {
  margin: 0;
}

/* ─── Footer ──────────────────────────────────────────────────── */

footer.meta {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
}

/* ─── Responsive ──────────────────────────────────────────────── */

@media (max-width: 900px) {
  .run-job-cell {
    max-width: 12rem;
  }
  table.pipeline-runs-table {
    font-size: 0.8rem;
  }
  table.pipeline-runs-table th,
  table.pipeline-runs-table td {
    padding: 0.45rem 0.6rem;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .main-content {
    margin-left: 0;
  }

  .wrap {
    padding: 1.25rem 1rem 2.5rem;
    padding-top: 4rem;
  }

  .grid-kpi {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}

/* ─── Listing expand button ───────────────────────────────────────── */

.btn-expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-expand:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

.btn-expand.expanded {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
  transform: rotate(180deg);
}

.btn-expand svg {
  display: block;
}

/* ─── Listing detail row ──────────────────────────────────────────── */

.listing-detail-row {
  display: none;
}

.listing-detail-row.visible {
  display: table-row;
}

.listing-detail-row td {
  padding: 0 !important;
  border-top: none !important;
  background: var(--bg);
}

.listing-detail {
  padding: 1rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  animation: detailFadeIn 0.18s ease;
}

@keyframes detailFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.detail-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.5rem 0;
}

.detail-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.detail-error {
  color: var(--danger);
  font-size: 0.82rem;
  padding: 0.35rem 0;
}

/* ─── Diff pills (inline change badges) ──────────────────────────── */

.diff-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.diff-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.diff-pill.price-down {
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.08);
}

.diff-pill.price-up {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.diff-pill.raise {
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
}

.diff-pill.promoted {
  color: #a78bfa;
  border-color: rgba(167, 139, 250, 0.35);
  background: rgba(167, 139, 250, 0.08);
}

/* ─── History timeline ────────────────────────────────────────────── */

.history-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  opacity: 0.7;
  margin-bottom: 0.6rem;
}

.history-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}

.history-timeline::before {
  content: "";
  position: absolute;
  left: 0.55rem;
  top: 0.6rem;
  bottom: 0.6rem;
  width: 1px;
  background: var(--border);
}

.h-entry {
  display: flex;
  gap: 0.85rem;
  padding: 0.5rem 0;
  position: relative;
}

.h-dot {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  margin-top: 0.15rem;
  position: relative;
  z-index: 1;
  transition: border-color 0.15s ease;
}

.h-entry.has-changes .h-dot {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.h-entry.first-seen .h-dot {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.15);
}

.h-body {
  flex: 1;
  min-width: 0;
}

.h-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  flex-wrap: wrap;
}

.h-date {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  font-family: var(--mono);
}

.h-source {
  font-size: 0.68rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
}

.h-price {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: auto;
}

.h-first-label {
  font-size: 0.72rem;
  color: var(--success);
  font-weight: 600;
}

.h-no-changes {
  font-size: 0.75rem;
  color: var(--muted);
  font-style: italic;
}

/* ─── Diff table (field before/after) ────────────────────────────── */

.diff-table {
  border-collapse: collapse;
  font-size: 0.8rem;
  width: auto;
}

.diff-table tr + tr td {
  padding-top: 0.15rem;
}

.diff-table td {
  padding: 0 0.4rem 0 0;
  vertical-align: middle;
  white-space: nowrap;
}

.diff-field-name {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 4.5rem;
}

.diff-old {
  color: var(--danger);
  text-decoration: line-through;
  opacity: 0.75;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.diff-arrow {
  color: var(--muted);
  padding: 0 0.25rem;
}

.diff-new {
  color: var(--success);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
}

/* ─── Day nav (prev/next) ─────────────────────────────────────────── */

.day-nav {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.day-nav a.btn {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  min-width: 2rem;
  text-align: center;
}

/* ─── Metric nav tabs ─────────────────────────────────────────────── */

.metric-tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.metric-tab {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
}

.metric-tab:hover {
  color: var(--text);
  border-color: var(--border-2);
  text-decoration: none;
}

.metric-tab.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

@media (max-width: 760px) {
  table.pipeline-runs-table thead {
    display: none;
  }
  table.pipeline-runs-table,
  table.pipeline-runs-table tbody,
  table.pipeline-runs-table tr,
  table.pipeline-runs-table td {
    display: block;
    width: 100%;
  }
  table.pipeline-runs-table tr {
    border-bottom: 1px solid var(--border);
    padding: 0.35rem 0.25rem;
  }
  table.pipeline-runs-table tr:last-child {
    border-bottom: none;
  }
  table.pipeline-runs-table td {
    border-bottom: none;
    padding: 0.22rem 0.5rem;
  }
  table.pipeline-runs-table td::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 5.6rem;
    margin-right: 0.5rem;
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
  }
  .run-job-main {
    white-space: normal;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Mobile optimisation (393–440px: iPhone 16 / S25 Ultra / 16 Pro Max)
   ═══════════════════════════════════════════════════════════════════ */

/* ── Global mobile tweaks ──────────────────────────────────────── */
@media (max-width: 480px) {
  .wrap {
    padding: 1rem 0.65rem 2rem;
    padding-top: 3.5rem;
  }

  .page-header h1 {
    font-size: 1.25rem;
  }

  .card {
    padding: 0.75rem 0.8rem;
    border-radius: 10px;
  }

  .grid-kpi {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .grid-kpi .card .val {
    font-size: 1.3rem;
  }

  section.block {
    margin-bottom: 0.8rem;
  }

  section.block h2 {
    font-size: 0.88rem;
  }

  footer.meta {
    font-size: 0.7rem;
    padding: 0.5rem 0;
  }
}

/* ── Filter grid: 2 columns on mobile ──────────────────────────── */
@media (max-width: 480px) {
  .filter-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.4rem !important;
  }

  .filter-cell label {
    font-size: 0.62rem;
    margin-bottom: 0.15rem;
  }

  .filter-cell input,
  .filter-cell select {
    padding: 0.45rem 0.5rem;
    font-size: 0.82rem;
  }

  /* KPI strip compact */
  .records-kpi {
    gap: 0.75rem;
  }

  .records-kpi .kpi-val {
    font-size: 1.15rem;
  }

  .records-kpi .kpi-label {
    font-size: 0.72rem;
  }
}

/* ── Records table → card layout on mobile ─────────────────────── */
@media (max-width: 480px) {
  #records-table thead {
    display: none;
  }

  #records-table,
  #records-table tbody,
  #records-table tr,
  #records-table td {
    display: block;
    width: 100%;
  }

  #records-table tr {
    padding: 0.6rem 0.7rem;
    border-bottom: 1px solid var(--border);
    position: relative;
  }

  #records-table tr:last-child {
    border-bottom: none;
  }

  #records-table td {
    border-bottom: none;
    padding: 0;
  }

  /* Score: float to top-right as badge */
  #records-table td:first-child {
    position: absolute;
    top: 0.6rem;
    right: 0.7rem;
    width: auto;
  }

  /* Listing title: full width with right padding for score badge */
  #records-table td:nth-child(2) {
    padding-right: 3rem;
    margin-bottom: 0.35rem;
  }

  #records-table td:nth-child(2) div:first-child {
    font-size: 0.9rem;
  }

  /* Price, Year, Mileage, City: inline row */
  #records-table td:nth-child(3),
  #records-table td:nth-child(4),
  #records-table td:nth-child(5),
  #records-table td:nth-child(6) {
    display: inline-block;
    width: auto;
    text-align: left !important;
    font-size: 0.8rem;
    padding-right: 0.6rem;
  }

  #records-table td:nth-child(3)::before { content: ""; }
  #records-table td:nth-child(4)::before { content: "· "; color: var(--muted); }
  #records-table td:nth-child(5)::before { content: "· "; color: var(--muted); }
  #records-table td:nth-child(6)::before { content: "· "; color: var(--muted); }

  /* Pagination compact */
  .btn,
  .btn-secondary {
    min-height: 2.2rem;
  }
}

/* ── Lifecycle table → card layout on mobile ───────────────────── */
@media (max-width: 480px) {
  #lifecycle-table thead {
    display: none;
  }

  #lifecycle-table,
  #lifecycle-table tbody {
    display: block;
    width: 100%;
  }

  #lifecycle-table tr.listing-main-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 0 0.5rem;
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border);
    align-items: center;
  }

  #lifecycle-table tr.listing-main-row td {
    border-bottom: none;
    padding: 0.1rem 0;
  }

  /* Expand btn: row 1 col 1 */
  #lifecycle-table tr.listing-main-row td:nth-child(1) {
    grid-row: 1 / 3;
    grid-column: 1;
  }

  /* Event time: hidden on mobile */
  #lifecycle-table tr.listing-main-row td:nth-child(2) {
    display: none;
  }

  /* ID: hidden */
  #lifecycle-table tr.listing-main-row td:nth-child(3) {
    display: none;
  }

  /* Brand + Model: combined as main title */
  #lifecycle-table tr.listing-main-row td:nth-child(4) {
    grid-row: 1;
    grid-column: 2;
    font-weight: 500;
  }

  #lifecycle-table tr.listing-main-row td:nth-child(5) {
    grid-row: 1;
    grid-column: 2;
    display: none;
  }

  /* Year: part of subtitle row */
  #lifecycle-table tr.listing-main-row td:nth-child(6) {
    grid-row: 2;
    grid-column: 2;
    font-size: 0.78rem;
    color: var(--muted);
  }

  /* Price: row 1 right */
  #lifecycle-table tr.listing-main-row td:nth-child(7) {
    grid-row: 1;
    grid-column: 3;
    text-align: right;
    font-weight: 600;
  }

  /* City: hidden */
  #lifecycle-table tr.listing-main-row td:nth-child(8) {
    display: none;
  }

  /* Deal badge: row 2 right */
  #lifecycle-table tr.listing-main-row td:nth-child(9) {
    grid-row: 2;
    grid-column: 3;
    text-align: right;
  }

  /* Detail expand rows */
  #lifecycle-table tr.listing-detail-row td {
    padding: 0.5rem;
  }

  #lifecycle-table tr.listing-detail-row td[colspan] {
    display: block;
  }
}

/* ── Modal: full-screen on mobile ──────────────────────────────── */
@media (max-width: 480px) {
  #listing-modal-overlay {
    padding: 0 !important;
  }

  #listing-modal {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    min-height: 100vh;
    padding: 1rem 0.8rem 2rem !important;
  }

  #listing-modal-2 {
    display: none !important;
  }
}

/* ── Metric tabs: scrollable on mobile ─────────────────────────── */
@media (max-width: 480px) {
  .metric-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
    padding-bottom: 0.15rem;
  }

  .metric-tab {
    white-space: nowrap;
    padding: 0.4rem 0.7rem;
    font-size: 0.78rem;
    flex-shrink: 0;
  }
}

/* ── Chart area compact ────────────────────────────────────────── */
@media (max-width: 480px) {
  .bar-chart.report-chart {
    min-height: 100px;
    max-height: 150px;
  }

  .bar-chart .bar span {
    font-size: 0.55rem;
  }

  .day-nav a.btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
  }

  .form-inline {
    gap: 0.4rem;
  }

  .form-inline input,
  .form-inline select {
    min-width: 6rem;
    font-size: 0.8rem;
    padding: 0.4rem 0.5rem;
  }
}

/* ── Sidebar: wider touch targets on mobile ────────────────────── */
@media (max-width: 480px) {
  .sidebar-nav a {
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
    min-height: 2.4rem;
  }

  .sidebar-toggle {
    width: 2.5rem;
    height: 2.5rem;
    top: 0.6rem;
    left: 0.5rem;
  }

  .nav-section-label {
    font-size: 0.62rem;
    padding: 0.2rem 0.9rem;
  }
}

/* ── Findings table on mobile ──────────────────────────────────── */
@media (max-width: 480px) {
  .block table.data thead th:nth-child(n+5) {
    display: none;
  }

  .block table.data tbody td:nth-child(n+5) {
    display: none;
  }

  table.data th,
  table.data td {
    padding: 0.45rem 0.5rem;
    font-size: 0.8rem;
  }
}

/* ── Compare bar: stack on mobile ──────────────────────────────── */
@media (max-width: 480px) {
  #compare-bar {
    flex-direction: column;
    padding: 0.5rem 0.8rem !important;
    gap: 0.4rem !important;
  }
}

/* ── Touch: larger tap targets ─────────────────────────────────── */
@media (pointer: coarse) {
  .btn, .btn-secondary {
    min-height: 2.2rem;
    min-width: 2.2rem;
  }

  #records-table tbody tr {
    min-height: 3rem;
  }

  table.data tbody tr {
    min-height: 2.5rem;
  }
}
