:root {
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f8fafc; --ink: #0e1b2e; --ink-2: #44546a; --ink-3: #6b7a8f;
  --line: #e2e7ee; --line-2: #cfd7e2; --brand: #0d3b66; --brand-2: #135a96; --accent: #0f766e; --accent-soft: #e6f4f2;
  --hi: #b42318; --hi-soft: #fdecea; --med: #b54708; --med-soft: #fef3e7; --low: #067647; --low-soft: #e8f5ee;
  --opp: #1d4ed8; --opp-soft: #e8efff; --crit: #7a1010;
  --h1: #fde8e6; --h2: #fbd0cb; --h3: #f59f94; --h4: #e45b4b; --h5: #b42318;
  --m1: #ecf8f0; --m2: #fff4d6; --m3: #fde3c3; --m4: #f9b98e; --m5: #ef7f5b;
  --radius: 10px; --shadow: 0 1px 2px rgba(14,27,46,.06), 0 1px 1px rgba(14,27,46,.04);
  --shadow-lg: 0 10px 30px rgba(14,27,46,.16);
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #121b2c; --surface-2: #172236; --ink: #e8eef7; --ink-2: #b6c2d3; --ink-3: #8696ab;
    --line: #22304a; --line-2: #2d3d5b; --brand: #7fb2e5; --brand-2: #9cc4ec; --accent: #3fc1b0; --accent-soft: #10302d;
    --hi: #ff8a7a; --hi-soft: #3a1717; --med: #f5b16b; --med-soft: #36250f; --low: #5fd39a; --low-soft: #0f2d20;
    --opp: #8fb0ff; --opp-soft: #172446;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 30px rgba(0,0,0,.5); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--brand-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
[dir="rtl"] .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: radial-gradient(1200px 600px at 20% 10%, #1b5c95 0%, #0d3b66 45%, #081f38 100%); color: #e9f1fb; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art h1 { font-size: 34px; font-weight: 700; max-width: 14ch; }
.login-art p { color: #b9cde4; max-width: 46ch; }
.login-art .grid-deco { position: absolute; inset-inline-end: -40px; bottom: -40px; display: grid; grid-template-columns: repeat(5, 46px); gap: 6px; opacity: .9; }
.login-art .grid-deco span { width: 46px; height: 46px; border-radius: 6px; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 32px 16px; background: var(--surface); }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 24px; margin-bottom: 4px; }
.login-card form { margin-top: 24px; display: grid; gap: 14px; }
.lang-btn { position: absolute; top: 16px; inset-inline-end: 16px; }
@media (max-width: 860px) { .login-wrap { grid-template-columns: 1fr; } .login-art { padding: 28px 16px; min-height: 220px; } .login-art h1 { font-size: 24px; } .login-art .grid-deco { display: none; } }

/* ---------- form controls ---------- */
label.field { display: grid; gap: 4px; font-size: 12px; font-weight: 500; color: var(--ink-2); }
.input, select.input, textarea.input { width: 100%; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); min-height: 36px; }
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--brand-2) 40%, transparent); border-color: var(--brand-2); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; min-height: 36px; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
[data-theme] .btn.primary, :root .btn.primary { color: #fff; }
.btn.danger { color: var(--hi); border-color: color-mix(in srgb, var(--hi) 40%, var(--line-2)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--hi-soft); color: var(--hi); font-size: 13px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: #0b2440; color: #cfdcec; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { display: block; color: #fff; font-size: 15px; }
.brand span { font-size: 12px; color: #8fa9c6; }
.nav { padding: 10px 8px; display: grid; gap: 2px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #cfdcec; text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav a .count { margin-inline-start: auto; background: rgba(255,255,255,.14); border-radius: 10px; padding: 0 7px; font-size: 11px; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.side-foot { margin-top: auto; padding: 14px 18px; font-size: 11px; color: #7f97b3; border-top: 1px solid rgba(255,255,255,.08); }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .proj { min-width: 0; }
.top .proj b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .proj span { font-size: 12px; color: var(--ink-3); }
.top .spacer { flex: 1; }
.livedot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.livedot i { width: 8px; height: 8px; border-radius: 50%; background: var(--low); box-shadow: 0 0 0 3px var(--low-soft); }
.livedot.off i { background: var(--med); box-shadow: 0 0 0 3px var(--med-soft); }
.content { padding: 20px 24px 48px; max-width: 1500px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--ink-3); font-size: 13px; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.menu-toggle { display: none; }
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; width: 260px; z-index: 30; transform: translateX(-105%); transition: transform .2s; }
  [dir="rtl"] .side { transform: translateX(105%); }
  .side.open { transform: none !important; box-shadow: var(--shadow-lg); }
  .menu-toggle { display: inline-flex; }
  .top { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .top .hide-sm { display: none; }
  .top .proj span { display: none; }
  .top .proj b { font-size: 14px; }
  .heat .cell { padding: 3px; }
}

/* ---------- cards / kpis ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 8px; padding: 14px 16px 0; }
.card-h h3 { font-size: 14px; font-weight: 600; }
.card-h .actions { margin-inline-start: auto; }
.card-b { padding: 14px 16px 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 14px; }
.kpi { padding: 14px 16px; }
.kpi .lbl { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 13px; font-weight: 500; color: var(--ink-3); }
.kpi.overall { color: #fff; border: none; }
.kpi.overall .lbl { color: rgba(255,255,255,.85); }
.kpi.overall.ov-high { background: linear-gradient(135deg, #b42318, #7a1010); }
.kpi.overall.ov-medium { background: linear-gradient(135deg, #c4580a, #8a3a05); }
.kpi.overall.ov-low { background: linear-gradient(135deg, #0f7a52, #075c3c); }
.dash-2 { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.dash-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .dash-2, .dash-3 { grid-template-columns: 1fr; } }

/* ---------- heat map ---------- */
.heat { display: grid; grid-template-columns: 22px 24px repeat(5, minmax(0, 1fr)); grid-template-rows: repeat(5, minmax(46px, auto)) 22px 18px; gap: 4px; }
.heat .ax-y { grid-column: 1; grid-row: 1 / span 5; writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; font-size: 11px; color: var(--ink-3); font-weight: 600; }
[dir="rtl"] .heat .ax-y { transform: none; }
.heat .tick { font-size: 11px; color: var(--ink-3); display: flex; align-items: center; justify-content: center; }
.heat .ax-x { grid-column: 3 / span 5; text-align: center; font-size: 11px; color: var(--ink-3); font-weight: 600; }
.heat .cell { border-radius: 6px; padding: 4px; display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start; min-height: 46px; position: relative; }
.heat .cell .n { position: absolute; inset-inline-end: 5px; bottom: 2px; font-size: 10px; opacity: .65; font-weight: 600; color: #3b1d12; }
.chip-code { white-space: nowrap; font-size: 10px; font-weight: 600; background: rgba(255,255,255,.85); color: #1a2433; border-radius: 4px; padding: 0 4px; cursor: pointer; border: none; line-height: 18px; }
.chip-code:hover { background: #fff; }
.z-low { background: var(--m1); } .z-med { background: var(--m2); } .z-med2 { background: var(--m3); } .z-high { background: var(--m4); } .z-ext { background: var(--m5); }
.heat.opp .z-low { background: #eef3ff; } .heat.opp .z-med { background: #dbe6ff; } .heat.opp .z-med2 { background: #c3d5ff; } .heat.opp .z-high { background: #9fbaff; } .heat.opp .z-ext { background: #7598ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .heat .cell { filter: saturate(.9) brightness(.92); } }

/* ---------- bars ---------- */
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 110px 1fr 28px; gap: 8px; align-items: center; font-size: 12.5px; }
.bar .track { background: var(--surface-2); border-radius: 4px; height: 10px; overflow: hidden; border: 1px solid var(--line); }
.bar .fill { height: 100%; background: var(--brand-2); border-radius: 4px; }

/* ---------- feed ---------- */
.feed { display: grid; gap: 0; max-height: 420px; overflow: auto; }
.feed .ev { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.feed .ev:last-child { border-bottom: none; }
.feed .ic { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.ic.ai { background: var(--accent-soft); color: var(--accent); }
.ic.user { background: var(--opp-soft); color: var(--opp); }
.ic.sys { background: var(--surface-2); color: var(--ink-3); }
.feed .msg { font-size: 13px; }
.feed .meta { font-size: 11.5px; color: var(--ink-3); }
.flash { animation: flash 2.2s ease-out; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--accent) 25%, transparent); } 100% { background: transparent; } }

/* ---------- tables ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; border-bottom: 1px solid var(--line); }
.toolbar .input { width: auto; min-width: 130px; }
.toolbar .search { min-width: 200px; flex: 1; max-width: 320px; }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
.t th { text-align: start; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .02em; color: var(--ink-3); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
[dir="rtl"] .t th { text-transform: none; letter-spacing: 0; font-size: 12px; }
.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: var(--surface-2); }
.t tr.closed td { color: var(--ink-3); }
.t .ttl { font-weight: 500; min-width: 220px; max-width: 420px; }
.t .ttl .sub2 { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.code { font-weight: 600; color: var(--brand-2); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- badges ---------- */
.b { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.b.high, .b.critical { background: var(--hi-soft); color: var(--hi); }
.b.critical { border-color: color-mix(in srgb, var(--hi) 35%, transparent); font-weight: 700; }
.b.medium { background: var(--med-soft); color: var(--med); }
.b.low, .b.info { background: var(--low-soft); color: var(--low); }
.b.threat { background: var(--hi-soft); color: var(--hi); }
.b.opportunity { background: var(--opp-soft); color: var(--opp); }
.b.neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }
.b.ai { background: var(--accent-soft); color: var(--accent); }
.score { display: inline-grid; place-items: center; min-width: 30px; height: 24px; border-radius: 6px; font-weight: 700; font-size: 12.5px; padding: 0 6px; font-variant-numeric: tabular-nums; }
.score.high { background: var(--h5); color: #fff; } .score.medium { background: #f2a33a; color: #3d2400; } .score.low { background: #5cbf8a; color: #062b18; }
.score.opp { background: var(--opp); color: #fff; }
.trend { font-weight: 700; } .trend.rising { color: var(--hi); } .trend.falling { color: var(--low); } .trend.stable { color: var(--ink-3); }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8,18,32,.45); z-index: 40; animation: fade .15s; }
.drawer { position: fixed; inset-block: 0; inset-inline-end: 0; width: min(760px, 100vw); background: var(--surface); z-index: 41; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slide .18s ease-out; }
[dir="rtl"] .drawer { animation-name: slide-rtl; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: .4; } }
@keyframes slide-rtl { from { transform: translateX(-30px); opacity: .4; } }
.drawer-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.drawer-h h2 { font-size: 18px; }
.drawer-h .x { margin-inline-start: auto; }
.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: none; padding: 11px 12px; cursor: pointer; font-weight: 500; color: var(--ink-3); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .n { font-size: 11px; color: var(--ink-3); margin-inline-start: 4px; }
.drawer-b { padding: 18px 20px; overflow-y: auto; flex: 1; }
.drawer-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--surface-2); }
.drawer-f .grow { flex: 1; min-width: 200px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form .third { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; grid-column: 1 / -1; }
@media (max-width: 640px) { .form, .form .third { grid-template-columns: 1fr; } }
.statement { background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }
.statement b { color: var(--brand); }
.pi-box { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.pi-box .big { font-size: 28px; font-weight: 700; }
.sect-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin: 18px 0 8px; }
[dir="rtl"] .sect-title { letter-spacing: 0; text-transform: none; }
.timeline { display: grid; gap: 8px; }
.timeline .row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; font-size: 13px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.ai-box { border-inline-start: 3px solid var(--accent); background: var(--accent-soft); padding: 10px 12px; border-radius: 6px; font-size: 13px; }

/* ---------- misc ---------- */
.empty { padding: 40px 16px; text-align: center; color: var(--ink-3); }
.toast-wrap { position: fixed; bottom: 16px; inset-inline-end: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #0b2440; color: #e9f1fb; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; animation: fade .2s; }
.toast b { color: #7fe0d2; }
.steps { display: grid; gap: 10px; }
.step { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: start; padding: 14px 16px; }
.step .no { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line-2); }
.step.done .no { background: var(--low-soft); color: var(--low); border-color: transparent; }
.step.next { outline: 2px solid var(--brand-2); }
.step details summary { cursor: pointer; color: var(--brand-2); font-size: 12.5px; margin-top: 4px; }
.step pre { white-space: pre-wrap; font-family: inherit; font-size: 12.5px; background: var(--surface-2); padding: 10px; border-radius: 8px; border: 1px solid var(--line); max-height: 300px; overflow: auto; }
@media (max-width: 640px) { .step { grid-template-columns: 1fr; } }
.md { font-size: 13.5px; }
.md h1 { font-size: 20px; margin: 12px 0 6px; } .md h2 { font-size: 16px; margin: 16px 0 6px; } .md h3 { font-size: 14px; margin: 12px 0 6px; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; } .md td, .md th { border: 1px solid var(--line); padding: 4px 8px; }
.md blockquote { margin: 8px 0; padding: 6px 12px; border-inline-start: 3px solid var(--med); background: var(--med-soft); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; }
.pmbok { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; margin-bottom: 14px; }
.pmbok span { padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
.pmbok i { color: var(--ink-3); font-style: normal; }
.hidden { display: none !important; }
