/* ============================================================================
   VYOMA design system — light-first, Fluent/Apple-HIG inspired.
   Tokens per spec §12. Consumed only via CSS variables (white-label ready).
   ========================================================================== */
:root {
  --bg: #F7F9FC;
  --surface: #FFFFFF;
  --surface-2: #EEF3F9;
  --ink: #011737;
  --ink-2: #3B4A63;
  --muted: #6B7A93;
  --line: #E3EAF2;

  --primary: #4AAEE2;
  --primary-600: #2F97CE;
  --primary-050: #EAF6FC;
  --secondary: #011737;

  --sev-critical: #E5484D;
  --sev-high: #F76808;
  --sev-medium: #F5A623;
  --sev-low: #4AAEE2;
  --sev-info: #8A94A6;
  --ok: #2FBF71;
  --warn: #F5A623;
  --bad: #E5484D;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --e1: 0 1px 2px rgba(1,23,55,.06);
  --e2: 0 1px 2px rgba(1,23,55,.06), 0 8px 24px rgba(1,23,55,.06);
  --e3: 0 12px 32px rgba(1,23,55,.12);
  --e4: 0 24px 64px rgba(1,23,55,.18);
  --rail-w: 256px;
  --rail-w-collapsed: 68px;
  --topbar-h: 60px;
  --font: -apple-system, "Segoe UI Variable", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #111A2E;
  --surface-2: #16223C;
  --ink: #E6EDF7;
  --ink-2: #C3D0E4;
  --muted: #8AA0C6;
  --line: #223354;
  --primary-050: #14283f;
  --e1: 0 1px 2px rgba(0,0,0,.4);
  --e2: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --e3: 0 12px 32px rgba(0,0,0,.5);
  --e4: 0 24px 64px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--mono); font-size: .82em; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.nowrap { white-space: nowrap; }
::selection { background: var(--primary-050); }

/* ---- App shell ---- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "rail topbar" "rail main";
  height: 100vh;
  transition: grid-template-columns .2s cubic-bezier(.2,.8,.2,1);
}
.app.collapsed { grid-template-columns: var(--rail-w-collapsed) 1fr; }

/* ---- Top bar (glass) ---- */
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar .search {
  flex: 1; max-width: 560px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 7px 14px; color: var(--muted); cursor: text;
}
.topbar .search kbd {
  margin-left: auto; font-family: var(--mono); font-size: .72rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 6px; color: var(--muted);
}
.topbar .spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent; color: var(--ink-2);
  cursor: pointer; position: relative; transition: background .12s, color .12s;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.iconbtn .dot-badge {
  position: absolute; top: 5px; right: 5px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: 999px; background: var(--bad); color: #fff;
  font-size: .62rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .82rem;
}
.tenant-select {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-pill); padding: 6px 12px; cursor: pointer; color: var(--ink);
}
.tenant-select select {
  border: 0; background: transparent; color: var(--ink); font: inherit; cursor: pointer; outline: none;
}
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .78rem; }
.live .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---- Left rail ---- */
.rail {
  grid-area: rail;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
.rail-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 18px; border-bottom: 1px solid var(--line);
}
.rail-brand .logo {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 800;
}
.rail-brand .word { font-weight: 800; letter-spacing: .14em; }
.rail-brand .sub { font-size: .62rem; color: var(--muted); letter-spacing: .04em; }
.app.collapsed .rail-brand .word, .app.collapsed .rail-brand .sub { display: none; }

.rail-scroll { flex: 1; overflow-y: auto; padding: 10px 10px 24px; }
.rail-scroll::-webkit-scrollbar { width: 8px; }
.rail-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.rail-group-label {
  font-size: .64rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); font-weight: 700; padding: 14px 12px 6px;
}
.app.collapsed .rail-group-label { text-align: center; padding: 12px 0 4px; font-size: 0; }
.app.collapsed .rail-group-label::before { content: "•"; font-size: .9rem; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin: 1px 0; border-radius: var(--radius-sm);
  color: var(--ink-2); cursor: pointer; position: relative; font-size: .9rem;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--primary-050); color: var(--primary-600); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 3px; background: var(--primary);
}
.nav-item .ic { width: 20px; height: 20px; flex: none; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count {
  font-size: .7rem; font-weight: 700; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: 1px 7px;
}
.nav-item.active .count { color: #fff; background: var(--primary); }
.app.collapsed .nav-item { justify-content: center; padding: 10px 0; }
.app.collapsed .nav-item .label, .app.collapsed .nav-item .count { display: none; }

/* ---- Main canvas ---- */
.main { grid-area: main; overflow-y: auto; }
.page { padding: 22px 26px 60px; max-width: 1640px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.crumb { color: var(--muted); font-size: .82rem; }
.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: .86rem;
  padding: 7px 13px; transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: .8rem; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--e2);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.card-head .t { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }

/* ---- Stat tiles ---- */
.stat {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--primary);
  border-radius: var(--radius); padding: 15px 18px; box-shadow: var(--e1);
}
.stat .l { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 2rem; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.stat .d { font-size: .74rem; color: var(--muted); }
.stat.crit { border-left-color: var(--sev-critical); }
.stat.high { border-left-color: var(--sev-high); }
.stat.ok { border-left-color: var(--ok); }
.stat.warn { border-left-color: var(--warn); }
.stat.clickable { cursor: pointer; transition: transform .08s ease, box-shadow .12s ease, border-color .12s ease; }
.stat.clickable:hover { transform: translateY(-2px); box-shadow: var(--e2, 0 8px 20px rgba(0,0,0,.14)); }
.stat.clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stat.clickable::after { content: '↗'; float: right; color: var(--muted); font-size: .8rem; margin-top: -2px; opacity: .5; }

/* ---- Threat Hunting library ---- */
.hunt-lib { display: flex; flex-direction: column; }
.hunt-card { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .12s ease; }
.hunt-card:last-child { border-bottom: 0; }
.hunt-card:hover { background: var(--surface-2); }
.hunt-card.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--primary); }
.hunt-card .hunt-name { font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.hunt-card .hunt-mitre { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---- Monitored Activities watchlist ---- */
.m-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.m-row:hover { background: var(--surface-2); }
.m-row input { cursor: pointer; }
.m-row .m-label { font-size: .85rem; }
.ai-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: .9rem; line-height: 1.5; }

/* ---- Legend catalog (collapsible) ---- */
.leg-group > summary { cursor: pointer; padding: 8px 12px; font-weight: 600; font-size: .82rem; border-bottom: 1px solid var(--line); list-style: revert; }
.leg-group > summary:hover { background: var(--surface-2); }
.leg-row { padding: 7px 12px 7px 22px; }
.tbl tbody tr.ev-row:hover { background: var(--surface-2); }

/* ---- Badges / chips ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .72rem; font-weight: 700; padding: 2px 9px; border-radius: var(--radius-pill);
  text-transform: capitalize; color: #fff;
}
.sev-critical { background: var(--sev-critical); }
.sev-high { background: var(--sev-high); }
.sev-medium { background: var(--sev-medium); }
.sev-low { background: var(--sev-low); }
.sev-informational, .sev-info { background: var(--sev-info); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: .72rem;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
  border-radius: var(--radius-pill); padding: 2px 9px;
}
.chip.mitre { color: var(--primary-600); border-color: color-mix(in srgb, var(--primary) 30%, var(--line)); }
.pri { font-family: var(--mono); font-weight: 700; font-size: .72rem; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.riskpill { display:inline-flex; align-items:center; justify-content:center; min-width: 36px; padding: 2px 8px; border-radius: var(--radius-pill); font-weight: 800; color: #fff; font-size: .76rem; }

/* ---- Tables ---- */
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl thead th {
  text-align: left; color: var(--muted); font-size: .68rem; text-transform: uppercase;
  letter-spacing: .05em; font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.tbl tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl .num { font-family: var(--mono); }

/* ---- Forms ---- */
.input, select.input {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius-sm); padding: 7px 11px; font: inherit; font-size: .84rem; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,174,226,.2); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }

/* ---- Rank list ---- */
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--line); }
.rank li:last-child { border: 0; }
.rank .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .v { color: var(--primary-600); font-weight: 800; font-family: var(--mono); }

/* ---- Chart wrap ---- */
.chart { position: relative; height: 260px; }
.chart.sm { height: 200px; }

/* ---- Drawer ---- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(1,23,55,.35); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(680px, 94vw);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--e4);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  z-index: 41; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 18px 20px; overflow-y: auto; }

/* ---- Command palette ---- */
.palette-backdrop {
  position: fixed; inset: 0; background: rgba(1,23,55,.3); backdrop-filter: blur(3px);
  display: none; z-index: 60; align-items: flex-start; justify-content: center; padding-top: 12vh;
}
.palette-backdrop.open { display: flex; }
.palette {
  width: min(620px, 92vw); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(20px); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--e4); overflow: hidden;
}
.palette input { width: 100%; border: 0; background: transparent; color: var(--ink); font-size: 1.05rem; padding: 16px 18px; outline: none; }
.palette .res { max-height: 340px; overflow-y: auto; border-top: 1px solid var(--line); }
.palette .res .row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; }
.palette .res .row:hover, .palette .res .row.sel { background: var(--primary-050); }

/* ---- Toast ---- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 70; }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: var(--radius-sm); box-shadow: var(--e3); padding: 12px 16px; min-width: 260px; animation: slidein .25s; }
.toast.bad { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Empty / loading ---- */
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---- Attack story swimlane ---- */
.swim { display: flex; gap: 0; overflow-x: auto; padding: 6px 0; }
.swim .node { min-width: 180px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); position: relative; }
.swim .node + .node { margin-left: 34px; }
.swim .node + .node::before { content: "→"; position: absolute; left: -26px; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* ---- Login overlay ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg), var(--surface-2));
}
.login-card {
  width: min(360px, 92vw); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--e4); padding: 28px;
}
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .14em; font-size: 1.2rem; margin-bottom: 6px; }
.login-brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--secondary));
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .app { grid-template-columns: var(--rail-w-collapsed) 1fr; }
  .app .rail-brand .word, .app .rail-brand .sub { display: none; }
  .app .nav-item .label, .app .nav-item .count { display: none; }
  .app .nav-item { justify-content: center; }
  .app .rail-group-label { font-size: 0; text-align: center; }
}
@media (max-width: 720px) {
  .topbar .search { display: none; }
  .page { padding: 16px; }
}
