:root {
  --canvas: oklch(0.952 0.018 82);
  --surface: oklch(0.982 0.012 82);
  --surface-raised: oklch(1 0 0);
  --ink: oklch(0.245 0.025 145);
  --ink-soft: oklch(0.45 0.02 145);
  --muted: oklch(0.58 0.018 145);
  --line: oklch(0.84 0.023 82);
  --line-strong: oklch(0.68 0.035 75);
  --clay: oklch(0.51 0.135 40);
  --clay-deep: oklch(0.4 0.115 38);
  --olive: oklch(0.47 0.075 135);
  --gold: oklch(0.62 0.11 76);
  --danger: oklch(0.48 0.16 25);
  --focus: oklch(0.62 0.14 230);
  --radius-xs: 3px;
  --radius-sm: 7px;
  --radius-md: 12px;
  --radius-pill: 999px;
  --sidebar: 262px;
  --shadow: 0 18px 50px oklch(0.3 0.02 80 / 0.09), 0 2px 8px oklch(0.3 0.02 80 / 0.05);
  --font-ui: "Noto Sans Arabic", "Noto Kufi Arabic", "Geeza Pro", Tahoma, sans-serif;
  --font-display: "Noto Kufi Arabic", "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); color: var(--ink); font-family: var(--font-ui); }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button, a { touch-action: manipulation; }
a { color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; inset-inline-start: 16px; top: -60px; z-index: 100;
  background: var(--ink); color: var(--surface); padding: 12px 18px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 16px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.boot-screen {
  min-height: 100vh; display: grid; place-content: center; gap: 18px; text-align: center;
  color: var(--ink-soft);
}
.brand-mark {
  width: 44px; height: 44px; display: inline-grid; place-items: center; flex: 0 0 auto;
  background: var(--ink); color: var(--surface); border-radius: 50% 50% 45% 55%;
  font-family: var(--font-display); font-weight: 800; font-size: 24px; line-height: 1;
}

.login-screen {
  min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  background:
    linear-gradient(to left, transparent 0 68%, oklch(0.9 0.035 75 / 0.62) 68% 68.12%, transparent 68.12%),
    var(--canvas);
}
.login-context {
  padding: clamp(36px, 7vw, 92px); display: flex; flex-direction: column; justify-content: center;
  position: relative; overflow: hidden;
}
.login-context::after {
  content: "جدة"; position: absolute; inset-inline-end: -28px; bottom: -70px;
  font-family: var(--font-display); font-size: clamp(180px, 28vw, 410px); font-weight: 800;
  color: oklch(0.78 0.045 75 / 0.2); letter-spacing: -0.08em; line-height: 1; pointer-events: none;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 90px; position: relative; z-index: 1; }
.login-brand div { display: grid; gap: 2px; }
.login-brand strong { font-family: var(--font-display); font-size: 18px; }
.login-brand span:last-child { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; }
.eyebrow {
  margin: 0 0 10px; color: var(--clay); font-size: 11px; font-weight: 750;
  letter-spacing: 0.09em; text-transform: uppercase;
}
.login-context h1 {
  position: relative; z-index: 1; max-width: 760px; margin: 0;
  font-family: var(--font-display); font-size: clamp(36px, 5.4vw, 74px); line-height: 1.22;
  letter-spacing: -0.025em; font-weight: 720;
}
.login-lede {
  position: relative; z-index: 1; max-width: 620px; margin: 28px 0;
  color: var(--ink-soft); font-size: clamp(16px, 1.5vw, 20px); line-height: 1.85;
}
.security-note {
  display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font-size: 13px;
  position: relative; z-index: 1;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--olive);
  box-shadow: 0 0 0 4px oklch(0.47 0.075 135 / 0.12); flex: 0 0 auto;
}
.login-form {
  align-self: center; margin: 32px; padding: clamp(28px, 4vw, 52px);
  background: var(--surface-raised); border-radius: var(--radius-md); box-shadow: var(--shadow);
}
.step-index { margin: 0 0 30px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.login-form label { display: block; margin-bottom: 12px; font-weight: 700; }
.login-form input {
  width: 100%; min-height: 64px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--canvas); padding: 14px 18px; color: var(--ink); direction: ltr; text-align: center;
  font-size: 30px; letter-spacing: 0.3em; font-variant-numeric: tabular-nums;
}
.field-help { margin: 12px 0 24px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.primary-button, .secondary-button, .text-button, .icon-button, .search-form button {
  min-height: 42px; border: 0; border-radius: var(--radius-sm);
}
.primary-button { background: var(--ink); color: var(--surface); padding: 10px 22px; font-weight: 750; }
.primary-button:active, .secondary-button:active, .search-form button:active { transform: scale(0.98); }
.secondary-button { background: transparent; color: var(--ink); border: 1px solid var(--line-strong); padding: 9px 18px; }
.text-button { background: transparent; color: var(--clay-deep); padding: 8px 4px; min-height: 40px; }
.icon-button { background: transparent; color: inherit; min-width: 42px; }
.login-form .primary-button { width: 100%; min-height: 52px; }
.form-actions { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.form-actions .primary-button { width: auto; }
.form-error {
  margin: 18px 0 0; padding: 12px 14px; border-radius: var(--radius-sm);
  background: oklch(0.93 0.045 25); color: var(--danger); font-size: 13px;
}
.bootstrap-message {
  margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line);
  color: var(--ink-soft); line-height: 1.7; font-size: 13px;
}
.bootstrap-message p { margin-bottom: 0; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar); z-index: 20;
  background: var(--ink); color: var(--surface); display: flex; flex-direction: column;
  padding: 24px 18px 18px;
}
.app-brand {
  display: flex; align-items: center; gap: 12px; text-decoration: none; padding: 4px 8px 25px;
  border-bottom: 1px solid oklch(1 0 0 / 0.12);
}
.app-brand .brand-mark { background: var(--surface); color: var(--ink); }
.app-brand > span:last-child { display: grid; gap: 3px; }
.app-brand strong { font-family: var(--font-display); font-size: 16px; }
.app-brand small { color: oklch(0.78 0.02 145); direction: ltr; font-size: 10px; letter-spacing: 0.07em; }
.nav-list { display: grid; gap: 2px; padding-block: 18px; overflow-y: auto; }
.nav-link {
  min-height: 42px; display: flex; align-items: center; gap: 12px; text-decoration: none;
  padding: 8px 10px; border-radius: var(--radius-sm); color: oklch(0.86 0.015 145); font-size: 13px;
}
.nav-link span { color: oklch(0.65 0.02 145); font-size: 10px; font-variant-numeric: tabular-nums; }
@media (hover: hover) {
  .nav-link:hover { background: oklch(1 0 0 / 0.06); color: var(--surface); }
  .primary-button:hover { background: var(--clay-deep); }
  .secondary-button:hover { background: oklch(0.9 0.03 75); }
}
.nav-link.is-active { background: var(--surface); color: var(--ink); }
.nav-link.is-active span { color: var(--clay); }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding-top: 16px; border-top: 1px solid oklch(1 0 0 / 0.12); }
.operator-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.operator-avatar {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%;
  background: var(--clay); color: white; font-weight: 750;
}
.operator-chip div { display: grid; gap: 1px; }
.operator-chip strong { font-size: 12px; }
.operator-chip small { color: oklch(0.72 0.02 145); font-size: 10px; }
.sidebar-foot .text-button { color: oklch(0.76 0.035 60); text-align: start; }
.workspace { margin-inline-start: var(--sidebar); min-height: 100vh; }
.topbar {
  min-height: 84px; display: flex; align-items: center; gap: 24px; padding: 14px clamp(22px, 4vw, 56px);
  border-bottom: 1px solid var(--line); background: oklch(0.972 0.014 82 / 0.94);
  position: sticky; top: 0; z-index: 10;
}
.today-block { display: grid; gap: 2px; min-width: 150px; }
.today-block strong { font-size: 13px; }
.today-block .eyebrow { margin: 0; font-size: 9px; }
.search-form { margin-inline-start: auto; display: flex; align-items: center; max-width: 360px; width: 100%; }
.search-form input {
  width: 100%; min-height: 40px; border: 1px solid var(--line); border-inline-end: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--surface); padding: 8px 13px;
}
.search-form button {
  min-height: 40px; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line); padding-inline: 16px; color: var(--ink);
}
.top-status { display: flex; align-items: center; gap: 9px; color: var(--ink-soft); font-size: 11px; white-space: nowrap; }
.menu-button { display: none; }
.menu-button span { display: block; width: 20px; height: 1px; background: currentColor; margin: 4px auto; }
.search-results {
  margin: 18px clamp(22px, 4vw, 56px) 0; padding: 18px; background: var(--surface-raised);
  border-radius: var(--radius-md); box-shadow: var(--shadow);
}

.view { padding: clamp(28px, 4.5vw, 62px); max-width: 1660px; }
.view-heading {
  display: flex; align-items: end; justify-content: space-between; gap: 28px; margin-bottom: 34px;
}
.view-heading h1 {
  margin: 0; font-family: var(--font-display); font-size: clamp(30px, 4vw, 54px);
  line-height: 1.15; letter-spacing: -0.022em; font-weight: 720;
}
.view-note { max-width: 420px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.ledger-grid {
  display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr));
  border-block: 1px solid var(--line-strong); margin-bottom: 34px;
}
.metric {
  min-height: 132px; padding: 22px 18px 18px; display: flex; flex-direction: column; justify-content: space-between;
  border-inline-start: 1px solid var(--line);
}
.metric:first-child { border-inline-start: 0; }
.metric-label { color: var(--ink-soft); font-size: 11px; }
.metric-value { font-size: clamp(25px, 3vw, 42px); font-weight: 680; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.metric-note { color: var(--muted); font-size: 10px; }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr); gap: 28px; }
.panel { background: var(--surface); border-radius: var(--radius-md); padding: 24px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.panel-heading > div { display: flex; align-items: center; gap: 10px; }
.panel h2 { margin: 0; font-family: var(--font-display); font-size: 17px; }
.section-number {
  width: 25px; height: 25px; display: inline-grid; place-items: center; border: 1px solid var(--line-strong);
  border-radius: 50%; color: var(--clay); font-size: 10px; font-weight: 750;
}
.inline-link { color: var(--clay-deep); font-size: 12px; text-underline-offset: 4px; }
.compact-list { display: grid; }
.compact-row {
  display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 12px;
  min-height: 48px; border-top: 1px solid var(--line); font-size: 12px;
}
.compact-row:first-child { border-top: 0; }
.compact-row time { color: var(--muted); direction: ltr; text-align: start; font-variant-numeric: tabular-nums; }
.status-panel p { color: var(--ink-soft); font-size: 13px; line-height: 1.8; }
.truth-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); font-size: 12px; }
.state {
  display: inline-flex; align-items: center; min-height: 25px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill); padding: 2px 9px; color: var(--ink-soft); font-size: 9px;
  letter-spacing: 0.04em; white-space: nowrap;
}
.state-blocked { border-color: oklch(0.68 0.08 40); color: var(--clay-deep); background: oklch(0.93 0.04 50); }
.state-ok { border-color: var(--olive); color: var(--olive); background: oklch(0.94 0.025 135); }
.data-surface { overflow-x: auto; border-block: 1px solid var(--line-strong); }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th {
  padding: 12px 12px; color: var(--muted); font-size: 10px; font-weight: 650; text-align: start;
  border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
.data-table td { padding: 15px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table td.num { text-align: end; font-variant-numeric: tabular-nums; }
.data-table code, .mono { direction: ltr; font-family: "DejaVu Sans Mono", monospace; font-size: 10px; }
.table-empty { padding: 42px 18px; color: var(--muted); text-align: center; }
.editor-panel { margin-bottom: 26px; box-shadow: var(--shadow); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid label, .settings-form label { display: grid; gap: 8px; color: var(--ink-soft); font-size: 12px; }
.form-grid input, .form-grid textarea, .form-grid select, .settings-form input, .settings-form select {
  width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-raised); color: var(--ink); padding: 8px 11px;
}
.form-grid textarea { resize: vertical; }
.check-field { display: flex !important; align-items: center; gap: 10px; min-height: 42px; }
.check-field input { width: 18px; min-height: 18px; }
.form-grid .form-actions { grid-column: 1 / -1; }
.provider-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr); gap: 28px; }
.provider-list { display: grid; border-block: 1px solid var(--line-strong); }
.provider-row {
  display: grid; grid-template-columns: minmax(140px, 1fr) 90px 110px 90px;
  gap: 16px; align-items: center; padding: 17px 8px; border-bottom: 1px solid var(--line); font-size: 12px;
}
.provider-row strong { display: grid; gap: 2px; }
.provider-row small { color: var(--muted); font-size: 10px; }
.provider-toggle { min-height: 36px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: transparent; }
.note-panel { align-self: start; }
.note-panel p { color: var(--ink-soft); font-size: 13px; line-height: 1.85; }
.empty-state {
  min-height: 400px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  border-block: 1px solid var(--line-strong); padding: 54px clamp(12px, 5vw, 80px); max-width: 880px;
}
.empty-index { color: var(--clay); font-size: 12px; font-weight: 700; }
.empty-state h2 { margin: 12px 0; font-family: var(--font-display); font-size: clamp(24px, 3vw, 38px); }
.empty-state p { max-width: 660px; margin: 0 0 22px; color: var(--ink-soft); line-height: 1.9; }
.state-line { display: flex; flex-wrap: wrap; gap: 8px; }
.agent-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); border-block: 1px solid var(--line-strong); }
.agent-tile { padding: 22px 16px; border-inline-start: 1px solid var(--line); min-height: 180px; display: flex; flex-direction: column; justify-content: space-between; }
.agent-tile:first-child { border-inline-start: 0; }
.agent-tile strong { font-family: var(--font-display); font-size: 14px; direction: ltr; align-self: flex-start; }
.agent-tile p { color: var(--muted); font-size: 11px; line-height: 1.7; }
.footnote { color: var(--muted); font-size: 11px; margin-top: 18px; }
.settings-panel { margin-top: 26px; }
.settings-form { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 18px; align-items: end; }
.settings-form .wide { grid-column: span 2; }
.settings-form .form-actions { display: flex; justify-content: flex-end; }
.role-ledger { width: min(100%, 720px); display: grid; }
.role-ledger div { display: grid; grid-template-columns: 100px 1fr; gap: 18px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 12px; }
.role-ledger strong { direction: ltr; text-align: start; }
.user-add-panel { margin-top: 24px; }
.secret-code { display: block; overflow-wrap: anywhere; user-select: all; }
.toast {
  position: fixed; inset-inline-start: 24px; bottom: 24px; z-index: 80; max-width: 380px;
  padding: 14px 18px; border-radius: var(--radius-sm); background: var(--ink); color: var(--surface);
  box-shadow: var(--shadow); font-size: 13px;
}
.toast-error { background: var(--danger); }
.error-panel { padding: 22px; background: oklch(0.94 0.035 28); color: var(--danger); border-radius: var(--radius-sm); }
.pulse { opacity: 0.55; }

@media (max-width: 1180px) {
  .ledger-grid { grid-template-columns: repeat(3, 1fr); }
  .metric:nth-child(4) { border-inline-start: 0; }
  .agent-grid { grid-template-columns: repeat(3, 1fr); }
  .agent-tile:nth-child(4) { border-inline-start: 0; }
  .settings-form { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
}

@media (max-width: 900px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-context { min-height: 52vh; padding: 32px 24px; }
  .login-brand { margin-bottom: 50px; }
  .login-form { margin: 0 18px 32px; }
  .sidebar {
    transform: translateX(105%); transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow); width: min(310px, 88vw);
  }
  .sidebar.is-open { transform: translateX(0); }
  .workspace { margin-inline-start: 0; }
  .menu-button { display: block; }
  .topbar { gap: 12px; padding-inline: 18px; }
  .search-form { max-width: 250px; }
  .top-status span:last-child { display: none; }
  .view { padding: 28px 18px 48px; }
  .split-grid, .provider-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .login-context h1 { font-size: 34px; }
  .login-form { padding: 26px 20px; }
  .today-block { display: none; }
  .search-form { max-width: none; }
  .view-heading { align-items: flex-start; flex-direction: column; gap: 14px; }
  .ledger-grid { grid-template-columns: repeat(2, 1fr); }
  .metric { min-height: 112px; }
  .metric:nth-child(odd) { border-inline-start: 0; }
  .form-grid, .settings-form { grid-template-columns: 1fr; }
  .settings-form .wide { grid-column: auto; }
  .provider-row { grid-template-columns: 1fr auto; }
  .provider-row > :nth-child(2), .provider-row > :nth-child(4) { text-align: end; }
  .agent-grid { grid-template-columns: 1fr; }
  .agent-tile { min-height: 140px; border-inline-start: 0; border-top: 1px solid var(--line); }
  .agent-tile:first-child { border-top: 0; }
  .compact-row { grid-template-columns: 78px 1fr; }
  .compact-row .state { grid-column: 2; justify-self: start; }
}

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