/* ============================================================================
   netwatch design system — bespoke CSS-variable tokens, dual theme.
   Default: dark, in the spirit of security/SOC tooling (Splunk, Elastic, Wiz,
   Snyk). Palette: Tailwind slate + sky. Severity: red/orange/yellow/blue/green.
   Fonts: Inter (UI) + JetBrains Mono (data/code).
   Light theme: :root[data-theme="light"]. Persisted in localStorage.qes_theme.
   ========================================================================== */

:root {
  /* base — slate + sky (dark) */
  --bg:        #0a0e1a;   /* slate-950 tint */
  --bg-2:      #0c111f;
  --panel:     #0f1626;
  --panel-2:   #131c30;
  --elev:      #16203580;
  --border:    #1e293b;   /* slate-800 */
  --border-2:  #2a3a52;
  --fg:        #e2e8f0;   /* slate-200 */
  --fg-muted:  #94a3b8;   /* slate-400 */
  --fg-faint:  #64748b;   /* slate-500 */

  --accent:    #38bdf8;   /* sky-400 */
  --accent-2:  #0ea5e9;   /* sky-500 */
  --accent-soft: rgba(56,189,248,.12);
  --ring:      rgba(56,189,248,.45);

  /* severity scale (Tailwind 500s) */
  --sev-critical: #ef4444;
  --sev-high:     #f97316;
  --sev-medium:   #eab308;
  --sev-low:      #3b82f6;
  --sev-ok:       #22c55e;
  --sev-info:     #64748b;

  /* typography */
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(0,0,0,.5), 0 12px 32px -8px rgba(0,0,0,.45);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);

  --sidebar-w: 280px;
  --topbar-h:  56px;
}

:root[data-theme="light"] {
  --bg:        #f1f5f9;   /* slate-100 */
  --bg-2:      #e9eef5;
  --panel:     #ffffff;
  --panel-2:   #f8fafc;
  --elev:      #ffffff;
  --border:    #e2e8f0;   /* slate-200 */
  --border-2:  #cbd5e1;
  --fg:        #0f172a;   /* slate-900 */
  --fg-muted:  #475569;   /* slate-600 */
  --fg-faint:  #94a3b8;

  --accent:    #0284c7;   /* sky-600 for contrast on light */
  --accent-2:  #0369a1;
  --accent-soft: rgba(2,132,199,.10);
  --ring:      rgba(2,132,199,.4);

  --shadow:    0 1px 2px rgba(15,23,42,.06), 0 12px 32px -10px rgba(15,23,42,.16);
  --shadow-sm: 0 1px 2px rgba(15,23,42,.08);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
  letter-spacing: -0.006em;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); font-size: .8rem; }

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

/* --- form controls -------------------------------------------------------- */
input, select {
  width: 100%;
  font-family: var(--font-sans);
  font-size: .875rem;
  padding: .55rem .7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--fg);
  transition: border-color .15s, box-shadow .15s;
}
:root[data-theme="light"] input, :root[data-theme="light"] select { background: #fff; }
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
input::placeholder { color: var(--fg-faint); }

button {
  font-family: var(--font-sans);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .55rem .85rem;
  background: var(--accent);
  color: #06141f;
  transition: filter .15s, background .15s, border-color .15s;
}
button:hover { filter: brightness(1.08); }
button.ghost {
  background: transparent; color: var(--fg-muted); border-color: var(--border);
}
button.ghost:hover { color: var(--fg); border-color: var(--border-2); filter: none; }
button.icon { padding: .45rem .55rem; background: transparent; border-color: var(--border);
  color: var(--fg-muted); font-size: 1rem; line-height: 1; }
button.icon:hover { color: var(--accent); border-color: var(--accent); filter: none; }

/* --- brand ---------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700;
  font-size: 1.05rem; letter-spacing: -0.03em; }
.brand .logo {
  width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 7px; color: #06141f; font-size: .9rem; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 1px rgba(56,189,248,.3), 0 4px 12px -2px rgba(56,189,248,.5);
}
.brand .sub { font-weight: 400; font-size: .72rem; color: var(--fg-faint);
  letter-spacing: 0; }

/* ============================================================================
   LOGIN
   ========================================================================== */
.login-body { display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #10213a 0%, var(--bg) 55%); }
.login-card {
  width: 340px; background: var(--panel); padding: 2rem 1.8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .65rem;
}
.login-card .brand { font-size: 1.3rem; margin-bottom: .1rem; }
.login-card .tagline { color: var(--fg-muted); font-size: .82rem; margin-bottom: .8rem; }
.login-card button { margin-top: .4rem; padding: .65rem; }
.err { color: var(--sev-critical); min-height: 1.2em; font-size: .82rem; margin-top: .3rem; }

/* ============================================================================
   APP SHELL
   ========================================================================== */
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 1rem;
  padding: 0 1.1rem; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.spacer { flex: 1; }
.whoami { color: var(--fg-muted); font-size: .82rem; font-family: var(--font-mono); }
.topbar .brand .sub { margin-left: .35rem; }

.sources { display: flex; gap: .3rem; flex-wrap: wrap; }
.src {
  font-family: var(--font-mono); font-size: .66rem; text-transform: uppercase;
  letter-spacing: .04em; padding: .18rem .45rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--fg-faint);
  display: inline-flex; align-items: center; gap: .3rem;
}
.src::before { content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--fg-faint); }
.src.on { color: var(--sev-ok); border-color: color-mix(in srgb, var(--sev-ok) 45%, transparent); }
.src.on::before { background: var(--sev-ok); box-shadow: 0 0 6px var(--sev-ok); }

.layout { display: flex; height: calc(100vh - var(--topbar-h)); }

/* --- sidebar -------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem;
}
.nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--fg-faint); font-weight: 600; margin: .2rem .25rem .1rem; }
.newscan { display: flex; flex-direction: column; gap: .5rem;
  background: var(--panel-2); padding: .9rem; border-radius: var(--radius);
  border: 1px solid var(--border); }
.newscan h3 { font-size: .9rem; }
.hint { color: var(--fg-faint); font-size: .72rem; margin: .1rem 0 0; line-height: 1.4; }

.scanlist { list-style: none; margin: 0; padding: 0; display: flex;
  flex-direction: column; gap: .25rem; }
.scanlist li {
  padding: .55rem .65rem; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid transparent; transition: background .12s, border-color .12s;
}
.scanlist li:hover { background: var(--panel-2); }
.scanlist li.sel { background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.scanlist .org { font-weight: 600; font-size: .85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scanlist .meta { display: flex; justify-content: space-between; align-items: center;
  gap: .4rem; margin-top: .2rem; }
.scanlist .meta .dom { color: var(--fg-faint); font-size: .72rem;
  font-family: var(--font-mono); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }

/* --- content -------------------------------------------------------------- */
.content { flex: 1; padding: 1.5rem; overflow-y: auto; background: var(--bg); }
.empty { color: var(--fg-faint); margin-top: 4rem; text-align: center; font-size: .95rem; }

.scanhead { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.1rem; }
.scanhead h2 { font-size: 1.25rem; }
.phase { font-family: var(--font-mono); font-size: .78rem; color: var(--accent);
  display: inline-flex; align-items: center; gap: .4rem; }
.phase.done { color: var(--sev-ok); }
.phase.err { color: var(--sev-critical); }

/* segmented tab control */
.segmented { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 1.2rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.segmented button { background: transparent; color: var(--fg-muted);
  border: 0; border-radius: 7px; padding: .4rem .85rem; font-weight: 500; }
.segmented button:hover { color: var(--fg); filter: none; background: var(--panel-2); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); }

/* ============================================================================
   PANELS + CARDS
   ========================================================================== */
.panel { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 1.1rem;
  overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--border); }
.panel-head h3 { font-size: .92rem; }
.panel-head .sub { color: var(--fg-faint); font-size: .76rem; font-weight: 400; }
.panel-body { padding: 1.1rem; }
.panel-body.flush { padding: 0; }

/* stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr));
  gap: .9rem; margin-bottom: 1.1rem; }
.stat { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow-sm); }
.stat .v { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 600;
  line-height: 1.1; letter-spacing: -.02em; }
.stat .l { color: var(--fg-muted); font-size: .76rem; margin-top: .35rem; }
.stat.feature { grid-column: span 1; }
.stat .gauge { font-size: 2.4rem; }

/* ============================================================================
   CHIPS (severity tiers) + tags
   ========================================================================== */
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--font-mono); font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
  padding: .15rem .5rem; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; }
.chip-tier-CRITICAL { color: var(--sev-critical);
  background: color-mix(in srgb, var(--sev-critical) 14%, transparent);
  border-color: color-mix(in srgb, var(--sev-critical) 40%, transparent); }
.chip-tier-HIGH { color: var(--sev-high);
  background: color-mix(in srgb, var(--sev-high) 14%, transparent);
  border-color: color-mix(in srgb, var(--sev-high) 40%, transparent); }
.chip-tier-MEDIUM { color: var(--sev-medium);
  background: color-mix(in srgb, var(--sev-medium) 14%, transparent);
  border-color: color-mix(in srgb, var(--sev-medium) 40%, transparent); }
.chip-tier-LOW { color: var(--sev-low);
  background: color-mix(in srgb, var(--sev-low) 14%, transparent);
  border-color: color-mix(in srgb, var(--sev-low) 40%, transparent); }
.chip-tier-OK { color: var(--sev-ok);
  background: color-mix(in srgb, var(--sev-ok) 14%, transparent);
  border-color: color-mix(in srgb, var(--sev-ok) 40%, transparent); }
.chip-tier-INFO { color: var(--fg-muted);
  background: color-mix(in srgb, var(--fg-muted) 14%, transparent);
  border-color: var(--border-2); }
.chip-kev { color: #fff; background: var(--sev-critical);
  border-color: var(--sev-critical); }
.chip-kev::before { background: #fff; box-shadow: 0 0 6px #fff; }
.chip-soft { color: var(--fg-muted); background: var(--panel-2);
  border-color: var(--border); }
.chip-soft::before { display: none; }

.tag { font-family: var(--font-mono); font-size: .72rem; color: var(--fg-faint);
  text-transform: uppercase; letter-spacing: .03em; }
.bars { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ============================================================================
   DATA TABLES
   ========================================================================== */
.data-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.data-table th { text-align: left; padding: .6rem 1.1rem; color: var(--fg-faint);
  font-weight: 600; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); background: var(--panel-2); }
.data-table td { padding: .6rem 1.1rem; border-bottom: 1px solid var(--border);
  vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  text-align: right; white-space: nowrap; }
.data-table .risk-num { font-family: var(--font-mono); font-weight: 600;
  font-size: .92rem; }
.data-table code, .mono-cell { font-family: var(--font-mono); font-size: .8rem; }
.ok  { color: var(--sev-ok); }
.bad { color: var(--sev-high); }

ul.exec { margin: .3rem 0; padding-left: 1.1rem; }
ul.exec li { margin: .3rem 0; }

/* ============================================================================
   MODAL
   ========================================================================== */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(3,7,18,.66); backdrop-filter: blur(3px); }
.modal-card { width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .6rem; }
.modal-card h3 { font-size: 1.05rem; margin-bottom: .2rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; }
.modal-wide { width: 440px; max-height: 86vh; overflow-y: auto; }

/* new-scan auto re-scan row */
.rescan { display: flex; align-items: center; gap: .4rem; font-size: .76rem;
  color: var(--fg-muted); }
.rescan input[type="checkbox"] { width: auto; }
.num-inline { width: 52px; padding: .2rem .35rem; text-align: center; }

/* settings key fields */
.keyrow { display: flex; align-items: center; gap: .6rem; padding: .5rem 0;
  border-bottom: 1px solid var(--border); }
.keyrow .meta { flex: 1; min-width: 0; }
.keyrow .klabel { font-weight: 600; font-size: .85rem; }
.keyrow .khelp { color: var(--fg-faint); font-size: .72rem; }
.keyrow input { flex: 0 0 150px; font-family: var(--font-mono); font-size: .78rem; }
.keyrow .status { flex: 0 0 auto; }

/* report tab action buttons */
.tab-actions { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.btn-link, .btn-link:hover { text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
