/* ==========================================================================
   Alshihab console — one hand-written stylesheet, no build step.
   RTL only. Mobile first; the sidebar layout starts at 900px.
   Sections: tokens · base · shell · components · forms · tables · utilities · deals · print
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --brown: #4B3324;
  --brown-2: #5E4130;
  --copper: #AF5233;
  --copper-dark: #964327;
  --cream: #F8E9D7;
  --bg: #F6F2EE;
  --surface: #FFFFFF;
  --line: #E8DFD6;
  --ink: #2B1F17;
  --muted: #606060;
  --profit: #1E7A4C;
  --profit-bg: #E7F4EC;
  --loss: #B42318;
  --loss-bg: #FDECEA;
  --warn: #8A5A00;
  --warn-bg: #FDF2D6;

  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(43, 31, 23, .05), 0 6px 18px rgba(43, 31, 23, .05);
  --sidebar-w: 268px;
  --topbar-h: 60px;
  --bottombar-h: 66px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Alexandria", "Segoe UI", Tahoma, "Noto Naskh Arabic", system-ui, sans-serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.35; font-weight: 700; }
h2 { font-size: 18px; line-height: 1.4; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
a { color: var(--copper); text-underline-offset: 3px; }
a:hover { color: var(--copper-dark); }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--copper); outline-offset: 2px; border-radius: 6px; }
.sidebar :focus-visible, .topbar :focus-visible, .drawer :focus-visible { outline-color: var(--cream); }

.skip-link {
  position: fixed; top: 8px; inset-inline-start: 8px; z-index: 100;
  padding: 10px 16px; background: var(--brown); color: var(--cream);
  border-radius: var(--radius-sm); text-decoration: none; font-weight: 600;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.ic {
  width: 24px; height: 24px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Shell ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.main { outline: none; min-width: 0; }
.page {
  width: 100%; max-width: 1280px; margin-inline: auto;
  padding: 20px 16px calc(var(--bottombar-h) + var(--safe-bottom) + 32px);
}
.page > * + * { margin-top: 16px; }
.app-bare .page { padding-bottom: 32px; }

/* Mobile top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding-inline: 16px;
  background: var(--brown); color: var(--cream);
}
.topbar-logo { display: block; height: 100%; padding-block: 5px; }
.topbar-logo img { height: 100%; width: auto; }
.topbar-branch {
  margin-inline-end: auto; font-size: 13px; font-weight: 500; opacity: .85;
  padding-inline: 10px; border-inline-start: 1px solid rgba(248, 233, 215, .25);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  background: transparent; color: inherit; cursor: pointer;
  border: 0; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: rgba(248, 233, 215, .12); }

/* Mobile bottom bar */
.bottombar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex; align-items: stretch;
  height: calc(var(--bottombar-h) + var(--safe-bottom));
  padding: 0 4px var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(43, 31, 23, .07);
}
.bb-item {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; padding: 6px 2px; cursor: pointer;
  color: var(--muted); text-decoration: none;
  font-size: 12px; font-weight: 500; line-height: 1.2;
}
.bb-item .ic { width: 24px; height: 24px; }
.bb-item[aria-current="page"] { color: var(--copper); font-weight: 600; }
.bb-item[aria-current="page"] .ic { stroke-width: 2.2; }
.bb-fab {
  flex: 1; display: grid; place-items: center; text-decoration: none;
  position: relative;
}
.bb-fab .ic {
  width: 58px; height: 58px; padding: 15px; margin-top: -26px;
  background: var(--copper); color: #fff; stroke-width: 2.4;
  border: 4px solid var(--surface); border-radius: 50%;
  box-shadow: 0 8px 18px rgba(175, 82, 51, .4);
  transition: transform .15s ease, background-color .15s ease;
}
.bb-fab:hover .ic { background: var(--copper-dark); }
.bb-fab:active .ic { transform: scale(.94); }
.bb-fab[aria-current="page"] .ic { background: var(--brown); box-shadow: 0 8px 18px rgba(75, 51, 36, .35); }

/* Mobile drawer */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(43, 31, 23, .5);
  opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility 0s .2s;
}
.drawer-backdrop.is-open { opacity: 1; visibility: visible; transition: opacity .2s ease, visibility 0s; }
.drawer {
  position: fixed; top: 0; bottom: 0; right: 0; z-index: 50;
  width: min(86vw, 340px);
  display: flex; flex-direction: column; gap: 16px;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  background: var(--brown); color: var(--cream);
  overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(100%); visibility: hidden;
  transition: transform .25s ease, visibility 0s .25s;
}
.drawer.is-open { transform: none; visibility: visible; transition: transform .25s ease, visibility 0s; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.drawer-foot { margin-top: auto; }

/* Navigation links (sidebar + drawer) */
.nav-list { display: grid; gap: 4px; }
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 46px; padding: 0 14px;
  color: var(--cream); text-decoration: none;
  font-weight: 500; border-radius: var(--radius-sm);
  transition: background-color .15s ease;
}
.nav-link:hover { background: rgba(248, 233, 215, .09); color: var(--cream); }
.nav-link[aria-current="page"] { background: var(--brown-2); font-weight: 600; }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 12px; bottom: 12px;
  width: 4px; border-radius: 4px; background: var(--copper);
}

/* Identity blocks */
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--copper); color: #fff; font-weight: 700; font-size: 17px;
}
.user-chip { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-chip-text { display: grid; line-height: 1.35; min-width: 0; }
.user-chip-text strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-text small { font-size: 13px; opacity: .78; }
.branch-chip {
  display: grid; gap: 2px; padding: 10px 14px;
  background: rgba(248, 233, 215, .08); border-radius: var(--radius-sm);
}
.branch-chip-label { font-size: 12px; opacity: .7; }
.branch-chip strong { font-weight: 600; }

/* Desktop: sidebar layout */
.sidebar { display: none; }
@media (min-width: 900px) {
  .app:not(.app-bare) { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 20px;
    padding: 24px 16px 20px;
    background: var(--brown); color: var(--cream);
  }
  .sidebar-logo { display: block; padding-inline: 8px; }
  .sidebar-logo img { width: 100%; max-width: 180px; height: auto; }
  .sidebar-foot { margin-top: auto; display: grid; gap: 14px; padding-top: 16px;
    border-top: 1px solid rgba(248, 233, 215, .15); }
  .topbar, .bottombar, .drawer, .drawer-backdrop { display: none; }
  .page { padding: 32px 32px 48px; }
  h1 { font-size: 28px; }
}

/* ---------- Components ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-head p { color: var(--muted); font-size: 14px; }
.title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; min-width: 0; }
.title-row h1 { min-width: 0; }
.page-head h1:has(+ .help-btn) { display: inline; }
.page-head h1 + .help-btn { margin-inline-start: 10px; vertical-align: middle; }

/* «؟» help: a round button next to the title and the panel it opens under the header */
.help-btn {
  display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; padding: 0;
  background: #fff; color: var(--copper); border: 2px solid var(--copper); border-radius: 50%;
  font: 700 17px/1 var(--font); cursor: pointer;
  transition: background-color .15s ease, color .15s ease, transform .1s ease;
}
.help-btn:hover { background: var(--bg); }
.help-btn:active { transform: scale(.94); }
.help-btn[aria-expanded="true"] { background: var(--copper); color: #fff; }
.help-panel {
  background: var(--surface); border: 2px solid var(--copper); border-radius: 16px;
  box-shadow: 0 10px 30px rgba(75, 51, 36, .12); padding: 18px 20px;
  font-size: 14px; line-height: 1.9; color: var(--ink);
}
.page-head > .help-panel { flex: 1 1 100%; order: 99; }
.help-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.help-panel-head strong { font-size: 16px; font-weight: 700; }
.help-close {
  flex: none; width: 36px; height: 36px; padding: 0; cursor: pointer;
  background: #F3ECE4; color: var(--brown); border: 0; border-radius: 10px; font-size: 20px; line-height: 1;
}
.help-close:hover { background: var(--line); }
.help-summary { margin: 0; }
.help-steps { counter-reset: help; display: grid; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.help-steps li { counter-increment: help; display: flex; gap: 10px; align-items: flex-start; }
.help-steps li::before {
  content: counter(help); flex: none; display: inline-grid; place-items: center;
  width: 24px; height: 24px; margin-top: 3px; border-radius: 50%;
  background: var(--copper); color: #fff; font-size: 13px; font-weight: 700; line-height: 1;
}
.help-tips { display: grid; gap: 4px; margin: 12px 0 0; padding: 10px 14px; list-style: none;
  background: var(--bg); border-radius: var(--radius-sm); color: var(--muted); font-size: 13.5px; line-height: 1.8; }
.help-tips li::before { content: "• "; color: var(--copper); font-weight: 700; }
@media (min-width: 640px) { .help-panel { padding: 20px 22px; } }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.section-title a { font-size: 14px; font-weight: 500; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.card-body { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-dark { background: var(--brown); color: var(--cream); border-color: var(--brown); }
.card-dark .muted { color: rgba(248, 233, 215, .75); }
.card-dark a { color: var(--cream); }

/* KPI tiles */
.kpi-row { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .kpi-row { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } }
.kpi {
  display: grid; align-content: start; gap: 4px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.kpi-label { font-size: 13px; font-weight: 500; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 700; line-height: 1.25; }
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.kpi-sub { font-size: 13px; color: var(--muted); }
.kpi-dark { background: var(--brown); border-color: var(--brown); color: var(--cream); }
.kpi-dark .kpi-label, .kpi-dark .kpi-sub, .kpi-dark .kpi-value small { color: rgba(248, 233, 215, .78); }
@media (min-width: 900px) { .kpi-value { font-size: 28px; } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px;
  font-weight: 600; font-size: 16px; line-height: 1.2; text-decoration: none; text-align: center;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; user-select: none;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:active { transform: translateY(1px); }
.btn .ic { width: 20px; height: 20px; }
.btn-primary { background: var(--copper); border-color: var(--copper); color: #fff; }
.btn-primary:hover { background: var(--copper-dark); border-color: var(--copper-dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border-color: #D6C9BD; }
.btn-ghost:hover { background: var(--surface); border-color: var(--copper); color: var(--copper-dark); }
.btn-ghost-dark { background: transparent; color: var(--cream); border-color: rgba(248, 233, 215, .35); }
.btn-ghost-dark:hover { background: rgba(248, 233, 215, .1); color: var(--cream); border-color: var(--cream); }
.btn-danger { background: var(--loss-bg); color: var(--loss); border-color: #F3C4BE; }
.btn-danger:hover { background: #FBDAD6; color: var(--loss); }
.btn-sm { min-height: 44px; padding: 0 16px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600; line-height: 1.6; white-space: nowrap;
  background: #EFE6DC; color: var(--brown);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-ready { background: var(--warn-bg); color: var(--warn); }
.badge-profit { background: var(--profit-bg); color: var(--profit); }
.badge-loss { background: var(--loss-bg); color: var(--loss); }
.badge-open { background: #EFE6DC; color: var(--brown); }
.badge-closed { background: #ECECEC; color: #4A4A4A; }
.badge-muted { background: #F1ECE7; color: var(--muted); }

/* Messages (Django messages and form errors) */
.messages { display: grid; gap: 8px; }
.msg {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px;
  border-radius: var(--radius-sm); border: 1px solid; font-weight: 500; line-height: 1.55;
}
.msg .ic { margin-top: 1px; }
.msg-success { background: var(--profit-bg); color: var(--profit); border-color: #BFE3CC; }
.msg-error { background: var(--loss-bg); color: var(--loss); border-color: #F3C4BE; }
.msg-warn { background: var(--warn-bg); color: var(--warn); border-color: #EBD59B; }
.msg-info { background: #EFE6DC; color: var(--brown); border-color: var(--line); }

/* Alert rows («تحتاج انتباهك») */
.alert-list { display: grid; }
.alert {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 12px 16px;
  color: var(--ink); text-decoration: none;
  border-top: 1px solid var(--line); border-inline-start: 4px solid var(--line);
}
.alert:first-child { border-top: 0; }
.alert-body { display: grid; flex: 1; min-width: 0; }
.alert-title { font-weight: 600; }
.alert-detail { font-size: 14px; color: var(--muted); }
.alert-warn { border-inline-start-color: #D9A21B; background: color-mix(in srgb, var(--warn-bg) 45%, #fff); }
.alert-loss { border-inline-start-color: var(--loss); background: color-mix(in srgb, var(--loss-bg) 45%, #fff); }
.alert-muted { border-inline-start-color: #C9BDB1; }
a.alert:hover { background: #FBF8F5; color: var(--ink); }
a.alert .ic { color: var(--muted); }

/* Filter tabs */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  min-height: 44px; padding: 0 18px;
  color: var(--ink); background: var(--surface); text-decoration: none;
  border: 1.5px solid var(--line); border-radius: 999px; font-weight: 500;
}
.tab:hover { border-color: var(--copper); color: var(--copper-dark); }
.tab[aria-current="page"] { background: var(--brown); border-color: var(--brown); color: var(--cream); font-weight: 600; }
.tab .count {
  min-width: 24px; padding: 0 7px; border-radius: 999px; text-align: center;
  font-size: 12px; font-weight: 700; background: rgba(75, 51, 36, .1);
}
.tab[aria-current="page"] .count { background: rgba(248, 233, 215, .2); }

/* Colour tones: one set of variables per operation group (also used on the op form header) */
.tone-deal    { --tone: #AF5233; --tone-bg: #FBEDE7; --tone-line: #F0D5C9; }
.tone-cash    { --tone: #1D5F8C; --tone-bg: #E7F0F7; --tone-line: #CFE0EE; }
.tone-spend   { --tone: #9A4D00; --tone-bg: #FEF1E2; --tone-line: #F7DCBE; }
.tone-people  { --tone: #6941C6; --tone-bg: #F1ECFB; --tone-line: #DDD2F5; }
.tone-capital { --tone: #1E7A4C; --tone-bg: #E7F4EC; --tone-line: #C9E6D4; }

/* Operations menu */
.op-search {
  display: flex; align-items: center; gap: 8px; flex: 1 1 240px; max-width: 360px; height: 48px;
  padding: 0 14px; background: var(--surface); border: 1.5px solid #D6C9BD; border-radius: var(--radius-sm);
}
.op-search .ic { width: 18px; height: 18px; color: var(--muted); }
.op-search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 15px; color: var(--ink);
}
.op-search:focus-within { border-color: var(--copper); box-shadow: 0 0 0 3px rgba(175, 82, 51, .22); }
.op-banner {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px;
  background: var(--brown); color: #fff; text-decoration: none; border-radius: 18px;
  font-size: 18px; transition: background-color .15s ease, transform .1s ease;
}
.op-banner:hover { background: var(--brown-2); color: #fff; }
.op-banner:active { transform: scale(.99); }
.op-banner strong { margin-inline-end: auto; font-weight: 700; }
.op-banner-chip {
  display: grid; place-items: center; flex: none; width: 52px; height: 52px;
  background: var(--copper); border-radius: 14px;
}
.op-banner-chip .ic { width: 28px; height: 28px; stroke-width: 2.4; }
.op-banner-go { color: var(--cream); width: 26px; height: 26px; }
@media (min-width: 640px) { .op-banner { padding: 20px 24px; gap: 18px; font-size: 20px; } .op-banner-chip { width: 56px; height: 56px; } }

.op-group { display: grid; gap: 12px; }
.op-group-title { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; margin-top: 8px; }
.op-dot { width: 12px; height: 12px; border-radius: 4px; background: var(--tone); flex: none; }
.grid-ops { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.op-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 104px; padding: 14px 8px; text-align: center;
  color: var(--ink); text-decoration: none; line-height: 1.4;
  background: var(--surface); border: 1px solid var(--tone-line); border-top: 4px solid var(--tone);
  border-radius: 14px;
  transition: box-shadow .15s ease, transform .1s ease, background-color .15s ease;
}
.op-tile strong { font-size: 15px; font-weight: 700; }
.op-tile:hover { box-shadow: var(--shadow); background: color-mix(in srgb, var(--tone-bg) 45%, #fff); color: var(--ink); }
.op-tile:active { transform: scale(.98); }
.op-chip {
  display: inline-grid; place-items: center; flex: none; width: 46px; height: 46px;
  color: var(--tone); background: var(--tone-bg); border-radius: 12px;
}
.op-chip .ic { width: 24px; height: 24px; stroke-width: 1.9; }
.op-empty { text-align: center; color: var(--muted); padding: 24px 0; }
@media (min-width: 640px) {
  .grid-ops { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
  .op-tile { flex-direction: row; justify-content: flex-start; gap: 14px; min-height: 88px; padding: 16px; text-align: start; }
  .op-tile strong { font-size: 16px; }
}
/* Operation form: group colour on the header chip and the card edge */
.op-form-head .op-chip { width: 44px; height: 44px; }
.op-form-card { border-top: 4px solid var(--tone, var(--copper)); }

/* Deal stage bar (4 segments); the card stepper lives in the Deals section */
.stage-bar { display: flex; gap: 4px; min-width: 96px; }
.stage-bar .seg { flex: 1; height: 8px; border-radius: 4px; background: var(--line); }
.stage-bar .seg.on { background: var(--copper); }
/* Key/value lists */
.kv { display: grid; gap: 0; margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.kv > div:first-child { border-top: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: end; }
.kv .total { font-size: 18px; }

/* Empty state */
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty > * + * { margin-top: 12px; }
.empty h1 { color: var(--ink); font-size: 22px; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 18px; }
.form-row { display: grid; gap: 18px; }
@media (min-width: 640px) { .form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.form-narrow { max-width: 560px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.form-actions .btn-primary { flex: 1 1 200px; }

.field { display: grid; gap: 6px; align-content: start; }
.field > label, .field > .choice-group > legend { font-weight: 600; font-size: 15px; }
.field .req { color: var(--copper); }
.field-help { font-size: 13px; color: var(--muted); }
.field-error { font-size: 14px; font-weight: 500; color: var(--loss); }
.errorlist { margin: 0; padding: 0; list-style: none; color: var(--loss); font-size: 14px; }

.form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.form select, .form textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1.5px solid #D6C9BD; border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.form input:hover, .form select:hover, .form textarea:hover { border-color: #BCA997; }
.form input:focus-visible, .form select:focus-visible, .form textarea:focus-visible {
  outline: none; border-color: var(--copper); box-shadow: 0 0 0 3px rgba(175, 82, 51, .28);
}
.form .has-error input, .form .has-error select, .form .has-error textarea { border-color: var(--loss); }
.form input::placeholder { color: #9A8D82; }
.form select {
  appearance: none; -webkit-appearance: none; padding-inline-end: 14px; padding-inline-start: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234B3324' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 14px center; background-size: 16px;
}
.form input[type="date"] { text-align: start; }
/* Money / number inputs: always typed left-to-right */
.form input[inputmode="decimal"], .form input[inputmode="numeric"], .form input.num-input {
  direction: ltr; text-align: end; font-variant-numeric: tabular-nums;
}

/* Checkbox, radio and grouped choices: 44px touch rows */
.choice {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 6px 4px; cursor: pointer; font-weight: 500;
}
.form input[type="checkbox"], .form input[type="radio"] {
  width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--copper); cursor: pointer;
}
.choice-group { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; gap: 4px; }
.choice-group legend { padding: 0; margin-bottom: 4px; }
.choice-group div div label { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 500; cursor: pointer; }
.choice-group div[id] { display: grid; }

/* Segmented switch: <div class="segmented"><label><input type="radio"><span>…</span></label>…</div> */
.segmented { display: flex; padding: 4px; gap: 4px; background: #EFE8E0; border-radius: var(--radius-sm); }
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segmented span {
  display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 12px;
  border-radius: 9px; font-weight: 600; font-size: 15px; color: var(--muted); text-align: center;
  transition: background-color .15s ease, color .15s ease;
}
.segmented input:checked + span { background: var(--surface); color: var(--brown); box-shadow: 0 1px 3px rgba(43, 31, 23, .15); }
.segmented input:focus-visible + span { outline: 3px solid var(--copper); outline-offset: 2px; }

/* Live helper under a field (e.g. flip difference) */
.live-note { padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 600; background: #EFE8E0; color: var(--brown); }
.live-note.is-profit { background: var(--profit-bg); color: var(--profit); }
.live-note.is-loss { background: var(--loss-bg); color: var(--loss); }

/* Login */
.page-login .page { padding-top: 0; padding-bottom: 24px; }
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding-block: 24px; }
.login-card { width: min(100%, 420px); padding: 32px 24px; display: grid; gap: 8px; }
.login-card .form { margin-top: 16px; }
.login-logo { width: 300px; max-width: 92%; height: auto; margin: 0 auto 8px; }
.login-title { text-align: center; font-size: 22px; }
.login-sub { text-align: center; }
@media (min-width: 640px) { .login-card { padding: 40px 36px; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th {
  padding: 12px 16px; text-align: start; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--muted);
  background: #FBF8F5; border-bottom: 1px solid var(--line);
}
.table td { padding: 14px 16px; vertical-align: middle; border-top: 1px solid var(--line); }
.table tbody tr:first-child td { border-top: 0; }
.table tbody tr:hover td { background: #FCFAF8; }
.table .t-num { text-align: left; white-space: nowrap; }
.table tfoot td { font-weight: 700; background: #FBF8F5; }
.table a.row-link { font-weight: 600; text-decoration: none; }
.table a.row-link:hover { text-decoration: underline; }
.table .sub { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }

@media (max-width: 639px) {
  .table, .table tbody, .table tfoot, .table tr, .table td { display: block; width: 100%; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table tr { padding: 8px 16px; border-top: 1px solid var(--line); }
  .table tbody tr:first-child { border-top: 0; }
  .table tbody tr:hover td { background: none; }
  .table td {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 40px; padding: 6px 0; border: 0; text-align: end;
  }
  .table td::before {
    content: attr(data-label); flex: none; font-size: 13px; font-weight: 500; color: var(--muted); text-align: start;
  }
  .table td:not([data-label])::before { content: none; }
  .table td.t-num { text-align: end; }
  .table td[data-label=""]::before { content: none; }
  .table tfoot tr { background: #FBF8F5; }
}

/* ---------- Numbers and utilities ---------- */
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; display: inline-block; }
.num-profit { color: var(--profit); }
.num-loss { color: var(--loss); }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.stack, .stack-sm, .grid-2, .form, .field { grid-template-columns: minmax(0, 1fr); }
.stack { display: grid; gap: 16px; }
.stack-sm { display: grid; gap: 8px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.grid-2 { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main-side { display: grid; gap: 16px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
}
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ==========================================================================
   Deals — list, new, card (detail), cost, sale and close pages.
   Every selector is scoped by a deal-only class (.deals-table, .dc-*, .emp-row,
   .sale-row, .more-rows, .close-*, .split-*, .stepper); nothing here restyles
   shared components.
   ========================================================================== */

/* Deals list: on phones each row becomes a compact card instead of five label/value lines */
.deals-table .num, .dc-entries .num { white-space: nowrap; }
.deals-pager { justify-content: center; }
@media (max-width: 639px) {
  .deals-table tr {
    display: grid; align-items: center; gap: 4px 12px; padding: 14px 16px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "deal status" "stages result" "emp car";
  }
  .deals-table td { display: block; min-height: 0; padding: 0; text-align: start; }
  .deals-table td::before { content: none; }
  .deals-table td[data-area="deal"] { grid-area: deal; font-size: 16px; }
  .deals-table td[data-area="status"] { grid-area: status; justify-self: end; }
  .deals-table td[data-area="stages"] { grid-area: stages; padding-block: 8px; }
  .deals-table td[data-area="stages"] .stage-bar { width: 120px; }
  .deals-table td[data-area="result"] { grid-area: result; justify-self: end; font-size: 20px; font-weight: 700; line-height: 1.3; }
  .deals-table td[data-area="emp"] { grid-area: emp; font-size: 14px; color: var(--muted); }
  .deals-table td[data-area="car"] { grid-area: car; justify-self: end; font-size: 14px; color: var(--muted); }
  .deals-table td[data-area="emp"]::before, .deals-table td[data-area="car"]::before {
    content: attr(data-label) ": "; display: inline; font-size: inherit; font-weight: 400;
  }
}

/* New deal and sale: repeated employee / allocation rows */
.emp-row, .sale-row {
  display: grid; gap: 12px; padding: 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #FBF8F5;
}
@media (max-width: 639px) { .emp-row, .sale-row { padding: 12px; } }
@media (min-width: 640px) {
  .emp-row { grid-template-columns: 2fr 1.4fr 1fr; align-items: start; }
  .sale-row { grid-template-columns: 2fr 1fr; align-items: start; }
}
.more-rows summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; color: var(--copper-dark); }
.more-rows[open] summary { margin-bottom: 8px; }
.more-rows > .sale-row + .sale-row { margin-top: 12px; }

/* Deal card: header */
.dc-title { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.dc-actions .btn { padding-inline: 14px; }
@media (max-width: 639px) {
  .dc-actions { width: 100%; }
  .dc-actions .btn { flex: 1 1 0; min-width: 0; padding-inline: 8px; font-size: 15px; }
  .dc-actions .btn-primary { flex-basis: 100%; order: -1; }
}
.dc-note { white-space: pre-line; }

/* Deal card: stage stepper (done stages are solid copper, missing ones dashed) */
.stepper { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 639px) { .stepper .step:last-child:nth-child(odd) { grid-column: 1 / -1; } }
@media (min-width: 640px) { .stepper { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); } }
.step { display: grid; gap: 4px; padding: 12px 14px; border: 1.5px dashed #D6C9BD; border-radius: var(--radius-sm); background: transparent; }
.step-name { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.step-name .ic { width: 16px; height: 16px; }
.step-value { font-weight: 700; }
.step.done { border: 1.5px solid var(--copper); background: color-mix(in srgb, var(--copper) 6%, #fff); }
.step.done .step-name { color: var(--copper-dark); }

/* Deal card: layout. On phones: result first, then the movements, then the side cards. */
.dc-side { display: grid; gap: 16px; }
@media (max-width: 899px) {
  .dc-grid { display: flex; flex-direction: column; gap: 16px; }
  .dc-grid > * { margin-top: 0; }
  .dc-side { display: contents; }
  .dc-result { order: 0; } .dc-main { order: 1; } .dc-other { order: 2; }
}

/* Deal card: result (brown) card */
.dc-result .card-body { display: grid; gap: 4px; }
.dc-result h2 { color: var(--cream); margin-bottom: 4px; }
.dc-result .kv > div { border-color: rgba(248, 233, 215, .18); }
.dc-result .kv dt { color: rgba(248, 233, 215, .82); }
.dc-result .num-profit { color: #9BE3B8; }
.dc-result .num-loss { color: #FFB4A9; }
.dc-result .kv .total dt, .dc-result .kv .total dd { font-size: 18px; font-weight: 700; color: var(--cream); }
.dc-result .kv .total dd .num-profit { color: #9BE3B8; }
.dc-result .kv .total dd .num-loss { color: #FFB4A9; }

/* Deal card: movements table. On phones a row is: type + value, then account + date, then note. */
@media (max-width: 639px) {
  .dc-entries tr {
    display: grid; align-items: center; gap: 4px 12px; padding: 12px 16px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "kind value" "counter date" "note note";
  }
  .dc-entries td { display: block; min-height: 0; padding: 0; text-align: start; }
  .dc-entries td::before { content: none; }
  .dc-entries td[data-area="kind"] { grid-area: kind; }
  .dc-entries td[data-area="value"] { grid-area: value; justify-self: end; font-size: 17px; font-weight: 700; }
  .dc-entries td[data-area="counter"] { grid-area: counter; font-size: 14px; }
  .dc-entries td[data-area="date"] { grid-area: date; justify-self: end; font-size: 13px; color: var(--muted); }
  .dc-entries td[data-area="note"] { grid-area: note; font-size: 14px; color: var(--muted); }
  .dc-entries td[data-area="note"]::before { content: "ملاحظة: "; display: inline; font-size: inherit; font-weight: 400; }
  .dc-entries td.dc-empty { display: none; }
}

/* Deal card: car timeline, people lists, reopen */
.dc-timeline { display: grid; gap: 0; margin: 12px 0 0; padding: 0; list-style: none; }
.dc-timeline li { position: relative; padding: 0 22px 14px 0; }
.dc-timeline li::before { content: ""; position: absolute; right: 0; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dc-timeline li::after { content: ""; position: absolute; right: 4px; top: 22px; bottom: 0; width: 2px; background: var(--line); }
.dc-timeline li:last-child::after { display: none; }
.dc-timeline li:first-child::before { background: var(--copper); }
.dc-timeline .tl-when { display: block; font-size: 13px; color: var(--muted); }
.dc-car-form { margin-top: 16px; }
.dc-people { display: grid; gap: 0; }
.dc-people > div { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.dc-people > div:first-child { border-top: 0; }
.dc-people small { display: block; color: var(--muted); }
.dc-people .dc-amt { display: grid; justify-items: end; text-align: end; font-weight: 600; }
.dc-people .dc-amt small { font-size: 12px; font-weight: 500; }
.dc-reopen { margin-top: 12px; }
.dc-reopen summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; color: var(--loss); }
.dc-reopen form { display: grid; gap: 12px; margin-top: 8px; }

/* Close page: summary tiles */
.close-tiles { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.close-tiles .kpi-dark { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .close-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .close-tiles .kpi-dark { grid-column: auto; }
}

/* Close page: split rows. The total row uses the same columns so the sum sits under the amounts. */
.form-close { max-width: 720px; }
.split-row, .split-total {
  display: grid; gap: 8px 12px; align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}
.split-row { padding: 10px 0; grid-template-areas: "who calc" "inp inp"; border-top: 1px solid var(--line); }
.split-row:first-child { border-top: 0; }
.split-row .who { grid-area: who; }
.split-row .inp { grid-area: inp; display: flex; align-items: center; gap: 8px; }
.split-row .inp input { flex: 1; }
.split-row .calc, .split-total .sum { font-weight: 700; min-width: 84px; text-align: end; }
.split-row .calc { grid-area: calc; }
.split-total { margin-top: 4px; padding: 14px 0 0; border-top: 2px solid var(--line); font-weight: 700; grid-template-areas: "label sum" "note note"; }
.split-total .label { grid-area: label; }
.split-total .sum { grid-area: sum; }
.split-diff { grid-area: note; font-size: 14px; font-weight: 600; color: var(--muted); }
.split-diff.is-ok { color: var(--profit); }
.split-diff.is-bad { color: var(--loss); }
@media (min-width: 640px) {
  .split-row { grid-template-columns: minmax(0, 1fr) 180px 130px; grid-template-areas: "who inp calc"; }
  .split-total { grid-template-columns: minmax(0, 1fr) 180px 130px; grid-template-areas: "label note sum"; }
}
.close-submit { font-size: 17px; min-height: 54px; }

/* ---------- Print (statements, deal cards) ---------- */
@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .sidebar, .topbar, .bottombar, .drawer, .drawer-backdrop, .skip-link, .no-print,
  .btn, .page-actions, .tabs, .help-btn, .help-panel { display: none !important; }
  .app:not(.app-bare) { display: block; }
  .page { max-width: none; padding: 0; }
  .card, .kpi { box-shadow: none; border-color: #999; break-inside: avoid; }
  .table th { background: #eee; }
  a { color: inherit; text-decoration: none; }
}
