:root {
  color-scheme: light;

  /* MAHRA brand tokens — aligned with the mahrabn.com landing page */
  --f-display: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --cyan: #1E8A93;
  --cyan-bright: #46E0DA;
  --blue: #3D63D6;
  --violet: #6B4FD1;
  --ok: #178F72;
  --warn: #B67A2E;
  --high: #C34D3E;

  --accent: var(--cyan);
  --accent-strong: #146069;
  --accent-soft: #E4F5F4;
  --accent-violet: var(--violet);
  --graphite: #0E1116;
  --graphite-soft: #171B22;
  --page: #F5F7FA;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-subtle: #EEF2F5;
  --ink: #0E1116;
  --muted: #5B6572;
  --line: #DEE3E9;
  --line-strong: #C7CEDA;
  --success: var(--ok);
  --warning: var(--warn);
  --danger: var(--high);
  --info: var(--blue);
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-pill: 100px;
  --shadow-sm: 0 1px 2px rgba(14, 17, 22, .06);
  --shadow: 0 12px 32px rgba(14, 17, 22, .08);
  --shadow-lg: 0 28px 80px rgba(7, 8, 10, .22);
  --focus-ring: 0 0 0 3px rgba(30, 138, 147, .22);
  --transition: 160ms ease;
  --content-width: 1480px;
  --sidebar: 264px;

  /* Temporary compatibility aliases for page-specific templates. */
  --gold: var(--accent);
  --gold2: var(--cyan-bright);
  --emerald: var(--graphite);
  --emerald2: var(--graphite-soft);
  --ivory: var(--page);
  --surface2: var(--surface-subtle);
}

body.dark {
  color-scheme: dark;
  --page: #07080A;
  --surface: #12151B;
  --surface-raised: #171B22;
  --surface-subtle: #171B22;
  --ink: #E9EDF4;
  --muted: #9BA4B5;
  --line: rgba(186, 202, 228, .12);
  --line-strong: rgba(186, 202, 228, .22);
  --accent: var(--cyan-bright);
  --accent-strong: #7BEAE5;
  --accent-soft: rgba(70, 224, 218, .14);
  --accent-violet: #9A7CF7;
  --success: #5FD3A6;
  --warning: #E5B368;
  --danger: #F0785F;
  --info: #5B8CFF;
  --shadow-sm: 0 1px 1px rgba(0, 0, 0, .3);
  --shadow: 0 16px 36px rgba(0, 0, 0, .35);
  --shadow-lg: 0 30px 80px -40px rgba(0, 0, 0, .9);
  --focus-ring: 0 0 0 3px rgba(70, 224, 218, .22);
}

* { box-sizing: border-box; }
html {
  max-width: 100%;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
body {
  max-width: 100%;
  overflow-x: hidden;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}
h1, h2, h3, h4 {
  font-family: var(--f-display);
  font-weight: 600;
  letter-spacing: -.02em;
}
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

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

.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;
  top: 10px;
  left: 10px;
  z-index: 200;
  transform: translateY(-150%);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  text-decoration: none;
}
.skip-link:focus { transform: translateY(0); }

h1, h2, h3, p { overflow-wrap: break-word; }
.eyebrow {
  display: block;
  font-family: var(--f-mono);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  line-height: 1.3;
  text-transform: uppercase;
}
.muted, .meta { color: var(--muted); }

.button,
button:not(.avatar):not(.icon-button):not(.sidebar-toggle) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--graphite);
  color: #fff;
  padding: 9px 16px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.button:hover,
button:not(.avatar):not(.icon-button):not(.sidebar-toggle):hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.button:disabled, button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.button.gold, button.gold, .button-primary {
  background: linear-gradient(135deg, var(--cyan-bright), var(--blue));
  color: #04222a;
  font-weight: 700;
}
.button.gold:hover, button.gold:hover, .button-primary:hover { filter: brightness(1.05); }
.button.secondary, button.secondary, .button-secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}
.button.secondary:hover, button.secondary:hover, .button-secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}
.button.danger, button.danger, .danger { background: var(--danger); color: #fff; }
.button.small, button.small, .small { min-height: 32px; padding: 6px 14px; font-size: 12px; }

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.icon-button:hover { border-color: var(--line-strong); background: var(--surface-subtle); }

.card {
  min-width: 0;
  margin: 0 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), background var(--transition);
}
.card > h2 { margin: 0 0 16px; font-size: 19px; letter-spacing: -.02em; }
.card:hover { border-color: var(--line-strong); }
.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.section-head h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.quick, .row, .action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
}
.quick { margin-bottom: 18px; }

.page-banner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 116px;
  margin: 0 0 20px;
  border: 1px solid rgba(70, 224, 218, .22);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 88% 20%, rgba(154, 124, 247, .22), transparent 32%),
    linear-gradient(135deg, #0E1116, #12232A);
  color: #F3F9FB;
  padding: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.page-banner h1, .page-banner h2 { margin: 0; color: #fff; letter-spacing: -.03em; }
.page-banner p { max-width: 720px; margin: 6px 0 0; color: #B7C7D1; }
.banner-icon {
  display: grid;
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  place-items: center;
  border: 1px solid rgba(70, 224, 218, .32);
  border-radius: 14px;
  background: rgba(70, 224, 218, .12);
  color: var(--cyan-bright);
  font-size: 22px;
}

.metric, .section-stat, .analytics-kpi, .mini-kpi {
  position: relative;
  min-height: 112px;
}
.metric span, .section-stat span, .analytics-kpi span, .mini-kpi span {
  color: var(--muted);
  font-size: 12px;
}
.metric strong, .section-stat strong, .analytics-kpi strong, .mini-kpi strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-family: var(--f-display);
  font-size: 27px;
  line-height: 1.1;
  letter-spacing: -.03em;
}
.metric-link, .mini-kpi { color: inherit; text-decoration: none; }
.metric-link:hover, a.mini-kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.metric-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.metric-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 12px;
}
th {
  background: var(--surface-subtle);
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: " ↕"; opacity: .45; }
th[aria-sort="ascending"]::after { content: " ↑"; opacity: 1; color: var(--accent); }
th[aria-sort="descending"]::after { content: " ↓"; opacity: 1; color: var(--accent); }

.badge, .live-pill, .read-only-access-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}
.badge.pending, .pending { border-color: #f3d6a1; background: #fff5df; color: #8a5200; }
.badge.confirmed, .confirmed, .badge.active { border-color: #afe0ce; background: #e5f7f0; color: #126743; }
.badge.rejected, .rejected, .badge.error { border-color: #efbbc0; background: #fff0f1; color: #9d2934; }
.badge.whatsapp, .whatsapp { background: #e5f7f0; color: #126743; }
.badge.telegram, .telegram { background: #e7f4fb; color: #12648c; }
body.dark .badge.pending, body.dark .pending { border-color: #6f5324; background: #362b19; color: #f0bf68; }
body.dark .badge.confirmed, body.dark .confirmed, body.dark .badge.active {
  border-color: #275e4b; background: #18352b; color: #78d5b2;
}
body.dark .badge.rejected, body.dark .rejected, body.dark .badge.error {
  border-color: #6e343b; background: #3b2227; color: #f1939c;
}

label { display: block; margin: 14px 0 6px; color: var(--ink); font-size: 12px; font-weight: 600; }
input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .72; }

.notice {
  margin-bottom: 18px;
  border: 1px solid #addfce;
  border-radius: var(--radius-sm);
  background: #e9f8f2;
  color: #126743;
  padding: 12px 14px;
  transition: opacity 260ms ease, transform 260ms ease;
}
.notice.error { border-color: #efbbc0; background: #fff0f1; color: #9d2934; }
.notice-leaving { opacity: 0; transform: translateY(-6px); }
.empty, .loading-state {
  display: grid;
  min-height: 110px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  padding: 24px;
  text-align: center;
}
.entry { padding: 16px 0; border-top: 1px solid var(--line); }
.entry:first-child { border-top: 0; }
.entry h3 { margin: 0 0 6px; font-size: 16px; }
.answer { margin-top: 10px; line-height: 1.65; white-space: pre-wrap; }
.inactive { opacity: .55; }
.setting {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.ok { color: var(--success); font-weight: 700; }
.missing { color: var(--danger); font-weight: 700; }

dialog, dialog.card, .dialog-shell {
  width: min(720px, calc(100vw - 28px));
  max-height: 88vh;
  margin: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(5, 8, 10, .66); backdrop-filter: blur(5px); }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.dialog-header h2 { margin: 2px 0 0; font-size: 19px; }
.dialog-body { max-height: calc(88vh - 78px); overflow: auto; padding: 20px; }

.service-admin-layout { display: grid; grid-template-columns: minmax(280px, .75fr) minmax(0, 1.75fr); gap: 18px; }
.service-main-card { min-width: 0; }
.service-form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.settings-grid, .settings-link-grid { display: grid; gap: 14px; }
.settings-link-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-link {
  display: flex;
  min-height: 88px;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  text-decoration: none;
}
.settings-link:hover { border-color: var(--accent); background: var(--accent-soft); }
.settings-link small { margin-top: 5px; color: var(--muted); }

.track { height: 8px; overflow: hidden; border-radius: 99px; background: var(--surface-subtle); }
.fill { height: 100%; min-width: 2px; border-radius: inherit; }
.pending-fill { background: var(--warning); }
.confirmed-fill { background: var(--success); }
.rejected-fill { background: var(--danger); }
.live-pill i, .status-indicator {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(23, 143, 114, .16);
}
body.dark .live-pill i, body.dark .status-indicator {
  background: #35cf91;
  box-shadow: 0 0 0 4px rgba(53, 207, 145, .14);
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .service-admin-layout { grid-template-columns: 1fr; }
  .settings-link-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  body { font-size: 13px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 15px; }
  .page-banner { align-items: flex-start; min-height: 0; padding: 18px; }
  .page-banner .banner-icon { display: none; }
  .section-head { align-items: flex-start; }
  .quick { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 3px; }
  .quick > * { flex: 0 0 auto; }
}

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

@media print {
  .sidebar, .topbar, .overlay, .quick, .notice { display: none !important; }
  .shell { margin: 0 !important; }
  .content { max-width: none !important; padding: 0 !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
