/* ==========================================================================
   Moqem — Dashboard base (member area + back office)
   RTL-first. Font: IBM Plex Sans Arabic. Tokens drive light & dark themes.
   ========================================================================== */

:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e6e2d9;
  --line-strong: #d6d0c3;
  --ink: #1b2422;
  --ink-2: #3b4643;
  --muted: #6d7673;
  --primary: #0f5b52;
  --primary-ink: #ffffff;
  --primary-soft: #e3efec;
  --accent: #b86e12;
  --accent-soft: #f8ecdb;
  --ok: #2c7a4b;
  --ok-soft: #e2f1e7;
  --warn: #a8660b;
  --warn-soft: #fbf0dc;
  --danger: #b3261e;
  --danger-soft: #f9e3e1;
  --info: #25609b;
  --info-soft: #e3edf8;
  --shadow: 0 1px 2px rgba(20, 30, 28, .05), 0 4px 16px rgba(20, 30, 28, .04);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar: 256px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111615; --surface: #182020; --surface-2: #1c2524; --line: #28332f; --line-strong: #34403c;
    --ink: #e9eeec; --ink-2: #c8d1ce; --muted: #93a09b;
    --primary: #4fb3a3; --primary-ink: #0b1513; --primary-soft: #1d3531;
    --accent: #e3a04a; --accent-soft: #3a2c19;
    --ok: #5cc486; --ok-soft: #1b3325; --warn: #e3ae4f; --warn-soft: #3a2e17;
    --danger: #f07a70; --danger-soft: #3d1f1c; --info: #7fb2ea; --info-soft: #1b2b3d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111615; --surface: #182020; --surface-2: #1c2524; --line: #28332f; --line-strong: #34403c;
  --ink: #e9eeec; --ink-2: #c8d1ce; --muted: #93a09b;
  --primary: #4fb3a3; --primary-ink: #0b1513; --primary-soft: #1d3531;
  --accent: #e3a04a; --accent-soft: #3a2c19;
  --ok: #5cc486; --ok-soft: #1b3325; --warn: #e3ae4f; --warn-soft: #3a2e17;
  --danger: #f07a70; --danger-soft: #3d1f1c; --info: #7fb2ea; --info-soft: #1b2b3d;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.7 var(--font); direction: rtl; text-align: right;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.35; font-weight: 700; color: var(--ink); }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
small, .small { font-size: .86rem; }
.muted { color: var(--muted); }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.num { font-variant-numeric: tabular-nums; }
.ic { width: 20px; height: 20px; flex: none; vertical-align: -4px; }
.ic-sm { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.ic-lg { width: 28px; height: 28px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-inline-start: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: var(--ink); font-weight: 700; font-size: 1.2rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary); color: var(--primary-ink); font-size: 1.05rem;
}
.brand small { display: block; font-size: .72rem; font-weight: 500; color: var(--muted); line-height: 1.2; }
.nav-label { font-size: .74rem; color: var(--muted); padding: 14px 10px 4px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav .count { margin-inline-start: auto; background: var(--danger); color: #fff; font-size: .72rem; border-radius: 99px; padding: 0 7px; line-height: 1.6; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.12rem; margin: 0; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 90px; max-width: 1180px; width: 100%; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); text-decoration: none; }
.badge-dot {
  position: absolute; top: -5px; inset-inline-end: -5px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 99px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1; border: 2px solid var(--bg);
}
.badge-dot[hidden] { display: none; }
.sos-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 12px;
  background: var(--danger-soft); color: var(--danger); font-weight: 700; border: 1px solid transparent;
}
.sos-btn:hover { text-decoration: none; border-color: var(--danger); }
.menu-toggle { display: none; }

/* Mobile bottom nav */
.bottom-nav { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: 280px; z-index: 50;
    transform: translateX(100%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .menu-toggle { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .content { padding: 18px 16px 100px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); padding: 4px 0; }
  .bottom-nav a.active { color: var(--primary); font-weight: 600; }
  .bottom-nav a:hover { text-decoration: none; }
  .sos-btn span { display: none; }
  .sos-btn { padding: 0 11px; }
}

/* ---------- Cards & layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-flat { box-shadow: none; }
.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)); }
.split { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) { .grid-2, .grid-3, .split { grid-template-columns: 1fr; } }
@media (max-width: 520px) { .grid-4 { grid-template-columns: 1fr 1fr; } }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
  font: 600 .94rem var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; min-height: auto; font-weight: 600; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .86rem; border-radius: 9px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-weight: 600; font-size: .9rem; color: var(--ink-2); }
.field .hint { font-size: .8rem; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: 400 .95rem var(--font);
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.7; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.is-invalid { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: .82rem; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: .92rem; line-height: 1.6; }
.check input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--primary); flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
input[type="date"].input { direction: rtl; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px 4px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }

/* ---------- Badges / pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 10px; border-radius: 99px;
  font-size: .78rem; font-weight: 600; line-height: 1.9; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.pill-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.pill-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.pill-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill-muted { color: var(--muted); }

/* ---------- Alerts ---------- */
.alert {
  display: flex; gap: 12px; align-items: flex-start; padding: 13px 15px; border-radius: 12px;
  border: 1px solid transparent; margin-bottom: 16px; font-size: .92rem;
}
.alert .ic { margin-top: 2px; }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert p { margin: 0; color: var(--ink-2); }
.alert strong { color: inherit; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 16px; inset-inline-start: 50%; transform: translateX(50%); z-index: 100;
  min-width: 280px; max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-weight: 500;
  display: flex; align-items: center; gap: 10px; animation: toast-in .25s ease;
}
.toast-error { background: var(--danger); color: #fff; }
.toast-success { background: var(--ok); color: #fff; }
.toast button { margin-inline-start: auto; background: none; border: 0; color: inherit; cursor: pointer; opacity: .8; }
.toast.hide { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { opacity: 0; transform: translate(50%, -8px); } }

/* ---------- 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: .92rem; }
.table th, .table td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; color: var(--ink); display: block; }
.list-item .sub { font-size: .84rem; color: var(--muted); }
a.list-item:hover { text-decoration: none; background: var(--surface-2); margin-inline: -12px; padding-inline: 12px; border-radius: 10px; }

.avatar {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--primary-soft); color: var(--primary); font-weight: 700;
}
.avatar-accent { background: var(--accent-soft); color: var(--accent); }

.empty {
  text-align: center; padding: 34px 20px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted);
}
.empty .ic-lg { color: var(--primary); margin-bottom: 8px; }
.empty h3 { color: var(--ink); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; font-weight: 500; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 8px; } }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
  padding: 6px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); font-size: .88rem; font-weight: 500;
}
.tab:hover { text-decoration: none; border-color: var(--line-strong); }
.tab.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tab .n { opacity: .7; margin-inline-start: 4px; }

.stat { padding: 16px 18px; }
.stat .label { font-size: .82rem; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 1.7rem; font-weight: 700; line-height: 1.3; }
.stat .foot { font-size: .8rem; color: var(--muted); }

.link-arrow { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: .9rem; }

/* Confirm-delete forms inline */
form.inline { display: inline; }

@media print {
  .sidebar, .topbar, .bottom-nav, .toast, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
