/* التحبير — الغلاف والمكوّنات. خصائص منطقية (inline-start/end) لتعمل RTL وLTR. */
.ico { display: inline-flex; flex: none; width: var(--s, 20px); height: var(--s, 20px); }
.ico svg { display: block; }

/* ======== الغلاف ======== */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; z-index: 40;
  color: #E4EEF0; overflow: hidden;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(174,207,208,.16), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cpath d='M16 16h32v32h-32zM32 9.370000000000001L54.629999999999995 32L32 54.629999999999995L9.370000000000001 32zM-16 -16h32v32h-32zM0 -22.63L22.63 0L0 22.63L-22.63 0zM48 -16h32v32h-32zM64 -22.63L86.63 0L64 22.63L41.370000000000005 0zM-16 48h32v32h-32zM0 41.370000000000005L22.63 64L0 86.63L-22.63 64zM48 48h32v32h-32zM64 41.370000000000005L86.63 64L64 86.63L41.370000000000005 64z' fill='none' stroke='%23AECFD0' stroke-opacity='.06' stroke-width='1'/%3E%3C/svg%3E"),
    linear-gradient(180deg, #153B55 0%, #102F45 100%);
  box-shadow: inset -1px 0 0 rgba(255,255,255,.06);
}
html[dir="ltr"] .sidebar { box-shadow: inset 1px 0 0 rgba(255,255,255,.06); }
.brand { display: flex; align-items: center; gap: 13px; padding: 24px 22px 8px; text-decoration: none; color: #fff; }
.brand img, .brand svg { width: 46px; height: 46px; flex: none; filter: drop-shadow(0 4px 10px rgba(0,0,0,.28)); }
.brand b { display: block; font-family: var(--font-head); font-size: 1.7rem; line-height: 1.1; font-weight: 700; }
html[lang="en"] .brand b { font-family: var(--font-en); font-size: 1.35rem; }
.brand small { display: block; font-size: .78rem; color: rgba(228,238,240,.72); margin-top: 3px; }
.workspace { margin: 14px 18px 6px; padding: 14px 14px 16px; border-radius: var(--radius); background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); }
.workspace .lbl { font-size: .74rem; color: rgba(228,238,240,.6); letter-spacing: .02em; }
.workspace .org { font-weight: 600; font-size: 1.08rem; margin: 1px 0 10px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 3px 12px; border-radius: 999px; font-size: .8rem; font-weight: 500; text-decoration: none; border: 0; }
.chip.role { background: rgba(174,207,208,.18); color: #CFE6E7; }
a.chip.me { background: rgba(255,255,255,.1); color: #fff; transition: background .2s; }
a.chip.me:hover { background: rgba(255,255,255,.18); }
.nav { flex: 1; overflow-y: auto; padding: 10px 14px 12px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.nav-group { margin: 12px 8px 6px; font-size: .72rem; letter-spacing: .06em; color: rgba(228,238,240,.5); }
.nav a {
  position: relative; display: flex; align-items: center; gap: 13px; min-height: 46px; padding: 8px 14px; margin: 2px 0; border-radius: 12px;
  color: #D9E7E9; text-decoration: none; font-weight: 500; transition: background .2s var(--ease), color .2s, transform .2s var(--ease);
}
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a .ico { opacity: .85; }
.nav a.active { background: var(--accent); color: #102F45; font-weight: 600; box-shadow: 0 6px 16px -8px rgba(0,0,0,.45); }
.nav a.active .ico { opacity: 1; }
.nav a .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .dot-badge, .badge-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; line-height: 1; background: #E7F2F3; color: #102F45; font-family: var(--font-en);
}
.nav a.active .dot-badge { background: #102F45; color: #fff; }
.side-foot { padding: 12px 18px 18px; border-top: 1px solid rgba(255,255,255,.08); display: grid; gap: 4px; }
.side-foot a, .side-foot button { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 6px 10px; border-radius: 10px; background: none; border: 0; color: #CFE0E3; text-decoration: none; font-size: .92rem; text-align: start; width: 100%; transition: background .2s; }
.side-foot a:hover, .side-foot button:hover { background: rgba(255,255,255,.08); color: #fff; }
.side-foot .saved { display: flex; align-items: center; gap: 8px; font-size: .75rem; color: rgba(228,238,240,.55); padding: 6px 10px 0; }
.side-foot .saved i { width: 7px; height: 7px; border-radius: 50%; background: #6CC49D; box-shadow: 0 0 0 3px rgba(108,196,157,.2); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top-h); display: flex; align-items: center; gap: 12px; padding: 0 clamp(16px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.topbar .crumb { font-weight: 500; color: var(--muted); font-size: .95rem; margin-inline-end: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); color: var(--primary); border: 1px solid var(--border); box-shadow: var(--shadow); text-decoration: none; transition: transform .2s var(--ease), background .2s;
}
.icon-btn:hover { transform: translateY(-1px); background: var(--secondary); }
.icon-btn .badge-count { position: absolute; top: -5px; inset-inline-start: -5px; background: var(--primary); color: var(--on-primary); box-shadow: 0 0 0 2px var(--bg); }
.menu-btn { display: none; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); }
.seg button { min-height: 36px; min-width: 44px; padding: 0 14px; border: 0; border-radius: 999px; background: none; color: var(--muted); font-size: .88rem; font-weight: 500; transition: background .25s var(--ease), color .25s; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.userchip { display: inline-flex; align-items: center; gap: 10px; max-width: 220px; padding: 4px 14px 4px 4px; border-radius: 999px; font-weight: 500; font-size: .92rem; color: var(--text); text-decoration: none; }
html[dir="rtl"] .userchip { padding: 4px 4px 4px 14px; }
.userchip span.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(145deg, var(--primary), var(--primary-dark)); color: var(--on-primary); font-weight: 700; font-size: .9rem; }
.view { flex: 1; padding: clamp(18px, 3vw, 36px) clamp(16px, 3vw, 36px) 64px; width: 100%; max-width: 1240px; margin-inline: auto; animation: rise .4s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.scrim { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(86vw, 320px); transition: transform .32s var(--ease); box-shadow: var(--shadow-lg); }
  html[dir="rtl"] .sidebar { transform: translateX(105%); }
  html[dir="ltr"] .sidebar { transform: translateX(-105%); }
  body.nav-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(8,22,32,.5); opacity: 0; pointer-events: none; transition: opacity .3s; backdrop-filter: blur(2px); }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .menu-btn { display: inline-flex; }
  .userchip .nm { display: none; }
  .userchip { padding: 0 !important; }
  .topbar .crumb { display: none; }
  .topbar { gap: 8px; }
  .topbar .spacer { flex: 1; }
}
@media (min-width: 961px) { .topbar .spacer { display: none; } }
@media (max-width: 420px) { .seg button { padding: 0 10px; min-width: 40px; } .icon-btn { width: 42px; height: 42px; } }

@media (max-height: 880px) {
  .brand { padding: 18px 22px 4px; } .brand img { width: 40px; height: 40px; }
  .workspace { margin-top: 10px; padding: 11px 14px 12px; } .workspace .org { margin-bottom: 8px; }
  .nav a { min-height: 42px; margin: 1px 0; } .nav-group { margin-top: 8px; }
  .side-foot { padding: 8px 18px 10px; } .side-foot a, .side-foot button { min-height: 40px; }
  .side-foot .saved { display: none; }
}
/* ======== الصفحات العامة (بلا غلاف) ======== */
.public-shell {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  background:
    radial-gradient(60% 50% at 85% 0%, color-mix(in srgb, var(--accent) var(--glow-a, 45%), transparent), transparent 70%),
    radial-gradient(50% 40% at 0% 100%, color-mix(in srgb, var(--accent) var(--glow-b, 28%), transparent), transparent 70%), var(--bg);
}
:root[data-theme="dark"] .public-shell { --glow-a: 9%; --glow-b: 5%; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .public-shell { --glow-a: 9%; --glow-b: 5%; } }
.public-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px clamp(16px, 4vw, 48px); }
.public-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.public-brand img { width: 46px; height: 46px; }
.public-brand b { display: block; font-family: var(--font-head); font-size: 1.45rem; line-height: 1.1; }
html[lang="en"] .public-brand b { font-family: var(--font-en); font-size: 1.2rem; }
.public-brand small { color: var(--muted); font-size: .78rem; }
.public-top .tools { display: flex; align-items: center; gap: 8px; }
.public-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px clamp(16px, 4vw, 48px) 48px; }
.public-main > .page { width: 100%; display: flex; justify-content: center; }

/* ======== مكوّنات ======== */
.page > * + * { margin-top: 22px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .eyebrow { color: var(--muted); font-size: .95rem; margin-bottom: 4px; }
.page-head p.sub { color: var(--muted); margin-top: 6px; }
.page-head .head-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(16px, 2.4vw, 24px); }
.card > h2, .card > h3 { margin-bottom: 4px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { color: var(--muted); font-size: .9rem; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
@media (max-width: 760px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset-inline-end: -18px; top: -18px; width: 80px; height: 80px; border-radius: 50%; background: var(--secondary); opacity: .7; }
.stat .k { color: var(--muted); font-size: .9rem; position: relative; z-index: 1; }
.stat .v { font-size: 2.1rem; font-weight: 700; line-height: 1.25; color: var(--primary); position: relative; z-index: 1; font-variant-numeric: tabular-nums; }
.stat .s { color: var(--muted); font-size: .82rem; position: relative; z-index: 1; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 180px; }
.tabs { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: var(--secondary); width: max-content; max-width: 100%; overflow-x: auto; }
.tab { min-height: 40px; padding: 0 18px; border: 0; border-radius: 999px; background: none; color: var(--muted); font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; transition: .2s; }
.tab[aria-selected="true"], .tab.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); font-weight: 600; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); color: var(--primary); font-weight: 600; text-decoration: none; transition: transform .2s var(--ease), background .2s, box-shadow .2s, opacity .2s; white-space: nowrap; }
.btn:hover { background: var(--secondary); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 8px 18px -10px var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
:root[data-theme="dark"] .btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.outline { background: transparent; color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 13px; font-size: .88rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after, .spinner { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-top-color: transparent; animation: spin .7s linear infinite; }
.btn.is-busy::after { position: absolute; inset: 0; margin: auto; color: var(--on-primary); }
.btn.ghost.is-busy::after, .btn:not(.primary):not(.danger).is-busy::after { color: var(--primary); }
.spinner { display: inline-block; color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; padding: 1px 11px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--secondary); color: var(--primary); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); } .badge.info { background: var(--info-bg); color: var(--primary); }
.back-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--card); color: var(--primary); box-shadow: var(--shadow); transition: transform .2s var(--ease), background .2s; }
.back-btn:hover { background: var(--secondary); transform: translateX(3px); }
html[dir="ltr"] .back-btn svg { transform: scaleX(-1); }
html[dir="ltr"] .back-btn:hover { transform: translateX(-3px); }
.back-row { display: flex; align-items: center; gap: 14px; }
a.phone-link { display: inline-flex; align-items: center; gap: 6px; color: #1F8A5B; font-weight: 500; text-decoration: none; padding: 2px 6px; margin: -2px -6px; border-radius: 8px; }
:root[data-theme="dark"] a.phone-link { color: #6CC49D; }
a.phone-link:hover { background: var(--ok-bg); }
.phone { unicode-bidi: plaintext; font-variant-numeric: tabular-nums; }

/* نماذج */
.field { display: grid; gap: 6px; }
.field > label { font-weight: 600; font-size: .92rem; }
.field .req { color: var(--danger); margin-inline-start: 4px; }
.field .hint { color: var(--muted); font-size: .82rem; }
.field input:not([type="checkbox"]), .field select, .field textarea, input.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--field-bg); color: var(--text); transition: border-color .2s, box-shadow .2s;
}
.field textarea { resize: vertical; min-height: 96px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 55%, transparent); }
.field-check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; }
.field-check input { width: 20px; height: 20px; accent-color: var(--primary); }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* جدول → بطاقات على الجوال */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-wrap.is-empty { padding: 8px; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: start; font-size: .82rem; font-weight: 600; color: var(--muted); padding: 13px 18px; background: color-mix(in srgb, var(--secondary) 55%, var(--card)); border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 14px 18px; border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .15s; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--secondary) 50%, transparent); }
table.data tr.clickable { cursor: pointer; }
.primary-cell { font-weight: 600; }
@media (max-width: 720px) {
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data tr { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 16px; margin-bottom: 12px; }
  table.data td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px dashed var(--border); text-align: end; }
  table.data td:last-child { border-bottom: 0; }
  table.data td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; font-weight: 500; text-align: start; flex: none; }
  table.data td.primary-cell { font-size: 1.05rem; justify-content: flex-start; }
  table.data td.primary-cell::before { display: none; }
  table.data td[data-label=""]::before { display: none; }
}

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 44px 20px; color: var(--muted); width: 100%; }
.empty strong { color: var(--text); font-size: 1.08rem; }
.empty p { max-width: 38ch; font-size: .92rem; }
.empty-ico { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--secondary); color: var(--primary); margin-bottom: 6px; }
.page-msg { padding-block: 80px; }
.page-loading { display: grid; place-items: center; padding: 70px 0; }
.page-loading .spinner { width: 30px; height: 30px; }

/* نافذة وتنبيهات */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(8,22,32,.55); backdrop-filter: blur(3px); animation: fade .18s both; overflow-y: auto; }
.modal-overlay.out { opacity: 0; transition: opacity .16s; }
.modal { width: min(520px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); animation: pop .26s var(--ease) both; outline: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 8px; }
.modal-head h3 { font-family: var(--font-head); font-size: 1.4rem; }
html[lang="en"] .modal-head h3 { font-family: var(--font-en); font-size: 1.15rem; }
.modal-head .icon-btn { width: 38px; height: 38px; box-shadow: none; }
.modal-body { padding: 8px 22px 18px; overflow-y: auto; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding: 14px 22px 20px; border-top: 1px solid var(--border); }
html[dir="rtl"] .modal-actions { flex-direction: row-reverse; justify-content: flex-end; }
body.modal-open { overflow: hidden; }
@keyframes fade { from { opacity: 0; } } @keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } }
#toasts { position: fixed; z-index: 200; inset-inline: 0; bottom: 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: min(460px, 100%); padding: 12px 18px; border-radius: 14px; background: var(--primary-dark); color: #fff; box-shadow: var(--shadow-lg); animation: toast .3s var(--ease) both; cursor: pointer; font-size: .95rem; }
:root[data-theme="dark"] .toast { background: #E6EEF0; color: #10222D; }
.toast.is-error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); transition: .25s; }
@keyframes toast { from { opacity: 0; transform: translateY(14px) scale(.96); } }

/* لوحة المعاينة (وضع mock فقط) */
.mockbar { position: fixed; z-index: 150; inset-inline-end: 12px; bottom: 12px; display: flex; gap: 4px; padding: 5px; border-radius: 999px; background: #17232B; color: #fff; font-size: .75rem; box-shadow: var(--shadow-lg); font-family: var(--font-en); }
.mockbar a { color: #cfe0e3; text-decoration: none; padding: 5px 11px; border-radius: 999px; }
.mockbar a.on { background: var(--accent); color: #102F45; font-weight: 700; }
