:root {
  --bg: #EEF1F4;
  --surface: #FFFFFF;
  --ink: #17233A;
  --steel: #5A6A80;
  --line: #D5DBE3;
  --amber: #D99A06;
  --low: #4C9A6A;
  --medium: #E2B53B;
  --high: #E07A35;
  --extreme: #C43D35;
  --opp: #2F6FAE;
  --radius: 6px;
  --font: 'IBM Plex Sans', 'IBM Plex Sans Arabic', system-ui, sans-serif;
}
:lang(ar) { --font: 'IBM Plex Sans Arabic', 'IBM Plex Sans', system-ui, sans-serif; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 600; }
h2 { font-size: 1.05rem; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.muted { color: var(--steel); }
.small { font-size: 0.82rem; }
.mono { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.lead { margin: 0 0 16px; max-width: 70ch; }

/* Buttons and inputs */
.btn { border: 1px solid transparent; border-radius: var(--radius); padding: 8px 16px; font-weight: 600; cursor: pointer; background: none; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #24345A; }
.btn.ghost { border-color: var(--line); background: var(--surface); }
.btn.ghost:hover { border-color: var(--steel); }
.btn.wide { width: 100%; padding: 11px; }
.icon-btn { border: 0; background: none; font-size: 1.1rem; cursor: pointer; padding: 4px 8px; color: var(--steel); }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: var(--surface); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(217, 154, 6, 0.35); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 500; }
.field > span { color: var(--steel); }
.form-error { color: var(--extreme); min-height: 1.2em; margin: 8px 0; font-size: 0.9rem; }

.lang { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.lang button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-weight: 500; color: var(--steel); }
.lang button.on { background: var(--ink); color: #fff; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.brand-mark { width: 22px; height: 22px; display: inline-grid; grid-template-columns: 1fr 1fr; gap: 2px; background:
  linear-gradient(var(--medium) 0 0) top left / 10px 10px no-repeat,
  linear-gradient(var(--extreme) 0 0) top right / 10px 10px no-repeat,
  linear-gradient(var(--low) 0 0) bottom left / 10px 10px no-repeat,
  linear-gradient(var(--high) 0 0) bottom right / 10px 10px no-repeat; }

/* Login */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 460px) 1fr; }
.login-panel { background: var(--surface); padding: 48px 44px; display: flex; flex-direction: column; gap: 18px; justify-content: center; }
.login-panel form { display: flex; flex-direction: column; gap: 14px; }
.login-panel .lang { align-self: flex-start; }
.login-art { background: var(--ink); display: grid; place-items: center; padding: 40px; }
.mini-heat { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: min(420px, 70%); aspect-ratio: 1; }
.mini-heat span { border-radius: 4px; opacity: 0.92; }

/* Shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 22px 14px; }
.side .brand { padding: 0 10px 22px; }
.side ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.side button { width: 100%; display: flex; align-items: center; justify-content: space-between; text-align: start; border: 0; background: none;
  padding: 10px 12px; border-radius: var(--radius); cursor: pointer; font-weight: 500; color: var(--steel); border-inline-start: 3px solid transparent; }
.side button:hover { background: var(--bg); color: var(--ink); }
.side button.on { color: var(--ink); background: var(--bg); border-inline-start-color: var(--amber); font-weight: 600; }
.count { background: var(--extreme); color: #fff; border-radius: 10px; font-size: 0.75rem; padding: 0 7px; font-weight: 600; }
.main { padding: 26px 32px 48px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.user { font-weight: 500; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.panel h2 + .muted { margin: 4px 0 0; }
.empty { color: var(--steel); padding: 18px 0; margin: 0; }

/* Dashboard */
.dash { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(240px, 1fr); gap: 20px; margin-bottom: 20px; }
.heat { display: grid; grid-template-columns: 26px 1fr; grid-template-rows: 1fr auto; gap: 6px; margin-top: 18px; }
.axis-y { display: flex; align-items: center; justify-content: center; }
.axis-y span { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 0.82rem; color: var(--steel); font-weight: 500; }
.axis-x { grid-column: 2; text-align: center; font-size: 0.82rem; color: var(--steel); font-weight: 500; }
.cells { display: grid; grid-template-columns: 22px repeat(5, 1fr); gap: 6px; }
.row-label, .col-label { display: grid; place-items: center; font-size: 0.82rem; color: var(--steel); font-variant-numeric: tabular-nums; }
.cell { aspect-ratio: 1.45; border: 0; border-radius: 5px; cursor: pointer; font-size: 1.5rem; font-weight: 700; color: #fff;
  opacity: 0.38; transition: transform 0.15s, opacity 0.15s; }
.cell.has { opacity: 1; }
.cell:hover { transform: scale(1.04); opacity: 1; }
.b-low { background: var(--low); } .b-medium { background: var(--medium); } .b-high { background: var(--high); } .b-extreme { background: var(--extreme); }
.cell.b-medium, .score.b-medium { color: var(--ink); }

.figures { margin: 0; display: grid; grid-template-columns: 1fr 1fr; align-content: start; border-top: 2px solid var(--ink); }
.fig { padding: 16px 4px 16px 0; border-bottom: 1px solid var(--line); }
.fig:nth-child(odd) { padding-inline-end: 16px; }
.fig dt { color: var(--steel); font-size: 0.85rem; }
.fig dd { margin: 4px 0 0; font-size: 1.55rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list-row { width: 100%; display: flex; gap: 12px; align-items: flex-start; text-align: start; padding: 10px 0; border: 0;
  border-bottom: 1px solid var(--line); background: none; cursor: pointer; }
.list li:last-child .list-row, .list li.list-row:last-child { border-bottom: 0; }
.list-row.static { cursor: default; }
.list-main { display: flex; flex-direction: column; min-width: 0; }
.list-main .small { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* Tags and badges */
.score { display: inline-grid; place-items: center; min-width: 32px; height: 26px; border-radius: 4px; font-weight: 700; color: #fff;
  font-variant-numeric: tabular-nums; flex-shrink: 0; }
.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 10px; margin-inline-start: 8px; white-space: nowrap; }
.tag.opp { background: #E3EEF8; color: var(--opp); }
.tag.ai { background: #FBF0D4; color: #7A5600; margin: 0; }
.src-tag { font-size: 0.75rem; font-weight: 600; border: 1px solid var(--line); border-radius: 4px; padding: 1px 7px; white-space: nowrap; color: var(--steel); }
.status { font-size: 0.82rem; font-weight: 500; white-space: nowrap; }
.status::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; background: var(--steel); }
.s-identified::before, .s-open::before { background: var(--extreme); }
.s-analyzed::before, .s-in_progress::before { background: var(--high); }
.s-response_planned::before { background: var(--medium); }
.s-response_implemented::before, .s-monitoring::before { background: var(--opp); }
.s-occurred::before { background: var(--ink); }
.s-closed::before, .s-resolved::before { background: var(--low); }
.prio { font-size: 0.8rem; font-weight: 600; padding: 2px 8px; border-radius: 4px; white-space: nowrap; }
.p-low { background: #E4F1E9; color: #2F6B47; } .p-medium { background: #FBF0D4; color: #7A5600; }
.p-high { background: #FBE6D8; color: #9A4613; } .p-critical { background: var(--extreme); color: #fff; }
.cls { font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.c-risk { color: var(--high); } .c-issue, .c-both { color: var(--extreme); } .c-info { color: var(--steel); }
.overdue { color: var(--extreme); font-weight: 600; }

/* Toolbar and tables */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }
.chip { border: 1px solid var(--ink); border-radius: 16px; background: var(--surface); padding: 5px 12px; cursor: pointer; font-size: 0.85rem; font-weight: 500; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.grid { width: 100%; border-collapse: collapse; min-width: 860px; }
.grid th { text-align: start; font-size: 0.8rem; font-weight: 600; color: var(--steel); padding: 10px 12px; border-bottom: 2px solid var(--ink); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th.c, .grid td.c { text-align: center; }
.grid tbody tr[tabindex] { cursor: pointer; }
.grid tbody tr[tabindex]:hover { background: #F6F8FA; }
.grid tbody tr:last-child td { border-bottom: 0; }
.title-cell { min-width: 240px; }
.summary-cell { min-width: 280px; max-width: 520px; font-size: 0.9rem; }
.table-wrap .empty { padding: 20px; }

/* Modal */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(900px, 94vw); max-height: 92vh; color: var(--ink); box-shadow: 0 24px 60px rgba(23, 35, 58, 0.3); }
dialog::backdrop { background: rgba(23, 35, 58, 0.55); }
.modal-body { display: flex; flex-direction: column; max-height: 92vh; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 24px 12px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1.2rem; }
.modal-head p { margin: 4px 0 0; }
.tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; font-weight: 500; color: var(--steel); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--amber); }
.tab-panel { padding: 8px 24px; overflow-y: auto; }
fieldset { border: 0; border-bottom: 1px solid var(--line); margin: 0; padding: 16px 0; }
fieldset:last-child { border-bottom: 0; }
legend { font-weight: 600; font-size: 0.95rem; padding: 0; margin-bottom: 10px; float: left; width: 100%; }
[dir=rtl] legend { float: right; }
.form-grid { clear: both; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field.full { grid-column: 1 / -1; }
.live { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.modal-body > .form-error { padding: 0 24px; margin: 0; }
.modal-foot { display: flex; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--line); background: #FAFBFC; border-radius: 0 0 10px 10px; }
.history { list-style: none; margin: 8px 0; padding: 0; }
.history > li { border-inline-start: 2px solid var(--line); padding: 4px 0 14px 16px; padding-inline-start: 16px; position: relative; }
.history > li::before { content: ''; position: absolute; inset-inline-start: -6px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--amber); }
.h-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.history ul { margin: 6px 0 0; padding-inline-start: 18px; font-size: 0.9rem; }
del { color: var(--steel); }
ins { text-decoration: none; font-weight: 600; }

.toast { position: fixed; bottom: 24px; inset-inline-start: 50%; transform: translate(-50%, 20px); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: var(--radius); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 10; }
[dir=rtl] .toast { transform: translate(50%, 20px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[dir=rtl] .toast.show { transform: translate(50%, 0); }

@media (max-width: 960px) {
  .dash, .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .login { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .login-panel { padding: 32px 22px; }
  .shell { grid-template-columns: 1fr; }
  .side { border-inline-end: 0; border-bottom: 1px solid var(--line); padding: 14px; }
  .side .brand { padding: 0 4px 12px; }
  .side ul { flex-direction: row; overflow-x: auto; }
  .side button { white-space: nowrap; border-inline-start: 0; border-bottom: 3px solid transparent; }
  .side button.on { border-bottom-color: var(--amber); }
  .main { padding: 18px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .figures { grid-template-columns: 1fr; }
  .fig:nth-child(odd) { padding-inline-end: 0; }
  .cell { font-size: 1.1rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Mixed-language content (e.g. English text inside the Arabic interface) */
.title-cell strong, .list-main strong, .list-main .small, .summary-cell, .modal-head h2, textarea, input[type=text], .history li { unicode-bidi: plaintext; }
