/* Saqala — app stylesheet. Follows docs/DESIGN.md.
   Uses logical properties (inline-start/end) so one file works for LTR and RTL. */

/* ---------- Font: IBM Plex Sans Arabic, self-hosted (works offline) ---------- */
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('../fonts/plex-arabic-arabic-400.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('../fonts/plex-arabic-arabic-500.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('../fonts/plex-arabic-arabic-600.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('../fonts/plex-arabic-arabic-700.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('../fonts/plex-arabic-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('../fonts/plex-arabic-latin-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('../fonts/plex-arabic-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('../fonts/plex-arabic-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- Design tokens ---------- */
:root {
  --ground: #F3F4F6;
  --surface: #FFFFFF;
  --surface-alt: #F7F8FA;
  --border: #DDE1E6;
  --divider: #EEF0F3;
  --input-border: #C5CCD4;
  --ink: #17212B;
  --ink-2: #3D4752;
  --muted: #5A6573;
  --primary: #B4530A;
  --primary-hover: #8A3F06;
  --primary-tint: #FFF7F0;
  --primary-tint-border: #F0C9A6;
  --nav-bg: #14212E;
  --nav-text: #C9D2DC;
  --nav-muted: #9AA7B5;
  --nav-divider: #26384B;
  --nav-active: #22364A;

  --ok-text: #1E6B3A;     --ok-bg: #E6F2EA;
  --warn-text: #8A4B00;   --warn-bg: #FDF0DC;
  --danger-text: #A61B1B; --danger-bg: #FBE7E7;
  --info-text: #1D4F91;   --info-bg: #E5EEF9;
  --neutral-text: #3D4752; --neutral-bg: #E9ECEF;

  --font: 'IBM Plex Sans Arabic', Tahoma, Arial, sans-serif;
  --nav-width: 252px;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--ground); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }
h1, h2, h3 { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 8px; border: 1px solid transparent; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--input-border); color: var(--ink); }
.btn-secondary:hover { background: var(--surface-alt); color: var(--ink); }
.btn-dark { background: var(--nav-bg); color: #fff; }
.btn-dark:hover { background: var(--nav-active); color: #fff; }
.btn-danger { background: var(--surface); border-color: var(--danger-text); color: var(--danger-text); }
.btn-add { background: var(--primary-tint); border: 1px dashed var(--primary); color: var(--primary-hover); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }

/* ---------- Chips ---------- */
.chip { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip-ok { color: var(--ok-text); background: var(--ok-bg); }
.chip-warn { color: var(--warn-text); background: var(--warn-bg); }
.chip-danger { color: var(--danger-text); background: var(--danger-bg); }
.chip-info { color: var(--info-text); background: var(--info-bg); }
.chip-neutral { color: var(--neutral-text); background: var(--neutral-bg); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-block-end: 14px; }
.card-head h2 { font-size: 17px; font-weight: 700; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-block-end: 16px; }
.field label { font-size: 13px; font-weight: 600; }
.input, .field input[type=text], .field input[type=password], .field input[type=email], .field input[type=number],
.field input[type=date], .field select, .field textarea {
  min-height: 44px; padding: 0 10px; border: 1px solid var(--input-border); border-radius: 8px; background: var(--surface); width: 100%; }
.field textarea { padding: 10px; min-height: 88px; }
.field input[readonly] { background: var(--surface-alt); }
.field .help { font-size: 12px; color: var(--muted); }
.field .errorlist, .errorlist { list-style: none; margin: 0; padding: 0; color: var(--danger-text); font-size: 12px; }
.alert { border-radius: 8px; padding: 10px 12px; margin-block-end: 16px; border: 1px solid; }
.alert-error { color: var(--danger-text); background: var(--danger-bg); border-color: #F2C4C4; }
.alert-success { color: var(--ok-text); background: var(--ok-bg); border-color: #BFDDC9; }
.alert-info { color: var(--info-text); background: var(--info-bg); border-color: #BFD3EE; }
.alert-warn { color: var(--warn-text); background: var(--warn-bg); border-color: #F0D9B5; }
.alert .inline-form { display: inline-block; margin-inline-start: 8px; }
/* Licence banner (trial copies, Ahmed 2026-11-22): info while running, amber in the last 7 days, red when read-only. */
.licence-banner { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 8px 24px;
  color: var(--info-text); background: var(--info-bg); border-block-end: 1px solid #BFD3EE; }
.licence-banner.licence-ending { color: var(--warn-text); background: var(--warn-bg); border-color: #F0D9B5; }
.licence-banner.licence-ended { color: var(--danger-text); background: var(--danger-bg); border-color: #F2C4C4; }
.prep-box { border: 1px solid var(--border, #E5E7EB); border-radius: 8px; padding: 10px 12px; margin-block-end: 10px; }
.prep-box p { margin: 4px 0; }
.input-qty { width: 7rem; }
.dispatch-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.dispatch-form .input { width: auto; }
.decide-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.decide-form .input { width: auto; }
.checkbox { display: flex; align-items: center; gap: 8px; min-height: 32px; font-weight: 400; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: start; color: var(--muted); font-weight: 500; padding: 10px 8px; background: var(--surface-alt); white-space: nowrap; }
.table td { padding: 10px 8px; border-block-start: 1px solid var(--divider); vertical-align: middle; }
.table td:first-child { font-weight: 600; }
.table .end { text-align: end; }
/* Document numbers, dates and quantities never break across lines. */
.table td.ltr, .table td.num, .table .chip { white-space: nowrap; }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }
/* Dark column runs the full page height; the menu inside stays put while scrolling. */
.sidenav-col { flex: 0 0 var(--nav-width); background: var(--nav-bg); }
.sidenav { width: var(--nav-width); flex: 0 0 var(--nav-width); background: var(--nav-bg); color: var(--nav-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; }
.brand-name { color: #fff; font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-by { color: var(--nav-muted); font-size: 12px; }
.nav-divider { border: 0; border-block-start: 1px solid var(--nav-divider); margin: 0 14px; }
.company-block { padding: 14px 18px; }
.company-block .label { color: var(--nav-muted); font-size: 11px; font-weight: 600; }
.company-block .name { color: #fff; font-weight: 600; }
.company-block .sub { color: var(--nav-muted); font-size: 12px; }
.nav { flex: 1; padding: 6px 10px 14px; }
.nav-group-title { color: var(--nav-muted); font-size: 11px; font-weight: 600; padding: 14px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border-radius: 8px;
  color: var(--nav-text); font-size: 14px; text-decoration: none; }
.nav-item:hover { background: var(--nav-active); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--nav-active); color: #fff; font-weight: 600; }
.nav-item .label { flex: 1; }
.nav-item.soon { color: #6F7E8E; cursor: not-allowed; }
.nav-item.soon:hover { background: transparent; color: #6F7E8E; }
.soon-tag { font-size: 11px; font-weight: 600; color: var(--nav-muted); border: 1px solid var(--nav-divider); border-radius: 999px; padding: 1px 8px; }
.nav-badge { background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 36px; }
/* Logged-in user at the top of every page (Ahmed 2026-11-07): full name and role, never cut. */
.user-chip { display: flex; align-items: center; gap: 10px; padding-inline-start: 10px;
  border-inline-start: 1px solid var(--border); }
.user-chip .who { min-width: 0; line-height: 1.25; }
.user-chip .who .name { font-weight: 600; color: var(--ink); }
.user-chip .who .role { color: var(--muted); font-size: 12px; }
.user-chip form { margin: 0; }
.logout-btn { background: transparent; border: 1px solid var(--border); color: var(--ink); border-radius: 8px;
  min-height: 36px; padding: 0 10px; cursor: pointer; font-size: 12px; }
.logout-btn:hover { background: var(--surface-alt); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { min-height: 72px; background: var(--surface); border-block-end: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 12px 28px; }
.topbar .titles { flex: 1; min-width: 0; }
.topbar h1 { font-size: 20px; font-weight: 700; line-height: 1.3; }
.breadcrumb { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.search { min-width: 240px; min-height: 44px; border: 1px solid var(--border); background: var(--surface-alt);
  border-radius: 8px; padding: 0 12px; }
.icon-btn { position: relative; width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--input-border);
  background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink-2); }
a.icon-btn { display: inline-flex; align-items: center; justify-content: center; color: inherit; }
.notifications li.unread .title { font-weight: 600; }
.notifications .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  margin-inline-end: 8px; vertical-align: middle; }
.icon-btn .count { position: absolute; top: -6px; inset-inline-end: -6px; background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 6px; }
.menu-toggle { display: none; }
/* Hide the left menu for more width (wide screens only; small screens use the menu button). */
@media (min-width: 901px) {
  body.nav-collapsed .sidenav-col { display: none; }
  body.nav-collapsed .content { max-width: 1480px; }
  body.nav-collapsed .doc-card { max-width: none; }
}
@media (max-width: 900px) { .sidebar-toggle { display: none; } }
.content { padding: 24px 28px; display: flex; flex-direction: column; gap: 20px; width: 100%; max-width: 1240px; }
.lang-form { margin: 0; }

/* ---------- Grids ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 28px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.kpi .note { font-size: 12px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 20px; }
.sample-banner { display: flex; align-items: center; gap: 10px; background: var(--primary-tint);
  border: 1px solid var(--primary-tint-border); color: var(--primary-hover); border-radius: 10px; padding: 10px 14px; font-size: 13px; }

/* ---------- Lists inside cards ---------- */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-block-start: 1px solid var(--divider); }
.rows li:first-child { border-block-start: 0; padding-block-start: 0; }
.rows .title { font-weight: 600; }
.rows .meta { font-size: 12px; color: var(--muted); }
.activity li { justify-content: flex-start; }
.activity .time { width: 48px; flex: 0 0 48px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.short { color: var(--danger-text); font-weight: 600; }

/* ---------- Login ---------- */
.login { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.login-brand { background: var(--nav-bg); color: var(--nav-text); padding: 48px; display: flex; flex-direction: column; justify-content: center; gap: 28px; }
.login-brand .logo-row { display: flex; align-items: center; gap: 14px; }
.login-brand .product { color: #fff; font-size: 26px; font-weight: 700; line-height: 1.2; }
.login-brand h2 { color: #fff; font-size: 22px; font-weight: 700; max-width: 420px; }
.login-brand p { margin: 8px 0 0; max-width: 420px; color: var(--nav-text); }
.login-form-side { display: flex; align-items: center; justify-content: center; padding: 32px 16px; background: var(--ground); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 100%; max-width: 400px; }
.login-card .head { display: flex; align-items: center; justify-content: space-between; margin-block-end: 20px; }
.login-card h1 { font-size: 20px; font-weight: 700; }
.login-card .btn-primary { min-height: 48px; }
.login-note { font-size: 12px; color: var(--muted); margin: 16px 0 0; }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .sidenav-col { flex-basis: 0; }
  .sidenav { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  [dir=rtl] .sidenav { transform: translateX(100%); }
  body.nav-open .sidenav { transform: none; }
  body.nav-open .scrim { position: fixed; inset: 0; background: rgba(20, 33, 46, .45); z-index: 40; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .search { min-width: 0; width: 100%; order: 3; }
  .topbar-actions { flex-wrap: wrap; }
  .user-chip { border-inline-start: 0; padding-inline-start: 0; }
  .content { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-brand { padding: 32px 24px; }
  .login-brand .frame { display: none; }
}
@media (prefers-reduced-motion: reduce) { .sidenav { transition: none; } }

/* ---------- Form pages ---------- */
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.form-layout > .card:only-child { grid-column: 1 / -1; max-width: 760px; }
.side-cards { display: flex; flex-direction: column; gap: 20px; }
.side-cards p { margin: 0 0 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-block-start: 8px; }
.fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.fieldset legend { font-size: 13px; font-weight: 600; padding: 0; margin-block-end: 6px; }
.check-grid { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.field .help ul { margin: 4px 0 0; padding-inline-start: 18px; }
.req { color: var(--primary); }
.card.narrow { max-width: 520px; }
.card p.muted { margin-block-start: 0; }
@media (max-width: 900px) { .form-layout { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Lists with filters, totals, prices ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: end; }
.filters .field { min-width: 160px; }
.filters .grow { flex: 1 1 260px; }
/* Payment terms: type, days, note on one row (days hidden for Cash). */
.terms-group { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 140px) minmax(0, 2fr); gap: 0 16px; }
.terms-group > [hidden] { display: block; visibility: hidden; }  /* keep the note in its column */
@media (max-width: 640px) { .terms-group { grid-template-columns: 1fr; } }
/* "a · b · c" lists that skip empty parts. */
.dot-item + .dot-item::before { content: " · "; }
/* "Filters" button: the filters stay folded until used (Ahmed 2026-11-07); open when one is set. */
.filter-box { flex: 0 0 auto; margin-block-end: 16px; }
.filter-box > summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.filter-box > summary::-webkit-details-marker { display: none; }
.filter-box[open] { flex: 1 0 100%; }
.filter-box[open] > summary { margin-block-end: 10px; }
.filter-fields { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: end; }
.filter-fields .field { min-width: 160px; margin-block-end: 0; }
/* One-line summary above a list (Open / Won / Lost / Win rate...). */
.summary-line { display: flex; flex-wrap: wrap; gap: 6px 22px; padding: 10px 14px; margin: 4px 0 10px;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.summary-line .k { color: var(--muted); }
.summary-line strong { color: var(--ink); }
.list-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 8px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-block-start: 12px; }
.outcome-box { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }
.outcome-box .inline-form { display: flex; gap: 8px; align-items: center; }
.outcome-box .inline-form .input { width: 280px; max-width: 100%; }
.incoming-po { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-block-end: 12px; }
.incoming-po h3 { font-size: 15px; margin: 0; }
.search-results h2 { font-size: 15px; margin: 16px 0 6px; }
select.input { padding-inline-end: 28px; }
.small { font-size: 12px; }
.table td.empty { text-align: center; color: var(--muted); font-weight: 400; padding: 28px 8px; }
.section-title { font-size: 17px; font-weight: 700; margin: 8px 0 6px; }
.pre-line { white-space: pre-line; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0 0 12px; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: end; font-variant-numeric: tabular-nums; }
.totals dd .chip { white-space: normal; }   /* long status chips wrap on a phone */
.price-grid { display: grid; grid-template-columns: 140px repeat(2, minmax(0, 1fr)); column-gap: 16px; align-items: start; }
.price-head { font-size: 13px; font-weight: 600; color: var(--muted); margin-block-end: 6px; }
.price-label { font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.price-grid .field label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (max-width: 640px) { .price-grid { grid-template-columns: 110px repeat(2, minmax(0, 1fr)); column-gap: 8px; } }

/* ---------- Contact persons table ---------- */
.contacts-table td { vertical-align: top; }
.contacts-table td:first-child { font-weight: 400; }
.contacts-table input[type=text], .contacts-table input[type=email] {
  width: 100%; min-width: 120px; min-height: 40px; padding: 0 8px; border: 1px solid var(--input-border); border-radius: 8px; background: var(--surface); }
.contacts-table input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--danger-text); }
.table .center { text-align: center; }

/* ---------- Document lines (quotations, orders) ---------- */
.doc-card { max-width: 1180px; }
.doc-meta { margin: -4px 0 16px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.doc-tools { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.doc-totals { max-width: 380px; margin-inline-start: auto; margin-block: 8px 20px; }
.discount-box { margin-block-end: 12px; }
.issue-box { display: flex; flex-direction: column; gap: 6px; padding: 12px 16px; margin-block-end: 16px;
  border: 1px solid var(--primary-tint-border); border-radius: 10px; background: var(--primary-tint); }
.issue-box ul { margin: 0; padding-inline-start: 20px; }
.actions-box { margin-block-end: 16px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; }
.actions-box summary { cursor: pointer; font-weight: 600; }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 12px; }
.actions-grid form { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.actions-grid label { font-weight: 600; font-size: 13px; }
.actions-grid .input { width: 100%; }
.versions { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; }
.issue-box form { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline-pair { display: flex; gap: 8px; }
.inline-pair input { flex: 1 1 auto; min-width: 0; }
.inline-pair select { flex: 0 0 120px; }
.lines-table input.pct { width: 60px; }
.doc-totals .grand { font-weight: 700; color: var(--ink); font-size: 16px; }
.lines-table td { vertical-align: top; }
.lines-table select, .lines-table input[type=number] {
  min-height: 40px; padding: 0 8px; border: 1px solid var(--input-border); border-radius: 8px;
  background: var(--surface); font: inherit; }
.lines-table td.col-item select { width: 100%; min-width: 200px; }
.lines-table input.num { width: 92px; text-align: end; }
.lines-table input[name$="-periods"] { width: 60px; }
.lines-table select[name$="-period_unit"] { width: 96px; }
.lines-table select[name$="-tax_type"] { width: 122px; }
.lines-table select[name$="-condition"] { width: 92px; }
.lines-table th, .lines-table td { padding-inline: 6px; }
.lines-table input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--danger-text); }
.lines-table .is-service .period-cell > * { visibility: hidden; }
.terms-box { display: flex; gap: 12px; flex-wrap: wrap; }
.terms-box .field { flex: 1 1 140px; }

/* ---------- Activity log ---------- */
.changes { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.changes li + li { margin-block-start: 2px; }
.change-field { font-weight: 600; }
[dir=rtl] .change-arrow { display: inline-block; transform: scaleX(-1); }
.nowrap { white-space: nowrap; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding-block-start: 14px; }

/* ---------- Backups ---------- */
.backup-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.path { font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-all; }
.check-list { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-block-end: 16px; }
.check-list .check { display: inline-flex; align-items: center; gap: 6px; }
.compare-table td { vertical-align: top; }
.compare-table .cell-cheapest { background: var(--ok-bg, #EAF6EE); }
.compare-table .input-qty { margin-block-start: 6px; }
.search-form { display: contents; }

.issue-box.outcome-box { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px 32px; }
.outcome-box .inline-form { flex-wrap: nowrap; }

/* Pickers with a search box + category filter (Ahmed 2026-11-07) */
.picker-tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.picker-tools .picker-q { flex: 1 1 14rem; min-width: 10rem; }
.picker-tools .picker-cat { flex: 0 1 12rem; width: auto; }
.picker [data-pick][hidden] { display: none !important; }
details.new-contact { grid-column: 1 / -1; }
details.new-contact > summary { cursor: pointer; color: var(--accent, #1d4ed8); margin-bottom: .4rem; }
details.new-contact[open] { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0 1rem; }
details.new-contact[open] > summary { grid-column: 1 / -1; }

/* Dashboard cards that open their page (Ahmed 2026-11-07: real figures) */
a.kpi-link { color: inherit; text-decoration: none; display: block; transition: border-color .15s, box-shadow .15s; }
a.kpi-link:hover, a.kpi-link:focus-visible { border-color: var(--primary, #1d4ed8); box-shadow: 0 1px 6px rgba(0,0,0,.06); }
.kpi .note .short { color: var(--danger, #b42318); }
/* Goods receipt: "Fix a typing mistake" and "Return goods to the supplier" side by side (2026-11-07) */
.adjust-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.adjust-choices .actions-box .help { margin: 4px 0 8px; }
.adjust-choices .form-grid { grid-template-columns: 1fr; }
.summary-help { display: block; font-weight: 400; font-size: 13px; color: var(--muted, #667085); margin: 2px 0 8px; padding-inline-start: 18px; }

/* Project profitability: the lines of one project inside its row */
.project-lines summary { cursor: pointer; }
.project-detail { margin-top: 6px; font-size: 13px; }
.project-detail td { padding: 4px 8px; }

.line-details-text { white-space: normal; }

/* Quotation / order lines, two rows per line (Ahmed 2026-11-19: no sideways scroll at 1366 px, every field
   visible). Row 1 = the numbers; row 2 (full width) = description, hire starts, billed, package box. */
.lines-2row { table-layout: auto; }
.lines-2row th, .lines-2row td { padding-inline: 4px; }
.lines-2row tbody.line { border-block-start: 1px solid var(--divider); }
.lines-2row tbody.line td { border-block-start: 0; }
.lines-2row tr.line-main td { padding-block: 8px 4px; vertical-align: middle; }
.lines-2row td.col-item { width: 100%; }
.lines-2row td.col-item select { min-width: 180px; }
.lines-2row input.num, .lines-2row input[name$="-unit_price"] { width: 92px; }
.lines-2row input[name$="-quantity"] { width: 76px; }
.lines-2row input[name$="-discount_percent"] { width: 56px; }
.lines-2row input[name$="-periods"] { width: 52px; }
.lines-2row select[name$="-period_unit"] { width: 88px; }
.lines-2row select.line-unit { width: 96px; }
.lines-2row select[name$="-tax_type"] { width: 116px; }
.lines-2row select[name$="-condition"] { width: 84px; }
.lines-2row td.col-amount { min-width: 84px; }
/* Sections (Ahmed 2026-11-19): a header bar over its lines, subtotal per section. */
.lines-2row tbody.section-head td { background: var(--surface-alt); padding-block: 8px; border-block-start: 2px solid var(--border); }
.section-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.section-bar .section-name { flex: 1 1 260px; min-height: 36px; font-weight: 600; }
.section-subtotal { margin-inline-start: auto; color: var(--muted); font-size: 13px; }
.section-subtotal strong { color: var(--ink); }
.table tr.section-row td { background: var(--surface-alt); font-weight: 700; }
.table tr.subtotal-row td { font-weight: 600; border-block-start: 1px solid var(--border); }
.lines-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.dup-btn { background: transparent; border: 1px solid var(--input-border); border-radius: 6px; width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); cursor: pointer;
  vertical-align: middle; margin-inline-end: 6px; }
.dup-btn:hover { background: var(--surface-alt); }
.rate-note { white-space: normal; display: inline-block; max-width: 96px; line-height: 1.3; }
.lines-2row tr.line-extra td { padding-block: 0 10px; }
.lines-2row tr.line-extra { display: none; }
.lines-2row.is-measured tr.line-extra, .lines-2row .is-service tr.line-extra,
.lines-2row .is-package tr.line-extra { display: table-row; }
.line-extra-box { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: flex-start; }
.line-extra-box > label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 0; }
.line-extra-box > label > span { white-space: nowrap; }
.line-extra-box .extra-details { flex: 1 1 320px; align-items: flex-start; }
.line-extra-box .extra-details > span { padding-block-start: 8px; }
.lines-table textarea.line-details { flex: 1; width: 100%; min-height: 40px; height: 40px; font-size: .95em; resize: vertical; }
.line-extra-box select { min-height: 36px; }
.line-extra-box .extra-hire, .line-extra-box .extra-bill { display: none; }
.lines-2row .is-period:not(.is-package) .extra-hire, .lines-2row .is-package .extra-hire { display: flex; }
.lines-2row .is-service .extra-bill, .lines-2row .is-package .extra-bill { display: flex; }
/* Package lines: included period + extension, shown only on package rows (Ahmed 2026-11-19). */
.lines-table .package-box { display: none; font-size: 13px; }
.lines-table .is-package .package-box { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.lines-table .package-box input { width: 64px; }
.lines-table .is-package .period-cell input[name$="-periods"] { visibility: hidden; }
/* Worked example under a billing setting (Ahmed 2026-11-21, task B) */
.help-example { display: block; margin-block-start: 4px; padding: 6px 8px; border-inline-start: 3px solid var(--border); background: var(--surface-alt); color: var(--ink-2); border-radius: 4px; line-height: 1.45; }
/* Material plan: one tab per section (Ahmed 2026-11-21, task D) */
.section-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.section-tabs a { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--ink-2); text-decoration: none; background: var(--surface); }
.section-tabs a.active { border-color: var(--primary); background: var(--primary-tint); color: var(--ink); font-weight: 600; }
