:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --sidebar: #0b1330;
  --sidebar-text: #c9d3f5;
  --line: #e2e6f0;
  --text: #141a2e;
  --muted: #5d6784;
  --accent: #006fd6;
  --accent-soft: #e5f0fd;
  --cyan: #00b8d9;
  --violet: #7c5cff;
  --ok: #0f8a5f;
  --ok-soft: #e3f6ee;
  --warn: #a76100;
  --warn-soft: #fff3df;
  --bad: #c62a47;
  --bad-soft: #fde8ec;
  --hold: #7c3aed;
  --hold-soft: #f1eafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 54, 0.06), 0 4px 16px rgba(16, 24, 54, 0.05);
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070b1d;
    --surface: #0f1631;
    --surface-2: #131c3d;
    --sidebar: #050816;
    --line: #232d55;
    --text: #e6ecff;
    --muted: #93a0c8;
    --accent: #4aa8ff;
    --accent-soft: #10264a;
    --ok: #3cd99a;
    --ok-soft: #0c2e25;
    --warn: #ffc65c;
    --warn-soft: #33270c;
    --bad: #ff6b81;
    --bad-soft: #3a1420;
    --hold: #b69bff;
    --hold-soft: #251a46;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

.boot { display: grid; place-items: center; min-height: 100vh; gap: 12px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; background: linear-gradient(to right, var(--sidebar) 236px, transparent 236px); }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 18px 12px; gap: 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: #fff; }
.brand img { width: 30px; height: 30px; }
.brand b { letter-spacing: 0.08em; }
.brand span { display: block; font-size: 11px; color: var(--sidebar-text); opacity: 0.8; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.55; padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); }
.nav a:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.nav a[aria-current="page"] { background: rgba(74, 168, 255, 0.16); color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: 0.9; }
.tenant-card { margin-top: auto; padding: 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); font-size: 12px; }
.tenant-card b { color: #fff; display: block; font-size: 13px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 28px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5; }
.topbar form { flex: 1; max-width: 560px; }
.search { width: 100%; padding: 9px 12px 9px 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2) no-repeat 11px 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235d6784' stroke-width='2.4'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E");
  color: var(--text); font: inherit; }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12px; }
.user .who { line-height: 1.2; text-align: right; }
.user .who .small { color: var(--muted); }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 18px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 4px; max-width: 760px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* Cards and grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card > h2, .card > .card-head { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 1100px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; background: none; }
  .sidebar { position: static; height: auto; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.hero { background: linear-gradient(120deg, #0b1330 0%, #142a6b 60%, #1b4fa8 100%); color: #fff; border: none; }
.hero .muted { color: #c9d3f5; }
.hero .chips span { background: rgba(255, 255, 255, 0.14); color: #fff; }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(120px, 38%) 1fr 44px; align-items: center; gap: 10px; font-size: 13px; }
.bar .track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--violet)); border-radius: 99px; }
.bar .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.columns { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 8px; }
.columns .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); min-width: 0; }
.columns .col .stick { width: 100%; max-width: 46px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, var(--violet), var(--accent)); min-height: 3px; }
.columns .col b { color: var(--text); font-size: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
td .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Badges and chips */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-hold { background: var(--hold-soft); color: var(--hold); }
.b-info { background: var(--accent-soft); color: var(--accent); }
.b-plain { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { padding: 3px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }

/* Forms */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
label, .label { font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 70px; resize: vertical; }
.help { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); font-weight: 500; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { min-width: 150px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: none; border: none; padding: 9px 12px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 600; }
.tabs button[aria-selected="true"], .tabs a[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a { padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; text-decoration: none; }
.decisions { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.steps-editor { display: grid; gap: 10px; margin: 8px 0; }
.step { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.step legend { font-weight: 600; padding: 0 4px; }
.step > button { justify-self: start; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }

/* Key-value lists */
.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Notices */
.notice { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); font-size: 13px; border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.notice.ok { background: var(--ok-soft); }
.notice b { display: block; margin-bottom: 2px; }

/* Preview */
.preview { border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); min-height: 320px; display: grid; place-items: center; overflow: hidden; }
.preview iframe { width: 100%; height: 620px; border: 0; background: #fff; }
.preview img { max-width: 100%; max-height: 620px; }
.preview pre { margin: 0; padding: 14px; width: 100%; max-height: 620px; overflow: auto; font: 12px/1.5 var(--mono); white-space: pre-wrap; align-self: start; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: grid; grid-template-columns: 16px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 16px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline .dot { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--accent); background: var(--surface); margin-top: 2px; }
.timeline .dot.ok { border-color: var(--ok); }
.timeline .dot.bad { border-color: var(--bad); }
.timeline .dot.hold { border-color: var(--hold); }
.timeline .what { font-weight: 600; }
.timeline .meta { color: var(--muted); font-size: 12px; }
.timeline details { margin-top: 4px; font-size: 12px; }
.timeline pre { margin: 6px 0 0; padding: 8px; border-radius: 8px; background: var(--surface-2); overflow-x: auto; font: 11.5px/1.45 var(--mono); }

/* Upload */
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center; background: var(--surface-2); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }
.receipt { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 6px 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.channel-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.channel-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; }
.channel-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
button.channel-card { text-align: left; font: inherit; color: inherit; cursor: pointer; }

/* Sign-in */
.signin { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.signin .pitch { background: linear-gradient(140deg, #050816 0%, #0d1b4d 55%, #1b4fa8 100%); color: #e6ecff; padding: 56px; display: flex; flex-direction: column; gap: 22px; justify-content: center; }
.signin .pitch h1 { font-size: 34px; color: #fff; }
.signin .pitch ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; color: #c9d3f5; }
.signin .panel { padding: 56px; display: flex; flex-direction: column; gap: 18px; justify-content: center; max-width: 620px; }
@media (max-width: 900px) { .signin { grid-template-columns: 1fr; } .signin .pitch, .signin .panel { padding: 28px 16px; } }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; background: var(--surface); color: var(--text); width: min(520px, 92vw); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(5, 8, 22, 0.5); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog.wide { width: min(760px, 94vw); max-height: 90vh; overflow-y: auto; }
dialog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 6px 0 0; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0b1330; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3); max-width: 90vw; }
.hash { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }

/* Language picker (app/i18n.js) and right-to-left layout for Arabic. Grid and flex follow the page direction by
   themselves; these rules flip what is set with left and right. */
select.lang { width: auto; padding: 6px 8px; font-size: 13px; border-radius: 8px; }
[dir="rtl"] body { font-family: system-ui, "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif; }
[dir="rtl"] .shell { background: linear-gradient(to left, var(--sidebar) 236px, transparent 236px); }
[dir="rtl"] .user { margin-left: 0; margin-right: auto; }
[dir="rtl"] .user .who { text-align: left; }
[dir="rtl"] .bar .n { text-align: left; }
[dir="rtl"] th, [dir="rtl"] td, [dir="rtl"] button.channel-card { text-align: right; }
[dir="rtl"] .timeline li::before { left: auto; right: 7px; }
[dir="rtl"] .signin .pitch ul { padding-left: 0; padding-right: 18px; }
[dir="rtl"] .mono, [dir="rtl"] code { direction: ltr; unicode-bidi: isolate; }
