:root {
  --bg: #F3F5F9;
  --panel: #FFFFFF;
  --ink: #15202B;
  --muted: #5B6675;
  --line: #E1E5EC;
  --navy: #0F2C4C;
  --navy-2: #173F6B;
  --accent: #1F5FAD;
  --sky: #4FA3E0;
  --green: #1E8E3E;
  --amber: #E8A100;
  --red: #D93025;
  --grey: #8C96A3;
  --green-bg: #E6F4EA;
  --amber-bg: #FEF5DC;
  --red-bg: #FCE8E6;
  --blue-bg: #E8F0FB;
  --grey-bg: #EEF1F5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); display: flex; min-height: 100vh; font-size: 14px; }
a { color: var(--accent); }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--navy); }
h3 { font-size: 12px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- layout */
.sidebar { width: 248px; flex: 0 0 248px; background: var(--navy); color: #C9D6E8; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; flex-direction: column; gap: 12px; padding: 16px 14px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.client-logo { background: #fff; border-radius: 9px; padding: 6px 8px; display: flex; align-items: center; justify-content: center; min-height: 56px; }
.client-logo img { display: block; width: 100%; max-height: 104px; height: auto; object-fit: contain; }
.client-logo .fallback { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; color: var(--navy); width: 100%; }
.client-logo .fallback[hidden] { display: none; }
.client-logo .fallback b { font-size: 20px; letter-spacing: .06em; }
.client-logo .fallback span { font-size: 9.5px; color: var(--muted); }
.brand-app { border-left: 3px solid var(--sky); padding-left: 9px; }
.brand-app strong { color: #fff; font-size: 15.5px; display: block; }
.brand-app span { font-size: 11px; color: #8FA6C4; }
.entity-switch { margin: 12px 10px 4px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: 9px; padding: 9px 11px; color: #fff; text-decoration: none; display: block; }
.entity-switch:hover { background: rgba(255,255,255,.1); }
.entity-switch small { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #8FA6C4; }
.entity-switch b { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; margin-top: 2px; }
.entity-switch em { font-style: normal; font-size: 11.5px; color: #A9BCD6; }
.sidebar nav { padding: 4px 8px; flex: 1; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6F87A8; padding: 13px 10px 5px; }
.sidebar nav a { display: flex; justify-content: space-between; align-items: center; gap: 6px; color: #C9D6E8; text-decoration: none; padding: 8px 10px; border-radius: 7px; margin: 1px 0; font-size: 13.5px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 var(--sky); }
.sidebar nav a .prod { font-size: 10px; color: #8FA6C4; font-weight: 600; }
.sidebar nav a.nav-tour { background: rgba(79,163,224,.16); color: #fff; font-weight: 600; margin: 6px 0 2px; }
.pill { background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.pill:empty { display: none; }
.sidebar-foot { font-size: 11px; color: #6F87A8; padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .logout { color: #8FA6C4; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { margin: 0; font-size: 19px; color: var(--navy); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.badge-synth { font-size: 11px; font-weight: 600; color: #7A5B00; background: var(--amber-bg); border: 1px solid #F3D98A; padding: 4px 9px; border-radius: 20px; white-space: nowrap; }
.view { padding: 20px 28px 40px; max-width: 1500px; width: 100%; }
.entity-strip { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 12.5px; color: var(--muted); }
.entity-strip b { color: var(--ink); font-weight: 600; }

/* ---------- components */
.btn { font: inherit; font-size: 13px; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 13px; border-radius: 7px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn[disabled] { opacity: .5; cursor: default; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 10px 30px rgba(16,24,40,.15); min-width: 290px; padding: 6px; z-index: 30; }
.menu-list[hidden] { display: none; }
.menu-list a { display: flex; justify-content: space-between; gap: 10px; padding: 7px 9px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 13px; }
.menu-list a:hover { background: var(--blue-bg); }
.menu-list a span { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 600; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.src { font-size: 11px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow); border-top: 4px solid var(--grey); }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 700; margin: 4px 0 2px; color: var(--navy); }
.kpi .s { font-size: 11.5px; color: var(--muted); }
.kpi.st-green { border-top-color: var(--green); } .kpi.st-amber { border-top-color: var(--amber); } .kpi.st-red { border-top-color: var(--red); } .kpi.st-none { border-top-color: var(--accent); }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 330px; }
.chart-box.short { height: 200px; }
.callout { background: #EEF4FC; border: 1px solid #CFE0F5; border-radius: 8px; padding: 11px 15px; font-size: 13.5px; color: #24425F; margin-bottom: 16px; line-height: 1.45; }
.callout.warn { background: var(--amber-bg); border-color: #F3D98A; color: #6B5000; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; padding: 8px; border-bottom: 1px solid var(--line); background: #FAFBFD; position: sticky; top: 0; z-index: 1; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; } tr.click:hover td { background: #F6F9FE; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 520px; overflow-y: auto; }
tr.detail td { background: #FAFBFD; font-size: 12.5px; }
tr.detail dl { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; margin: 0; }
tr.detail dt { color: var(--muted); font-weight: 600; }
tr.detail dd { margin: 0; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; padding: 2px 9px; border-radius: 20px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.green { color: var(--green); background: var(--green-bg); }
.status.amber { color: #A86F00; background: var(--amber-bg); }
.status.red { color: var(--red); background: var(--red-bg); }
.status.blue { color: var(--accent); background: var(--blue-bg); }
.status.grey { color: #5B6675; background: var(--grey-bg); }
.grade { display: inline-block; min-width: 24px; text-align: center; font-weight: 700; border-radius: 5px; color: #fff; padding: 1px 5px; }
.grade.A { background: #1E8E3E; } .grade.B { background: #6BA539; } .grade.C { background: #E8A100; } .grade.D { background: #E8743B; } .grade.F { background: #D93025; }
.grade.big { font-size: 15px; padding: 2px 8px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 4px; background: #EEF2F8; color: #3B4A5E; margin: 1px 2px 1px 0; white-space: nowrap; }
.tag.prod { background: #FFF1E6; color: #8A3E00; }
.tag.tlp-amber { background: #FFC000; color: #000; font-weight: 700; }
.tag.tlp-clear { background: #fff; color: #000; border: 1px solid #999; font-weight: 700; }
.tag.mine { background: var(--green-bg); color: var(--green); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--green); } .down { color: var(--red); }
.progress { height: 8px; background: #EDF0F5; border-radius: 6px; overflow: hidden; min-width: 70px; }
.progress span { display: block; height: 100%; background: var(--accent); }
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar-cell .track { position: relative; flex: 1; height: 8px; background: #EDF0F5; border-radius: 6px; min-width: 80px; }
.bar-cell .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; background: var(--accent); }
.bar-cell .base { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #8C96A3; }
.bar-cell .target { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--navy); border-radius: 2px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select, .form input, .form select { font: inherit; padding: 6px 9px; border: 1px solid #C9D1DD; border-radius: 6px; background: #fff; }
.seg { display: inline-flex; border: 1px solid #C9D1DD; border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg a, .seg button { font: inherit; padding: 6px 12px; font-size: 13px; color: var(--ink); text-decoration: none; border: none; border-right: 1px solid #E1E5EC; background: #fff; cursor: pointer; }
.seg a:last-child, .seg button:last-child { border-right: none; }
.seg a.on, .seg button.on { background: var(--navy-2); color: #fff; }

/* required elements chips */
.el-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.el { border: 1px solid var(--line); border-left: 5px solid var(--grey); border-radius: 8px; padding: 9px 11px; background: #fff; }
.el.met { border-left-color: var(--green); } .el.partial { border-left-color: var(--amber); } .el.not-met { border-left-color: var(--red); }
.el b { display: block; font-size: 12.5px; color: var(--navy); }
.el .v { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* goals */
.goal { border: 1px solid var(--line); border-radius: 9px; margin-bottom: 12px; overflow: hidden; }
.goal-head { background: #F7F9FC; padding: 9px 13px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.goal-head b { color: var(--navy); font-size: 13px; }
.goal table td:first-child { width: 52px; font-weight: 700; color: var(--navy); }

/* map / entity picker */
.pr-map { width: 100%; height: auto; display: block; }
.pr-map path { stroke: #fff; stroke-width: 1; cursor: pointer; transition: fill .12s; }
.pr-map path:hover { fill: var(--navy-2) !important; }
.pr-map path.sel { fill: var(--navy) !important; stroke: #FFC000; stroke-width: 2.5; }
.pr-map text { font-size: 9px; fill: #24425F; pointer-events: none; text-anchor: middle; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }
.picker-list { columns: 3 220px; column-gap: 18px; }
.picker-list a { display: flex; justify-content: space-between; gap: 6px; padding: 4px 6px; border-radius: 5px; text-decoration: none; color: var(--ink); break-inside: avoid; font-size: 13px; }
.picker-list a:hover { background: var(--blue-bg); }
.picker-list a.sel { background: var(--navy); color: #fff; }
.picker-list a small { color: var(--muted); font-size: 11px; }
.picker-list a.sel small { color: #C9D6E8; }

/* MITRE matrix */
.matrix { display: grid; grid-template-columns: repeat(12, minmax(104px, 1fr)); gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.matrix .col h4 { font-size: 10.5px; margin: 0 0 5px; color: var(--navy); text-transform: uppercase; letter-spacing: .03em; min-height: 26px; }
.matrix .t { font-size: 11px; border-radius: 5px; padding: 5px 6px; margin-bottom: 4px; color: #fff; line-height: 1.25; }
.matrix .t small { display: block; opacity: .85; font-size: 10px; }
.matrix .t.prevented { background: var(--green); } .matrix .t.detected { background: var(--amber); color: #3b2a00; } .matrix .t.missed { background: var(--red); } .matrix .t.not-tested { background: #C9D1DD; color: #3B4A5E; }
.matrix .t.hp { box-shadow: inset 0 0 0 2px var(--navy); }

/* tour */
.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; margin-bottom: 18px; }
.case { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.case-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.case-n { font-weight: 700; font-size: 12px; color: #fff; background: var(--navy-2); border-radius: 6px; padding: 2px 8px; white-space: nowrap; }
.case p { margin: 0; font-size: 13px; color: #33404F; flex: 1; }
.case .ev { font-size: 12px; color: var(--accent); font-weight: 600; }
.tour-h { font-size: 14px; color: var(--navy); margin: 6px 0 10px; }

/* timeline */
.gantt td.m { padding: 4px 2px; text-align: center; }
.gantt td.m span { display: block; height: 14px; border-radius: 3px; background: #EDF0F5; }
.gantt td.m span.on { background: var(--accent); }
.gantt td.m span.on.past { background: #8FB3E0; }
.gantt th.now, .gantt td.now { background: #FFF6D6; }

/* connectors */
.conn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 16px; }
.conn { border-top: 4px solid var(--accent); }
.conn.out { border-top-color: var(--sky); }
.conn .mode { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: #EEF2F8; color: #3B4A5E; }
.conn dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; margin: 10px 0 0; }
.conn dt { color: var(--muted); }
.conn dd { margin: 0; }
pre.payload { background: #0E1726; color: #D6E2F5; font-size: 11.5px; padding: 10px 12px; border-radius: 7px; overflow: auto; max-height: 280px; margin: 6px 0 0; }
details summary { cursor: pointer; }

/* simulator */
.sim-controls { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 12px 16px; align-items: end; }
.sim-controls label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.sim-controls select, .sim-controls input[type=number] { font: inherit; padding: 6px 9px; border: 1px solid #C9D1DD; border-radius: 6px; background: #fff; }
.sim-controls input[type=range] { accent-color: var(--accent); }
.sim-controls b { color: var(--navy); }

/* modal and toasts */
.modal { position: fixed; inset: 0; background: rgba(11, 22, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 34px 16px; z-index: 40; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; width: min(1100px, 100%); padding: 22px 24px; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-x { position: absolute; top: 10px; right: 12px; border: none; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0; flex-wrap: wrap; }
.tabs button { font: inherit; font-size: 13px; border: none; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--navy); border-bottom-color: var(--accent); font-weight: 600; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: 13px; max-width: 380px; animation: fade .25s ease; }
.toast.red { background: var(--red); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1100px) {
  .g3, .g-2-1, .g-1-2 { grid-template-columns: minmax(0, 1fr); }
  .sim-controls { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  body { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; flex: none; }
  .brand { flex-direction: row; align-items: center; justify-content: space-between; }
  .client-logo { min-height: 44px; max-width: 170px; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group, .sidebar-foot, .sidebar nav a .prod { display: none; }
  .g2 { grid-template-columns: minmax(0, 1fr); }
  .topbar { position: static; flex-direction: column; align-items: flex-start; padding: 12px 16px; }
  .view { padding: 16px; }
  .sim-controls { grid-template-columns: 1fr; }
  .case-grid { grid-template-columns: 1fr; }
}
@media print { .sidebar, .top-actions { display: none; } }

/* language toggle */
.lang-toggle button { padding: 4px 10px; font-size: 12px; font-weight: 600; }
