/* SafePhish design system — dual-theme (dark default + light), animated. */

/* ---------- Design tokens ---------- */
:root {
  /* Dark theme (default) */
  --bg: #0a0e1a;
  --bg-a: rgba(91,141,239,.10);
  --bg-b: rgba(139,123,255,.12);
  --surface: #131a2b;
  --surface-2: #0f1524;
  --elevate: #18213a;
  --border: #232d44;
  --border-soft: #1b2338;
  --text: #eef2fb;
  --text-dim: #b3bed6;
  --muted: #7f8ca8;
  --faint: #5a6785;
  --brand: #6ea8fe;
  --brand-2: #8b7bff;
  --grad: linear-gradient(135deg, #5b8def 0%, #8b7bff 100%);
  --grad-soft: linear-gradient(135deg, rgba(91,141,239,.18), rgba(139,123,255,.18));
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #38bdf8;
  --code-bg: #070c17;
  --code-text: #a7b6d4;
  --shadow: 0 20px 45px -20px rgba(0,0,0,.75);
  --shadow-sm: 0 8px 22px -14px rgba(0,0,0,.7);
  --ring: 0 0 0 3px rgba(110,168,254,.28);
  --hairline: rgba(255,255,255,.08);
  --hover: rgba(255,255,255,.04);

  --radius: 15px;
  --radius-sm: 10px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(.2,.7,.2,1);
}

:root[data-theme="light"] {
  --bg: #eef1f8;
  --bg-a: rgba(91,141,239,.14);
  --bg-b: rgba(139,123,255,.16);
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --elevate: #eef2f9;
  --border: #dbe2ee;
  --border-soft: #e7ecf4;
  --text: #0f1a2e;
  --text-dim: #384357;
  --muted: #6b7688;
  --faint: #97a1b3;
  --brand: #3f6fe0;
  --brand-2: #7355f0;
  --grad: linear-gradient(135deg, #4d7cf0 0%, #7355f0 100%);
  --grad-soft: linear-gradient(135deg, rgba(77,124,240,.12), rgba(115,85,240,.12));
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --info: #0284c7;
  --code-bg: #0f172a;
  --code-text: #cbd5e1;
  --shadow: 0 24px 50px -26px rgba(30,50,90,.35);
  --shadow-sm: 0 10px 26px -18px rgba(30,50,90,.35);
  --ring: 0 0 0 3px rgba(63,111,224,.22);
  --hairline: rgba(15,26,46,.06);
  --hover: rgba(15,26,46,.04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1200px 700px at 12% -8%, var(--bg-a), transparent 55%),
    radial-gradient(1000px 620px at 108% 6%, var(--bg-b), transparent 50%),
    var(--bg);
  background-attachment: fixed;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-2); }
::selection { background: color-mix(in srgb, var(--brand) 35%, transparent); }

/* Smooth theme cross-fade on color-bearing surfaces. */
body, .sidebar, .brand .name, .nav a, .card, .stat, input, select, textarea, pre,
button, .btn, table, th, td, .flash, .pill, .account .who, .account .logout, .theme-toggle {
  transition: background-color .32s var(--ease), color .28s var(--ease),
              border-color .28s var(--ease), box-shadow .28s var(--ease);
}

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; align-self: flex-start; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 4px; margin-bottom: 16px;
}
.brand .logo {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--grad); box-shadow: 0 8px 20px -6px color-mix(in srgb, var(--brand) 70%, transparent);
  color: #fff; font-size: 17px;
  animation: floaty 6s ease-in-out infinite;
}
.brand .brand-logo {
  height: 38px; width: auto; max-width: 170px; flex-shrink: 0;
  object-fit: contain;
  animation: floaty 6s ease-in-out infinite;
}
.brand .name {
  font-size: 19px; font-weight: 800; letter-spacing: -.02em;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.theme-toggle {
  margin-left: auto; width: 34px; height: 34px; flex-shrink: 0;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text-dim);
  padding: 0;
}
.theme-toggle:hover { color: var(--brand); border-color: var(--brand); box-shadow: var(--shadow-sm); }
.theme-toggle svg { width: 17px; height: 17px; transition: transform .5s var(--ease), opacity .3s; }
.theme-toggle .i-sun { display: none; }
.theme-toggle .i-moon { display: block; }
:root[data-theme="light"] .theme-toggle .i-sun { display: block; }
:root[data-theme="light"] .theme-toggle .i-moon { display: none; }
.theme-toggle:active svg { transform: rotate(40deg) scale(.9); }

.nav { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; scrollbar-width: thin; }
.nav-section { margin: 10px 0 2px; }
.nav-section > summary {
  list-style: none; cursor: pointer;
  color: var(--faint); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  padding: 6px 10px; display: flex; align-items: center; gap: 8px; user-select: none;
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary::after {
  content: "›"; margin-left: auto; font-size: 14px; color: var(--faint); transition: transform .22s var(--ease);
}
.nav-section[open] > summary::after { transform: rotate(90deg); }

.nav a {
  position: relative; display: flex; align-items: center; gap: 10px;
  color: var(--text-dim); font-size: 13.5px; font-weight: 500;
  padding: 9px 11px; border-radius: var(--radius-sm);
  transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
}
.nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .78; transition: opacity .2s, transform .2s var(--ease); }
.nav a:hover { background: var(--hover); color: var(--text); transform: translateX(3px); }
.nav a:hover svg { transform: scale(1.12); }
.nav a.active { color: var(--text); background: var(--grad-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 28%, transparent); }
.nav a.active svg { opacity: 1; color: var(--brand); }
.nav a.active::before {
  content: ""; position: absolute; left: -14px; top: 50%;
  width: 3px; height: 22px; border-radius: 0 3px 3px 0; background: var(--grad);
  transform: translateY(-50%) scaleY(0); transform-origin: center;
  animation: barIn .3s var(--ease) forwards;
}

.account { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.account .who {
  display: flex; align-items: center; gap: 9px; padding: 8px; margin-bottom: 6px;
  border-radius: var(--radius-sm); text-decoration: none; color: var(--text);
}
.account .who:hover { background: var(--hover); }
.account .who.active { background: var(--grad-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 25%, transparent); }
.account .avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; background: var(--grad); text-transform: uppercase;
}
.account .who-meta { min-width: 0; }
.account .who-name { font-size: 13px; font-weight: 600; }
.account .who-role { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.account .who-cog { margin-left: auto; color: var(--muted); flex-shrink: 0; transition: transform .4s var(--ease); }
.account .who:hover .who-cog { color: var(--brand); transform: rotate(45deg); }
.account .logout {
  width: 100%; background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 7px; box-shadow: none;
}
.account .logout:hover { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }

.content { flex: 1; min-width: 0; }
/* Fill the width available after the sidebar — no centered max-width gutters. */
main { max-width: none; margin: 0; padding: 26px 32px 48px; }

/* Staggered entrance for page content. */
main > * { animation: fadeUp .5s var(--ease) both; }
main > *:nth-child(1) { animation-delay: .02s; }
main > *:nth-child(2) { animation-delay: .08s; }
main > *:nth-child(3) { animation-delay: .14s; }
main > *:nth-child(4) { animation-delay: .20s; }
main > *:nth-child(5) { animation-delay: .26s; }
main > *:nth-child(n+6) { animation-delay: .30s; }

/* ---------- Page header ---------- */
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 23px; font-weight: 800; letter-spacing: -.025em; display: inline-flex; align-items: center; gap: 12px; }
.page-head p { margin: 8px 0 0; color: var(--muted); font-size: 13.5px; }

/* Contextual title icon (cloned from the active nav item by anim.js). It sits in
   a soft brand badge; its own color overrides the gradient-text transparent fill. */
.page-icon {
  width: 36px; height: 36px; flex-shrink: 0; padding: 8px; border-radius: 11px;
  color: var(--brand); -webkit-text-fill-color: currentColor;
  background: var(--grad-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 24%, transparent);
  animation: iconPop .45s var(--ease) both;
}

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; margin-bottom: 20px; box-shadow: var(--shadow-sm); position: relative;
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--hairline), transparent);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card h2 { margin: 0 0 4px; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.card .card-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 16px; }
.card h2 + .row, .card h2 + form, .card h2 + table, .card h2 + pre { margin-top: 14px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.stat { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 14px 16px; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em; }

/* ---------- Forms ---------- */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-dim); margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 13.5px; font-family: inherit;
}
textarea { resize: vertical; min-height: 90px; }
input[type=file] {
  width: 100%; padding: 9px 12px; background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); color: var(--text-dim); font-size: 13px; cursor: pointer;
}
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 7px 13px; border: none; border-radius: 8px;
  background: var(--elevate); color: var(--text); font-weight: 600; font-family: inherit; font-size: 12.5px; cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: var(--border); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--faint); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); margin: 0; cursor: pointer; }
.check input { width: auto; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--grad); color: #fff; border: none; cursor: pointer;
  border-radius: var(--radius-sm); padding: 10px 16px; font-size: 13.5px; font-weight: 700; font-family: inherit;
  box-shadow: 0 8px 18px -10px color-mix(in srgb, var(--brand) 80%, transparent);
  transition: transform .12s var(--ease), filter .18s, box-shadow .2s;
}
button:hover, .btn:hover { filter: brightness(1.07); transform: translateY(-1px); box-shadow: 0 12px 24px -10px color-mix(in srgb, var(--brand) 85%, transparent); }
button:active, .btn:active { transform: translateY(0); }
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); box-shadow: none; }
button.secondary:hover { color: var(--text); border-color: var(--brand); background: var(--elevate); }
button.danger, .btn.danger { background: linear-gradient(135deg, var(--bad), color-mix(in srgb, var(--bad) 75%, #fff)); color: #fff; }
button.ghost { background: transparent; box-shadow: none; color: var(--muted); border: 1px solid var(--border); }
form.inline { display: inline; }

/* ---------- Pills / badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.pill.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 32%, transparent); }
.pill.info { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
/* Wrap wide tables so they scroll within their card instead of overflowing it. */
.table-wrap { overflow-x: auto; }
.table-wrap table { min-width: 640px; }
.table-wrap th, .table-wrap td { white-space: nowrap; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
tbody tr { transition: background .14s; }
tbody tr:hover { background: var(--hover); }
td.actions { display: flex; gap: 8px; }

/* ---------- Code / output ---------- */
pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; overflow: auto; font-size: 12.5px; color: var(--code-text); white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92em;
  background: var(--hover); padding: 1px 5px; border-radius: 5px; }

/* ---------- Flash ---------- */
.flash { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 20px; font-size: 13.5px; font-weight: 500; animation: slideDown .4s var(--ease) both; }
.flash::before { font-size: 15px; font-weight: 700; }
.flash.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.flash.ok::before { content: "✓"; }
.flash.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); color: var(--bad); }
.flash.bad::before { content: "!"; }

.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); font-size: 13.5px; padding: 8px 0; }

/* ---------- Template editor (chips + toolbar) ---------- */
.editor-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 4px; }
.editor-bar .bar-label { font-size: 11.5px; color: var(--muted); margin-right: 4px; }
.var-chip {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
  padding: 3px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--brand); cursor: pointer; box-shadow: none; font-weight: 500;
}
.var-chip:hover { background: var(--brand); color: #fff; border-color: var(--brand); transform: none; }
.tool-btn {
  font-size: 12.5px; padding: 4px 10px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-dim); cursor: pointer; box-shadow: none; font-weight: 600;
}
.tool-btn:hover { color: var(--text); border-color: var(--brand); background: var(--elevate); transform: none; }
.tool-sep { width: 1px; align-self: stretch; background: var(--border-soft); margin: 2px 4px; }

/* ---------- Quiz builder ---------- */
.qb-q { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; background: var(--surface-2); }
.qb-q > input[type=text] { margin-top: 8px; }
.qb-opts { display: flex; flex-direction: column; gap: 7px; }
.qb-opt { display: flex; align-items: center; gap: 9px; margin: 0; }
.qb-opt input[type=radio] { width: 18px; height: 18px; accent-color: var(--ok); flex-shrink: 0; }
.qb-opt input[type=text] { flex: 1; }
.qb-opt .tool-btn { padding: 6px 9px; }

/* ---------- Help icon + modal ---------- */
.help-btn {
  display: inline-grid; place-items: center; width: 19px; height: 19px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 12px; font-weight: 700; cursor: pointer; margin-left: 7px; vertical-align: middle;
  padding: 0; box-shadow: none; line-height: 1;
}
.help-btn:hover { color: #fff; background: var(--brand); border-color: var(--brand); transform: none; }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(3,7,18,.62); backdrop-filter: blur(3px);
  display: none; align-items: flex-start; justify-content: center; padding: 44px 20px; z-index: 100; overflow: auto;
}
.modal-overlay.open { display: flex; animation: fadeUp .22s var(--ease); }
.modal {
  width: 100%; max-width: 640px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 17px; cursor: pointer; box-shadow: none; padding: 4px 8px; }
.modal-close:hover { color: var(--text); transform: none; filter: none; }
.modal-body { padding: 20px 22px; max-height: 68vh; overflow: auto; font-size: 13.5px; color: var(--text-dim); line-height: 1.6; }
.modal-body ol, .modal-body ul { padding-left: 20px; margin: 4px 0 14px; }
.modal-body li { margin-bottom: 7px; }
.modal-body h4 { margin: 18px 0 6px; font-size: 13.5px; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }
.modal-body a { color: var(--brand); }
.modal-body .warn-box { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 10px; padding: 12px 14px; margin-top: 6px; color: var(--text-dim); }

/* ---------- Funnel bars ---------- */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.funnel-row span { width: 90px; color: var(--text-dim); }
.funnel-row b { width: 48px; text-align: right; font-variant-numeric: tabular-nums; }
.funnel-row .bar { flex: 1; height: 10px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 999px; overflow: hidden; }
.funnel-row .bar i { display: block; height: 100%; border-radius: 999px; background: var(--grad); transition: width .6s var(--ease); }
.funnel-row .bar i.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.funnel-row .bar i.bad { background: linear-gradient(90deg, #ef4444, #f87171); }
.funnel-row .bar i.ok { background: linear-gradient(90deg, #10b981, #34d399); }

/* ---------- Dashboard ---------- */
.nav-top { margin-bottom: 4px; font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(212px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  position: relative; display: flex; align-items: center; gap: 14px; overflow: hidden;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow-sm); color: var(--text);
  transition: transform .2s var(--ease), box-shadow .25s var(--ease), border-color .2s var(--ease);
  animation: fadeUp .5s var(--ease) both;
}
a.kpi { text-decoration: none; }
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--kpi-c, var(--brand)) 50%, var(--border)); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kpi-c, var(--brand)); }
.kpi-ic {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 13px; display: grid; place-items: center;
  color: var(--kpi-c, var(--brand)); background: color-mix(in srgb, var(--kpi-c, var(--brand)) 15%, transparent);
}
.kpi-ic svg { width: 23px; height: 23px; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-v { font-size: 31px; font-weight: 800; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi-k { font-size: 11.5px; color: var(--muted); margin-top: 5px; text-transform: uppercase; letter-spacing: .05em; }
.kpi-tag {
  position: absolute; top: 12px; right: 14px; font-size: 11px; font-weight: 600; color: var(--kpi-c, var(--brand));
  background: color-mix(in srgb, var(--kpi-c, var(--brand)) 13%, transparent); padding: 3px 9px; border-radius: 999px;
}
.kpi-brand { --kpi-c: var(--brand); }
.kpi-info  { --kpi-c: var(--info); }
.kpi-warn  { --kpi-c: var(--warn); }
.kpi-bad   { --kpi-c: var(--bad); }
.kpi-grid .kpi:nth-child(2) { animation-delay: .06s; }
.kpi-grid .kpi:nth-child(3) { animation-delay: .12s; }
.kpi-grid .kpi:nth-child(4) { animation-delay: .18s; }

/* Security posture gauge */
.dash-center { display: flex; flex-direction: column; }
.gauge {
  --val: 0; --gauge-c: var(--brand);
  width: 158px; height: 158px; margin: 12px auto 4px; border-radius: 50%;
  display: grid; place-items: center; position: relative;
  background: conic-gradient(var(--gauge-c) calc(var(--val) * 1%), color-mix(in srgb, var(--border) 55%, transparent) 0);
}
.gauge.g-ok { --gauge-c: var(--ok); }
.gauge.g-warn { --gauge-c: var(--warn); }
.gauge.g-bad { --gauge-c: var(--bad); }
.gauge::before {
  content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--surface);
  box-shadow: inset 0 2px 12px color-mix(in srgb, #000 14%, transparent);
}
.gauge-inner { position: relative; text-align: center; }
.gauge-num { font-size: 42px; font-weight: 800; letter-spacing: -.03em; line-height: 1; color: var(--gauge-c); font-variant-numeric: tabular-nums; }
.gauge-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.posture-tag { text-align: center; margin-top: 8px; }

/* Program inventory tiles */
.inv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.inv {
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none;
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 15px 8px; color: var(--text);
  transition: transform .18s var(--ease), border-color .2s var(--ease), background .2s var(--ease);
}
.inv:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--brand) 42%, var(--border)); background: var(--grad-soft); }
.inv-v { font-size: 25px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.inv-k { font-size: 11.5px; color: var(--muted); }

@media (max-width: 560px) { .inv-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Auth / login ---------- */
.auth-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; position: relative; overflow: hidden;
}

/* Drifting aurora orbs + parallax grid behind the card. Brand-colored, so they
   re-tint automatically in light and dark themes. */
.auth-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.auth-bg .orb { position: absolute; border-radius: 50%; filter: blur(72px); will-change: transform; }
.auth-bg .orb-1 {
  width: 480px; height: 480px; left: -130px; top: -120px; opacity: .5;
  background: radial-gradient(circle at 30% 30%, var(--brand), transparent 70%);
  animation: drift1 19s ease-in-out infinite;
}
.auth-bg .orb-2 {
  width: 540px; height: 540px; right: -150px; top: 8%; opacity: .5;
  background: radial-gradient(circle at 60% 40%, var(--brand-2), transparent 70%);
  animation: drift2 23s ease-in-out infinite;
}
.auth-bg .orb-3 {
  width: 440px; height: 440px; left: 32%; bottom: -180px; opacity: .38;
  background: radial-gradient(circle at 50% 50%, var(--info), transparent 70%);
  animation: drift3 27s ease-in-out infinite;
}
.auth-bg::after {
  content: ""; position: absolute; inset: -2px;
  background-image:
    linear-gradient(var(--hairline) 1px, transparent 1px),
    linear-gradient(90deg, var(--hairline) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(circle at 50% 42%, #000, transparent 68%);
  mask-image: radial-gradient(circle at 50% 42%, #000, transparent 68%);
  animation: gridPan 42s linear infinite;
}

.auth-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 412px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 86%, transparent), color-mix(in srgb, var(--surface-2) 86%, transparent));
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent); border-radius: 22px;
  padding: 40px 36px 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
  animation: cardIn .7s var(--ease) both, cardGlow 7s ease-in-out .7s infinite;
}

/* Staggered entrance of the card contents. */
.auth-card > * { animation: fadeUp .5s var(--ease) both; }
.auth-card > h1 { animation-delay: .10s; }
.auth-card > .sub { animation-delay: .16s; }
.auth-card > label:nth-of-type(1) { animation-delay: .22s; }
.auth-card > input:nth-of-type(1) { animation-delay: .26s; }
.auth-card > label:nth-of-type(2) { animation-delay: .32s; }
.auth-card > input:nth-of-type(2) { animation-delay: .36s; }
.auth-card > button { animation-delay: .44s; }
.auth-card > .foot { animation-delay: .52s; }

.auth-card .brand-logo-lg {
  display: block; width: 224px; max-width: 82%; height: auto; margin: 0 auto 12px;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px color-mix(in srgb, var(--brand) 32%, transparent));
  animation: logoIn .8s var(--ease) both, floaty 6s ease-in-out 1s infinite;
}
.auth-card h1 {
  text-align: center; font-size: 27px; font-weight: 800; margin: 4px 0 3px; letter-spacing: -.03em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 26px; }
.auth-card label {
  display: block; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-dim); margin: 14px 0 6px;
}
.auth-card input {
  width: 100%; font-size: 14.5px;
  transition: border-color .2s var(--ease), box-shadow .25s var(--ease), transform .18s var(--ease), background .2s var(--ease);
}
.auth-card input:focus {
  box-shadow: var(--ring), 0 10px 24px -14px color-mix(in srgb, var(--brand) 60%, transparent);
  transform: translateY(-1px);
}
.auth-card button {
  position: relative; overflow: hidden; width: 100%; margin-top: 24px; padding: 13px;
  font-size: 15px; font-weight: 700; letter-spacing: .01em; border: none; border-radius: var(--radius-sm);
  color: #fff; background: var(--grad);
  box-shadow: 0 16px 32px -14px color-mix(in srgb, var(--brand) 78%, transparent);
  cursor: pointer;
  transition: transform .18s var(--ease), box-shadow .25s var(--ease), filter .2s var(--ease);
}
.auth-card button:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 42px -14px color-mix(in srgb, var(--brand) 88%, transparent);
  filter: brightness(1.06);
}
.auth-card button:active { transform: translateY(0); }
/* Recurring shine sweep across the button. */
.auth-card button::after {
  content: ""; position: absolute; top: 0; left: -60%; width: 45%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.38), transparent);
  transform: skewX(-20deg); animation: shine 3.6s ease-in-out infinite;
}
.auth-card .foot { text-align: center; color: var(--faint); font-size: 11px; margin-top: 26px; letter-spacing: .03em; }
.auth-error { background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent);
  color: var(--bad); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; text-align: center; margin-bottom: 4px;
  animation: slideDown .35s var(--ease) both; }
.auth-toggle { position: fixed; top: 20px; right: 20px; z-index: 3; }

/* ---------- Global visual polish ---------- */
html { scroll-behavior: smooth; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: padding-box; }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 65%, transparent); outline-offset: 2px; }

/* Cards: materialize on load, lift on hover, and light up a brand top-accent. */
.card {
  transition: transform .22s var(--ease), box-shadow .28s var(--ease), border-color .22s var(--ease);
  animation: cardRise .5s var(--ease) both;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--brand) 24%, var(--border));
}
.card::before {
  height: 3px; border-radius: var(--radius) var(--radius) 0 0;
  background: var(--grad); opacity: .5; transition: opacity .25s var(--ease);
}
.card:hover::before { opacity: 1; }

/* Page titles rendered in the brand gradient. */
.page-head h1 {
  width: fit-content;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

/* Stat tiles: gradient numbers and a gentle hover lift. */
.stat { transition: transform .18s var(--ease), border-color .2s var(--ease), box-shadow .2s var(--ease); }
.stat:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--brand) 32%, var(--border)); box-shadow: var(--shadow-sm); }
.stat .v { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }

/* Inputs: smooth focus lift. */
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number],
input[type=date], input[type=search], input[type=tel], select, textarea {
  transition: border-color .18s var(--ease), box-shadow .2s var(--ease), transform .16s var(--ease), background .18s var(--ease);
}
input:focus, select:focus, textarea:focus { transform: translateY(-1px); }

/* Primary/action buttons in the app: a shine sweep on hover. */
main button:not(.secondary):not(.ghost):not(.modal-close):not(.help-btn):not(.var-chip):not(.tool-btn),
main .btn:not(.secondary):not(.ghost) { position: relative; overflow: hidden; }
main button:not(.secondary):not(.ghost):not(.modal-close):not(.help-btn):not(.var-chip):not(.tool-btn)::after,
main .btn:not(.secondary):not(.ghost)::after {
  content: ""; position: absolute; top: 0; left: -80%; width: 55%; height: 100%; pointer-events: none;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.28), transparent);
  transform: skewX(-20deg); transition: left .55s var(--ease);
}
main button:not(.secondary):not(.ghost):not(.modal-close):not(.help-btn):not(.var-chip):not(.tool-btn):hover::after,
main .btn:not(.secondary):not(.ghost):hover::after { left: 135%; }

/* Tables: shaded header + a crisp row-hover accent. */
thead th { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
tbody tr { transition: background .14s var(--ease), box-shadow .14s var(--ease); }
tbody tr:hover { box-shadow: inset 3px 0 0 var(--brand); }
.pill { transition: transform .14s var(--ease); }
tbody tr:hover .pill { transform: translateY(-1px); }

/* Flash: colored left accent bar. */
.flash { box-shadow: inset 4px 0 0 currentColor; }

/* ---------- Motion & delight ---------- */

/* Material-style click ripple (added by anim.js). Buttons must clip it. */
main button, main .btn { position: relative; overflow: hidden; }
.ripple {
  position: absolute; border-radius: 50%; transform: scale(0);
  background: currentColor; opacity: .28; pointer-events: none;
  animation: rippleFx .6s ease-out forwards;
}

/* Nav: the active item glows and its icon lifts. */
.nav a.active {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 30%, transparent),
              0 6px 18px -10px color-mix(in srgb, var(--brand) 60%, transparent);
}
.nav a.active svg { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--brand) 60%, transparent)); }
.nav a:hover svg { transform: scale(1.15) rotate(-3deg); }

/* Sidebar brand: a soft, slowly breathing glow behind the logo. */
.brand { position: relative; }
.brand::after {
  content: ""; position: absolute; left: 4px; top: 2px; width: 44px; height: 44px;
  border-radius: 14px; background: var(--grad); filter: blur(16px); opacity: .28;
  z-index: -1; animation: breathe 5s ease-in-out infinite;
}

/* Theme toggle: a brief global cross-fade when switching light/dark. */
.theme-anim, .theme-anim * {
  transition: background-color .4s var(--ease), color .4s var(--ease),
              border-color .4s var(--ease), box-shadow .4s var(--ease) !important;
}

/* Live SSE: a shimmering "connecting" badge, a pulsing "Live" dot, and a syncing
   sheen swept across regions until the first event arrives. */
.live-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; vertical-align: middle; letter-spacing: .02em; }
.live-badge .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: currentColor; }
.live-badge.connecting {
  color: var(--muted);
  background: linear-gradient(100deg, var(--surface-2) 30%, color-mix(in srgb, var(--brand) 16%, var(--surface-2)) 50%, var(--surface-2) 70%);
  background-size: 220% 100%; animation: shimmerBg 1.3s linear infinite;
}
.live-badge.live { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.live-badge.live .dot { animation: livePulse 1.6s ease-out infinite; }
.live-badge.done { color: var(--muted); background: var(--surface-2); }

/* Syncing sheen — a skeleton-style shimmer swept over live regions, without
   hiding the values already rendered. */
.syncing { position: relative; overflow: hidden; }
.syncing::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background: linear-gradient(100deg, transparent 20%, color-mix(in srgb, var(--brand) 14%, transparent) 50%, transparent 80%);
  transform: translateX(-100%); animation: shimmerSweep 1.4s ease-in-out infinite;
}

/* ---------- Keyframes ---------- */
@keyframes shimmerBg { to { background-position: -220% 0; } }
@keyframes shimmerSweep { to { transform: translateX(100%); } }
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes rippleFx { to { transform: scale(2.6); opacity: 0; } }
@keyframes breathe { 0%,100% { opacity: .22; transform: scale(1); } 50% { opacity: .38; transform: scale(1.08); } }
@keyframes iconPop { from { opacity: 0; transform: scale(.7) rotate(-8deg); } to { opacity: 1; transform: none; } }
@keyframes cardRise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes barIn { to { transform: translateY(-50%) scaleY(1); } }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) scale(.965); } to { opacity: 1; transform: none; } }
@keyframes cardGlow {
  0%,100% { box-shadow: var(--shadow), 0 20px 60px -28px color-mix(in srgb, var(--brand) 55%, transparent); }
  50%     { box-shadow: var(--shadow), 0 20px 60px -28px color-mix(in srgb, var(--brand-2) 62%, transparent); }
}
@keyframes logoIn { from { opacity: 0; transform: translateY(-12px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shine { 0%, 55% { left: -60%; } 100% { left: 150%; } }
@keyframes drift1 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(64px,44px) scale(1.1); } }
@keyframes drift2 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-54px,52px) scale(1.08); } }
@keyframes drift3 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(46px,-42px) scale(1.12); } }
@keyframes gridPan { to { background-position: 46px 46px, 46px 46px; } }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { overflow: visible; }
  main { padding: 22px 18px 40px; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
