/* =========================================================================
   CREDIT RISK AI · TSG STUDIO SUITE
   Design system — dark + light themes
   ========================================================================= */

:root {
  /* dark theme (default) — cool neutral charcoal matching the TSG design */
  --bg: #121417;
  --bg-elev: #171a1e;
  --bg-elev2: #1c2026;
  --surface: #1c2026;
  --surface-2: #22272e;
  --surface-3: #2a3038;
  --border: #2a2f36;
  --border-strong: #3a414a;

  --text: #e9ecef;
  --text-dim: #9aa3af;
  --text-mute: #6b7482;

  --accent: #e76b2c;
  --accent-2: #ff8a4c;
  --accent-soft: rgba(231, 107, 44, 0.14);
  --accent-ring: rgba(231, 107, 44, 0.32);

  --good: #4caa6c;
  --warn: #d6a93a;
  --bad: #d9533c;
  --info: #4ea0e0;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-pop: 0 20px 40px -10px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.02);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, Arial, sans-serif;
  --serif: "DM Serif Display", Georgia, "Times New Roman", serif;
}

[data-theme="light"] {
  --bg: #f6f2ea;
  --bg-elev: #ece6da;
  --bg-elev2: #ffffff;
  --surface: #ffffff;
  --surface-2: #faf6ee;
  --surface-3: #f0ead9;
  --border: #e1d9c6;
  --border-strong: #cbbfa3;

  --text: #1a160f;
  --text-dim: #5a4f3c;
  --text-mute: #897d64;

  --accent: #d45a1c;
  --accent-2: #e76b2c;
  --accent-soft: rgba(212, 90, 28, 0.10);
  --accent-ring: rgba(212, 90, 28, 0.22);

  --shadow-pop: 0 24px 50px -16px rgba(70, 48, 20, 0.25), 0 0 0 1px rgba(0,0,0,0.03);
}

/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; line-height: 1.4; }
body { background: var(--bg); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }
h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; }
p { margin: 0; }

/* RTL */
[dir="rtl"] { direction: rtl; }
[dir="rtl"] .rail__nav a .chev { transform: rotate(180deg); }
[dir="rtl"] .rail__govbtn svg { transform: scaleX(-1); }

/* ============ SHELL ============ */
.app {
  display: grid;
  grid-template-columns: 268px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

/* ============ RAIL ============ */
.rail {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.rail__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 10px;
}
.brand__mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #ff8a4c 0%, #d45a1c 100%);
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
  position: relative;
}
.brand__mark span {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(255,255,255,0.9);
}
.brand__name { font-weight: 700; font-size: 15px; letter-spacing: -0.1px; }
.brand__sub  { color: var(--text-mute); font-size: 10.5px; letter-spacing: 1.6px; font-weight: 600; margin-top: 2px; }

.rail__user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left; width: 100%;
  transition: background 160ms ease, border-color 160ms ease;
}
.rail__user:hover { background: var(--surface-2); border-color: var(--border-strong); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #efe4d0, #c9b78f);
  color: #1a160f; display: grid; place-items: center;
  font-weight: 700; font-size: 11.5px;
  flex: 0 0 auto;
}
.rail__user-text { flex: 1; min-width: 0; }
.rail__user-label { color: var(--text-mute); font-size: 9.5px; letter-spacing: 1.5px; font-weight: 600; }
.rail__user-name { font-weight: 600; font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.rail__group-label {
  color: var(--text-mute);
  font-size: 10px; letter-spacing: 2px; font-weight: 600;
  padding: 8px 8px 2px;
}

.rail__nav { display: flex; flex-direction: column; gap: 2px; }
.rail__nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 13px; font-weight: 500;
  transition: background 180ms ease, color 180ms ease, box-shadow 180ms ease, padding-left 180ms ease;
  position: relative;
}
.rail__nav a .ic {
  width: 18px; display: inline-grid; place-items: center;
  color: var(--text-mute);
  font-size: 14px;
  transition: color 180ms ease, transform 180ms ease;
}
.rail__nav a:hover {
  background: var(--surface);
  color: var(--text);
  padding-left: 16px;
}
.rail__nav a:hover .ic { color: var(--accent); transform: scale(1.15); }
.rail__nav a.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}
.rail__nav a.is-active .ic { color: var(--accent); }
.rail__nav a .chev { margin-left: auto; color: var(--accent); opacity: 0; transition: opacity 150ms ease; }
.rail__nav a.is-active .chev { opacity: 1; }
.rail__nav a .badge {
  margin-left: auto;
  background: var(--surface-3);
  color: var(--text);
  font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 10px;
  min-width: 20px; text-align: center;
}
.rail__nav a.is-active .badge { background: var(--accent-soft); color: var(--accent); }

.rail__status {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px 8px;
}
.rail__status li {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
}
.rail__status .val { margin-left: auto; color: var(--text); font-weight: 600; font-size: 11.5px; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 auto; box-shadow: 0 0 0 2px rgba(0,0,0,0.1); position: relative; }
.dot--green { background: var(--good); }
.dot--amber { background: var(--warn); }
.dot--red   { background: var(--bad); }
.dot--blue  { background: var(--info); }
.dot--mute  { background: var(--text-mute); }
/* soft pulse on the engine-live dot(s) */
.dot--green::after, .dot--blue::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: inherit; opacity: 0.6; animation: dotPulse 2.4s ease-out infinite;
  pointer-events: none;
}
.topbar__pill .dot::after { animation-duration: 1.8s; }
@keyframes dotPulse {
  0%   { transform: scale(0.6); opacity: 0.55; }
  60%  { opacity: 0; }
  100% { transform: scale(2.4); opacity: 0; }
}

.rail__govbtn {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text); font-weight: 600; font-size: 13px;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}
.rail__govbtn:hover { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--accent); }

/* ============ MAIN ============ */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(6px);
}
.topbar__crumbs { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex-shrink: 0; }
.topbar__title { font-weight: 700; font-size: 15px; }
.topbar__crumb { color: var(--accent); font-size: 10.5px; letter-spacing: 1.6px; font-weight: 700; }

.topbar__pill {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12px; font-weight: 500;
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}
.topbar__pill:hover {
  border-color: color-mix(in srgb, var(--good) 50%, var(--border));
  background: color-mix(in srgb, var(--good) 6%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 10%, transparent);
}
.topbar__pill strong { color: var(--good); font-weight: 700; }

.topbar__spacer { flex: 1; }
.topbar__tools { display: flex; gap: 6px; }
.tool {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--text-dim);
  font-size: 12px; font-weight: 700;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}
.tool:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

.view { padding: 24px 28px 36px; min-height: calc(100vh - 110px); animation: viewIn 320ms cubic-bezier(.2,.8,.2,1); }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
/* staggered entrance of children (cards, bar-rows, list-items, grid tiles) */
.view .card,
.view .list-item,
.view .gov-tile,
.view .bar-row,
.view .studio,
.view .wf-step {
  animation: popInUp 420ms cubic-bezier(.2,.8,.2,1) both;
}
.view > *:nth-child(1) .card:nth-child(1),
.view > *:nth-child(1) .gov-tile:nth-child(1),
.view > *:nth-child(1) .list-item:nth-child(1) { animation-delay: 0ms; }
.view .card:nth-child(2), .view .gov-tile:nth-child(2), .view .list-item:nth-child(2), .view .wf-step:nth-child(2) { animation-delay: 40ms; }
.view .card:nth-child(3), .view .gov-tile:nth-child(3), .view .list-item:nth-child(3), .view .wf-step:nth-child(3) { animation-delay: 80ms; }
.view .card:nth-child(4), .view .gov-tile:nth-child(4), .view .list-item:nth-child(4), .view .wf-step:nth-child(4) { animation-delay: 120ms; }
.view .card:nth-child(5), .view .gov-tile:nth-child(5), .view .list-item:nth-child(5), .view .wf-step:nth-child(5) { animation-delay: 160ms; }
.view .card:nth-child(6), .view .gov-tile:nth-child(6), .view .list-item:nth-child(6) { animation-delay: 200ms; }
.view .card:nth-child(7), .view .gov-tile:nth-child(7), .view .list-item:nth-child(7) { animation-delay: 240ms; }
.view .card:nth-child(8), .view .gov-tile:nth-child(8), .view .list-item:nth-child(8) { animation-delay: 280ms; }
@keyframes popInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}

.footer {
  padding: 10px 28px 16px;
  color: var(--text-mute);
  font-size: 11px;
  font-style: italic;
}

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition:
    transform 220ms cubic-bezier(.2,.8,.2,1),
    border-color 220ms ease,
    box-shadow 220ms ease,
    background 220ms ease;
  will-change: transform;
}
.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px -14px rgba(0,0,0,0.4), 0 0 0 1px color-mix(in srgb, var(--accent) 10%, transparent);
}
.card--accent {
  border-color: var(--accent-ring);
  background: linear-gradient(180deg, var(--accent-soft), transparent 55%), var(--surface);
}
.card--accent:hover {
  border-color: var(--accent);
  box-shadow: 0 14px 32px -14px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 0 1px var(--accent-ring);
}
.card--muted  { background: var(--surface-2); }
.card--muted:hover { background: var(--surface-3); }
.card--pad-lg { padding: 24px; }
/* metric text subtly brightens on card hover */
.card .metric { transition: color 220ms ease, letter-spacing 220ms ease; }
.card:hover .metric { letter-spacing: -0.4px; }
.card:hover .metric:not(.metric--neutral) { color: var(--accent-2); }

.card__eyebrow {
  color: var(--text-mute);
  font-size: 10.5px; letter-spacing: 1.6px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.card__title { font-size: 20px; font-weight: 700; margin: 4px 0 2px; letter-spacing: -0.2px; }
.card__sub { color: var(--text-dim); font-size: 12.5px; }

.metric {
  font-family: var(--serif);
  font-size: 36px;
  color: var(--accent);
  line-height: 1.1;
  font-weight: 400;
  letter-spacing: -0.5px;
}
.metric--small { font-size: 26px; }
.metric--neutral { color: var(--text); }

/* explain pill (little chip at top-right of a tile) */
.explain-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-dim);
  font-size: 10.5px; font-weight: 700; letter-spacing: 1.1px;
  transition: background 150ms ease, color 150ms ease;
  text-transform: uppercase;
}
.explain-pill:hover { background: var(--accent-soft); color: var(--accent); }
.explain-pill::before { content: "+"; font-weight: 900; }

/* ============ EXECUTIVE WALKTHROUGH BAR ============ */
.walkthrough {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.walkthrough__label {
  color: var(--accent); font-weight: 700; font-size: 10.5px; letter-spacing: 1.8px;
  display: flex; align-items: center; gap: 6px;
}
.walkthrough__label::before { content: "▸"; }
.walkthrough__step {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim);
  font-size: 12px; font-weight: 500;
  border: 1px solid transparent;
  transition: background 150ms, color 150ms, border-color 150ms;
}
.walkthrough__step .num {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface-3);
  display: grid; place-items: center;
  color: var(--text); font-weight: 700; font-size: 11px;
}
.walkthrough__step:hover { color: var(--text); background: var(--surface-3); }
.walkthrough__step.is-active {
  background: var(--accent); color: #fff;
  box-shadow: 0 4px 14px -4px var(--accent-ring);
}
.walkthrough__step.is-active .num { background: rgba(255,255,255,0.25); color: #fff; }
.walkthrough__step.is-done { color: var(--good); }
.walkthrough__step.is-done .num { background: var(--good); color: #fff; }

/* ============ WORKFLOW BAR (for cases) ============ */
.workflow {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.wf-step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  position: relative;
  min-height: 92px;
}
.wf-step .wf-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-3); color: var(--text-dim);
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
  margin-bottom: 6px;
}
.wf-step .wf-title { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.wf-step .wf-sub   { color: var(--text-dim); font-size: 11.5px; line-height: 1.35; }
.wf-step .wf-actor { position: absolute; bottom: 10px; left: 14px; color: var(--text-mute); font-size: 9.5px; letter-spacing: 1.4px; font-weight: 700; }
.wf-step.is-active { border-color: var(--accent-ring); background: linear-gradient(180deg, var(--accent-soft), transparent 60%), var(--surface); }
.wf-step.is-active .wf-num { background: var(--accent); color: #fff; }
.wf-step.is-active .wf-actor { color: var(--accent); }
.wf-step.is-done .wf-num { background: var(--good); color: #fff; }

/* ============ GRID ============ */
.grid { display: grid; gap: 14px; }
.grid--3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid--2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid--5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
@media (max-width: 1100px) {
  .grid--3, .grid--4, .grid--5 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* ============ STUDIO CARD (landing tiles) ============ */
.studio {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 12px;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}
.studio:hover {
  transform: translateY(-2px);
  border-color: var(--accent-ring);
  background: linear-gradient(180deg, var(--accent-soft), transparent 70%), var(--surface);
}
.studio__ic {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--surface-3);
  display: grid; place-items: center;
  color: var(--accent);
  font-size: 18px;
}
.studio__title { font-size: 17px; font-weight: 700; letter-spacing: -0.1px; }
.studio__desc  { color: var(--text-dim); font-size: 12.5px; line-height: 1.5; }
.studio__stats { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.studio__stats .row { display: flex; justify-content: space-between; font-size: 12px; }
.studio__stats .row .k { color: var(--text-dim); }
.studio__stats .row .v { font-weight: 700; }
.studio__stats .row .v--orange { color: var(--accent); }
.studio__stats .row .v--green  { color: var(--good); }
.studio__stats .row .v--amber  { color: var(--warn); }

/* ============ TABLES ============ */
.tbl-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.tbl { width: 100%; }
.tbl thead th {
  text-align: left; font-size: 10.5px; letter-spacing: 1.3px; font-weight: 700;
  color: var(--text-mute);
  padding: 11px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}
.tbl tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr {
  transition: background 180ms ease, transform 180ms ease, box-shadow 180ms ease;
  cursor: pointer;
}
.tbl tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 7%, var(--surface-2));
  box-shadow: inset 3px 0 0 var(--accent);
}
.tbl tbody tr:hover td:first-child { color: var(--accent); }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .sort-ind { opacity: 0.5; margin-left: 4px; }
.tbl th.is-sorted .sort-ind { opacity: 1; color: var(--accent); }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.right { text-align: right; }

/* chip */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--surface-3); color: var(--text);
  white-space: nowrap;
  transition: transform 180ms ease, filter 180ms ease;
}
.chip:hover { transform: translateY(-1px); filter: brightness(1.12); }
.chip--good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.chip--warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.chip--bad  { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.chip--info { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }
.chip--orange { background: var(--accent-soft); color: var(--accent); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 8px;
  background: var(--surface-3); color: var(--text);
  font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border);
  transition:
    background 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    transform 120ms ease,
    box-shadow 180ms ease;
  position: relative;
  overflow: hidden;
}
.btn::after {
  /* subtle sheen on hover */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.08) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 500ms ease;
  pointer-events: none;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px -8px rgba(0,0,0,0.5);
}
.btn:hover::after { transform: translateX(100%); }
.btn:active { transform: scale(0.97) translateY(0); }
.btn--primary {
  background: var(--accent); color: #fff; border-color: transparent;
  box-shadow: 0 2px 10px -2px var(--accent-ring);
}
.btn--primary:hover {
  background: var(--accent-2); color: #fff;
  box-shadow: 0 10px 22px -8px color-mix(in srgb, var(--accent) 55%, transparent);
}
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 10px; font-size: 11.5px; }
.btn--danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, var(--border)); }
.btn--danger:hover { background: color-mix(in srgb, var(--bad) 10%, transparent); }
.btn[disabled], .btn:disabled { opacity: 0.42; cursor: not-allowed; filter: grayscale(0.4); }
.btn[disabled]:hover, .btn:disabled:hover { background: var(--surface-3); border-color: var(--border); }

.iconbtn {
  width: 30px; height: 30px; border-radius: 8px;
  background: transparent; color: var(--text-dim);
  display: inline-grid; place-items: center;
  font-size: 18px; line-height: 1;
  transition: background 140ms ease, color 140ms ease;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }

/* ============ FORM BITS ============ */
.input, .select, .textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent-ring);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.textarea { min-height: 90px; resize: vertical; }

/* styled select — removes native OS chrome, draws our own chevron */
.select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 32px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5 L6 7.5 L9 4.5' stroke='%239aa3af' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
}
.select::-ms-expand { display: none; }
.select:hover { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5 L6 7.5 L9 4.5' stroke='%23e76b2c' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>"); }
.select option {
  background: var(--bg-elev);
  color: var(--text);
  padding: 8px 10px;
}
[dir="rtl"] .select {
  padding-right: 12px;
  padding-left: 32px;
  background-position: left 10px center;
}

.label { display: block; font-size: 11px; color: var(--text-dim); font-weight: 600; letter-spacing: 0.4px; margin-bottom: 6px; }

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.toolbar .input, .toolbar .select { width: auto; min-width: 160px; }
.toolbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
[dir="rtl"] .toolbar .right { margin-left: 0; margin-right: auto; }

/* ============ DRAWER ============ */
.drawer {
  position: fixed; inset: 0; z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
}
.drawer.is-open { opacity: 1; pointer-events: auto; }
.drawer__scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.drawer__panel {
  position: absolute; top: 0; right: 0; height: 100%;
  width: min(560px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(.2,.8,.2,1);
  box-shadow: var(--shadow-pop);
}
[dir="rtl"] .drawer__panel { right: auto; left: 0; border-left: 0; border-right: 1px solid var(--border); transform: translateX(-100%); }
.drawer.is-open .drawer__panel { transform: translateX(0); }
.drawer__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.drawer__eyebrow { color: var(--accent); font-size: 10.5px; font-weight: 700; letter-spacing: 1.8px; }
.drawer__title { font-size: 20px; font-weight: 700; margin-top: 2px; letter-spacing: -0.2px; }
.drawer__body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.ex-section { padding: 14px 0; border-bottom: 1px dashed var(--border); }
.ex-section:last-child { border-bottom: 0; }
.ex-section h4 {
  font-size: 11px; font-weight: 700; letter-spacing: 1.3px;
  color: var(--accent); margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.ex-section h4 .n {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-grid; place-items: center; font-weight: 800; font-size: 10px;
}
.ex-section p { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }
.ex-section .fact {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; background: var(--surface-2);
  margin-top: 6px;
  cursor: pointer; transition: background 140ms ease;
}
.ex-section .fact:hover { background: var(--surface-3); }
.ex-section .fact .k { color: var(--text-dim); font-size: 11.5px; }
.ex-section .fact .v { margin-left: auto; font-family: var(--mono); font-size: 12px; }
.ex-section .fact .d { color: var(--text-mute); font-size: 10.5px; }

/* waterfall */
.waterfall { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.wf-row { display: grid; grid-template-columns: 160px 1fr 70px; gap: 10px; align-items: center; font-size: 12px; }
.wf-row .lbl { color: var(--text-dim); }
.wf-row .bar { position: relative; height: 10px; background: var(--surface-2); border-radius: 4px; }
.wf-row .bar .fill { position: absolute; top: 0; height: 100%; border-radius: 4px; }
.wf-row .bar .fill.pos { background: var(--accent); }
.wf-row .bar .fill.neg { background: var(--bad); }
.wf-row .bar .fill.base { background: var(--text-mute); }
.wf-row .val { text-align: right; font-family: var(--mono); font-size: 11.5px; }

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0; z-index: 110;
  display: none; align-items: center; justify-content: center;
}
.modal.is-open { display: flex; }
.modal__scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(2px); }
.modal__panel {
  position: relative; z-index: 2;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(520px, 92vw);
  max-height: 86vh;
  overflow: auto;
  box-shadow: var(--shadow-pop);
  animation: popIn 180ms ease;
}
@keyframes popIn { from { transform: translateY(10px) scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }

.modal__panel .m-head { padding: 20px 22px 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal__panel .m-head h3 { font-size: 16px; font-weight: 700; }
.modal__panel .m-body { padding: 18px 22px; }
.modal__panel .m-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ============ TOAST ============ */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
[dir="rtl"] .toasts { right: auto; left: 20px; }
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 10px 14px; border-radius: 8px;
  font-size: 12.5px;
  min-width: 240px;
  box-shadow: var(--shadow-pop);
  animation: toastIn 220ms ease;
}
.toast.good { border-left-color: var(--good); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad  { border-left-color: var(--bad); }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============ CHART PIECES ============ */
.spark {
  display: inline-block; vertical-align: middle; width: 100%; height: 24px;
}
.bar-row {
  display: grid; grid-template-columns: 140px 1fr 70px; align-items: center; gap: 10px;
  font-size: 12.5px;
  padding: 4px 6px; border-radius: 6px; margin: 0 -6px;
  transition: background 180ms ease;
  cursor: default;
}
.bar-row:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.bar-row:hover .v { color: var(--text); }
.bar-row .bar { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; position: relative; }
.bar-row .bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 4px;
  transition: width 500ms cubic-bezier(.2,.8,.2,1), filter 200ms ease;
  animation: barGrow 700ms cubic-bezier(.2,.8,.2,1);
  transform-origin: left center;
}
.bar-row:hover .bar > span { filter: brightness(1.15); }
.bar-row .v { text-align: right; font-family: var(--mono); color: var(--text-dim); font-size: 11.5px; transition: color 180ms ease; }
@keyframes barGrow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* heat tile for governorate map — flex so the last row stretches to fill the width */
.gov-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.gov-grid > .gov-tile {
  flex: 1 1 140px;      /* grow and shrink; minimum basis 140px */
  min-width: 140px;
}
.gov-tile {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
  cursor: pointer;
  transition: transform 220ms cubic-bezier(.2,.8,.2,1),
              border-color 220ms ease,
              box-shadow 220ms ease,
              background 220ms ease;
  position: relative;
  overflow: hidden;
}
.gov-tile::after {
  content: ""; position: absolute; inset: 0; border-radius: 8px;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%);
  opacity: 0; transition: opacity 220ms ease; pointer-events: none;
}
.gov-tile:hover {
  transform: translateY(-3px);
  border-color: var(--accent-ring);
  box-shadow: 0 10px 24px -12px color-mix(in srgb, var(--accent) 35%, transparent);
}
.gov-tile:hover::after { opacity: 1; }
.gov-tile:active { transform: translateY(-1px) scale(0.99); }
.gov-tile .nm { font-size: 12.5px; font-weight: 600; }
.gov-tile .ct { color: var(--text-dim); font-size: 11px; }
.gov-tile .mt { font-family: var(--mono); font-weight: 700; color: var(--accent); margin-top: 2px; }
.gov-tile.heat-1 { background: color-mix(in srgb, var(--accent) 7%, var(--surface-2)); }
.gov-tile.heat-2 { background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.gov-tile.heat-3 { background: color-mix(in srgb, var(--accent) 28%, var(--surface-2)); }
.gov-tile.heat-4 { background: color-mix(in srgb, var(--accent) 42%, var(--surface-2)); color: #fff; }
.gov-tile.heat-4 .mt { color: #fff; }

/* ============ CASE / DECISION AREA ============ */
.case-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.case-head h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.2px; }
.case-head .meta { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.case-head .meta b { color: var(--text); font-weight: 600; }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }

.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.tabs button {
  padding: 10px 16px;
  color: var(--text-dim); font-weight: 600; font-size: 12.5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 140ms, border-color 140ms;
}
.tabs button:hover { color: var(--text); }
.tabs button.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* 3-case comparison */
.cases-3 {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
.cases-3 .case-col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.cases-3 .case-col h4 { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-mute); font-weight: 700; margin-bottom: 8px; }
.cases-3 .case-col .big { font-family: var(--serif); font-size: 24px; color: var(--text); }
.cases-3 .case-col .lbl { color: var(--text-dim); font-size: 11px; margin-bottom: 10px; }
.cases-3 .case-col .policy-lines { display: flex; flex-direction: column; gap: 4px; }
.cases-3 .case-col .policy-lines .pl {
  display: flex; justify-content: space-between; font-size: 11.5px; gap: 10px;
}
.cases-3 .case-col .policy-lines .pl .k { color: var(--text-dim); }
.cases-3 .case-col .policy-lines .pl .v { font-family: var(--mono); }
.cases-3 .case-col .policy-lines .pl.pass { color: var(--good); }
.cases-3 .case-col .policy-lines .pl.fail { color: var(--bad); }

/* integrity list */
.integrity {
  display: flex; flex-direction: column; gap: 8px;
}
.integrity .ic-row {
  display: grid; grid-template-columns: 160px 90px 1fr auto; gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  align-items: center;
}

/* ============ DO-IT / AUDIT LISTS ============ */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  cursor: pointer;
  transition:
    background 200ms ease,
    border-color 200ms ease,
    transform 200ms cubic-bezier(.2,.8,.2,1),
    box-shadow 200ms ease;
  position: relative;
}
.list-item::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
  transform: scaleY(0); transform-origin: center;
  transition: transform 220ms cubic-bezier(.2,.8,.2,1);
}
.list-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  transform: translateX(2px);
  box-shadow: 0 8px 20px -14px rgba(0,0,0,0.5);
}
.list-item:hover::before { transform: scaleY(1); }
.list-item .lead { font-weight: 600; font-size: 13px; }
.list-item .sub  { color: var(--text-dim); font-size: 11.5px; margin-top: 2px; }
.list-item .side { text-align: right; color: var(--text-mute); font-size: 11px; }

/* schedule table */
.sched-table th, .sched-table td { padding: 7px 10px; font-size: 11.5px; }

/* slider */
.sliderbox {
  display: grid; grid-template-columns: 160px 1fr 70px; align-items: center; gap: 10px;
  padding: 8px 0;
}
.sliderbox label { color: var(--text-dim); font-size: 12px; }
.sliderbox input[type=range] { width: 100%; }
.sliderbox .val { font-family: var(--mono); text-align: right; font-size: 12px; color: var(--accent); font-weight: 600; }

/* small screens */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .workflow { grid-template-columns: repeat(2, 1fr); }
  .cases-3 { grid-template-columns: 1fr; }
}

/* utility */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.mt-sm { margin-top: 8px; } .mt-md { margin-top: 14px; } .mt-lg { margin-top: 22px; }
.mb-sm { margin-bottom: 8px; } .mb-md { margin-bottom: 14px; } .mb-lg { margin-bottom: 22px; }
.hidden { display: none !important; }
.text-dim { color: var(--text-dim); }
.text-mute { color: var(--text-mute); }
.text-accent { color: var(--accent); }
.text-good { color: var(--good); }
.text-bad { color: var(--bad); }
.text-warn { color: var(--warn); }
.fw-b { font-weight: 700; }
.fsize-sm { font-size: 11.5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.serif { font-family: var(--serif); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text);
  font-size: 11px; font-weight: 600;
}

/* breadcrumb */
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-mute); margin-bottom: 10px; }
.crumbs a { color: var(--text-dim); }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { opacity: 0.6; }

/* chart svg lines */
.spark path, .chart path { transition: stroke-dashoffset 500ms ease; }

/* pagination */
.pager {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 12.5px;
}
.pager .info { color: var(--text-dim); }
.pager .spacer { flex: 1; }
.pager .pbtn {
  min-width: 30px; height: 28px; padding: 0 10px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  display: inline-grid; place-items: center;
  font-weight: 600; cursor: pointer;
  transition: background 140ms, border-color 140ms, color 140ms;
}
.pager .pbtn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.pager .pbtn:disabled { opacity: 0.4; cursor: not-allowed; }
.pager .pbtn.is-current { background: var(--accent); color: #fff; border-color: transparent; }
.pager .psize {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 4px 8px;
  font-size: 12px; cursor: pointer;
}
.pager .ellipsis { color: var(--text-mute); padding: 0 2px; }
.tbl-wrap.paged { border-radius: var(--radius) var(--radius) 0 0; }

/* print-like memo */
.memo {
  background: #fff; color: #111; font-family: Georgia, serif;
  border-radius: 8px; padding: 28px; box-shadow: var(--shadow-pop);
  max-width: 760px;
}
.memo h3 { font-size: 20px; margin: 10px 0; }
.memo table { font-size: 12.5px; }
.memo table td, .memo table th { padding: 4px 8px; border-bottom: 1px solid #ddd; }
