/* Cyber Readiness & Threat Analytics: theme variables, layout and shared ins-* chart primitives. */
:root {
  --font-ar: 'Cairo', 'Noto Sans Arabic', 'Segoe UI', sans-serif;
  --font-en: 'Plus Jakarta Sans', 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;

  --transition-fast: 160ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 260ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 400ms cubic-bezier(0.16, 1, 0.3, 1);
}
html {
  --bg-primary: #090d16;
  --bg-surface: #0f172a;
  --bg-card: #15203b;
  --bg-card-hover: #1c2b4d;
  --bg-glass: rgba(15, 23, 42, 0.78);
  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-active: rgba(56, 189, 248, 0.45);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-cyan: #38bdf8;
  --accent-blue: #3b82f6;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;
  
  --status-critical: #ef4444;
  --status-watch: #f97316;
  --status-advisory: #eab308;
  --status-normal: #10b981;

  --glow-accent: rgba(56, 189, 248, 0.25);
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px rgba(56, 189, 248, 0.15);
}
html[data-mode="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.88);
  --border-subtle: rgba(203, 213, 225, 0.8);
  --border-active: #0284c7;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-cyan: #0284c7;
  --accent-blue: #2563eb;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --accent-purple: #7c3aed;
  
  --status-critical: #dc2626;
  --status-watch: #ea580c;
  --status-advisory: #ca8a04;
  --status-normal: #16a34a;

  --glow-accent: rgba(2, 132, 199, 0.15);
  --shadow-card: 0 4px 20px -2px rgba(15, 23, 42, 0.08);
  --shadow-glow: 0 0 15px rgba(2, 132, 199, 0.1);
}

/* RESET & TYPOGRAPHY */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ar);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  background-image: 
    radial-gradient(circle at 15% 10%, rgba(56, 189, 248, 0.03) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(16, 185, 129, 0.03) 0%, transparent 40%);
}
html[dir="ltr"] body { font-family: var(--font-en); }
.app-header { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 28px; background: var(--bg-glass); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border-subtle); }
.app-header h1 { font-size: 1.15rem; font-weight: 800; }
.app-header h1 small { display: block; font-size: 0.74rem; font-weight: 400; color: var(--text-muted); }
.app-tools { margin-inline-start: auto; display: flex; gap: 8px; }
.app-tools button, .tab-btn { background: var(--bg-surface); color: var(--text-secondary); border: 1px solid var(--border-subtle); border-radius: var(--radius-full); padding: 7px 14px; font: inherit; font-size: 0.82rem; cursor: pointer; transition: var(--transition-fast); }
.app-tools button:hover, .tab-btn:hover { border-color: var(--border-active); color: var(--text-primary); }
.tab-nav { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 28px 0; }
.tab-btn.active { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--border-active); box-shadow: var(--shadow-glow); }
main { padding: 18px 28px 40px; }
.tab-view { display: none; }
.tab-view.active { display: block; }
.tab-view .section-card { margin-bottom: 20px; }
.section-card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow-card); }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.section-titles h3 { font-size: 1.25rem; font-weight: 800; color: var(--text-primary); display: flex; align-items: center; gap: 10px; }
.section-titles p { font-size: 0.84rem; color: var(--text-muted); margin-top: 2px; }
.ins-grid-2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 1100px) { .ins-grid-2 { grid-template-columns: 1fr; } }

.ins-card-h h4 { margin: 0 0 4px; font-size: 1.02rem; color: var(--text-primary); }
.ins-card-h p { margin: 0 0 12px; font-size: 0.82rem; color: var(--text-secondary); line-height: 1.6; }
.ins-mt { margin-top: 18px; }
.ins-muted { color: var(--text-secondary); }
.ins-svg { width: 100%; height: auto; display: block; font-family: inherit; }
.ins-hit, .ins-node { cursor: pointer; }

/* KPI strip */
.ins-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 8px; }
@media (max-width: 900px) { .ins-kpis { grid-template-columns: repeat(2, 1fr); } }
.ins-kpi { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 14px 16px; }
.ins-kpi .v { font-size: 1.7rem; font-weight: 800; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ins-kpi .l { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.ins-kpi.hero { border-color: var(--border-active); box-shadow: var(--shadow-glow); }
.ins-kpi.hero .v { color: var(--accent-cyan); }
.ins-caveat { margin: 14px 0 0; font-size: 0.78rem; color: var(--text-muted); line-height: 1.7; }

/* Horizontal bars */
.ins-hbar { display: grid; grid-template-columns: minmax(110px, 1.2fr) 2fr 44px; gap: 10px; align-items: center; margin: 6px 0; font-size: 0.8rem; }
.ins-hbar .lbl { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ins-hbar .track { height: 10px; background: var(--bg-surface); border-radius: 4px; overflow: hidden; }
.ins-hbar .fill { display: block; height: 100%; border-radius: 4px; }
.ins-hbar .val { color: var(--text-primary); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Network */
.ins-controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin-bottom: 10px; font-size: 0.82rem; color: var(--text-secondary); }
.ins-controls label { display: flex; gap: 8px; align-items: center; }
.ins-controls b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ins-controls select { background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-subtle); border-radius: var(--radius-xs); padding: 5px 8px; font-family: inherit; }
.ins-controls input[type=range], .ins-shock input[type=range] { accent-color: var(--accent-cyan); }
.ins-count { margin-inline-start: auto; font-variant-numeric: tabular-nums; }
.ins-net-wrap { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 16px; }
@media (max-width: 1100px) { .ins-net-wrap { grid-template-columns: 1fr; } }
.ins-net { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); }
.ins-node.sel circle:last-child { stroke: var(--text-primary); stroke-width: 3; }
.ins-node:hover circle:last-child { stroke: var(--text-primary); }
.ins-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 0.76rem; color: var(--text-secondary); align-items: center; }
.ins-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 6px; vertical-align: -1px; }
.ins-legend i.ln { width: 18px; height: 3px; border-radius: 2px; }
.ins-legend i.dash { height: 0; border-top: 2px dashed; background: none !important; border-radius: 0; }

/* Shock simulator */
.ins-shock { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 14px; font-size: 0.8rem; }
.ins-shock h5 { margin: 0 0 10px; font-size: 0.95rem; color: var(--text-primary); }
.ins-driver { display: flex; gap: 10px; align-items: flex-start; padding: 10px; background: var(--bg-card); border-radius: var(--radius-xs); margin-bottom: 10px; }
.ins-driver .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; margin-top: 4px; }
.ins-driver small { display: block; color: var(--text-muted); }
.ins-driver b { color: var(--text-primary); line-height: 1.5; }
.ins-shock-amt { display: block; color: var(--text-secondary); margin-bottom: 10px; }
.ins-shock-amt input { width: 100%; }
.ins-shock-amt b { color: var(--text-primary); }
.ins-sub { color: var(--text-muted); margin-bottom: 6px; }
.ins-div-bars .row { display: grid; grid-template-columns: minmax(0, 1.3fr) 1fr 42px; gap: 8px; align-items: center; margin: 5px 0; cursor: default; }
.ins-div-bars .lbl, .ins-dumb .lbl, .ins-ews .lbl, .ins-hbar .lbl, .ins-heat .rh { unicode-bidi: plaintext; text-align: start; }
.ins-div-bars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.ins-div-bars .lbl i, .ins-dumb .lbl i, .ins-table i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; }
.ins-div-bars .axis { position: relative; height: 12px; direction: ltr; border-left: 0; }
.ins-div-bars .axis::before { content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--border-subtle); }
.ins-div-bars .bar { position: absolute; top: 2px; height: 8px; border-radius: 4px; }
.ins-div-bars .val, .ins-dumb .val { font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 700; text-align: end; }
.ins-hint { color: var(--text-muted); font-size: 0.74rem; line-height: 1.6; margin: 10px 0 0; }

/* Heatmaps */
.ins-heat { display: grid; gap: 2px; font-size: 0.74rem; }
.ins-heat .ch { text-align: center; color: var(--text-secondary); padding-bottom: 4px; }
.ins-heat .rh { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-inline-end: 8px; align-self: center; }
.ins-heat .c { height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 4px; font-weight: 700; font-variant-numeric: tabular-nums; cursor: default; }
.ins-heat .c.empty { color: var(--text-muted); background: transparent; font-weight: 400; }
.ins-heat .c.diag { outline: 1px dashed var(--border-active); outline-offset: -2px; }

/* Gap lens */
.ins-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.ins-chip { background: var(--bg-surface); color: var(--text-secondary); border: 1px solid var(--border-subtle); border-radius: var(--radius-full); padding: 6px 12px; font: inherit; font-size: 0.76rem; cursor: pointer; transition: var(--transition-fast); }
.ins-chip span { color: var(--text-muted); margin: 0 4px; }
.ins-chip em { font-style: normal; margin-inline-start: 6px; color: var(--text-primary); font-weight: 700; }
.ins-chip:hover { border-color: var(--border-active); }
.ins-chip.on { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--border-active); }
.ins-dumb .row { display: grid; grid-template-columns: minmax(0, 1.4fr) 2fr 54px; gap: 12px; align-items: center; min-height: 26px; font-size: 0.78rem; }
.ins-dumb .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.ins-dumb .track { position: relative; height: 14px; }
.ins-dumb .track::before { content: ''; position: absolute; left: 0; right: 0; top: 6px; height: 2px; background: var(--border-subtle); }
.ins-dumb .span { position: absolute; top: 5px; height: 4px; background: var(--text-muted); opacity: 0.5; border-radius: 2px; }
.ins-dumb .pt { position: absolute; top: 2px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg-card); }
.ins-dumb .ticks::before { display: none; }
.ins-dumb .ticks b { position: absolute; transform: translateX(-50%); font-weight: 400; color: var(--text-muted); font-size: 0.7rem; }

/* EWS pressure */
.ins-ews .row { display: grid; grid-template-columns: 96px minmax(0, 1.6fr) 2fr 48px 92px; gap: 10px; align-items: center; min-height: 26px; font-size: 0.78rem; }
.ins-ews .code { font-family: var(--font-mono); color: var(--text-muted); font-size: 0.72rem; }
.ins-ews .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.ins-ews .track { position: relative; height: 10px; background: var(--bg-surface); border-radius: 4px; }
.ins-ews .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; }
.ins-ews .tick { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--text-muted); opacity: 0.6; }
.ins-ews .tick.crit { width: 2px; background: var(--text-primary); opacity: 0.85; }
.ins-ews .val { font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; text-align: end; }
.ins-ews .st { font-weight: 700; font-size: 0.74rem; }
@media (max-width: 900px) { .ins-ews .row { grid-template-columns: 80px 1fr 48px; } .ins-ews .lbl, .ins-ews .st { display: none; } }

/* Table view */
.ins-table-wrap { max-height: 420px; overflow: auto; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); }
.ins-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.ins-table th { position: sticky; top: 0; background: var(--bg-surface); color: var(--text-secondary); text-align: start; padding: 8px 10px; font-weight: 600; }
.ins-table td { padding: 7px 10px; border-top: 1px solid var(--border-subtle); color: var(--text-primary); vertical-align: top; }
.ins-table td small { display: block; color: var(--text-muted); margin-top: 2px; }
.ins-table .num { font-variant-numeric: tabular-nums; text-align: end; font-weight: 700; }
.ins-table .pos { color: var(--accent-cyan); }
.ins-table .neg { color: var(--accent-rose); }

/* Tooltip */
.ins-tip { position: fixed; z-index: 9999; display: none; pointer-events: none; max-width: 340px; background: var(--bg-glass); backdrop-filter: blur(10px); border: 1px solid var(--border-active); border-radius: var(--radius-xs); padding: 8px 11px; font-size: 0.76rem; line-height: 1.6; color: var(--text-primary); box-shadow: var(--shadow-card); }
