:root {
  --canvas: #e9d5c5;
  --card: #f8f0e9;
  --well: #f1e4d8;
  --line: #e0cdbc;
  --ink: #2c1413;
  --ink-2: #6f5a52;
  --ink-3: #8a7468;
  --accent: #4e1d1b;
  --accent-deep: #421414;
  --accent-soft: #e4b9a5;
  --gold: #c49a62;
  --gold-ink: #6e4f26;
  --live: #2f7a4f;
  --warn: #a4631a;
  --stop: #a3302a;
  --r-lg: 28px;
  --r-md: 20px;
  --r-sm: 14px;
  --shadow: 0 1px 2px rgba(66, 20, 20, .04), 0 12px 32px -12px rgba(66, 20, 20, .14);
  --shadow-up: 0 2px 4px rgba(66, 20, 20, .06), 0 24px 60px -16px rgba(66, 20, 20, .34);
  --font: 'Outfit', 'IBM Plex Sans Arabic', system-ui, sans-serif;
}
html[lang="ar"] { --font: 'IBM Plex Sans Arabic', 'Outfit', system-ui, sans-serif; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--canvas); color: var(--ink); font: 400 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hide { display: none !important; }

/* ---------- shell ---------- */
.shell { max-width: 1320px; margin: 0 auto; padding: 18px 24px 64px; }
.top { display: flex; align-items: center; gap: 16px; background: var(--card); border-radius: 999px; padding: 10px 14px 10px 20px; box-shadow: var(--shadow); }
[dir="rtl"] .top { padding: 10px 20px 10px 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; color: var(--accent); text-decoration: none; flex: none; }
.brand img { width: 36px; height: auto; }
.nav { display: flex; gap: 2px; padding: 4px; background: var(--well); border-radius: 999px; margin-inline: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 8px 16px; border-radius: 999px; text-decoration: none; color: var(--ink-2); white-space: nowrap; font-weight: 500; transition: background .18s, color .18s; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--card); }
.tools { display: flex; align-items: center; gap: 8px; flex: none; }
.round { width: 40px; height: 40px; border-radius: 50%; background: var(--well); display: grid; place-items: center; font-weight: 500; font-size: 13px; transition: background .18s; }
.round:hover { background: var(--line); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 34px 4px 22px; }
.head h1 { font-size: 38px; line-height: 1.1; font-weight: 400; letter-spacing: -.01em; }
.head h1 span { color: var(--ink-3); }
html[lang="ar"] .head h1 { letter-spacing: 0; }
.head p { color: var(--ink-2); margin-top: 6px; max-width: 62ch; }

/* ---------- pieces ---------- */
.card { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 22px; min-width: 0; }
.card h2 { font-size: 16px; font-weight: 500; }
.card .sub { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px; border-radius: 999px; font-weight: 500; background: var(--card); box-shadow: var(--shadow); transition: transform .12s, background .18s; white-space: nowrap; }
.btn:hover { background: var(--well); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--card); }
.btn.primary:hover { background: var(--accent-deep); }
.btn.quiet { box-shadow: none; background: var(--well); }
.btn.quiet:hover { background: var(--line); }
.btn.danger { box-shadow: none; background: none; color: var(--stop); }
.btn.danger:hover { background: rgba(163, 48, 42, .09); }
.btn[disabled] { opacity: .55; cursor: default; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 500; background: var(--well); color: var(--ink-2); white-space: nowrap; }
[dir="rtl"] .chip { padding: 3px 9px 3px 11px; }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.live { color: var(--live); background: rgba(47, 122, 79, .11); }
.chip.expired { color: var(--stop); background: rgba(163, 48, 42, .1); }
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--well); gap: 2px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg button { padding: 7px 14px; min-height: 34px; border-radius: 999px; color: var(--ink-2); font-weight: 500; white-space: nowrap; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--card); }
.seg b { font-weight: 400; opacity: .72; margin-inline-start: 4px; }

/* ---------- overview ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.cash { background: radial-gradient(120% 140% at 15% 10%, #6b2a26, var(--accent) 55%, var(--accent-deep)); color: #f6e7da; display: flex; flex-direction: column; min-height: 196px; }
.cash h2 { color: #f6e7da; } .cash .sub { color: var(--accent-soft); }
.cash .big { font-size: 38px; font-weight: 300; line-height: 1.1; margin-top: auto; overflow-wrap: anywhere; }
.cash .big small { font-size: 15px; font-weight: 400; color: var(--accent-soft); margin-inline-start: 6px; }
.cash .foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--accent-soft); font-size: 13px; }
.kpi { display: flex; flex-direction: column; text-decoration: none; transition: transform .15s; min-height: 118px; }
a.kpi:hover { transform: translateY(-2px); }
.kpi .label { color: var(--ink-2); font-size: 14px; }
.kpi .value { font-size: 42px; font-weight: 300; line-height: 1.05; margin-top: auto; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 200px; }
.bar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 7px; text-decoration: none; border-radius: var(--r-sm); }
.bar .fill { width: min(100%, 64px); border-radius: 18px; background: var(--accent-soft); min-height: 10px; transition: background .18s; }
.bar:hover .fill { background: var(--gold); }
.bar.on .fill { background: var(--accent); }
.bar .n { font-size: 14px; font-weight: 500; }
.bar .k { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------- lists ---------- */
.feed { display: flex; flex-direction: column; }
.feed .row { display: flex; gap: 12px; padding: 11px 0; border-top: 1px solid var(--well); align-items: flex-start; }
.feed .row:first-child { border-top: 0; padding-top: 0; }
.feed .dot { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--well); color: var(--accent); }
.feed .text { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.feed .when { flex: none; color: var(--ink-3); font-size: 13px; }
.day { color: var(--ink-3); font-size: 13px; margin: 20px 0 8px; font-weight: 500; }
.day:first-child { margin-top: 0; }
.mini { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin-inline: -12px; border-radius: var(--r-sm); width: calc(100% + 24px); text-align: start; }
.mini:hover { background: var(--well); }
.mini span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; padding: 38px 18px; color: var(--ink-2); }
.empty svg { margin: 0 auto 12px; color: var(--gold-ink); }
.empty h3 { font-size: 17px; font-weight: 500; color: var(--ink); margin-bottom: 4px; }
.empty p { max-width: 50ch; margin: 0 auto; }
.empty .btn { margin-top: 16px; }

/* ---------- table ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.search { flex: 1 1 220px; display: flex; align-items: center; gap: 8px; background: var(--well); border-radius: 999px; padding: 0 16px; min-height: 42px; color: var(--ink-2); }
.search input { border: 0; background: none; outline: 0; width: 100%; color: var(--ink); min-height: 42px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th { text-align: start; font-size: 13px; font-weight: 400; color: var(--ink-2); padding: 8px 12px; white-space: nowrap; }
td { padding: 10px 12px; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .15s; }
tbody tr:hover td { background: var(--well); }
tbody td:first-child { border-start-start-radius: var(--r-sm); border-end-start-radius: var(--r-sm); }
tbody td:last-child { border-start-end-radius: var(--r-sm); border-end-end-radius: var(--r-sm); }
tr.plain { cursor: default; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.thumb { flex: none; width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); display: grid; place-items: center; color: var(--accent); font-weight: 500; }
.who b { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.who small { color: var(--ink-2); font-size: 13px; }
.switch { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--line); transition: background .18s; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: inset-inline-start .18s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { inset-inline-start: 21px; }
.switch-hit { padding: 9px 0; display: inline-flex; }

/* ---------- drawer ---------- */
.veil { position: fixed; inset: 0; background: rgba(44, 20, 19, .34); z-index: 20; animation: fade .2s; }
.drawer { position: fixed; top: 12px; bottom: 12px; inset-inline-end: 12px; width: min(560px, calc(100vw - 24px)); background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-up); z-index: 21; display: flex; flex-direction: column; animation: slide .26s cubic-bezier(.2, .8, .2, 1); }
[dir="rtl"] .drawer { animation-name: slide-rtl; }
.drawer header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 12px; }
.drawer header h2 { font-size: 21px; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.drawer .body { overflow-y: auto; padding: 4px 22px 22px; flex: 1; overscroll-behavior: contain; }
.drawer footer { display: flex; gap: 10px; align-items: center; padding: 12px 22px 18px; border-top: 1px solid var(--well); }
.drawer footer .grow { flex: 1; }
@keyframes slide { from { transform: translateX(32px); opacity: 0; } }
@keyframes slide-rtl { from { transform: translateX(-32px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.group { font-size: 13px; color: var(--ink-3); font-weight: 500; margin: 22px 0 10px; }
.group:first-child { margin-top: 4px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 13px; color: var(--ink-2); }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; background: var(--well); border: 1px solid transparent; border-radius: var(--r-sm); padding: 10px 14px; outline: 0; transition: border-color .15s, background .15s; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); background: var(--card); }
.field textarea { min-height: 88px; resize: vertical; }
.field small { color: var(--ink-3); font-size: 12px; }
.field.bad input { border-color: var(--stop); }
.inline { display: flex; gap: 8px; }
.inline > :first-child { flex: 1; min-width: 0; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { padding: 5px 12px; border-radius: 999px; background: var(--well); font-size: 13px; color: var(--ink-2); min-height: 32px; }
.quick button:hover { background: var(--line); color: var(--ink); }
.photo { display: flex; align-items: center; gap: 14px; }
.photo img, .photo .none { width: 84px; height: 84px; border-radius: 22px; object-fit: cover; background: var(--well); display: grid; place-items: center; color: var(--ink-3); flex: none; }
.pay { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--well); }
.pay:first-child { border-top: 0; }
.box { background: var(--well); border-radius: var(--r-md); padding: 14px; margin-top: 10px; }
.box .field input, .box .field select { background: var(--card); }

.box > p { margin-bottom: 10px; }
.box .check { margin-top: 4px; }

#toast { position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translateX(-50%); background: var(--accent-deep); color: #f6e7da; padding: 10px 20px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; max-width: calc(100vw - 32px); }
[dir="rtl"] #toast { transform: translateX(50%); }
#toast.on { opacity: 1; }
#toast.bad { background: var(--stop); color: #fff; }

/* ---------- sign-in ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate form { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 34px 30px; }
.gate img { width: 88px; height: auto; margin: 0 auto 4px; }
.gate h1 { font-size: 26px; font-weight: 400; text-align: center; color: var(--accent); }
.gate p { text-align: center; color: var(--ink-2); margin-bottom: 6px; }
.gate .err { color: var(--stop); text-align: center; min-height: 20px; font-size: 14px; margin: 0; }

@media (max-width: 1040px) {
  .span-3 { grid-column: span 6; } .span-4, .span-5, .span-7, .span-8, .span-6 { grid-column: span 12; }
  .kpi.span-6 { grid-column: span 6; min-height: 104px; }
  .top { flex-wrap: wrap; border-radius: 28px; padding: 12px 14px; }
  [dir="rtl"] .top { padding: 12px 14px; }
  .tools { margin-inline-start: auto; }
  .nav { order: 3; width: 100%; margin: 0; }
}
@media (max-width: 720px) {
  .shell { padding: 12px 16px 56px; }
  .head { margin-top: 24px; }
  .head h1 { font-size: 30px; }
  .card { border-radius: 24px; padding: 18px; }
  .fields { grid-template-columns: 1fr; }
  .kpi .value { font-size: 34px; }
  .cash .big { font-size: 32px; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { padding: 10px 0; border-top: 1px solid var(--well); }
  tbody tr:first-child { border-top: 0; }
  tbody tr:hover td { background: none; }
  td { padding: 3px 0; }
  td[data-label]:not([data-label=""]) { display: flex; justify-content: space-between; gap: 12px; }
  td[data-label]:not([data-label=""])::before { content: attr(data-label); color: var(--ink-2); font-size: 13px; }
  .who b { max-width: 60vw; }
  .bars { gap: 6px; height: 170px; }
  .bar .k { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
