/* منصة يسير — the platform console. Local font only (CSP font-src 'self'). */
@font-face {
  font-family: "Noto Sans Arabic";
  src: url("fonts/NotoSansArabic-Regular.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --primary: #1e3a5f;
  --primary-hover: #17304f;
  --on-primary: #ffffff;
  --accent: #047857;
  --accent-soft: #e7f5ef;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --warn: #92400e;
  --warn-soft: #fdf3e1;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #526075;
  --border: #e2e7ee;
  --ring: #2563eb;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 10px;
  --font: "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #5b8fd1;
    --primary-hover: #74a2dc;
    --on-primary: #0b1424;
    --accent: #34d399;
    --accent-soft: #0f2e24;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --warn: #fbbf24;
    --warn-soft: #34270d;
    --info: #93b4ff;
    --info-soft: #18233d;
    --bg: #0d131c;
    --surface: #151d29;
    --surface-2: #1a2432;
    --text: #e6ebf2;
    --muted: #9aa8bc;
    --border: #263243;
    --ring: #7aa7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; inset-inline-start: 8px; top: -60px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }

/* ── buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, opacity .15s ease;
  touch-action: manipulation;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-block { width: 100%; min-height: 44px; font-size: 15px; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-ghost.busy::after { border-color: var(--border); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* small row actions */
.act { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.act-extend { background: var(--info-soft); color: var(--info); }
.act-convert { background: var(--accent-soft); color: var(--accent); }
.act-activate { background: var(--accent-soft); color: var(--accent); }
.act-suspend { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.act-suspend:hover:not(:disabled) { background: var(--danger-soft); }
.act-link { background: transparent; color: var(--muted); }
.act-link:hover { color: var(--text); background: var(--surface-2); }
.act-extend:hover, .act-convert:hover, .act-activate:hover { filter: brightness(.96); }

/* ── fields ──────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 600; }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; min-height: 42px; padding: 8px 12px; width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 22%, transparent); }
input.code { font-family: var(--mono); font-size: 22px; letter-spacing: .45em; text-align: center; font-variant-numeric: tabular-nums; }
.pw { position: relative; display: block; }
/* the field is LTR inside an RTL page: keep the toggle and the room for it on the same physical side */
.pw input { padding-left: 72px; }
.pw-toggle {
  position: absolute; left: 4px; top: 4px; bottom: 4px; padding: 0 10px; border: 0;
  background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; border-radius: 6px;
}
.pw-toggle:hover { background: var(--surface-2); color: var(--text); }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 0 0 14px; font-size: 14px; }
.note { color: var(--warn); background: var(--warn-soft); padding: 8px 12px; border-radius: 8px; margin: 0 0 14px; font-size: 14px; }

/* ── sign-in ─────────────────────────────────────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 24px 24px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand h1 { font-size: 20px; }
.brand p { margin: 2px 0 0; font-size: 13px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--primary); color: var(--on-primary); font-size: 22px; font-weight: 700;
}
.brand-sm { margin: 0; gap: 8px; }
.brand-sm .brand-mark { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }

/* ── shell ───────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 0 20px; min-height: 58px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex: 1 1 auto; justify-content: center; align-self: stretch; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; color: var(--muted);
  text-decoration: none; font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; transition: color .15s ease, border-color .15s ease;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.count { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; display: inline-grid; place-items: center; font-family: var(--mono); }
.who { display: flex; align-items: center; gap: 10px; }
main { max-width: 1280px; margin: 0 auto; padding: 20px; outline: none; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  text-align: start; font: inherit; color: inherit; cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease;
}
.kpi:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.kpi[aria-pressed="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.kpi b { display: block; font-family: var(--mono); font-size: 24px; font-weight: 700; line-height: 1.2; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi small { display: block; font-size: 12px; color: var(--warn); margin-top: 2px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search .ic { position: absolute; inset-inline-start: 12px; top: 12px; color: var(--muted); }
.search input { padding-inline-start: 38px; }
.select select { min-width: 150px; }
.hint { font-size: 13px; margin: -2px 0 12px; }

.seg { display: inline-flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; font: inherit; font-size: 13px; color: var(--muted); padding: 0 12px; min-height: 32px;
  border-radius: 6px; cursor: pointer; transition: background-color .15s ease, color .15s ease;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"], .seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.seg-sm { margin-bottom: 8px; align-self: flex-start; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--info-soft); color: var(--info); border-radius: 16px; padding: 4px 6px 4px 12px; font-size: 13px; }
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; width: 24px; height: 24px; border-radius: 50%; font: inherit; }
.chip button:hover { background: color-mix(in srgb, var(--info) 15%, transparent); }

/* ── tables ──────────────────────────────────────────── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px; }
.grid th {
  text-align: start; font-weight: 600; font-size: 12.5px; color: var(--muted); background: var(--surface-2);
  padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0;
}
.grid td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr { transition: background-color .12s ease; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tr.flash { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.actions-col { width: 1%; }
.grid td:first-child { min-width: 170px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; }
.lab-name { font-weight: 600; }
.lab-slug { font-family: var(--mono); font-size: 12px; color: var(--muted); direction: ltr; unicode-bidi: isolate; }
.when { display: block; font-size: 12px; }
.when.late { color: var(--danger); }
.when.soon { color: var(--warn); }
.details { font-size: 13px; color: var(--muted); max-width: 420px; }
.details b { color: var(--text); font-weight: 600; }
.ev-danger { color: var(--danger); font-weight: 600; }
.ev-warn { color: var(--warn); font-weight: 600; }
.empty td { text-align: center; padding: 36px 14px; color: var(--muted); }
.skel td { padding: 14px; }
.skel span { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* status: a dot AND a word, never colour alone */
.st { display: inline-flex; align-items: center; gap: 6px; padding-block: 2px; padding-inline: 8px 10px; border-radius: 12px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.st::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-demo { background: var(--info-soft); color: var(--info); }
.st-trial { background: var(--warn-soft); color: var(--warn); }
.st-active { background: var(--accent-soft); color: var(--accent); }
.st-suspended { background: var(--danger-soft); color: var(--danger); }
.st-deleted { background: var(--surface-2); color: var(--muted); }
.st-request { background: var(--surface-2); color: var(--muted); }

/* ── dialog ──────────────────────────────────────────── */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
dialog[open] { animation: pop .18s ease-out; }
dialog::backdrop { background: rgba(15, 23, 42, .5); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
dialog form { padding: 22px 22px 18px; }
dialog h2 { font-size: 18px; margin-bottom: 6px; }
#dlg-text { margin: 0 0 16px; font-size: 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 4px; }
.dlg-actions .btn { min-width: 96px; }

.toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%); z-index: 50;
  background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
  animation: pop .18s ease-out;
}
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .top { flex-wrap: wrap; padding: 8px 16px 0; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; justify-content: flex-start; overflow-x: auto; min-height: 44px; }
  .who { margin-inline-start: auto; }
}
@media (max-width: 600px) {
  main { padding: 14px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:first-child { grid-column: 1 / -1; }
  .search { max-width: none; }
  .who .muted { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
