/* ============================================================
   Mass Meals ERP — Enterprise Design System
   Brand: Purple #5B2A86 · Green #128A4C · Orange #E67E30
   RTL primary · Light/Dark · Inspired by Fiori/Dynamics/Odoo
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* ---------- Tokens ---------- */
:root {
  /* Brand */
  --brand:        #5B2A86;   /* purple */
  --brand-600:    #4a2170;
  --brand-700:    #3b1a5a;
  --brand-050:    #f3eefb;
  --brand-100:    #e7dcf6;
  --green:        #128A4C;
  --green-050:    #e6f5ed;
  --orange:       #E67E30;
  --orange-050:   #fdf1e6;

  /* Semantic */
  --ok:      #128A4C;  --ok-bg:   #e6f5ed;
  --warn:    #B7791F;  --warn-bg: #fdf3e0;
  --bad:     #C62828;  --bad-bg:  #fdecec;
  --info:    #5B2A86;  --info-bg: #f0eafa;

  /* Surfaces (light) */
  --bg:        #f5f4f8;
  --surface:   #ffffff;
  --surface-2: #faf9fc;
  --sidebar:   #2a1140;      /* deep aubergine */
  --sidebar-2: #351550;
  --sidebar-fg:#d9cdea;
  --sidebar-active:#ffffff;

  --fg:        #1a1523;
  --fg-2:      #5b5566;
  --fg-3:      #8b8598;
  --border:    #e7e4ee;
  --border-2:  #efedf4;
  --ring:      rgba(91,42,134,.30);

  /* Elevation */
  --sh-sm: 0 1px 2px rgba(24,16,40,.06), 0 1px 3px rgba(24,16,40,.05);
  --sh-md: 0 4px 12px rgba(24,16,40,.08), 0 2px 4px rgba(24,16,40,.05);
  --sh-lg: 0 12px 32px rgba(24,16,40,.12), 0 4px 8px rgba(24,16,40,.06);
  --sh-brand: 0 8px 24px rgba(91,42,134,.28);

  /* Geometry */
  --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-xl: 22px;
  --sb-w: 268px;
  --topbar-h: 66px;

  --font-ar: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-en: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font: var(--font-ar);
}

[data-theme="dark"] {
  --bg:        #120c1c;
  --surface:   #1c1528;
  --surface-2: #221a30;
  --sidebar:   #160d24;
  --sidebar-2: #1f1332;
  --sidebar-fg:#b3a6c6;
  --fg:        #f1edf7;
  --fg-2:      #b6afc4;
  --fg-3:      #7d7590;
  --border:    #2e2540;
  --border-2:  #271e39;
  --brand-050: #241635;
  --brand-100: #2d1b45;
  --green-050: #14241c;
  --orange-050:#2a1d12;
  --ok-bg:#12281d; --warn-bg:#2a2110; --bad-bg:#2c1516; --info-bg:#221636;
  --sh-sm: 0 1px 2px rgba(0,0,0,.4);
  --sh-md: 0 4px 12px rgba(0,0,0,.45);
  --sh-lg: 0 12px 32px rgba(0,0,0,.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html[lang="en"] { --font: var(--font-en); }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
/* Safety net: an icon outside a sized container must never explode to full width.
   Specific contexts (.nav-link .ic, .btn .ic, .kpi-ic .ic, …) override this. */
svg.ic { width: 1.15em; height: 1.15em; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-3); }

/* ---------- App shell ---------- */
/* CSS Grid auto-reverses column placement in RTL, so the same template
   works for both directions — do NOT swap the columns for RTL. */
.app { display: grid; grid-template-columns: var(--sb-w) 1fr; min-height: 100dvh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(185deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: var(--sidebar-fg);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh;
  border-inline-end: 1px solid rgba(255,255,255,.04);
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px; min-height: var(--topbar-h);
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-logo {
  width: 42px; height: 42px; border-radius: 11px; background: #fff;
  display: grid; place-items: center; overflow: hidden; flex-shrink: 0;
  box-shadow: var(--sh-sm);
}
.brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-name { font-weight: 700; color: #fff; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--sidebar-fg); opacity: .7; }

.nav { flex: 1; overflow-y: auto; padding: 12px 12px 24px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-color: transparent; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; opacity: .5; padding: 16px 12px 6px; }
.nav-item { position: relative; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--sidebar-fg); font-weight: 500; font-size: 13.5px;
  transition: background .16s ease, color .16s ease;
  cursor: pointer; user-select: none;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link .ic { width: 19px; height: 19px; flex-shrink: 0; opacity: .85; }
.nav-link .chv { margin-inline-start: auto; width: 15px; height: 15px; opacity: .55; transition: transform .2s; }
html[dir="rtl"] .nav-link .chv { transform: scaleX(-1); }
.nav-item.open > .nav-link .chv { transform: rotate(90deg); }
html[dir="rtl"] .nav-item.open > .nav-link .chv { transform: rotate(90deg) scaleX(-1); }
.nav-item.active > .nav-link {
  background: linear-gradient(90deg, rgba(230,126,48,.18), rgba(255,255,255,.02));
  color: #fff;
}
.nav-item.active > .nav-link::before {
  content: ''; position: absolute; inset-inline-start: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 4px; background: var(--orange);
}
.nav-item.active > .nav-link .ic { opacity: 1; color: var(--orange); }
.subnav { display: none; margin: 2px 0 6px; padding-inline-start: 30px; }
.nav-item.open .subnav { display: block; }
.subnav a {
  display: block; padding: 7px 12px; border-radius: 7px; font-size: 12.8px;
  color: var(--sidebar-fg); opacity: .82; transition: .14s; position: relative;
}
.subnav a:hover { background: rgba(255,255,255,.06); opacity: 1; }
.subnav a.active { color: #fff; opacity: 1; font-weight: 600; }
.subnav a.active::before { content:''; position:absolute; inset-inline-start:-14px; top:50%; transform:translateY(-50%); width:5px;height:5px;border-radius:50%;background:var(--orange); }

.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.07); }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r-sm); }
.sb-user:hover { background: rgba(255,255,255,.06); }
.sb-user .meta { line-height: 1.3; overflow: hidden; }
.sb-user .meta b { color: #fff; font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user .meta span { font-size: 11px; opacity: .65; }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topbar .burger { display: none; background: none; border: none; color: var(--fg-2); }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--fg-3); font-size: 13px; }
.crumbs b { color: var(--fg); font-weight: 600; }
.crumbs .sep { opacity: .5; }
html[dir="rtl"] .crumbs .sep { transform: scaleX(-1); }

.searchbox {
  margin-inline: auto; display: flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 16px; width: min(420px, 34vw); color: var(--fg-3);
  transition: .18s;
}
.searchbox:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); }
.searchbox input { border: none; background: none; outline: none; color: var(--fg); width: 100%; font-size: 13px; }
.searchbox .ic { width: 17px; height: 17px; }

.topbar-actions { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid transparent;
  background: none; color: var(--fg-2); display: grid; place-items: center; transition: .16s; position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--brand); border-color: var(--border); }
.icon-btn .ic { width: 19px; height: 19px; }
.icon-btn .dot { position: absolute; top: 8px; inset-inline-end: 9px; width: 8px; height: 8px; background: var(--orange); border-radius: 50%; border: 2px solid var(--surface); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-700)); color: #fff; font-weight: 700; font-size: 13px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.avatar-upload { position: relative; display: inline-block; }
.avatar-upload .cam-btn {
  position: absolute; inset-inline-end: -4px; bottom: -4px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--surface); color: var(--brand); display: grid; place-items: center;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.avatar-upload .cam-btn .ic { width: 14px; height: 14px; }
.avatar-upload input[type="file"] { display: none; }

.content { padding: 26px; max-width: 1560px; width: 100%; margin: 0 auto; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 23px; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 12px; }
.page-title .th-ic { width: 40px; height: 40px; border-radius: 12px; background: var(--brand-050); color: var(--brand); display: grid; place-items: center; }
.page-title .th-ic .ic { width: 22px; height: 22px; }
.page-sub { color: var(--fg-3); font-size: 13.5px; margin-top: 3px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
  transition: .16s; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); border-color: var(--fg-3); }
.btn .ic { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: var(--sh-brand); }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-accent { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-accent:hover { filter: brightness(.94); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--brand); }
.btn-danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-2); }
.card-head h3 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 9px; }
.card-head h3 .ic { width: 18px; height: 18px; color: var(--brand); }
.card-body { padding: 20px; }
.card-pad { padding: 20px; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 20px; box-shadow: var(--sh-sm); position: relative; overflow: hidden; transition: .2s;
}
.kpi:hover { box-shadow: var(--sh-md); transform: translateY(-2px); }
.kpi::after { content:''; position:absolute; inset-inline-end:-30px; top:-30px; width:110px;height:110px;border-radius:50%; background: var(--brand-050); opacity:.5; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; position: relative; z-index: 1; }
.kpi-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; }
.kpi-ic .ic { width: 21px; height: 21px; }
.kpi-ic.c-brand { background: var(--brand-050); color: var(--brand); }
.kpi-ic.c-green { background: var(--green-050); color: var(--green); }
.kpi-ic.c-orange { background: var(--orange-050); color: var(--orange); }
.kpi-ic.c-info  { background: var(--info-bg); color: var(--info); }
.kpi-val { font-size: 27px; font-weight: 800; letter-spacing: -.02em; margin-top: 14px; position: relative; z-index: 1; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--fg-3); font-size: 12.5px; position: relative; z-index: 1; }
.kpi-trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; margin-top: 8px; position: relative; z-index: 1; }
.kpi-trend.up { color: var(--green); } .kpi-trend.down { color: var(--bad); }
.kpi-trend .ic { width: 14px; height: 14px; }

/* ---------- Grid utilities ---------- */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }
@media (max-width: 1080px){ .g-2,.g-3,.g-2-1,.g-1-2 { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
  text-align: start; padding: 12px 16px; color: var(--fg-3); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0;
}
table.data tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.cell-main { font-weight: 600; color: var(--fg); }
.cell-sub { color: var(--fg-3); font-size: 12px; }
.cell-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.t-avatar { display: flex; align-items: center; gap: 10px; }
.t-avatar .avatar { width: 34px; height: 34px; font-size: 12px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.badge::before { content:''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }
.badge.muted { color: var(--fg-3); background: var(--surface-2); }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--brand-050); color: var(--brand); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border-2); }
.toolbar .searchbox { margin: 0; width: min(320px, 40vw); }
.field-inline { display: flex; align-items: center; gap: 8px; }
select, textarea,
input[type="text"], input[type="search"], input[type="date"], input[type="datetime-local"],
input[type="time"], input[type="number"], input[type="email"], input[type="password"],
input[type="tel"], input[type="url"] {
  font-family: inherit; font-size: 13px; color: var(--fg); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; transition: .16s; width: 100%;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); }
select { cursor: pointer; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px 20px; }
@media (max-width: 760px){ .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }
.form-section-title { grid-column: 1 / -1; font-size: 13px; font-weight: 800; color: var(--brand); padding-top: 14px; margin-top: 4px; border-top: 1px dashed var(--border-2); display: flex; align-items: center; gap: 8px; }
.form-section-title:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.dl-section { grid-column: 1 / -1; font-size: 12.5px; font-weight: 800; color: var(--brand); padding: 12px 0 4px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--fg-2); margin-bottom: 7px; }
.field label .req { color: var(--bad); }
.field .hint { font-size: 11.5px; color: var(--fg-3); margin-top: 5px; }
.form-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border-2); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 60px 24px; color: var(--fg-3); max-width: 460px; margin: 0 auto; }
.empty-icon { width: 74px; height: 74px; border-radius: 20px; background: var(--brand-050); color: var(--brand); display: grid; place-items: center; margin: 0 auto 18px; }
.empty-icon svg { width: 34px; height: 34px; }
.empty-state h2 { color: var(--fg); font-size: 18px; margin-bottom: 6px; }
.empty-state p { margin-bottom: 18px; }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-inline-start: 8px; }
.tl-item { position: relative; padding-inline-start: 24px; padding-bottom: 18px; }
.tl-item::before { content:''; position:absolute; inset-inline-start: 4px; top: 4px; bottom: -4px; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-dot { position: absolute; inset-inline-start: 0; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); box-shadow: 0 0 0 3px var(--brand-050); }
.tl-item .tl-time { font-size: 11.5px; color: var(--fg-3); }
.tl-item .tl-text { font-size: 13px; }
.tl-item .tl-text b { font-weight: 600; }

/* ---------- Flash / toast ---------- */
.toast-wrap { position: fixed; top: 20px; inset-inline-end: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--green); box-shadow: var(--sh-lg); border-radius: 12px; padding: 12px 16px; font-size: 13px; font-weight: 500; min-width: 260px; animation: slideIn .3s ease; }
.toast.error { border-inline-start-color: var(--bad); }
.toast.warn { border-inline-start-color: var(--warn); }
.toast .ic { width: 18px; height: 18px; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* ---------- Progress ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--border-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--orange)); }
.mini-bar { height: 6px; border-radius: 999px; background: var(--border-2); overflow: hidden; }
.mini-bar > span { display: block; height: 100%; background: var(--brand); }

/* ---------- Chips / segmented ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg a { padding: 6px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--fg-2); }
.seg a.active { background: var(--surface); color: var(--brand); box-shadow: var(--sh-sm); }

/* ---------- Detail layout ---------- */
.detail-hero { display: flex; align-items: center; gap: 18px; padding: 24px; }
.detail-hero .avatar { width: 68px; height: 68px; font-size: 24px; border-radius: 18px; }
.detail-hero h2 { font-size: 20px; }
.dl { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
@media (max-width:640px){ .dl { grid-template-columns: 1fr; } }
.dl .dl-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border-2); font-size: 13px; }
.dl .dl-row .k { color: var(--fg-3); }
.dl .dl-row .v { font-weight: 600; text-align: end; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; grid-template-columns: 1fr 1fr; }
.login-visual {
  background:
    radial-gradient(circle at 20% 20%, rgba(230,126,48,.28), transparent 42%),
    radial-gradient(circle at 80% 80%, rgba(18,138,76,.26), transparent 45%),
    linear-gradient(160deg, #3b1a5a, #2a1140);
  color: #fff; padding: 60px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.login-visual::before { content:''; position:absolute; inset:0; background-image: radial-gradient(rgba(255,255,255,.06) 1px, transparent 1px); background-size: 26px 26px; opacity:.5; }
.login-visual .lv-brand { display: flex; align-items: center; gap: 14px; position: relative; }
.login-visual .lv-brand .brand-logo { width: 54px; height: 54px; border-radius: 15px; }
.login-visual h1 { font-size: 34px; font-weight: 800; line-height: 1.2; position: relative; max-width: 420px; }
.login-visual p.tag { opacity: .82; font-size: 15px; position: relative; max-width: 400px; margin-top: 14px; }
.lv-stats { display: flex; gap: 28px; position: relative; }
.lv-stats b { font-size: 26px; font-weight: 800; display: block; }
.lv-stats span { opacity: .7; font-size: 12px; }
.login-form-side { display: grid; place-items: center; padding: 40px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 24px; font-weight: 700; }
.login-card .sub { color: var(--fg-3); margin: 6px 0 28px; }
@media (max-width: 900px){ .login-wrap { grid-template-columns: 1fr; } .login-visual { display: none; } }

/* ---------- Chart helpers ---------- */
.chart-box { position: relative; height: 300px; }
.chart-sm { height: 220px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* donut center */
.donut-wrap { position: relative; }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.donut-center b { font-size: 26px; font-weight: 800; }
.donut-center span { font-size: 11px; color: var(--fg-3); }

/* ---------- Utilities ---------- */
.muted { color: var(--fg-3); }
.mono { font-variant-numeric: tabular-nums; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8{margin-top:8px}.mt-16{margin-top:16px}.mt-24{margin-top:24px}.mb-16{margin-bottom:16px}
.text-end { text-align: end; } .text-center { text-align: center; }
.w-full { width: 100%; } .hidden { display: none; }
.stack { display: flex; flex-direction: column; gap: 4px; }

/* ---------- Responsive sidebar ---------- */
.sb-overlay { display: none; }
@media (max-width: 1024px){
  .app { grid-template-columns: 1fr; }
  html[dir="rtl"] .app { grid-template-columns: 1fr; }
  /* Offset by 100vw (not a % of the sidebar's own width) so the "closed"
     drawer is guaranteed to clear the viewport at ANY width — including the
     intermediate widths produced by tablets or a resized/split browser
     window, where a self-relative % transform used to leave part of the
     sidebar visibly stuck inside the viewport. */
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sb-w); transform: translateX(calc(-100vw - 20px)); transition: transform .25s ease; }
  /* No inset override here: inset-inline-start:0 above resolves to the
     physical right edge under dir="rtl" automatically, matching the
     desktop grid sidebar's side (which CSS Grid also flips for RTL). */
  html[dir="rtl"] .sidebar { transform: translateX(calc(100vw + 20px)); }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .sb-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; }
  .topbar .burger { display: grid; place-items: center; }
  .searchbox { display: none; }
}
@media (max-width: 640px){
  .content { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .page-title { font-size: 19px; }
}

/* print-only elements (e.g. the letterhead below) are hidden on screen by default */
.print-only { display: none; }

/*
 * Print styling applies in two situations, kept perfectly in sync so the
 * on-screen preview shows exactly what will print:
 *   1. @media print       — an actual print/PDF-save (e.g. Cmd+P directly)
 *   2. html.print-mode    — the "طباعة" button toggles this class first so the
 *      user can review the print layout live on screen before printing —
 *      see the print-preview script in crud/view.php
 */
@media print {
  /* browsers strip background colors/gradients from print output by default —
     without this the brand stripe, badge fills and table shading all vanish */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }
  .sidebar, .topbar, .head-actions, .toolbar, .row-actions, .icon-btn, .sb-overlay,
  .no-print, .print-preview-bar, .page-head { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .card { box-shadow: none; border-color: #ccc; }
  body { background: #fff; }
  .print-only { display: block; }
}
html.print-mode .sidebar, html.print-mode .topbar, html.print-mode .head-actions,
html.print-mode .toolbar, html.print-mode .row-actions, html.print-mode .icon-btn,
html.print-mode .sb-overlay, html.print-mode .no-print, html.print-mode .page-head { display: none !important; }
html.print-mode .app { grid-template-columns: 1fr; }
html.print-mode .card { box-shadow: none; border-color: #ccc; }
html.print-mode body { background: #fff; }
html.print-mode .print-only { display: block; }

/* Formal print document — a self-contained "sheet" styled independently from the
   app UI (own typography/table, not the site's cards), so print output reads as
   an official record, not "the website with the sidebar removed". */
@media print, screen {
  .print-doc {
    background: #fff;
    color: #1a1523;
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    max-width: 900px;
    margin: 0 auto;
    padding: 10mm 12mm 8mm;
    border: 1px solid #e3e0ea;
    border-radius: 10px;
    box-shadow: 0 2px 16px rgba(24,16,40,.06);
  }
  .print-stripe {
    height: 3mm;
    margin: -10mm -12mm 8mm;
    background: linear-gradient(90deg, var(--brand) 0 45%, var(--green) 45% 75%, var(--orange) 75% 100%);
  }
  .print-page-header { margin-bottom: 8px; }
  .print-page-footer { margin-top: 20px; }

  /* display:table instead of flexbox — some print/PDF engines (older Safari
     especially) don't reliably render flex children when printing */
  .print-hd {
    display: table;
    width: 100%;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--brand);
  }
  .print-hd > * { display: table-cell; vertical-align: middle; }
  .print-hd img { width: 44px; height: 44px; object-fit: contain; padding-inline-end: 14px; }
  .print-hd b { display: block; font-size: 16px; color: var(--brand); }
  .print-hd span { font-size: 11px; color: #666; }
  .print-hd-meta { text-align: end; }
  .print-hd-meta b { display: block; font-size: 14px; color: #1a1523; }
  .print-hd-meta span { font-size: 11px; color: #666; }

  .print-doc-title {
    display: table;
    width: 100%;
    margin: 22px 0 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e3e0ea;
  }
  .print-doc-title > * { display: table-cell; vertical-align: middle; }
  .print-doc-title > .badge { text-align: end; white-space: nowrap; }
  .print-doc-title h2 { font-size: 17px; font-weight: 700; color: #1a1523; margin: 0; }

  .print-table-wrap { border-radius: 10px; overflow: hidden; }
  .print-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .print-table th, .print-table td {
    border: 1px solid #e3e0ea;
    padding: 9px 14px;
    text-align: start;
    vertical-align: top;
  }
  .print-table th {
    width: 34%;
    background: #faf9fc;
    font-weight: 600;
    color: #5b5566;
  }
  .print-table tr:nth-child(even) td { background: #fcfbfd; }
  .print-table-section td {
    background: var(--brand-050, #f2ecf8) !important;
    color: var(--brand);
    font-weight: 700;
    font-size: 12px;
    letter-spacing: .02em;
  }

  .print-doc-footer {
    display: table;
    width: 100%;
    padding-top: 12px;
    border-top: 1px solid #e3e0ea;
    font-size: 10.5px;
    color: #8b8598;
    background: #fff;
  }
  .print-doc-footer > span { display: table-cell; }
  .print-doc-footer > span:last-child { text-align: end; }
}
@media print {
  @page { margin: 14mm; }

  .print-doc { border: none; box-shadow: none; border-radius: 0; max-width: none; padding: 0; }
  .print-stripe { margin: 0 0 8mm; }
  .print-page-header { break-after: avoid; break-inside: avoid; }
  .print-page-footer { break-before: avoid; break-inside: avoid; }
  .print-table tr { break-inside: avoid; }
}

/* floating bar shown only during the on-screen print preview — never in the actual print output */
.print-preview-bar {
  position: fixed;
  bottom: 20px;
  inset-inline: 0;
  margin-inline: auto;
  width: fit-content;
  display: none;
  gap: 10px;
  align-items: center;
  background: var(--fg, #1a1523);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,.28);
  z-index: 500;
}
.print-preview-bar .btn { box-shadow: none; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Inline document preview (mammoth-rendered .docx content) — the converted
   HTML ships with no styling of its own, so headings/paragraphs/tables need
   rules here. Arabic manuals are RTL regardless of the current UI language. */
.docx-preview { direction: rtl; text-align: right; font-size: 14px; color: var(--fg); }
.docx-preview h1, .docx-preview h2, .docx-preview h3, .docx-preview h4 { font-weight: 800; color: var(--fg); margin: 20px 0 10px; line-height: 1.5; }
.docx-preview h1 { font-size: 20px; }
.docx-preview h2 { font-size: 17px; }
.docx-preview h3, .docx-preview h4 { font-size: 15px; }
.docx-preview p { margin: 0 0 12px; }
.docx-preview ul, .docx-preview ol { margin: 0 0 12px; padding-inline-start: 24px; }
.docx-preview li { margin-bottom: 4px; }
.docx-preview strong, .docx-preview b { font-weight: 700; }
.docx-preview img { max-width: 100%; border-radius: 6px; }
.docx-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 18px;
  direction: rtl;
  font-size: 13px;
}
.docx-preview table, .docx-preview th, .docx-preview td {
  border: 1px solid var(--border-2);
}
.docx-preview th, .docx-preview td {
  padding: 8px 12px;
  text-align: right;
  vertical-align: top;
}
.docx-preview thead th, .docx-preview tr:first-child th {
  background: var(--surface-2);
  font-weight: 700;
}
.docx-preview tr:nth-child(even) td { background: rgba(0,0,0,.015); }

/* Show/hide-password toggle on the login form */
.pass-field { position: relative; }
.pass-field input { padding-inline-end: 40px; }
.pass-toggle {
  position: absolute;
  top: 50%;
  inset-inline-end: 8px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg-3);
  cursor: pointer;
  border-radius: 6px;
}
.pass-toggle:hover { color: var(--brand); background: var(--surface-2); }
.pass-toggle .ic { width: 18px; height: 18px; }
