/* ─────────────────────────────────────────────────────────────────────
   Terminator Reports — UI styles
   - CSS variables for dark/light theming
   - Mobile-first responsive (sidebar collapses < 768px)
   - Severity color tokens
   ───────────────────────────────────────────────────────────────────── */

:root {
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(0,0,0,.18), 0 8px 24px rgba(0,0,0,.18);
  --transition: 120ms ease-out;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0b0f14;
  --bg-elev: #111821;
  --bg-elev-2: #182230;
  --border: #1f2a3a;
  --border-strong: #2a3a52;
  --text: #e6edf6;
  --text-muted: #8a99ad;
  --text-dim: #5a6a82;
  --accent: #5eead4;     /* teal */
  --accent-2: #38bdf8;   /* sky */
  --link: #7dd3fc;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;

  --sev-critical: #f43f5e;
  --sev-high:     #fb923c;
  --sev-medium:   #facc15;
  --sev-low:      #38bdf8;
  --sev-info:     #94a3b8;
}

:root[data-theme="light"] {
  --bg: #f7fafc;
  --bg-elev: #ffffff;
  --bg-elev-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --accent: #0d9488;
  --accent-2: #0284c7;
  --link: #0369a1;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #15803d;

  --sev-critical: #be123c;
  --sev-high:     #c2410c;
  --sev-medium:   #a16207;
  --sev-low:      #0369a1;
  --sev-info:     #475569;
}

/* ── Reset & base ─────────────────────────────────────────────────── */

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

[hidden] { display: none !important; }

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

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

button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.muted { color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition);
}
.btn--primary {
  background: var(--accent);
  color: #0b0f14;
  border-color: var(--accent);
}
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 85%, white 15%); }
.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--ghost:hover { background: var(--bg-elev-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.iconbtn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  line-height: 1;
}
.iconbtn:hover { background: var(--bg-elev-2); }

/* ── Login overlay ───────────────────────────────────────────────── */

.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at top, var(--bg-elev) 0%, var(--bg) 70%);
  z-index: 50;
}
.login[hidden] { display: none; }
.login__card {
  width: 100%; max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login__title { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.login__subtitle { margin: -10px 0 4px 0; color: var(--text-muted); font-size: 13px; }
.login__error { color: var(--danger); font-size: 13px; margin: 0; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field > span { color: var(--text-muted); }
.field--inline { flex-direction: row; align-items: center; gap: 8px; }
.field--inline > span { min-width: 70px; }
.field--inline select, .field--inline input { flex: 1; }

/* ── App grid ────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 52px 1fr;
  grid-template-areas: "top top" "side main";
  height: 100vh;
}
.app[hidden] { display: none; }

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.topbar__menu { display: none; }
.topbar__brand { display: flex; align-items: baseline; gap: 6px; min-width: 200px; }
.brand { font-weight: 600; letter-spacing: -.01em; }
.brand__sub { color: var(--text-muted); font-size: 12px; }
.topbar__search { flex: 1; max-width: 600px; }
.topbar__search input { width: 100%; }
.topbar__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.user {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
}
.user:hover { background: var(--bg-elev-2); border-color: var(--border-strong); }

.sidebar {
  grid-area: side;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 16px;
}
.side-section { display: flex; flex-direction: column; gap: 8px; }
.side-title {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  font-weight: 600;
}
.side-tree { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.tree-node {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
}
.tree-node:hover { background: var(--bg-elev-2); }
.tree-node--active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }
.tree-node--proj { font-weight: 500; color: var(--text); }
.tree-node--exec { color: var(--text-muted); }
.tree-node__caret { width: 12px; display: inline-block; }
.tree-node__date { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.tree-children { padding-left: 14px; }

.main {
  grid-area: main;
  overflow-y: auto;
  padding: 20px 24px;
  max-width: 100%;
}

/* ── Empty state ─────────────────────────────────────────────────── */

.empty {
  height: 100%;
  display: grid; place-items: center;
  text-align: center;
  color: var(--text-muted);
}
.empty h2 { color: var(--text); margin: 0 0 4px 0; }

/* ── Execution view ──────────────────────────────────────────────── */

.exec { display: flex; flex-direction: column; gap: 16px; max-width: 1100px; }
.exec__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.exec__title { margin: 0; font-size: 20px; }
.exec__meta { margin: 4px 0 0 0; color: var(--text-muted); font-size: 13px; }
.exec__counts { display: flex; gap: 8px; flex-wrap: wrap; }

.count-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
}
.count-pill__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ── Panels ──────────────────────────────────────────────────────── */

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.panel__title {
  margin: 0 0 10px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 8px;
}
.panel__count {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.panel__head .panel__title { margin: 0; }
.panel__actions { display: flex; gap: 6px; }
.panel--report { padding: 0; overflow: hidden; }
.panel--report .panel__head { padding: 12px 16px; border-bottom: 1px solid var(--border); margin: 0; }

/* ── Live execution stream ───────────────────────────────────────── */

.live-panel { display: flex; flex-direction: column; gap: 12px; }
.live-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.live-panel__meta {
  margin: -4px 0 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.live-panel__status {
  min-width: 82px;
  text-align: center;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-elev-2);
  font-size: 12px;
  text-transform: uppercase;
}
.live-panel__status--active {
  color: #06231f;
  background: var(--accent);
  border-color: var(--accent);
}
.live-progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
}
.live-progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 180ms ease-out;
}
.live-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.live-stat {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
}
.live-stat span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.live-stat strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-log {
  min-height: 160px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 78%, black 22%);
  font-family: var(--font-mono);
  font-size: 12px;
  list-style: none;
}
.live-discoveries {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}
.live-discovery {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text-muted);
  font-size: 12px;
}
.live-log__row {
  display: grid;
  grid-template-columns: 132px 72px minmax(0, 1fr);
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
}
.live-log__row:last-child { border-bottom: 0; }
.live-log__time, .live-log__level { color: var(--text-dim); }
.live-log__row--error .live-log__level { color: var(--danger); }
.live-log__row--finding .live-log__level { color: var(--warn); }
.live-log__row--status .live-log__level { color: var(--accent-2); }
.live-log__line {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
}

@media (max-width: 980px) {
  .live-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── Reports row ─────────────────────────────────────────────────── */

.reports { display: flex; flex-wrap: wrap; gap: 8px; }
.report-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.report-chip:hover { border-color: var(--accent); }
.report-chip--active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
}
.report-chip__type { font-weight: 500; }
.report-chip__format {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}
.report-chip__exec {
  color: var(--text-muted);
  font-size: 11px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.report-chip__size { color: var(--text-dim); font-size: 11px; }

/* ── Findings list ───────────────────────────────────────────────── */

.findings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.finding {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition);
}
.finding:hover { border-color: var(--border-strong); }
.finding__sev {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  letter-spacing: .04em;
}
.finding__body { min-width: 0; }
.finding__title { font-weight: 500; }
.finding__desc {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.finding__refs { display: flex; gap: 8px; font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.finding__cvss { font-weight: 600; font-family: var(--font-mono); }
.finding__cvss[data-score^="0"], .finding__cvss[data-score="0.0"] { color: var(--text-muted); }

/* ── Severity color tokens (severity-color) ──────────────────────── */

.sev-critical, .finding__sev--critical { color: var(--sev-critical); background: color-mix(in srgb, var(--sev-critical) 12%, transparent); }
.sev-high,     .finding__sev--high     { color: var(--sev-high);     background: color-mix(in srgb, var(--sev-high) 12%, transparent); }
.sev-medium,   .finding__sev--medium   { color: var(--sev-medium);   background: color-mix(in srgb, var(--sev-medium) 12%, transparent); }
.sev-low,      .finding__sev--low      { color: var(--sev-low);      background: color-mix(in srgb, var(--sev-low) 12%, transparent); }
.sev-info,     .finding__sev--info     { color: var(--sev-info);     background: color-mix(in srgb, var(--sev-info) 12%, transparent); }

/* ── Finding detail (expanded) ───────────────────────────────────── */

.finding-detail {
  grid-column: 1 / -1;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font-size: 13px;
}
.finding-detail__field { display: flex; flex-direction: column; gap: 2px; }
.finding-detail__field > span { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.finding-detail__code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow: auto;
}
.finding-detail__refs a { display: inline-block; margin-right: 8px; }

/* ── Report view (iframe + json) ──────────────────────────────────── */

.report-view { background: #fff; }
#report-frame { width: 100%; min-height: 600px; border: 0; display: block; background: #fff; }
.report-json {
  margin: 0;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Operational readiness ───────────────────────────────────────── */

.ops { display: flex; flex-direction: column; gap: 16px; max-width: 1100px; }
.pentest { display: flex; flex-direction: column; gap: 16px; max-width: 1100px; }
.run-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.run-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 160px;
  gap: 12px;
}
.template-detail {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 13px;
}
.template-detail__meta {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
.template-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.tool-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
}
.panel__actions--run {
  justify-content: flex-end;
  margin-top: 14px;
}
.ops-components {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.ops-component {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  padding: 10px 12px;
}
.ops-component--ok { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.ops-component--bad { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.ops-component__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.ops-component__detail { color: var(--text-muted); font-size: 12px; }
.ops-component__meta { color: var(--text-dim); font-size: 11px; margin-top: 6px; }
.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.status-dot--ok { color: var(--ok); }
.status-dot--bad { color: var(--danger); }
.ops-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.ops-table th,
.ops-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.ops-table th {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}
.ops-table tr:last-child td { border-bottom: 0; }
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
}

/* ── Toast ───────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 360px;
  font-size: 13px;
  animation: toast-in 200ms ease-out;
}
.toast--err { border-left-color: var(--danger); }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ── Mobile ──────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "main";
  }
  .sidebar {
    position: fixed;
    top: 52px; bottom: 0; left: 0;
    width: 280px;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 200ms ease-out;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: translateX(0); }
  .topbar__menu { display: inline-block; }
  .topbar__brand { min-width: 0; }
  .topbar__brand .brand__sub { display: none; }
  .topbar__search { max-width: none; }
  .run-grid { grid-template-columns: 1fr; }
  .finding { grid-template-columns: 64px 1fr; }
  .finding__cvss { grid-column: 2; justify-self: start; }
  .finding-detail { grid-template-columns: 1fr; }
}

/* ── Print ───────────────────────────────────────────────────────── */

@media print {
  .topbar, .sidebar, .panel--reports { display: none; }
  .main { padding: 0; }
}
