/* =========================================================================
   Platform design system — shared by the marketing site, owner panel and
   company panel. RTL first (Arabic), LTR supported via [dir="ltr"].
   Brand: burgundy #7A2232 primary (#5E1A27 hover; #E2A0A8 tint for brand text on dark), black and
   white, neutral greys only for lines and surfaces.
   ========================================================================= */
:root {
  --brand-900: #7A2232;   /* Primary: burgundy */
  --brand-700: #5E1A27;   /* Darker: hover / pressed */
  --brand-500: #7A2232;   /* Accent (same colour) */
  --accent-text: #7A2232; /* brand-coloured text; a lighter tint in dark mode */
  --charcoal: #000000;
  --silver: #D9D9D9;
  --white: #FFFFFF;

  --bg: #F6F6F6;
  --surface: #FFFFFF;
  --surface-2: #FAFAFA;
  --ink: #000000;
  --ink-2: #3D3D3D;
  --muted: #6B6B6B;
  --line: #E5E5E5;
  --focus: #7A2232;
  --link: #7A2232;

  --ok: #0F7B4B;      --ok-bg: #E6F4EC;
  --info: #1D5FA8;    --info-bg: #E7F0FA;
  --warn: #8A5A00;    --warn-bg: #FFF4D6;
  --danger: #5E1A27;  --danger-bg: #FDE8EA;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --font: "Cairo", "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --surface: #111111; --surface-2: #1A1A1A; --accent-text: #E2A0A8; --ink: #F5F5F5; --ink-2: #CFCFCF; --muted: #9E9E9E;
    --line: #262626; --focus: #E2A0A8; --link: #E2A0A8;
    --ok: #4CC38A; --ok-bg: #12261C; --info: #6EA8FE; --info-bg: #13213A; --warn: #F5C451; --warn-bg: #2E2410;
    --danger: #FF6B73; --danger-bg: #331417; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #111111; --surface-2: #1A1A1A; --accent-text: #E2A0A8; --ink: #F5F5F5; --ink-2: #CFCFCF; --muted: #9E9E9E;
  --line: #262626; --focus: #E2A0A8; --link: #E2A0A8;
  --ok: #4CC38A; --ok-bg: #12261C; --info: #6EA8FE; --info-bg: #13213A; --warn: #F5C451; --warn-bg: #2E2410;
  --danger: #FF6B73; --danger-bg: #331417; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.7 var(--font); }
a { color: var(--link); }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: 26px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 13px; } .nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- layout: app shell (owner / company panels) ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--charcoal); color: #E9EAEC; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; padding: 4px 8px 18px; border-bottom: 1px solid #262626; margin-bottom: 12px; color: #fff; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, var(--brand-900), var(--brand-700) 60%, var(--brand-500)); box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.nav { list-style: none; margin: 0; padding: 0; }
.nav a { display: flex; align-items: center; gap: 10px; color: #CFCFCF; text-decoration: none; padding: 9px 12px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.nav a:hover { background: #141414; color: #fff; }
.nav a[aria-current="page"] { background: linear-gradient(90deg, rgba(122,34,50,.28), rgba(122,34,50,.12)); color: #fff; box-shadow: inset -3px 0 0 var(--brand-500); }
[dir="ltr"] .nav a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--brand-500); }
.nav .sep { height: 1px; background: #262626; margin: 10px 4px; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar .who { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--ink-2); }
.content { padding: 24px; }
.menu-toggle { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 270px; transform: translateX(105%); transition: transform .2s; z-index: 50; }
  [dir="ltr"] .sidebar { inset: 0 auto 0 0; transform: translateX(-105%); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .plans > .card + .card, .stats > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } }
.stat { position: relative; overflow: hidden; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat::after { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: linear-gradient(var(--brand-900), var(--brand-500)); opacity: .85; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 10px;
  padding: 9px 16px; font: 700 14px/1.2 var(--font); cursor: pointer; text-decoration: none; transition: background .15s, box-shadow .15s, transform .05s; min-height: 40px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-900); color: #fff; }
.btn-primary:hover { background: var(--brand-700); box-shadow: 0 6px 18px rgba(122,34,50,.25); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--silver); background: var(--surface-2); }
.btn-dark { background: var(--charcoal); color: #fff; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; align-content: start; }
.field label { font-weight: 700; font-size: 13px; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font: 400 14px/1.5 var(--font); min-height: 40px; }
.input:focus { border-color: var(--brand-700); outline: 3px solid rgba(122,34,50,.15); outline-offset: 0; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; align-items: start; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand-900); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: start; font-size: 12px; text-transform: none; color: var(--muted); font-weight: 700; background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- badges / alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); } .badge-info { background: var(--info-bg); color: var(--info); }
.badge-warn { background: var(--warn-bg); color: var(--warn); } .badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; font-weight: 600; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok); } .alert-info { background: var(--info-bg); color: var(--info); }
.alert-warning { background: var(--warn-bg); color: var(--warn); } .alert-error { background: var(--danger-bg); color: var(--danger); }

/* ---------- dialogs (native <dialog>) ---------- */
dialog.modal { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog.modal::backdrop { background: rgba(14,15,18,.55); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; } .modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- states ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .icon { font-size: 34px; margin-bottom: 6px; opacity: .6; }
.error-state { text-align: center; padding: 32px 16px; color: var(--danger); background: var(--danger-bg); border-radius: var(--radius); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand-700); animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- misc ---------- */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-900), var(--brand-500)); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brand-700); }
.chart-box { position: relative; height: 260px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .input { width: auto; min-width: 200px; }

/* <details class="pop">: action forms open as a centred dialog (never clipped by a scrolling table) */
details.pop[open] > summary::before { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; cursor: default; }
details.pop[open] > .card { position: fixed; z-index: 41; inset: 0; margin: auto; width: min(380px, calc(100vw - 32px)); height: fit-content; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
details.pop .pop-close { float: inline-end; margin: -6px -6px 6px 0; }
details.pop.pop-wide[open] > .card { width: min(760px, calc(100vw - 32px)); }
.receipt-preview iframe, .receipt-preview img { display: block; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.receipt-preview iframe { height: min(60vh, 560px); }
.receipt-preview .pdf-pages { max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #f3f3f3; padding: 8px; }
.receipt-preview img { max-height: 60vh; object-fit: contain; }

/* ---------- company panel: subscription page ---------- */
.theme-toggle .t-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .t-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .t-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .t-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .t-moon { display: none; }
}
.co-hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: center; padding: 24px 28px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); border-inline-start: 6px solid var(--ok); }
.co-hero.co-warn { border-inline-start-color: #D99A00; }
.co-hero.co-danger { border-inline-start-color: var(--brand-900); }
.co-kicker { color: var(--muted); font-size: 13px; }
.co-plan { margin: 4px 0 6px; font-size: 28px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.co-note { margin: 0 0 12px; color: var(--ink-2); }
.co-progress { height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.co-progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-900), #C24A5E); border-radius: 99px; }
.co-progress-sm { height: 6px; margin: 8px 0 6px; }
.co-progress-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.co-hero-cta { display: flex; flex-direction: column; align-items: stretch; gap: 8px; min-width: 230px; text-align: center; }
.co-due { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--line); }
.co-due strong { font-size: 24px; color: var(--accent-text); }
.co-btn { padding: 12px 18px; font-size: 15px; font-weight: 800; }
.co-muted { color: var(--muted); font-size: 13px; display: block; }
.co-stats .value small { font-size: 15px; color: var(--muted); font-weight: 600; }
.co-renew { margin: 18px 0; }
.co-cycles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; align-items: stretch; margin-top: 12px; }
.co-cycles .co-btn { grid-column: 1 / -1; justify-self: start; }
.co-cycle { cursor: pointer; display: block; }
.co-cycle input { position: absolute; opacity: 0; pointer-events: none; }
.co-cycle-box { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 16px 18px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface-2); transition: border-color .15s, box-shadow .15s; }
.co-cycle input:checked + .co-cycle-box { border-color: var(--brand-900); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-900) 18%, transparent); background: var(--surface); }
.co-cycle input:focus-visible + .co-cycle-box { outline: 3px solid var(--focus); outline-offset: 2px; }
.co-cycle-name { font-weight: 800; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.co-cycle-price { font-size: 26px; font-weight: 800; color: var(--accent-text); }
.co-cols { margin-top: 18px; align-items: start; }
.co-modules { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.co-modules li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.co-modules li small { display: block; }
.co-mod-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--ok-bg); color: var(--ok); }
.co-modules li.off .co-mod-icon { background: var(--surface); color: var(--muted); }
@media (max-width: 760px) {
  .co-hero { grid-template-columns: 1fr; padding: 18px; }
  .co-hero-cta { min-width: 0; }
  .co-plan { font-size: 22px; }
  .co-cycles .co-btn { justify-self: stretch; }
}
html { background: var(--bg); }
/* the system's brand theme (legacy-theme.css) is added to every company page and paints body with a light gradient: panel pages keep their own day / night background */
:root:root body { background: var(--bg); }
.co-cols > .card, .co-stats > .card { min-width: 0; }
.co-duebar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.co-plan-card { margin: 0; }
.co-feat { margin: 4px 0 8px; padding-inline-start: 18px; color: var(--ink-2); font-size: 14px; }
.co-extra { display: grid; gap: 10px; max-width: 360px; }
.co-build { margin: 12px 0 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.co-build-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 700; }
.co-build-head strong { font-size: 20px; color: var(--accent-text); }
