/* ═══════════════════════════════════════════════════════════════
   CORTEX BIBLE — DESIGN SYSTEM v3 — NE PAS MODIFIER PAR LES WORKERS
   Bloomberg-warm aesthetic — beige palette, zero blue
   ═══════════════════════════════════════════════════════════════ */

/* ── RESET ──────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── DESIGN TOKENS ──────────────────────────────────────────── */
:root {
  /* Core palette */
  --bg:           #f0ece6;
  --bg-deep:      #ebe5dd;
  --surface:      #e8e2da;
  --surface-hi:   #ede8e1;
  --card:         #f7f3ee;
  --card-hi:      #faf6f1;
  --border:       #d4cec4;
  --border-soft:  #ddd8ce;

  /* Accent — gold/brown family only */
  --accent:       #8a6840;
  --accent2:      #a07848;
  --accent3:      #6a5030;
  --accent-dim:   rgba(138,104,64,0.08);
  --accent-glow:  rgba(138,104,64,0.18);
  --accent-glass: rgba(138,104,64,0.06);

  /* Status colors — warm, no blue */
  --green:        #3d8c45;
  --green-dim:    rgba(61,140,69,0.12);
  --red:          #c04040;
  --red-dim:      rgba(192,64,64,0.10);
  --orange:       #b07030;
  --orange-dim:   rgba(176,112,48,0.12);
  --yellow:       #a09020;
  --yellow-dim:   rgba(160,144,32,0.12);

  /* Text */
  --text:         #2a2420;
  --text-dim:     #8a8478;
  --text-faint:   #b0a898;

  /* Semantic aliases */
  --gold:         var(--accent);
  --warm:         var(--accent2);

  /* Shadows */
  --shadow-xs:    0 1px 3px rgba(42,36,32,0.06);
  --shadow-sm:    0 2px 8px rgba(42,36,32,0.08), 0 1px 3px rgba(42,36,32,0.05);
  --shadow-md:    0 4px 16px rgba(42,36,32,0.10), 0 2px 6px rgba(42,36,32,0.06);
  --shadow-card:  0 2px 12px rgba(42,36,32,0.07), 0 1px 4px rgba(42,36,32,0.05);

  /* Radii */
  --r-sm:         6px;
  --r-md:         10px;
  --r-lg:         14px;

  /* Transitions */
  --t-fast:       0.12s ease;
  --t-mid:        0.22s ease;
  --t-slow:       0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── BASE ───────────────────────────────────────────────────── */
body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(138,104,64,0.06), transparent);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui,
               'Helvetica Neue', Arial, sans-serif;
  font-size: 13px;
  line-height: 1.55;
  min-height: 100vh;
}

/* Monospace for data/code contexts */
code, pre, .mono,
.gpu-bar-label, table, th, td,
.badge, .dot + * {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code',
               Consolas, 'Courier New', monospace;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

/* ── SCROLLBARS ─────────────────────────────────────────────── */
::-webkit-scrollbar           { width: 6px; height: 6px; }
::-webkit-scrollbar-track     { background: transparent; }
::-webkit-scrollbar-thumb     { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ── KEYFRAMES ──────────────────────────────────────────────── */
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

@keyframes breathe-glow {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 4px currentColor); }
  50%       { opacity: 0.5; filter: drop-shadow(0 0 1px currentColor); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.35); opacity: 0.7; }
}

@keyframes score-in {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── HEADER ─────────────────────────────────────────────────── */
.header {
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-hi) 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent2), transparent);
  opacity: 0.5;
}

.header h1 {
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 4px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  text-transform: uppercase;
  position: relative;
}

.header h1::before {
  content: '◈ ';
  font-size: 12px;
  opacity: 0.6;
}

.score-wrap {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.score {
  font-size: 32px;
  font-weight: 800;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1;
  animation: score-in 0.5s ease both;
  letter-spacing: -1px;
}

.score-wrap #gen-at {
  font-size: 9px;
  color: var(--text-faint);
  font-family: 'JetBrains Mono', monospace;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── NAV ────────────────────────────────────────────────────── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  position: sticky;
  top: 0;
  z-index: 100;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  box-shadow: 0 2px 8px rgba(42,36,32,0.06);
}

nav::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--border) 20%, var(--border) 80%, transparent 100%);
}

/* Hide scrollbar on webkit for nav */
nav::-webkit-scrollbar { height: 3px; }
nav::-webkit-scrollbar-thumb { background: var(--border-soft); }

nav button {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
  padding: 6px 13px;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.5px;
  border-radius: var(--r-sm);
  transition: all var(--t-fast);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

nav button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent-dim);
  opacity: 0;
  transition: opacity var(--t-fast);
  border-radius: inherit;
}

nav button:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}

nav button.active {
  color: var(--card);
  background: var(--accent);
  border-color: var(--accent3);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(138,104,64,0.3);
  transform: translateY(-1px);
}

/* Special tab styles — override inline styles from HTML */
nav button.tab-audit,
nav button[data-panel="audit"] {
  background: var(--accent) !important;
  color: var(--bg) !important;
  border-color: var(--accent3) !important;
  font-weight: 700 !important;
}

nav button.tab-next,
nav button[data-panel="revolution"],
nav button[data-panel="todo"] {
  background: var(--accent3) !important;
  color: var(--bg) !important;
  border-color: #3a2a14 !important;
  font-weight: 700 !important;
}

nav button[data-panel="research"],
nav button[data-panel="ecosystem"] {
  background: #3d6e30 !important;
  color: var(--bg) !important;
  border-color: #2d5020 !important;
  font-weight: 700 !important;
}

nav button[data-panel="mini"],
nav button[data-panel="users"] {
  background: var(--accent) !important;
  color: var(--bg) !important;
  font-weight: 700 !important;
}

nav button[data-panel="errors"] {
  background: #8c2828 !important;
  color: var(--bg) !important;
  border-color: #6a1e1e !important;
  font-weight: 700 !important;
}

/* Active state overrides */
nav button.active[data-panel="revolution"],
nav button.active[data-panel="todo"] {
  background: #3a2a14 !important;
  box-shadow: 0 2px 8px rgba(74,53,32,0.35) !important;
}
nav button.active[data-panel="research"],
nav button.active[data-panel="ecosystem"] {
  background: #2d5020 !important;
  box-shadow: 0 2px 8px rgba(45,80,32,0.35) !important;
}
nav button.active[data-panel="errors"] {
  background: #6a1e1e !important;
  box-shadow: 0 2px 8px rgba(140,40,40,0.35) !important;
}

/* Nav right links */
nav .nav-right {
  margin-left: auto;
  padding-left: 12px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
  border-left: 1px solid var(--border-soft);
}

nav .nav-right a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  padding: 5px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  transition: all var(--t-fast);
  white-space: nowrap;
}

nav .nav-right a:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
  transform: translateY(-1px);
}

/* ── PANELS ─────────────────────────────────────────────────── */
.panel {
  display: none;
  padding: 16px 20px 24px;
}

.panel.active {
  display: block;
  animation: slideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* ── GRID ───────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

/* ── CARDS ──────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  position: relative;
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--t-mid), transform var(--t-mid), border-color var(--t-fast);
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent2) 50%, transparent 100%);
  opacity: 0.7;
}

.card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    145deg,
    rgba(255,252,248,0.6) 0%,
    transparent 60%
  );
  pointer-events: none;
  border-radius: inherit;
}

.card:hover {
  border-color: var(--border-soft);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card h3 {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
  position: relative;
  z-index: 1;
}

.card .meta {
  color: var(--text-faint);
  font-size: 9px;
  margin-top: 10px;
  border-top: 1px solid var(--border-soft);
  padding-top: 6px;
  font-family: 'JetBrains Mono', monospace;
  position: relative;
  z-index: 1;
}

/* Card inner content above the ::after overlay */
.card > *:not(.card::before):not(.card::after) {
  position: relative;
  z-index: 1;
}

/* Glassmorphism variant for special cards */
.card-glass {
  background: rgba(247, 243, 238, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-color: rgba(212, 206, 196, 0.6);
}

/* ── STATUS INDICATORS ──────────────────────────────────────── */
.live {
  color: var(--green);
  font-size: 11px;
  animation: breathe-glow 3s ease-in-out infinite;
}

.proved {
  color: var(--green);
  font-size: 11px;
  animation: breathe-glow 4s ease-in-out infinite;
}

.dead {
  color: var(--red);
  font-size: 11px;
}

.stale {
  color: var(--orange);
  font-size: 11px;
  animation: breathe 2s ease-in-out infinite;
}

.unproved {
  color: var(--red);
  font-size: 11px;
}

/* ── BADGES ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.4;
  text-transform: uppercase;
}

.badge.ok {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(61,140,69,0.2);
}

.badge.err {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(192,64,64,0.2);
}

.badge.warn {
  background: var(--orange-dim);
  color: var(--orange);
  border: 1px solid rgba(176,112,48,0.2);
}

.badge.dim {
  background: rgba(138,132,120,0.10);
  color: var(--text-dim);
  border: 1px solid rgba(138,132,120,0.18);
}

/* ── DOTS (status indicators) ───────────────────────────────── */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}

.dot.on {
  background: var(--green);
  box-shadow: 0 0 0 2px var(--green-dim), 0 0 6px rgba(61,140,69,0.5);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

.dot.off {
  background: var(--red);
  box-shadow: 0 0 0 2px var(--red-dim);
}

/* ── GPU BARS ───────────────────────────────────────────────── */
.gpu-bar {
  margin: 6px 0;
}

.gpu-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 3px;
  font-family: 'JetBrains Mono', monospace;
  gap: 8px;
}

.gpu-bar-label span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  color: var(--text);
}

.gpu-bar-label span:last-child {
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 9px;
}

.gpu-bar-track {
  background: var(--surface);
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  position: relative;
}

.gpu-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent3), var(--accent2));
  border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.gpu-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: rgba(255,255,255,0.2);
  border-radius: inherit;
}

.gpu-bar-fill.hot {
  background: linear-gradient(90deg, var(--orange), var(--red));
  box-shadow: 0 0 8px rgba(192,64,64,0.4);
}

/* ── TABLES ─────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

th {
  text-align: left;
  color: var(--text-dim);
  padding: 5px 8px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.8px;
  white-space: nowrap;
  background: var(--card);
}

td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  line-height: 1.4;
}

/* Alternating row colors — beige tones */
tbody tr:nth-child(even) td {
  background: rgba(232, 226, 218, 0.35);
}

tbody tr:hover td {
  background: var(--accent-dim);
  transition: background var(--t-fast);
}

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

/* ── BUG SEVERITY BORDERS ───────────────────────────────────── */
.bug-critical {
  border-left: 3px solid var(--red);
  padding-left: 8px !important;
}

.bug-high {
  border-left: 3px solid var(--orange);
  padding-left: 8px !important;
}

.bug-medium {
  border-left: 3px solid var(--yellow);
  padding-left: 8px !important;
}

.bug-low {
  border-left: 3px solid var(--border);
  padding-left: 8px !important;
}

/* ── LOADING SKELETONS ──────────────────────────────────────── */
@keyframes skeleton-shine {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface-hi) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shine 1.5s ease-in-out infinite;
  border-radius: var(--r-sm);
  display: block;
}

/* Replace "Loading..." text with skeleton automatically */
.panel .grid:empty::before,
.panel > p:only-child:not([class]) {
  content: '';
  display: block;
  height: 16px;
  width: 60%;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface-hi) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shine 1.5s ease-in-out infinite;
}

/* Style the "Loading..." text that JS generates */
p[style*="text-dim"] {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  font-size: 11px;
}

p[style*="text-dim"]::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* ── SCORE DISPLAY (large in audit card) ────────────────────── */
.card [style*="font-size:28px"],
.card [style*="font-size: 28px"] {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif !important;
  font-weight: 800 !important;
  letter-spacing: -0.5px;
  line-height: 1;
}

/* ── ROADMAP PHASE BARS ─────────────────────────────────────── */
.gpu-bar-track[style*="height:6px"] {
  height: 6px !important;
  border-radius: 99px;
}

/* ── FLEX STAT BOXES (audit card) ───────────────────────────── */
.card [style*="display:flex"][style*="gap:24px"],
.card [style*="display: flex"][style*="gap: 24px"] {
  gap: 20px !important;
  flex-wrap: wrap;
  padding: 8px 0;
}

.card [style*="text-align:center"] {
  background: var(--accent-dim);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: 12px 16px;
  min-width: 80px;
  flex: 1;
  transition: all var(--t-fast);
}

.card [style*="text-align:center"]:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}

/* ── INLINE PROGRESS PHASE ROWS ─────────────────────────────── */
.card [style*="display:flex"][style*="align-items:center"][style*="border-bottom"],
.card [style*="display: flex"][style*="align-items: center"][style*="border-bottom"] {
  padding: 5px 2px !important;
  gap: 10px !important;
  transition: background var(--t-fast);
  border-radius: 4px;
}

.card [style*="display:flex"][style*="align-items:center"][style*="border-bottom"]:hover,
.card [style*="display: flex"][style*="align-items: center"][style*="border-bottom"]:hover {
  background: var(--accent-dim);
  padding-left: 6px !important;
}

/* ── ISSUE / ALERT ROWS ─────────────────────────────────────── */
.card [style*="padding:4px 0"][style*="border-bottom"],
.card [style*="padding: 4px 0"][style*="border-bottom"] {
  padding: 7px 4px !important;
  border-radius: 4px;
  transition: background var(--t-fast);
}

.card [style*="padding:4px 0"][style*="border-bottom"]:hover {
  background: var(--accent-dim);
}

/* ── LINKS ──────────────────────────────────────────────────── */
a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--t-fast), opacity var(--t-fast);
}

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

/* ── MISC UTILITY ───────────────────────────────────────────── */
hr {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 10px 0;
}

p {
  font-size: 11px;
  line-height: 1.5;
}

/* Inline styles that JS generates — font-size:10px paragraphs */
p[style*="font-size:10px"],
p[style*="font-size: 10px"] {
  font-size: 10px !important;
  line-height: 1.45;
  margin: 3px 0;
}

/* Small meta text */
[style*="font-size:9px"],
[style*="font-size: 9px"] {
  font-size: 9px !important;
  color: var(--text-faint);
  letter-spacing: 0.3px;
}

/* ── RESPONSIVE — MOBILE ────────────────────────────────────── */
@media (max-width: 768px) {
  .header {
    padding: 10px 14px;
    gap: 8px;
  }

  .header h1 {
    font-size: 13px;
    letter-spacing: 2px;
  }

  .header h1::before {
    display: none;
  }

  .score {
    font-size: 26px;
  }

  nav {
    padding: 6px 10px;
    gap: 3px;
  }

  nav button {
    padding: 5px 10px;
    font-size: 10px;
  }

  .panel {
    padding: 10px 12px 18px;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .card {
    padding: 12px;
    border-radius: var(--r-sm);
  }

  table {
    font-size: 10px;
  }

  th, td {
    padding: 4px 6px;
  }

  .card [style*="text-align:center"] {
    min-width: 60px;
    padding: 8px 10px;
  }
}

@media (max-width: 480px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .score-wrap {
    align-items: flex-start;
    flex-direction: row;
    gap: 6px;
    align-items: baseline;
  }

  .score {
    font-size: 22px;
  }

  nav .nav-right {
    display: none;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}

/* ── PRINT ──────────────────────────────────────────────────── */
@media print {
  nav { display: none; }
  .panel { display: block !important; }
  .card { break-inside: avoid; box-shadow: none; }
  .card::after { display: none; }
}
