:root {
  --ink: #1b2430;
  --muted: #667084;
  --canvas: #f3f5f8;
  --sheet: #ffffff;
  --line: #e4e8ee;
  --navy: #1b3a4b;
  --navy-soft: #e7eef2;
  --merchant: #0e7c66;
  --house: #2457a6;
  --state: #9a4638;
  --merchant-bg: #e7f5f1;
  --house-bg: #e8f0fb;
  --state-bg: #f8eeeb;
  --danger: #9b2c2c;
  --danger-bg: #f8ecec;
  --ok: #0e7c66;
  --sidebar: 232px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  width: 100%;
}
body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--ink);
  line-height: 1.5;
  font-size: 15px;
  overflow-x: hidden;
}
#app {
  width: 100%;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--house); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.35rem; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; font-weight: 600; }

.skip {
  position: absolute;
  inset-inline-start: 12px;
  top: -40px;
  background: var(--navy);
  color: white;
  padding: 8px 12px;
  z-index: 5;
}
.skip:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.nav-backdrop { display: none; }

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  font-weight: 500;
}
.money {
  display: inline-flex;
  align-items: baseline;
  gap: 0.28em;
  direction: rtl;
  unicode-bidi: isolate;
}
.sar {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  line-height: 1;
}
.sar-icon {
  width: 0.92em;
  height: 0.92em;
  display: block;
  fill: currentColor;
  flex: 0 0 auto;
}
.money .sar { flex: 0 0 auto; }
.metric .money .sar,
.metric.merchant .sar,
.metric.house .sar,
.metric.state .sar { color: inherit; }
.metric b .money { font-size: inherit; }

.logo { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.logo:hover { text-decoration: none; }
.logo i {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--navy);
  color: white;
  display: grid;
  place-items: center;
  font-style: normal;
  font-weight: 600;
  flex: 0 0 auto;
}
.logo strong { font-size: 1rem; font-weight: 600; }
.logo em { display: block; font-style: normal; color: var(--muted); font-size: 0.75rem; font-weight: 400; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.gate-card {
  width: min(420px, 100%);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px 24px;
  box-shadow: 0 12px 40px rgba(27, 36, 48, 0.06);
}
.gate-card h1 { margin: 22px 0 6px; font-size: 1.5rem; }
.gate-card .quiet-copy { color: var(--muted); margin-bottom: 22px; }
.gate form, form { display: grid; gap: 14px; }
.gate button[type="submit"] { width: 100%; }

label { display: grid; gap: 6px; font-size: 0.86rem; font-weight: 600; }
[hidden], label[hidden], .compact[hidden] { display: none !important; }
input, select, textarea {
  width: 100%;
  border: 1px solid #d5dbe3;
  background: #fff;
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--navy-soft);
  border-color: var(--navy);
}

button, .button {
  border: 0;
  border-radius: 10px;
  min-height: 40px;
  padding: 0 14px;
  background: var(--navy);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
}
button:hover, .button:hover { text-decoration: none; filter: brightness(1.08); }
button.quiet, .button.quiet {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}
button.danger { background: white; color: var(--danger); border: 1px solid #e7c7c3; }
button:disabled { opacity: 0.55; cursor: wait; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.demo { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.demo p { color: var(--muted); font-size: 0.78rem; }
.demo button {
  width: 100%;
  background: transparent;
  color: var(--ink);
  border: 0;
  min-height: 36px;
  padding: 6px 2px;
  justify-content: space-between;
  font-weight: 500;
}
.demo button:hover { background: var(--canvas); }
.demo button span:first-child { color: var(--muted); }

.form-error, .banner {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
}
.banner.ok, .form-error.ok { background: var(--merchant-bg); color: var(--ok); }

.shell {
  --sidebar-size: var(--sidebar);
  min-height: 100vh;
  width: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-size) minmax(0, 1fr);
  grid-template-areas: "sidebar workspace";
  transition: grid-template-columns 0.2s ease;
}
.shell.is-collapsed { --sidebar-size: 72px; }
.sidebar {
  grid-area: sidebar;
  background: var(--sheet);
  border-inline-end: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 3;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-toggle {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 10px;
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.sidebar-toggle.mobile { display: none; }
.nav { display: grid; gap: 2px; }
.nav a {
  color: var(--ink);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 8px;
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--canvas); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--navy-soft); color: var(--navy); font-weight: 600; }
.who { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--muted); font-size: 0.8rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who button { margin-top: 10px; width: 100%; }

.shell.is-collapsed .logo span,
.shell.is-collapsed .who strong,
.shell.is-collapsed .who span,
.shell.is-collapsed .nav a span { display: none; }
.shell.is-collapsed .sidebar { padding: 12px 8px; align-items: stretch; }
.shell.is-collapsed .logo { justify-content: center; width: 100%; }
.shell.is-collapsed .sidebar-top {
  justify-content: center;
  flex-direction: column;
  width: 100%;
}
.shell.is-collapsed .nav { width: 100%; }
.shell.is-collapsed .nav a {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px;
}
.shell.is-collapsed .nav a::after {
  content: attr(data-short);
  font-weight: 700;
}
.shell.is-collapsed .who {
  width: 100%;
  display: grid;
  gap: 8px;
  justify-items: stretch;
}
.shell.is-collapsed .who button { padding-inline: 6px; font-size: 0.75rem; }

.workspace {
  grid-area: workspace;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  background: var(--canvas);
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 28px;
  background: rgba(243, 245, 248, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid transparent;
}
.topbar-copy { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar p { color: var(--muted); margin-top: 2px; font-size: 0.88rem; }
.view, #view {
  box-sizing: border-box;
  padding: 12px 28px 40px;
  width: 100%;
  max-width: none;
  margin: 0;
}

.stack { display: grid; gap: 16px; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.metric, .panel {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.metric { padding: 14px 16px 12px; display: grid; gap: 6px; }
.metric span, .panel-head p, .meta, .note { color: var(--muted); }
.metric span { font-size: 0.8rem; }
.metric b { font-size: 1.35rem; letter-spacing: -0.03em; }
.metric small { font-size: 0.75rem; }
.metric.merchant b { color: var(--merchant); }
.metric.house b { color: var(--house); }
.metric.state b { color: var(--state); }

.panel { padding: 16px 16px 8px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}
.share {
  height: 12px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--canvas);
  box-shadow: inset 0 0 0 1px rgba(27, 36, 48, 0.04);
}
.share-svg { display: block; width: 100%; height: 12px; }
.share-track { fill: var(--canvas); }
.share-merchant { fill: var(--merchant); }
.share-house { fill: var(--house); }
.share-state { fill: var(--state); }
.legend { display: flex; flex-wrap: wrap; gap: 14px 22px; list-style: none; padding: 14px 0 10px; margin: 0; }
.legend li { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; }
.dot.merchant { background: var(--merchant); }
.dot.house { background: var(--house); }
.dot.state { background: var(--state); }

.facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 16px;
  margin: 0;
}
.facts div { display: grid; gap: 2px; }
.facts dt { color: var(--muted); font-size: 0.75rem; }
.facts dd { margin: 0; font-weight: 600; }

.table-wrap { overflow: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td {
  text-align: start;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}
th { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f8fafb; }
td.num { text-align: left; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 99px;
  padding: 2px 8px;
  font-size: 0.75rem;
  background: var(--canvas);
  color: var(--ink);
}
.badge.on { background: var(--merchant-bg); color: var(--merchant); }
.badge.off { background: var(--danger-bg); color: var(--danger); }
.badge.sorhty { background: var(--house-bg); color: var(--house); }
.badge.debit { background: var(--canvas); }
.badge.credit { background: var(--navy-soft); color: var(--navy); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}
.statement { min-width: 0; }
.statement td:last-child, .statement th:last-child { text-align: left; }
.statement small { display: block; color: var(--muted); font-weight: 400; }
.statement tr.total td { font-weight: 600; background: var(--canvas); }

.choice { display: flex; flex-wrap: wrap; gap: 8px; }
.choice label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 8px 12px;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0;
  padding: 12px;
  display: grid;
  gap: 10px;
}
legend { padding: 0 6px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.note { font-size: 0.84rem; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.quiet-copy { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }

.policy { display: grid; gap: 14px; }
.policy-hero, .policy-card, .policy-bar {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.policy-hero {
  padding: 18px 18px 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.policy-hero-main { display: flex; gap: 14px; align-items: center; min-width: 0; }
.policy-hero h2 { font-size: 1.25rem; }
.policy-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--navy);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.2rem;
  flex: 0 0 auto;
}
.policy-hero-side { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--canvas);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: var(--muted);
}
.chip b { color: var(--ink); font-weight: 600; }
.policy-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.policy-strip div {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}
.policy-strip span { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.policy-strip strong { font-size: 0.95rem; font-weight: 600; }
.policy-strip small { color: var(--muted); font-size: 0.75rem; line-height: 1.35; }

.tax-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--canvas);
}
.tax-badge b {
  font-family: var(--mono);
  font-weight: 600;
  direction: ltr;
  unicode-bidi: isolate;
}
.tax-badge.tax-inclusive { background: var(--house-bg); color: var(--house); border-color: transparent; }
.tax-badge.tax-exempt { background: var(--canvas); color: var(--muted); }
.tax-cell { display: grid; gap: 4px; white-space: normal; min-width: 160px; }
.tax-cell small { color: var(--muted); font-size: 0.72rem; font-weight: 400; }

.tax-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.tax-preset {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfd;
  cursor: pointer;
  font-weight: 500;
}
.tax-preset:has(input:checked) {
  border-color: var(--navy);
  background: var(--navy-soft);
}
.tax-preset input { width: auto; min-height: 0; margin-top: 3px; accent-color: var(--navy); }
.tax-preset span { display: grid; gap: 4px; min-width: 0; }
.tax-preset strong { font-size: 0.92rem; }
.tax-preset small { color: var(--muted); font-weight: 400; font-size: 0.78rem; line-height: 1.35; }
.tax-preset em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
}
.policy-card { padding: 16px 18px 18px; display: grid; gap: 14px; }
.policy-section {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--line);
}
.policy-section h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.policy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}
.policy-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
.choice-card {
  flex: 1 1 140px;
  border-radius: 12px !important;
  padding: 12px 14px !important;
  gap: 10px !important;
  align-items: flex-start !important;
  background: #fbfcfd;
}
.choice-card:has(input:checked) {
  border-color: var(--navy);
  background: var(--navy-soft);
}
.choice-card input { width: auto; min-height: 0; margin-top: 3px; accent-color: var(--navy); }
.choice-card span { display: grid; gap: 2px; font-weight: 600; }
.choice-card small { color: var(--muted); font-weight: 400; font-size: 0.78rem; }
label.compact { max-width: 180px; }
.policy-bar {
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  bottom: 12px;
  box-shadow: 0 8px 28px rgba(27, 36, 48, 0.06);
}
.policy-bar .note { margin: 0; flex: 1 1 220px; }
.policy-bar .form-error { flex: 1 1 100%; margin: 0; }
.policy-bar .actions { margin-inline-start: auto; }
.empty { padding: 28px 8px 20px; color: var(--muted); }
pre.payload {
  white-space: pre-wrap;
  background: var(--ink);
  color: #edf1f4;
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
}
details summary { cursor: pointer; font-weight: 600; }

@media (max-width: 1100px) {
  .metrics, .facts, .policy-strip { grid-template-columns: 1fr 1fr; }
  .layout, .grid-2, .policy-split, .policy-grid, .tax-presets { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .shell, .shell.is-collapsed {
    grid-template-columns: 1fr;
    grid-template-areas: "workspace";
  }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    border: 0;
    padding: 0;
    margin: 0;
    background: rgba(27, 36, 48, 0.42);
    z-index: 12;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .shell:not(.is-collapsed) .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    width: min(288px, 86vw);
    height: 100vh;
    max-height: 100vh;
    border-inline-end: 1px solid var(--line);
    border-bottom: 0;
    z-index: 13;
    transform: translateX(110%);
    transition: transform 0.2s ease;
    box-shadow: -12px 0 40px rgba(27, 36, 48, 0.12);
  }
  html[dir="rtl"] .sidebar { transform: translateX(110%); }
  html[dir="ltr"] .sidebar { transform: translateX(-110%); }
  .shell:not(.is-collapsed) .sidebar,
  html[dir="rtl"] .shell:not(.is-collapsed) .sidebar,
  html[dir="ltr"] .shell:not(.is-collapsed) .sidebar {
    transform: translateX(0);
  }
  .shell.is-collapsed .logo span,
  .shell.is-collapsed .who strong,
  .shell.is-collapsed .who span,
  .shell.is-collapsed .nav a span { display: initial; }
  .shell.is-collapsed .nav a::after { content: none; }
  .shell.is-collapsed .sidebar-top { flex-direction: row; justify-content: space-between; }
  .shell.is-collapsed .who { display: block; }
  .sidebar-toggle.mobile { display: inline-grid; place-items: center; }
  .sidebar-toggle:not(.mobile) { display: none; }
  .nav { display: grid; gap: 2px; overflow: visible; }
  .who { margin-top: auto; }
  .topbar {
    padding: 12px 16px;
    gap: 10px;
    align-items: flex-start;
  }
  .topbar .button { flex: 0 0 auto; white-space: nowrap; font-size: 0.86rem; padding: 8px 12px; }
  .topbar h1 { font-size: 1.15rem; }
  .topbar p { font-size: 0.8rem; }
  .view, #view { padding: 10px 16px 32px; width: 100%; max-width: none; }
  .metrics, .facts, .policy-strip { grid-template-columns: 1fr; }
  .metric b { font-size: 1.2rem; }
  .table-wrap { margin-inline: 0; }
  .policy-bar { position: static; }
  label.compact { max-width: none; }
}
