:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --critical: #ff4d4f;
  --high: #ff7a00;
  --medium: #f0c040;
  --low: #3fb950;
  --info: #58a6ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* DEV MODE ribbon — only rendered when NODE_ENV !== 'production' */
.dev-ribbon {
  position: fixed;
  top: 18px;
  right: -30px;
  background: #e53935;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 4px 40px;
  transform: rotate(45deg);
  z-index: 9999;
  pointer-events: none;
  text-transform: uppercase;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

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

/* Nav */
.topnav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand {
  font-weight: 700;
  font-size: 1.05em;
  color: var(--text);
  margin-right: 16px;
  flex-shrink: 0;
}
.nav-links { display: flex; gap: 2px; }
.nav-links a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.85em;
  transition: background .15s, color .15s;
}
.nav-links a:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.nav-username { color: var(--text-muted); font-size: 0.82em; white-space: nowrap; }

/* Page */
.page { max-width: 1400px; margin: 0 auto; padding: 24px 20px; }
.page-header { margin-bottom: 24px; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 1.5em; font-weight: 600; }
.subtitle { color: var(--text-muted); font-size: 0.9em; }
.total-badge { background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; padding: 2px 12px; font-size: 0.85em; color: var(--text-muted); }

/* Alerts */
.alert { padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-ok { background: rgba(63,185,80,.15); border: 1px solid var(--low); color: var(--low); }
.alert-err { background: rgba(255,77,79,.15); border: 1px solid var(--critical); color: var(--critical); }

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 16px;
  text-align: center;
  display: block;
  transition: border-color .2s, background .2s;
  text-decoration: none;
}
.stat-card:hover { border-color: var(--accent); background: var(--surface2); text-decoration: none; }
.stat-card.sev-crit { border-color: rgba(255,77,79,.4); }
.stat-icon { font-size: 1.8em; margin-bottom: 6px; }
.stat-num { font-size: 1.8em; font-weight: 700; color: var(--text); }
.stat-label { color: var(--text-muted); font-size: 0.8em; margin-top: 2px; }

/* Two column layout */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h2 { font-size: 0.95em; font-weight: 600; }
.panel > table { margin: 0; }

/* Bar charts */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.bar-row:last-child { border-bottom: none; }
.bar-label { width: 120px; flex-shrink: 0; font-size: 0.85em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .3s; }
.bar-count { width: 50px; text-align: right; font-size: 0.85em; color: var(--text-muted); }

/* Keyword cards */
.kw-card {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.kw-card:last-child { border-bottom: none; }
.kw-title { font-weight: 500; margin-bottom: 4px; }
.kw-body { color: var(--text-muted); font-size: 0.82em; line-height: 1.4; white-space: pre-line; word-break: break-all; }
.kw-date { color: var(--text-muted); font-size: 0.78em; margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--surface2);
  padding: 10px 12px;
  text-align: left;
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.date-cell { color: var(--text-muted); font-size: 0.85em; white-space: nowrap; }
.empty-state { text-align: center; color: var(--text-muted); padding: 32px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-critical, .badge-crit  { background: rgba(255,77,79,.2); color: var(--critical); border: 1px solid rgba(255,77,79,.4); }
.badge-high                   { background: rgba(255,122,0,.2); color: var(--high); border: 1px solid rgba(255,122,0,.4); }
.badge-medium, .badge-med     { background: rgba(240,192,64,.2); color: var(--medium); border: 1px solid rgba(240,192,64,.4); }
.badge-low, .badge-ok         { background: rgba(63,185,80,.2); color: var(--low); border: 1px solid rgba(63,185,80,.4); }
.badge-info, .badge-unknown, .badge-error { background: rgba(88,166,255,.15); color: var(--info); border: 1px solid rgba(88,166,255,.3); }
.badge-active                 { background: rgba(255,77,79,.2); color: var(--critical); border: 1px solid rgba(255,77,79,.4); }
.badge-incident, .badge-domain-detection { background: rgba(255,122,0,.2); color: var(--high); border: 1px solid rgba(255,122,0,.3); }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border: none;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88em;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82em;
  text-decoration: none;
  transition: border-color .15s, color .15s;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 0.9em;
  flex: 1;
  min-width: 200px;
}
.filter-input:focus { outline: none; border-color: var(--accent); }
.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 0.9em;
}

/* Pagination */
.pagination {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.page-info { color: var(--text-muted); font-size: 0.88em; }

/* Detail view */
.detail-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.detail-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.detail-row:last-child { border-bottom: none; }
.detail-key { color: var(--text-muted); font-size: 0.85em; font-weight: 500; text-transform: capitalize; padding-top: 2px; }
.detail-val { word-break: break-word; }
.pre-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: 'Courier New', monospace;
  font-size: 0.82em;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
  color: var(--text-muted);
}
.ext-link { display: inline-block; font-family: monospace; font-size: 0.85em; margin-bottom: 4px; }

/* Explorer */
.explorer-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  height: calc(100vh - 160px);
}
.explorer-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.explorer-search { padding: 10px; border-bottom: 1px solid var(--border); }
.ep-group {
  padding: 8px 12px 4px;
  font-size: 0.72em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.ep-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background .1s;
  color: var(--text);
}
.ep-item:hover, .ep-item.active { background: var(--surface2); }
.ep-method { font-size: 0.7em; font-weight: 700; padding: 2px 6px; border-radius: 3px; flex-shrink: 0; }
.ep-method.get { background: rgba(63,185,80,.2); color: var(--low); }
.ep-method.post { background: rgba(88,166,255,.2); color: var(--info); }
.ep-path { font-family: monospace; font-size: 0.82em; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explorer-main { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.explorer-url-bar { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.ep-method-badge { padding: 4px 10px; border-radius: 4px; font-size: 0.8em; font-weight: 700; flex-shrink: 0; }
.ep-method-badge.get { background: rgba(63,185,80,.2); color: var(--low); }
.ep-method-badge.post { background: rgba(88,166,255,.2); color: var(--info); }
.url-input { flex: 1; background: none; border: none; color: var(--text); font-family: monospace; font-size: 0.9em; }
.url-input:focus { outline: none; }
.param-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; margin-bottom: 8px; }
.param-label { display: flex; flex-direction: column; gap: 2px; }
.param-name { font-weight: 600; font-size: 0.9em; }
.param-desc { color: var(--text-muted); font-size: 0.8em; }
.resp-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.resp-header h3 { flex: 1; }
.resp-pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Courier New', monospace;
  font-size: 0.82em;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 500px;
  overflow-y: auto;
  color: #8b949e;
}

/* Token expiry warning in nav */
.token-expiry-badge { border-radius: 4px; padding: 2px 8px; font-size: 0.8em; font-weight: 700; letter-spacing: 0.3px; }
.token-warn   { background: #ffc107; color: #000 !important; }
.token-critical { background: #dc3545; color: #fff !important; }

/* Alert variants */
.alert-ok  { background: rgba(63,185,80,0.15); border: 1px solid #3fb950; color: #3fb950; border-radius: 8px; padding: 12px 16px; margin-bottom: 1rem; }
.alert-err { background: rgba(220,53,69,0.15); border: 1px solid #dc3545; color: #f85149; border-radius: 8px; padding: 12px 16px; margin-bottom: 1rem; }
