/* ============================================================
   Ephemeral Sentinel — main stylesheet
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --bg:          #070c18;
  --bg-surface:  #0d1829;
  --bg-card:     #111f35;
  --bg-input:    #0d1829;
  --border:      #1e3350;
  --accent:      #2b7de9;
  --accent-dim:  #1a5fc4;
  --accent-cyan: #00c8e8;
  --text:        #e8f0fe;
  --text-muted:  #8faebf;
  --safe:        #22d3a0;
  --suspicious:  #f59e0b;
  --malicious:   #ef4444;
  --radius:      10px;
  --font:        'Inter', system-ui, sans-serif;
  --mono:        'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
  --shadow-glow: 0 0 40px rgba(43,125,233,0.10);
  --shadow-card: 0 4px 24px rgba(0,0,0,0.3);
}

html { font-size: 16px; }
body {
  background: radial-gradient(ellipse 90% 50% at 50% 0%, rgba(43,125,233,0.10) 0%, transparent 70%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(30,51,80,0.25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30,51,80,0.25) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 100% 50% at 50% 0%, black, transparent);
  pointer-events: none;
  z-index: 0;
}
main, header, footer { position: relative; z-index: 1; }

/* ---- Header ---- */
header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 2rem;
  box-shadow: 0 1px 0 rgba(43,125,233,0.15);
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-size: 1.2rem; font-weight: 700; letter-spacing: .02em; }
.version { color: var(--text-muted); font-size: 0.8rem; }

/* ---- Main ---- */
main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ---- Input panel ---- */
.input-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-glow), var(--shadow-card);
}
.input-panel h2 { font-size: 1.1rem; margin-bottom: 0.3rem; }
.hint { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1rem; }
code { font-family: var(--mono); background: var(--bg-input); border: 1px solid var(--border); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.85em; }

/* Tabs */
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tab, .az-subtab {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all .15s;
}
.tab.active, .tab:hover,
.az-subtab.active, .az-subtab:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Tab panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }
#tab-analyse.tab-panel.active { display: flex; flex-direction: column; gap: 1rem; }

/* Textarea */
textarea {
  width: 100%;
  min-height: 220px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.75rem;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
textarea:focus { border-color: var(--accent); }

/* Actions */
.actions { display: flex; gap: 0.75rem; margin-top: 0.75rem; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }

/* Drop zone */
.drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  cursor: pointer;
  text-align: center;
  color: var(--text-muted);
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: #112040;
  color: var(--text);
}
.drop-label { font-size: 0.9rem; }
.file-name { margin-top: 0.5rem; font-size: 0.8rem; color: var(--accent); font-family: var(--mono); }

/* ---- Spinner ---- */
.spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-muted);
  padding: 1.5rem;
}
.spin-ring {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Verdict banner ---- */
.verdict-banner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
}
.verdict-banner.safe     { border-color: var(--safe);       background: #071a14; }
.verdict-banner.suspicious { border-color: var(--suspicious); background: #1a1200; }
.verdict-banner.malicious  { border-color: var(--malicious);  background: #1a0606; }

.verdict-icon { font-size: 2rem; }
.verdict-label { font-size: 1.3rem; font-weight: 700; text-transform: capitalize; }
.verdict-score { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.15rem; }
.confidence-badge {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.3rem 0.75rem;
  white-space: nowrap;
}

.summary-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding: 0.25rem 0;
}

/* ---- Signal columns ---- */
.signal-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) { .signal-columns { grid-template-columns: 1fr; } }
.signal-col h3 { font-size: 0.85rem; margin-bottom: 0.6rem; color: var(--text-muted); }
.signal-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }
.signal-list li {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  line-height: 1.4;
}
.signal-list li .sig-id {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}
.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 5px;
  vertical-align: middle;
}
.badge-low  { background: #052e1e; color: var(--safe); }
.badge-medium { background: #3a2800; color: var(--suspicious); }
.badge-high { background: #3a0a0a; color: var(--malicious); }
.badge-mitigated { background: #0d1e3a; color: var(--accent-cyan); cursor: help; }
.empty-list { color: var(--text-muted); font-size: 0.8rem; padding: 0.25rem 0; font-style: italic; }

/* Metadata reliability badge variants */
.reliability-high   { color: var(--safe); }
.reliability-medium { color: var(--suspicious); }
.reliability-low    { color: var(--malicious); }

/* Suppressed URL details */
.url-suppressed-details {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.url-suppressed-details summary { cursor: pointer; padding: 0.25rem 0; }

/* Admin config grid */
.cfg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.75rem;
}
@media (max-width: 700px) { .cfg-grid { grid-template-columns: 1fr; } }
.cfg-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.cfg-fieldset legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 0.4rem;
}
.cfg-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  outline: none;
  transition: border-color .15s;
}
.cfg-input:focus { border-color: var(--accent); }
.cfg-textarea { resize: vertical; min-height: 60px; width: 100%; }
select.cfg-input { width: 100%; }

/* Print / PDF export */
@media print {
  header, footer, .input-panel, .spinner, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .results { display: flex !important; }
  .verdict-banner { border: 2px solid #000; background: #f9f9f9 !important; }
  .verdict-banner.safe     { border-color: #22c55e; }
  .verdict-banner.suspicious { border-color: #f59e0b; }
  .verdict-banner.malicious  { border-color: #ef4444; }
  .detail-section { border: 1px solid #ccc; page-break-inside: avoid; }
  .detail-section[open] > div, details > div { display: block !important; }
  details { open: true; }
  .signal-list li { background: #f4f4f4; border: 1px solid #ddd; }
  .url-table th, .url-table td { border-color: #ccc; }
  .kv-key, .kv-val { color: #333; }
  .badge-high { background: #fee2e2; color: #b91c1c; }
  .badge-medium { background: #fef3c7; color: #92400e; }
  .badge-low { background: #dcfce7; color: #166534; }
  .badge-mitigated { background: #dbeafe; color: #1d4ed8; }
  .confidence-badge { border: 1px solid #ccc; color: #333; }
  a { color: inherit; text-decoration: none; }
}

/* ---- Detail sections ---- */
.detail-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.detail-section summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  -webkit-user-select: none;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.detail-section summary::-webkit-details-marker { display: none; }
.detail-section summary::before {
  content: '›';
  font-size: 1rem;
  transition: transform .15s;
  display: inline-block;
}
.detail-section[open] summary::before { transform: rotate(90deg); }
.detail-section > div { padding: 0 1rem 1rem; }

/* KV grid for header details */
.kv-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  font-size: 0.8rem;
}
.kv-key { color: var(--text-muted); font-family: var(--mono); }
.kv-val { font-family: var(--mono); word-break: break-all; }
.pass  { color: var(--safe); }
.fail  { color: var(--malicious); }
.softfail { color: var(--suspicious); }
.unknown  { color: var(--text-muted); }

/* URL table */
.url-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; margin-top: 0.5rem; }
.url-table th, .url-table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.url-table th { color: var(--text-muted); font-weight: 600; }
.url-table td { font-family: var(--mono); word-break: break-all; }
.flag-risky { color: var(--malicious); }
.flag-clean { color: var(--safe); }

/* Error box */
.error-box {
  background: #1a0606;
  border: 1px solid var(--malicious);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  color: #f87171;
  font-size: 0.875rem;
}

/* ---- Footer ---- */
footer {
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
footer a { color: var(--accent); text-decoration: none; }

/* Utility */
.hidden { display: none !important; }
.results { display: flex; flex-direction: column; gap: 1rem; }

/* ---- Header API key field ---- */
.header-right { display: flex; align-items: center; gap: 1rem; }
.api-key-field { display: flex; align-items: center; gap: 0.5rem; }
.api-key-field label { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; }
.api-key-field input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  width: 180px;
  outline: none;
  transition: border-color .15s;
}
.api-key-field input:focus { border-color: var(--accent); }

/* ---- Admin page ---- */
.admin-auth-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.5rem;
}
.admin-auth-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.45rem 0.75rem;
  outline: none;
  transition: border-color .15s;
}
.admin-auth-row input:focus { border-color: var(--accent); }
.auth-status { margin-top: 0.5rem; font-size: 0.8rem; min-height: 1.2em; }
.auth-status-ok    { color: var(--safe); }
.auth-status-error { color: var(--malicious); }
.new-key-box {
  margin-top: 1rem;
  background: #071a10;
  border: 1px solid var(--safe);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
.new-key-box p { font-size: 0.8rem; color: var(--suspicious); margin-bottom: 0.5rem; }
.new-key-row { display: flex; align-items: center; gap: 0.75rem; }
.new-key-value {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.8rem;
  word-break: break-all;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  display: block;
  color: var(--safe);
}
.admin-keys-table td { vertical-align: middle; }
.status-active   { color: var(--safe);       font-weight: 600; font-size: 0.8rem; }
.status-inactive { color: var(--text-muted); font-size: 0.8rem; }
.btn-revoke {
  font-size: 0.75rem !important;
  padding: 0.25rem 0.6rem !important;
  color: var(--malicious) !important;
  border-color: var(--malicious) !important;
}
.btn-revoke:hover { background: #1a0606 !important; }
.mono { font-family: var(--mono); }

/* ══════════════════════════════════════════════════════════════
   Admin UI — workstream 01 additions
   ══════════════════════════════════════════════════════════════ */

/* ── Dashboard view toggle ── */
.dash-toggle-btn {
  background: transparent;
  border: none;
  padding: 6px 18px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dash-toggle-btn:hover { background: var(--bg-input); color: var(--text); }
.dash-toggle-btn.active { background: var(--accent); color: #fff; }

/* ── Dashboard summary tiles ── */
.dash-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.dash-tile {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 0.75rem;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
  font-family: inherit;
  color: var(--text);
}
.dash-tile:hover { border-color: var(--accent); background: #112040; }
.dash-tile-icon { font-size: 1.4rem; line-height: 1; }
.dash-tile-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.dash-tile-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.15rem;
}

/* ── Signal checkbox grid ── */
.signal-category-header {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0.75rem 0 0.35rem;
}
.signal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.3rem;
}
.signal-check-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
}
.signal-check-item:hover { border-color: #2b5080; }
.signal-check-item input[type="checkbox"] {
  margin-top: 3px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.signal-check-item label { cursor: pointer; line-height: 1.3; flex: 1; }
.signal-check-id {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  display: block;
}
.signal-check-desc { font-size: 0.72rem; color: var(--text); }
.signal-check-score {
  font-size: 0.65rem;
  font-family: var(--mono);
  font-weight: 700;
  white-space: nowrap;
  padding: 1px 5px;
  border-radius: 4px;
  margin-top: 2px;
}
.score-pos { background: #3a0a0a; color: #f87171; }
.score-neg { background: #052e1e; color: #4ade80; }
.score-zero { background: var(--bg-surface); color: var(--text-muted); }

/* ── Correlation rules ── */
.corr-rule-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.5rem 0; }
.corr-rule-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.corr-rule-info { flex: 1; min-width: 0; }
.corr-rule-id { font-family: var(--mono); font-size: 0.7rem; color: var(--text-muted); }
.corr-rule-desc { font-size: 0.78rem; color: var(--text); margin: 2px 0; }
.corr-rule-triggers {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: var(--mono);
  word-break: break-all;
}
.corr-rule-bonus {
  font-size: 0.75rem;
  color: var(--suspicious);
  font-weight: 700;
  white-space: nowrap;
  align-self: center;
}
.corr-rule-actions { display: flex; gap: 0.35rem; align-self: center; }
.btn-sm {
  font-size: 0.72rem !important;
  padding: 0.2rem 0.5rem !important;
}
.corr-rule-form {
  background: var(--bg-input);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 0.75rem;
}
.corr-rule-form h4 { font-size: 0.85rem; margin-bottom: 0.75rem; color: var(--accent); }
.form-row { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.6rem; }
.form-row label { font-size: 0.75rem; color: var(--text-muted); }
.form-row input[type="text"],
.form-row input[type="number"],
.form-row select { width: 100%; }
select[multiple].cfg-input { min-height: 130px; font-size: 0.75rem; }

/* ── History tab ── */
.history-filters {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.history-filters select { width: auto; min-width: 120px; }
.history-filters input[type="text"] { min-width: 0; }
th.sortable { cursor: pointer; -webkit-user-select: none; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--accent); }
th.sort-active { color: var(--accent); }
.sort-ind { font-size: 0.65rem; margin-left: 3px; opacity: 0.7; }
.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.verdict-safe      { color: var(--safe);       font-weight: 600; }
.verdict-suspicious{ color: var(--suspicious);  font-weight: 600; }
.verdict-malicious { color: var(--malicious);   font-weight: 600; }
.no-db-notice {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.no-db-notice code { font-size: 0.85em; }

/* ── Collapsible config sections ──────────────────────────────────────────── */
.cfg-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}
.cfg-section > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
  list-style: none;
}
.cfg-section > summary::before {
  content: "▶";
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.cfg-section[open] > summary::before {
  transform: rotate(90deg);
}
.cfg-section > summary::-webkit-details-marker { display: none; }
.cfg-section > *:not(summary) {
  padding: 0 1rem 1rem;
}

/* ── Tooltip icons ────────────────────────────────────────────────────────── */
.tip {
  display: inline-block;
  cursor: help;
  color: var(--text-muted);
  font-size: 0.78rem;
  position: relative;
  vertical-align: middle;
  margin-left: 3px;
}
.tip::after {
  content: attr(data-tip);
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary, #cbd5e1);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.45;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  width: 260px;
  white-space: normal;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  pointer-events: none;
}
.tip:hover::after { display: block; }
