/* Ensure [hidden] always wins over display:flex/grid on modal backdrops etc. */
[hidden] { display: none !important; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #14161f;
  --surface-3: #11141c;
  --text: #e1e4ea;
  --muted: #8b8fa3;
  --border: #2a2d3a;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --radius: 8px;
  --radius-sm: 4px;
  --font-sans: system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #60a5fa; }

h1, h2, h3, h4, h5, h6, p { margin-top: 0; }
small, .text-muted, .muted { color: var(--muted); }

/* ── Nav ── */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  align-items: center;
  padding: 12px 24px;
  background: rgba(20, 22, 31, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.nav .brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  font-size: 16px;
  text-decoration: none;
  justify-self: start;
}
.nav .brand:hover { color: #60a5fa; }

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.nav-right {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  font-size: 12px;
  color: var(--muted);
}

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 12px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: color 0.18s, background 0.18s, border-color 0.18s;
}

.nav a:hover { color: var(--text); background: rgba(255,255,255,0.03); border-color: var(--border); }

.nav a.active, .nav a[aria-current='page'] {
  color: #fff;
  background: var(--accent-soft);
  border-color: rgba(59,130,246,0.45);
}

/* ── Container ── */
.container { width: 100%; max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ── Cards ── */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

/* ── Stats bar ── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-label { margin-bottom: 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; }

/* ── Tables ── */
.table-wrap, .table-container { width: 100%; overflow-x: auto; border-radius: var(--radius); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

thead { background: var(--surface-2); }

th, td { text-align: left; vertical-align: middle; }

th {
  padding: 12px 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  user-select: none;
  white-space: nowrap;
}

th.sortable, th[data-sort] { cursor: pointer; }
th.sortable:hover, th[data-sort]:hover { color: var(--text); background: rgba(255,255,255,0.02); }
th .sort-arrow { margin-left: 4px; opacity: 0.5; }
th.sort-asc .sort-arrow, th.sort-desc .sort-arrow { opacity: 1; color: var(--accent); }

td { padding: 14px; border-bottom: 1px solid var(--border); }

tbody tr { transition: background-color 0.16s; }
tbody tr:hover { background: rgba(255,255,255,0.025); }
tbody tr:last-child td { border-bottom: 0; }

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: rgba(59,130,246,0.08); }

/* ── Timeline ── */
.timeline {
  position: relative;
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 4px 0 4px 24px;
  list-style: none;
}

.timeline::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 8px;
  width: 2px;
  background: var(--border);
}

.timeline-item, .timeline > li { position: relative; }

.timeline-item::before, .timeline > li::before {
  content: '';
  position: absolute;
  top: 6px; left: -20px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(59,130,246,0.14);
}

.timeline-content {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-blue, .badge-info, .badge-primary { color: #bfdbfe; background: rgba(59,130,246,0.14); border-color: rgba(59,130,246,0.4); }
.badge-green, .badge-success { color: #bbf7d0; background: rgba(34,197,94,0.14); border-color: rgba(34,197,94,0.4); }
.badge-yellow, .badge-warning { color: #fde68a; background: rgba(245,158,11,0.14); border-color: rgba(245,158,11,0.4); }
.badge-red, .badge-error, .badge-danger { color: #fecaca; background: rgba(239,68,68,0.14); border-color: rgba(239,68,68,0.4); }
.badge-neutral, .badge-muted { color: var(--muted); background: rgba(255,255,255,0.03); border-color: var(--border); }

/* ── Recall metric cells ── */
td.recall-cell {
  font-family: var(--font-mono, 'Fira Mono', 'Courier New', monospace);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
}
td.recall-cell:not(:empty):not([data-val="—"]) {
  color: var(--text);
}

/* ── Log viewer ── */
.log-container {
  padding: 16px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 80vh;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 13px;
}

.log-entry {
  padding: 12px 14px;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.log-entry + .log-entry { margin-top: 10px; }
.log-entry time, .log-entry .timestamp { color: var(--muted); font-size: 12px; }

/* ── Status dot ── */
.status-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.green, .status-dot.success { background: var(--success); box-shadow: 0 0 0 4px rgba(34,197,94,0.14); }
.status-dot.yellow, .status-dot.warning { background: var(--warning); box-shadow: 0 0 0 4px rgba(245,158,11,0.14); }
.status-dot.red, .status-dot.error { background: var(--error); box-shadow: 0 0 0 4px rgba(239,68,68,0.14); }

/* ── Buttons ── */
.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 14px;
  font: inherit;
  color: #fff;
  background: var(--accent);
  border: 1px solid rgba(59,130,246,0.45);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.16s, transform 0.16s;
}

.btn:hover, button:hover { filter: brightness(1.06); }
.btn:active, button:active { transform: translateY(1px); }

.btn.secondary, .btn-outline { color: var(--text); background: rgba(255,255,255,0.03); border-color: var(--border); }
.btn:disabled, button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ── Info grid (run detail) ── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.info-item { }
.info-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
.info-value { font-size: 15px; font-weight: 600; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: #0c0f15; }
::-webkit-scrollbar-thumb { background: #2b3142; border: 3px solid #0c0f15; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #3a4258; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .nav { padding: 12px 16px; }
  .container { padding: 16px; }
  .stats-bar, .card-grid, .info-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .nav { grid-template-columns: 1fr; grid-template-rows: auto auto auto; gap: 8px; }
  .nav .brand { justify-self: center; }
  .nav-links { justify-content: center; }
  .nav-right { justify-content: center; }
  .nav a { flex: 1 1 auto; }
  th, td { padding: 12px; }
  .log-container { max-height: 60vh; }
}

/* CLB-1821: Mobile strategy breakpoints */
@media (max-width: 768px) {
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .card-grid { grid-template-columns: 1fr 1fr; }
  .info-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .nav { padding: 10px 12px; }
  .container { padding: 12px; }
  .stat-value { font-size: 20px; }
  .btn { min-height: 40px; padding: 10px 12px; }
  .nav-links { flex-wrap: wrap; gap: 8px; }
}

/* CLB-1822: Offline indicator + sync status */
.offline-indicator {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: none;
  align-items: center;
  gap: 6px;
  background: #fbbf24;
  color: #111827;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

body.is-offline .offline-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-status {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

body.has-pending .sync-status {
  display: inline-flex;
}
