/* ---------- design tokens ---------- */
:root {
  --bg: #0f1320;
  --panel: #161b2c;
  --panel-2: #1c2138;
  --border: #262c44;
  --text: #e7eaf3;
  --muted: #9aa1b8;
  --accent: #3aa0ff;
  --accent-2: #6c5ce7;
  --good: #20c997;
  --warn: #f5a524;
  --bad: #ef4444;
  --crit: #d11149;
  --row-hover: #1f2540;
  /* Text-size scale (Preferences → Text size). 1 = default. Only font sizes
     multiply by this, so text grows without resizing the whole layout. */
  --fscale: 1;
}
[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f0f3fa;
  --border: #d8dde9;
  --text: #1a1f33;
  --muted: #5a6280;
  --row-hover: #eef2fc;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  font-size: calc(14px * var(--fscale));
  background: var(--bg); color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; transition: grid-template-columns 0.18s; }
.app.collapsed { grid-template-columns: 60px 1fr; }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar .brand {
  padding: 18px 16px; font-weight: 700; font-size: calc(16px * var(--fscale)); letter-spacing: 0.4px;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border);
}
.sidebar .brand .logo {
  width: 28px; height: 28px; display: block; flex-shrink: 0;
}
.sidebar nav { padding: 8px; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin: 2px 0; border-radius: 8px; color: var(--text);
  white-space: nowrap; overflow: hidden;
}
.sidebar nav a:hover { background: var(--panel-2); text-decoration: none; }
.sidebar nav a.active { background: var(--panel-2); color: var(--accent); }
.sidebar nav .group-label {
  font-size: calc(11px * var(--fscale)); text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); padding: 12px 12px 4px;
}
.sidebar .footer { padding: 10px 12px; border-top: 1px solid var(--border); font-size: calc(12px * var(--fscale)); color: var(--muted); }
.app.collapsed .sidebar nav a span,
.app.collapsed .sidebar .brand span,
.app.collapsed .sidebar .group-label,
.app.collapsed .sidebar .footer { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar .title { font-weight: 600; font-size: calc(15px * var(--fscale)); }
.topbar .spacer { flex: 1; }
.topbar .search { flex: 0 1 360px; }

.content { padding: 18px; overflow-y: auto; }

/* ---------- common controls ---------- */
.btn {
  background: var(--accent); color: white; border: 0;
  padding: 7px 13px; border-radius: 7px; cursor: pointer;
  font: inherit; line-height: 1;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 4px 8px; font-size: calc(12px * var(--fscale)); }

.input, select, textarea {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 9px; font: inherit; width: 100%;
}
.input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: calc(16px * var(--fscale)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { min-width: 140px; }
.label { display: block; font-size: calc(12px * var(--fscale)); color: var(--muted); margin-bottom: 4px; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: calc(11px * var(--fscale)); font-weight: 600; line-height: 1.6;
  border: 1px solid var(--border); background: var(--panel-2);
}
.pill.info { color: #7da9ff; }
.pill.low { color: #4dabf7; }
.pill.medium { color: var(--warn); }
.pill.high { color: #ff7e6b; }
.pill.critical { color: #ff5e8a; background: rgba(209, 17, 73, 0.15); border-color: rgba(209, 17, 73, 0.4); }
.pill.new, .pill.in_progress { color: var(--accent); }
.pill.remediated { color: var(--good); }
.pill.false_positive { color: var(--muted); }
.pill.suppressed { color: #c084fc; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: calc(12px * var(--fscale)); text-transform: uppercase; letter-spacing: 0.5px;
     position: sticky; top: 0; background: var(--panel); cursor: pointer; user-select: none; }
th .sort-ind { color: var(--accent); margin-left: 4px; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.claimed { box-shadow: inset 4px 0 0 var(--claim-color, var(--accent)); }
tbody tr.claimed td:first-child { background: color-mix(in srgb, var(--claim-color, var(--accent)) 12%, transparent); }

/* ---------- filters / collapsible ---------- */
.filters { transition: max-height 0.2s ease; overflow: hidden; }
.filters.collapsed { max-height: 0; padding: 0; margin: 0; border: 0; }
.filters:not(.collapsed) { max-height: 600px; }
.filter-toggle { cursor: pointer; user-select: none; color: var(--muted); }
.filter-toggle:hover { color: var(--text); }

/* ---------- login ---------- */
.login-wrap {
  display: grid; place-items: center; height: 100vh; padding: 20px;
}
.login-card {
  width: 360px; padding: 24px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px;
}
.login-card h1 { margin: 0 0 6px; font-size: calc(22px * var(--fscale)); }
.login-card .sub { color: var(--muted); margin-bottom: 18px; }
.login-card form > * { margin-top: 10px; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(5, 8, 18, 0.55);
  display: none; align-items: center; justify-content: center; z-index: 30;
}
.modal-back.open { display: flex; }
.modal {
  width: min(900px, 96vw); max-height: 88vh; overflow: hidden;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; display: flex; flex-direction: column;
}
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border);
                display: flex; align-items: center; gap: 10px; }
.modal-header .x { margin-left: auto; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-body pre {
  background: var(--bg); padding: 12px; border-radius: 8px;
  border: 1px solid var(--border); overflow: auto; max-height: 320px;
  font-size: calc(12px * var(--fscale));
}
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border);
                display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- misc ---------- */
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer;
  display: inline-grid; place-items: center; padding: 0;
}
.icon-btn:hover { background: var(--panel-2); }
.muted { color: var(--muted); }
.kbd { font-family: monospace; background: var(--panel-2); border: 1px solid var(--border);
       padding: 1px 6px; border-radius: 4px; font-size: calc(11px * var(--fscale)); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--border);
        border-radius: 10px; padding: 14px; }
.stat .v { font-size: calc(26px * var(--fscale)); font-weight: 700; }
.stat .k { color: var(--muted); font-size: calc(12px * var(--fscale)); text-transform: uppercase; letter-spacing: 0.6px; }

.alert-banner { padding: 10px 14px; border-radius: 8px;
                background: rgba(245, 165, 36, 0.12); border: 1px solid rgba(245, 165, 36, 0.4);
                color: var(--warn); margin-bottom: 12px; }

.badge {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  font-size: calc(11px * var(--fscale)); background: var(--panel-2); border: 1px solid var(--border);
}

/* ---------- loading / busy feedback ---------- */
/* Global indeterminate progress bar pinned to the top of the viewport. Shown
   while any api() fetch is in flight (after a short delay, so quick calls don't
   flicker). Driven from app.js. */
#loading-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 9999;
  background: transparent; overflow: hidden; pointer-events: none;
  opacity: 0; transition: opacity .2s ease;
}
#loading-bar.active { opacity: 1; }
#loading-bar::before {
  content: ""; position: absolute; top: 0; left: 0; height: 100%; width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  animation: loadingbar 1.05s ease-in-out infinite;
}
@keyframes loadingbar {
  0%   { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

/* Spinner shown inside a button while its async action runs (see withBusy). */
.btn-spinner {
  display: inline-block; width: 12px; height: 12px; margin-right: 7px;
  vertical-align: -1px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  animation: btnspin .6s linear infinite;
}
.btn.ghost .btn-spinner, .btn.secondary .btn-spinner {
  border-color: rgba(127,127,127,.35); border-top-color: var(--accent);
}
.btn.is-busy { opacity: .9; cursor: progress; }
@keyframes btnspin { to { transform: rotate(360deg); } }

/* Subtle dim on a content area while it refreshes (optional, used for tables). */
.is-refreshing { opacity: .55; transition: opacity .15s ease; pointer-events: none; }

/* Built-in (undeletable) filter presets: tinted so they stand apart from the
   user's own deletable presets. */
.badge.preset-builtin {
  background: linear-gradient(0deg, rgba(58,160,255,.16), rgba(108,92,231,.16));
  border-color: var(--accent);
  color: var(--text);
}

/* Wide tables (many columns) should get a horizontal scrollbar rather than
   overflowing the viewport. The !important beats the inline `overflow:hidden`
   that some table cards set for rounded corners; overflow-y stays hidden. */
.card:has(> table) { overflow-x: auto !important; }

/* A shared-link target row in the tools history, briefly emphasised. */
tr.focus-row td { background: rgba(58,160,255,.16); }

/* ---------- new-critical-alert notification ---------- */
.crit-banner {
  position: fixed; top: 14px; left: 50%; transform: translate(-50%, -140%);
  z-index: 9998; display: flex; align-items: center; gap: 12px;
  min-width: 340px; max-width: 92vw; padding: 12px 14px;
  border-radius: 12px; color: #fff;
  background: linear-gradient(135deg, #d11149, #ef4444);
  border: 1px solid rgba(255,255,255,.25);
  box-shadow: 0 10px 30px rgba(209,17,73,.45);
  opacity: 0; pointer-events: none;
}
.crit-banner.show {
  opacity: 1; pointer-events: auto;
  animation: critdrop .45s cubic-bezier(.2,.9,.3,1.4) forwards, critglow 1.1s ease-in-out infinite .45s;
}
@keyframes critdrop {
  from { transform: translate(-50%, -140%); }
  to   { transform: translate(-50%, 0); }
}
@keyframes critglow {
  0%,100% { box-shadow: 0 10px 30px rgba(209,17,73,.40); }
  50%     { box-shadow: 0 12px 46px rgba(239,68,68,.85); }
}
.crit-banner .crit-siren { font-size: calc(24px * var(--fscale)); display: inline-block; animation: critshake .6s ease-in-out infinite; transform-origin: 50% 60%; }
@keyframes critshake {
  0%,100% { transform: rotate(0deg); }
  25% { transform: rotate(-14deg); }
  75% { transform: rotate(14deg); }
}
.crit-banner .crit-text { flex: 1; min-width: 0; }
.crit-banner .crit-title { font-weight: 800; font-size: calc(14px * var(--fscale)); letter-spacing: .3px; }
.crit-banner .crit-sub { font-size: calc(12px * var(--fscale)); opacity: .95;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crit-banner .btn.small { background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.4); color:#fff; }
.crit-banner .crit-x { background: transparent; border: 0; color: #fff; opacity: .8; cursor: pointer; font-size: calc(14px * var(--fscale)); }
.crit-banner .crit-x:hover { opacity: 1; }

/* A brief red pulse on the whole viewport edge when a critical fires. */
#crit-flash {
  position: fixed; inset: 0; z-index: 9997; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 0 4px var(--crit), inset 0 0 60px rgba(209,17,73,.5);
}
#crit-flash.flash { animation: critflash 1.2s ease-out 2; }
@keyframes critflash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
