/* ==========================================================================
   APEX Threat & Vulnerability Scanner — UI theme
   A dark, high-contrast, commercial-scanner look (Tenable / Rapid7 / Qualys
   inspired): left sidebar, colorful stat cards, clear severity coding.
   All historical class names are preserved so every template keeps working.
   ========================================================================== */

:root {
  --bg: #070b16;
  --bg-2: #0a0f1d;
  --panel: #111726;
  --panel-2: #0d1320;
  --panel-3: #161d2f;
  --border: #1e2738;
  --border-2: #283248;
  --text: #e6ebf5;
  --muted: #8a97b0;
  --muted-2: #6b7793;

  --accent: #36d3e0;       /* cyan — primary */
  --accent-ink: #042027;   /* text on accent */
  --accent-2: #7c5cff;     /* violet — secondary */
  --accent-3: #f5a623;     /* amber */

  --critical: #ff5c7a;
  --high: #ff9f43;
  --medium: #ffd23f;
  --low: #4fc3f7;
  --ok: #3ecf8e;
  --info: #4f8cff;

  --shadow: 0 10px 30px -12px rgba(0, 0, 0, .6);
  --shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, .5);
  --radius: 12px;
  --sidebar-w: 232px;
  --topbar-h: 58px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(124, 92, 255, .10), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, rgba(54, 211, 224, .08), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 12.5px; color: var(--accent);
  background: rgba(54, 211, 224, .07); padding: 1px 6px; border-radius: 5px;
}
::selection { background: rgba(54, 211, 224, .3); }

/* ---- Scrollbars ---------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #36425f; background-clip: padding-box; }

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h); padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 15, 29, .82);
  backdrop-filter: blur(10px);
}
.brand {
  font-weight: 800; letter-spacing: .2px; font-size: 15px;
  display: flex; align-items: center; gap: 10px;
}
.brand img { flex: none; border-radius: 7px; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar-right { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.topbar-right a { color: var(--text); }

/* ==========================================================================
   Layout — sidebar nav (.tnav) + content (.wrap)
   .tnav appears on every app page (not auth pages), so :has() lets auth
   pages keep a normal centered layout automatically.
   ========================================================================== */
.wrap { width: 100%; padding: 26px 32px 60px; }
.wrap:has(.tnav) { padding-left: calc(var(--sidebar-w) + 32px); }

.tnav {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 12px; overflow-y: auto;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border);
}
.tnav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--muted); font-weight: 500; font-size: 13.5px;
  border: 1px solid transparent; white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.tnav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.tnav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.tnav a.on {
  color: var(--text);
  background: linear-gradient(90deg, rgba(54, 211, 224, .16), rgba(124, 92, 255, .10));
  border-color: rgba(54, 211, 224, .35);
  box-shadow: inset 3px 0 0 var(--accent);
}
.tnav a.on svg { opacity: 1; color: var(--accent); }

.page-head { display: flex; align-items: baseline; gap: 14px; margin: 2px 0 20px; flex-wrap: wrap; }
.page-head h1 {
  margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -.3px;
}
.muted { color: var(--muted); }
.error { color: var(--critical); }

/* ==========================================================================
   Cards & grids
   ========================================================================== */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.card h2 {
  margin: 0 0 14px; font-size: 15px; font-weight: 700; letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px;
}
.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.auth-card {
  max-width: 400px; margin: 12vh auto; padding: 32px 30px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border-2); border-radius: 16px; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.auth-logo {
  display: block; width: 64px; height: 64px; margin-bottom: 16px; border-radius: 14px;
  box-shadow: 0 8px 24px -6px rgba(54, 211, 224, .45);
}

/* ==========================================================================
   Forms
   ========================================================================== */
form.stack label, .auth-card label {
  display: block; margin: 0 0 14px; font-size: 13px; color: var(--muted); font-weight: 500;
}
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 9px; font-size: 14px;
  font-family: inherit; transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(54, 211, 224, .15);
}
input[type="checkbox"] { width: auto; display: inline-block; margin: 0; accent-color: var(--accent); }
select { cursor: pointer; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* ==========================================================================
   Buttons
   ========================================================================== */
button, .btn {
  background: var(--panel-3); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 9px;
  padding: 10px 16px; font-weight: 600; cursor: pointer; font-size: 13.5px;
  font-family: inherit; transition: border-color .12s, filter .12s, background .12s, transform .05s;
}
button:hover, .btn:hover { border-color: var(--accent); background: var(--panel); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary {
  background: linear-gradient(135deg, var(--accent), #2bb6c6);
  color: var(--accent-ink); border: 0; box-shadow: 0 6px 18px -6px rgba(54, 211, 224, .55);
}
button.primary:hover, .btn.primary:hover { filter: brightness(1.07); border: 0; }
button.danger, button.danger.small {
  background: rgba(255, 92, 122, .14); color: var(--critical); border: 1px solid rgba(255, 92, 122, .4);
}
button.danger:hover { background: rgba(255, 92, 122, .22); border-color: var(--critical); }
button.small, button.primary.small, button.danger.small, .btn.small { padding: 6px 11px; font-size: 12.5px; }

/* ==========================================================================
   Inline / row-action layouts
   ========================================================================== */
form.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0 6px 0 0; }
form.inline input, form.inline select { display: inline-block; width: auto; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.row-actions form { margin: 0; }
.inline { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline input, .inline select { width: auto; margin: 0; }
.inline-label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.inline-label select, .inline-label input { display: inline-block; width: auto; margin: 0; }

/* ==========================================================================
   Tables
   ========================================================================== */
/* Contained scroll box for listing tables (Assets-style): the table body
   scrolls inside a fixed-height region while the sticky thead stays pinned,
   and infinite-scroll reveals more rows on this element's scroll. Applied
   to every listing table by the global enhancer in base.html, which also
   measures each box and sets an inline max-height filling down to the bottom
   of the window. The 60vh below is just the no-JS fallback. */
.table-scroll { max-height: 60vh; overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; padding: 10px 12px;
  color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .6px;
  background: var(--panel-2); border-bottom: 1px solid var(--border-2);
}
table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: rgba(54, 211, 224, .045); }
table.data tbody tr:last-child td { border-bottom: 0; }

/* ==========================================================================
   Pills & badges
   ========================================================================== */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
  background: var(--panel-3); border: 1px solid var(--border-2); color: var(--muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill.ok { color: var(--ok); border-color: rgba(62, 207, 142, .4); background: rgba(62, 207, 142, .1); }
.pill.error { color: var(--critical); border-color: rgba(255, 92, 122, .4); background: rgba(255, 92, 122, .1); }
.pill.warn { color: var(--high); border-color: rgba(255, 159, 67, .4); background: rgba(255, 159, 67, .1); }

/* ==========================================================================
   Flash alerts
   ========================================================================== */
.flash {
  padding: 11px 14px 11px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 13px;
  border: 1px solid var(--border-2); border-left-width: 3px; background: var(--panel);
  display: flex; align-items: center; gap: 8px;
}
.flash.ok { color: #b8f2d8; border-color: var(--ok); background: rgba(62, 207, 142, .08); }
.flash.error { color: #ffc6d2; border-color: var(--critical); background: rgba(255, 92, 122, .08); }

/* ==========================================================================
   Stat grid — colorful KPI cards
   ========================================================================== */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow-sm);
  transition: transform .12s, border-color .12s;
}
.stat:hover { transform: translateY(-2px); border-color: var(--border-2); }
.stat::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--accent);
}
.stat::after {
  content: ""; position: absolute; top: -40px; right: -40px; width: 110px; height: 110px;
  border-radius: 50%; background: radial-gradient(circle, rgba(54, 211, 224, .14), transparent 70%);
}
.stat .num { font-size: 30px; font-weight: 800; line-height: 1.1; letter-spacing: -.5px; position: relative; }
.stat .lbl { color: var(--muted); font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; position: relative; }
/* Auto color rotation for KPI cards */
.stat-grid .stat:nth-child(5n+1)::before { background: var(--accent); }
.stat-grid .stat:nth-child(5n+1)::after { background: radial-gradient(circle, rgba(54,211,224,.16), transparent 70%); }
.stat-grid .stat:nth-child(5n+2)::before { background: var(--accent-2); }
.stat-grid .stat:nth-child(5n+2)::after { background: radial-gradient(circle, rgba(124,92,255,.16), transparent 70%); }
.stat-grid .stat:nth-child(5n+3)::before { background: var(--high); }
.stat-grid .stat:nth-child(5n+3)::after { background: radial-gradient(circle, rgba(255,159,67,.16), transparent 70%); }
.stat-grid .stat:nth-child(5n+4)::before { background: var(--ok); }
.stat-grid .stat:nth-child(5n+4)::after { background: radial-gradient(circle, rgba(62,207,142,.16), transparent 70%); }
.stat-grid .stat:nth-child(5n+5)::before { background: var(--info); }
.stat-grid .stat:nth-child(5n+5)::after { background: radial-gradient(circle, rgba(79,140,255,.16), transparent 70%); }

/* Explicit severity-colored stat variants (optional, used where set) */
.stat.crit::before { background: var(--critical); }
.stat.crit .num { color: var(--critical); }
.stat.high::before { background: var(--high); }
.stat.high .num { color: var(--high); }
.stat.ok::before { background: var(--ok); }
.stat.ok .num { color: var(--ok); }

/* ==========================================================================
   Severity badges
   ========================================================================== */
.sev {
  display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
}
.sev-critical { background: rgba(255, 92, 122, .18); color: var(--critical); box-shadow: inset 0 0 0 1px rgba(255, 92, 122, .35); }
.sev-high { background: rgba(255, 159, 67, .18); color: var(--high); box-shadow: inset 0 0 0 1px rgba(255, 159, 67, .35); }
.sev-medium { background: rgba(255, 210, 63, .16); color: var(--medium); box-shadow: inset 0 0 0 1px rgba(255, 210, 63, .3); }
.sev-low { background: rgba(79, 195, 247, .16); color: var(--low); box-shadow: inset 0 0 0 1px rgba(79, 195, 247, .3); }
.sev-none { background: var(--panel-3); color: var(--muted); }

/* Per-asset severity bar sub-row in the inventory (attached under its row). */
tr.asset-main > td { border-bottom: none; }
tr.sev-row > td { border-top: none; padding-top: 2px; padding-bottom: 16px; }

/* Clickable rows (e.g. a credential row opening its assigned-assets modal). */
tr.cred-row { cursor: pointer; }
tr.cred-row:hover { background: rgba(54, 211, 224, .05); }

/* Tabbed panels (e.g. asset detail: Vulnerabilities / Softwares / Services). */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
  background: none; border: none; padding: 9px 16px; color: var(--muted);
  cursor: pointer; font-size: 14px; font-weight: 600; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.on { color: var(--accent); border-bottom-color: var(--accent); }

/* Click-to-sort table headers. */
th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.th-sort:hover { color: var(--text); }
th.th-sort .arrow { font-size: 10px; margin-left: 5px; opacity: .35; }
th.th-sort.sorted .arrow { opacity: 1; }

/* Reference / remediation lists on the finding report. */
.rem-list { margin: 0; padding-left: 18px; }
.rem-list li { margin-bottom: 10px; line-height: 1.5; }
.rem-list li:last-child { margin-bottom: 0; }

/* Raw probe evidence on the finding report — preformatted but wrapping. */
.evidence {
  margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--panel-3);
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 280px; overflow-y: auto;
}

/* Stacked severity bar (dashboard) */
.sev-bar {
  display: flex; height: 14px; border-radius: 8px; overflow: hidden;
  background: var(--panel-3); margin-bottom: 16px; gap: 2px;
}
.sev-seg { display: block; min-width: 4px; }
.sev-seg-critical { background: var(--critical); }
.sev-seg-high { background: var(--high); }
.sev-seg-medium { background: var(--medium); }
.sev-seg-low { background: var(--low); }
.sev-seg-none { background: var(--muted-2); }
.sev-legend { display: flex; flex-wrap: wrap; gap: 16px; }
.sev-stat { display: flex; align-items: center; gap: 8px; }
.sev-count { font-size: 20px; font-weight: 800; }

/* Fixed-layout table whose long cells wrap instead of overflowing
   (console scanner profiles → Detects/Reference). */
.profiles-table { table-layout: fixed; width: 100%; }
.profiles-table td, .profiles-table th { vertical-align: top; }
.profiles-table .wrap, td .wrap { white-space: normal; overflow-wrap: anywhere; word-break: break-word; }
.profiles-table code { background: none; padding: 0; }

/* Progress bar (running agent/job) */
.progress {
  position: relative; height: 8px; min-width: 120px; border-radius: 6px;
  background: var(--panel-3); overflow: hidden; border: 1px solid var(--border);
}
.progress-bar {
  display: block; height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .4s ease;
}
.progress-bar.indeterminate {
  width: 35% !important; animation: progress-slide 1.1s ease-in-out infinite;
}
@keyframes progress-slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

/* cred_test per-asset result lines (Scans → Recent jobs) */
.cred-result { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; padding: 2px 0; }
.cred-result + .cred-result { border-top: 1px dashed var(--border); }
.cred-result .error { word-break: break-word; }

/* ==========================================================================
   Pill action button (page-head "+ Add …" actions) + modal dialogs
   ========================================================================== */
.btn.pill-btn, button.pill-btn { border-radius: 999px; }
/* Sit the action button at the right edge of a flex .page-head. */
.page-head .pill-btn { margin-left: auto; }

dialog.modal {
  border: 1px solid var(--border-2);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  color: var(--text);
  border-radius: 14px;
  padding: 0;
  width: min(540px, 94vw);
  box-shadow: 0 28px 70px -22px rgba(0, 0, 0, .75);
}
dialog.modal::backdrop { background: rgba(5, 8, 16, .62); backdrop-filter: blur(2px); }
dialog.modal .modal-body { padding: 20px 24px 24px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; }
.modal-close {
  background: none; border: 0; color: var(--muted);
  font-size: 22px; line-height: 1; padding: 2px 6px; cursor: pointer; border-radius: 8px;
}
.modal-close:hover { color: var(--text); background: var(--panel-3); border: 0; }

/* ==========================================================================
   Responsive — collapse sidebar to a horizontal bar on narrow screens
   ========================================================================== */
@media (max-width: 860px) {
  .wrap, .wrap:has(.tnav) { padding: 18px 16px 50px; }
  .tnav {
    position: static; width: auto; flex-direction: row; flex-wrap: wrap;
    border-right: 0; border-bottom: 1px solid var(--border);
    margin: -4px -16px 16px; padding: 10px 16px; background: var(--bg-2);
  }
  .tnav a.on { box-shadow: none; }
  .stat-grid { gap: 10px; }
}
