/* ═══════════════════════════════════════════════════════════════════════════
   Crash Analyzer — Dark Tactical Dashboard
   Design: Military-green accent, deep-black glass, Inter + JetBrains Mono
   ═══════════════════════════════════════════════════════════════════════════ */

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

:root {
  --bg0:         #0a0c0e;
  --bg1:         #111417;
  --bg2:         #181c20;
  --bg3:         #1f2428;
  --surface:     rgba(255,255,255,.04);
  --surface-hov: rgba(255,255,255,.07);
  --border:      rgba(255,255,255,.08);

  --accent:      #39d353;   /* military green */
  --accent-dim:  #1f7a2e;
  --accent-glow: rgba(57,211,83,.18);

  --red:         #ff4444;
  --red-dim:     rgba(255,68,68,.18);
  --yellow:      #f5c842;
  --yellow-dim:  rgba(245,200,66,.15);
  --blue:        #4fa3e0;
  --grey:        #5a6270;

  --text0:       #e8eaed;
  --text1:       #9aa0aa;
  --text2:       #5a6270;

  --mono:        'JetBrains Mono', monospace;
  --sans:        'Inter', system-ui, sans-serif;

  --sidebar-w:   220px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.5);

  --transition:  180ms ease;
}

html, body {
  height: 100%;
  background: var(--bg0);
  color: var(--text0);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
body { display: flex; }

#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

#main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-icon {
  font-size: 22px;
  color: var(--accent);
  filter: drop-shadow(0 0 6px var(--accent));
}
.brand-title { font-weight: 700; font-size: 13px; color: var(--text0); }
.brand-sub   { font-size: 11px; color: var(--text2); }

.nav-links { list-style: none; padding: 12px 8px; flex: 1; }
.nav-links li { margin-bottom: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text1);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: var(--surface-hov); color: var(--text0); }
.nav-link.active {
  background: var(--accent-glow);
  color: var(--accent);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  font-size: 12px;
  color: var(--text2);
  border-top: 1px solid var(--border);
}
.connection-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--grey);
  flex-shrink: 0;
  transition: background .4s, box-shadow .4s;
}
.connection-dot.ok  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.connection-dot.err { background: var(--red);    box-shadow: 0 0 6px var(--red); }

/* ── Top bar ──────────────────────────────────────────────────────────────── */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#top-bar h1 { font-size: 20px; font-weight: 700; }
#last-updated { font-size: 12px; color: var(--text2); }

/* ── Views ────────────────────────────────────────────────────────────────── */
.view { display: none; flex-direction: column; gap: 20px; }
.view.active { display: flex; }

/* ── Server cards ─────────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.server-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.server-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--transition);
}
.server-card:hover { border-color: rgba(255,255,255,.14); box-shadow: var(--shadow); }
.server-card:hover::before { opacity: 1; }
.server-card.status-crashed  { border-color: var(--red); }
.server-card.status-crashed::before { background: var(--red); opacity: 1; }
.server-card.status-online::before  { background: var(--accent); opacity: 1; }

.card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.card-name { font-weight: 600; font-size: 14px; }
.card-node { font-size: 11px; color: var(--text2); margin-top: 2px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge-online       { background: rgba(57,211,83,.15); color: var(--accent); }
.badge-crashed      { background: var(--red-dim);      color: var(--red); animation: pulse-red 1.4s infinite; }
.badge-offline,
.badge-stopped      { background: rgba(90,98,112,.2);  color: var(--grey); }
.badge-connecting,
.badge-disconnected { background: rgba(245,200,66,.12); color: var(--yellow); }

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,68,68,.4); }
  50%       { box-shadow: 0 0 0 5px rgba(255,68,68,0); }
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.card-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric-label { font-size: 11px; color: var(--text2); }
.metric-value { font-size: 18px; font-weight: 700; font-family: var(--mono); color: var(--text0); }
.metric-value.crit { color: var(--red); }

.progress-wrap { margin-top: 10px; }
.progress-bar {
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .6s ease;
}
.progress-fill.warn { background: var(--yellow); }
.progress-fill.crit { background: var(--red); }
.progress-label { font-size: 11px; color: var(--text2); margin-top: 4px; }

/* ── Section heading ──────────────────────────────────────────────────────── */
.section-heading {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text2);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Crash list ───────────────────────────────────────────────────────────── */
.crash-list { display: flex; flex-direction: column; gap: 6px; }

.crash-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.crash-item:hover { background: var(--surface-hov); border-color: rgba(255,255,255,.13); }
.crash-icon { font-size: 18px; flex-shrink: 0; }
.crash-meta { flex: 1; min-width: 0; }
.crash-server { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crash-time   { font-size: 11px; color: var(--text2); font-family: var(--mono); }
.crash-view-btn { font-size: 11px; color: var(--accent); white-space: nowrap; }

.empty-state { color: var(--text2); font-size: 13px; padding: 20px 0; text-align: center; }

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input, .select-input {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text0);
  padding: 7px 12px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.search-input { flex: 1; min-width: 160px; }
.search-input:focus, .select-input:focus { border-color: var(--accent); }

.btn-primary {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
}
.btn-primary:hover { background: #28602e; box-shadow: 0 0 12px var(--accent-glow); }

.btn-ghost {
  background: transparent;
  color: var(--text1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.btn-ghost:hover { background: var(--surface-hov); color: var(--text0); }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text1);
  cursor: pointer;
  user-select: none;
}
.toggle-label input { accent-color: var(--accent); }

/* ── Report viewer ────────────────────────────────────────────────────────── */
.report-viewer {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 640px;
}
.report-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.report-title-label { font-size: 12px; color: var(--text1); font-family: var(--mono); }
.report-content {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  color: var(--text0);
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  white-space: pre;
}
.report-content .line-crit { color: var(--red); }
.report-content .line-sus  { color: var(--yellow); }
.report-content .line-ok   { color: var(--accent); }

.hidden { display: none !important; }

/* ── Pattern view ─────────────────────────────────────────────────────────── */
.server-selector-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.selector-label { font-size: 13px; color: var(--text1); }

.stats-row { display: flex; gap: 14px; flex-wrap: wrap; }
.stat-pill {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 100px;
}
.stat-pill-value { font-size: 24px; font-weight: 700; font-family: var(--mono); color: var(--text0); }
.stat-pill-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }

/* ── Mod attribution table ────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-hov); }
tbody td { padding: 9px 14px; }
.td-mod  { font-weight: 600; color: var(--accent); font-family: var(--mono); }
.td-comp { font-size: 12px; color: var(--text1); font-family: var(--mono); }
.td-cnt  { font-family: var(--mono); }
.td-bar  { width: 120px; }
.bar-fill { height: 6px; background: var(--accent); border-radius: 3px; }
.rank-1 .td-mod { color: var(--red); }
.rank-2 .td-mod, .rank-3 .td-mod { color: var(--yellow); }

/* ── Charts ───────────────────────────────────────────────────────────────── */
.patterns-charts { display: none; }   /* shown by JS only when crash data exists */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 960px) { .two-col { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chart-title { font-size: 13px; font-weight: 600; color: var(--text1); margin-bottom: 12px; }

/* ── Console ──────────────────────────────────────────────────────────────── */
.console-output {
  flex: 1;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  height: calc(100vh - 180px);
}
.console-line { display: flex; gap: 10px; padding: 1px 0; }
.console-tier {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  align-self: flex-start;
  margin-top: 2px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.tier-CRITICAL { background: var(--red-dim);    color: var(--red); }
.tier-SUSPECT  { background: var(--yellow-dim); color: var(--yellow); }
.tier-BENIGN   { background: rgba(57,211,83,.1); color: var(--accent); }
.tier-UNKNOWN  { background: transparent; color: var(--text2); }
.console-text  { color: var(--text0); word-break: break-all; }
.console-line.tier-CRITICAL .console-text { color: #ff8888; }
.console-line.tier-SUSPECT  .console-text { color: #f5e28a; }

/* ── Scrollbars ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar              { width: 6px; height: 6px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: var(--bg3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover  { background: var(--grey); }
