@font-face { font-family: 'Tajawal'; font-weight: 400; font-display: swap; src: url(fonts/tajawal-400-arabic-6c9081fd00.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Tajawal'; font-weight: 400; font-display: swap; src: url(fonts/tajawal-400-latin-b081f7bf79.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Tajawal'; font-weight: 500; font-display: swap; src: url(fonts/tajawal-500-arabic-4255019c1c.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Tajawal'; font-weight: 500; font-display: swap; src: url(fonts/tajawal-500-latin-9986de5db8.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Tajawal'; font-weight: 700; font-display: swap; src: url(fonts/tajawal-700-arabic-fa5e723266.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Tajawal'; font-weight: 700; font-display: swap; src: url(fonts/tajawal-700-latin-de8f431c14.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --ink: #0b0b0c;
  --ink-2: #3a3b3f;
  --muted: #6b6d73;
  --line: #e4e5e6;
  --bg: #f4f4f5;
  --card: #ffffff;
  --brand: #a50d27;
  --brand-2: #870a20;
  --lime: #d4ff5a;
  --pos: #137a3f;
  --neg: #b4232f;
  --warn-bg: #fff6e0;
  --late-bg: #fdecee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 12, .06), 0 1px 1px rgba(11, 11, 12, .03);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.6 'Tajawal', system-ui, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; line-height: 1.3; }
h2 { font-size: 1.08rem; margin: 1.6rem 0 .6rem; }
.card h2:first-child, .card .cat-head h2 { margin-top: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: .85rem; }
.n { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; direction: ltr; unicode-bidi: plaintext; }
td.n { text-align: left; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
code { background: #eee; padding: 0 4px; border-radius: 4px; }

/* ---------- top bar & shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; height: 58px; padding: 0 18px; background: var(--ink); color: #f2f2f3; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand img { height: 22px; filter: invert(1); }
.brand span { font-weight: 500; opacity: .85; border-inline-start: 1px solid #444; padding-inline-start: 12px; }
.who { margin-inline-start: auto; display: flex; gap: 14px; align-items: center; }
.who a { color: #f2f2f3; }
.who .link { color: #cacbce; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
.shell { display: flex; min-height: calc(100vh - 58px); }
.side { width: 220px; flex: none; background: #fff; border-inline-end: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 58px; height: calc(100vh - 58px); overflow: auto; }
.side a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.side a i { font-style: normal; width: 18px; text-align: center; opacity: .55; }
.side a:hover { background: var(--bg); text-decoration: none; }
.side a.on { background: var(--ink); color: #fff; }
.side a.on i { opacity: 1; color: var(--lime); }
.side .quick { display: grid; gap: 8px; margin-top: 18px; padding: 14px 4px 0; border-top: 1px solid var(--line); }
.main { flex: 1; min-width: 0; padding: 22px 26px 60px; max-width: 1280px; }

/* ---------- elements ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid #cfd0d3; border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; line-height: 1.3; white-space: nowrap; }
.btn:hover { background: #f6f6f7; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--neg); border-color: #efc2c6; }
.btn.danger:hover { background: var(--late-bg); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn.ok { color: var(--pos); border-color: #b9dfc8; }
.btn.ok:hover { background: #eaf6ef; }
.btn.wa { color: #fff; background: #1f9d55; border-color: #1f9d55; }
.btn.wa:hover { background: #188046; }
.send-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.send-bar.due { background: #fff8e6; border-color: #f0d995; }
.send-bar .block { flex-basis: 100%; }
.badge.b-followup { background: #fff1cc; color: #7a5600; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; padding: 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--late-bg); color: var(--neg); }
form.inline { display: inline; }
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert.ok { background: #eaf7ef; border-color: #bfe3cc; color: #0f5a2f; }
.alert.err { background: var(--late-bg); border-color: #f2c4c9; color: #8a1520; }

/* forms */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: .9rem; color: var(--ink-2); }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); width: 100%; padding: 8px 10px; border: 1px solid #cfd0d3; border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(165, 13, 39, .25); border-color: var(--brand); }
textarea { resize: vertical; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input[type=checkbox] { width: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid.narrow { max-width: 560px; }
.span2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-actions.sticky { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 10px; z-index: 5; }
.with-btn { display: flex; gap: 6px; align-items: center; }
.with-btn select, .with-btn input { flex: 1; min-width: 0; }
.with-btn select#disc-type { flex: 0 0 72px; }
.w-xs { width: 70px !important; display: inline-block; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters label { flex-direction: row; align-items: center; gap: 6px; }
.words-preview { align-self: end; padding: 9px 12px; background: #fbfbf2; border: 1px dashed #d8d9c0; border-radius: 8px; font-size: .9rem; min-height: 40px; color: var(--ink-2); }
.words-preview:empty { visibility: hidden; }
.inline-form { display: flex; gap: 6px; flex: 1; }
.row-form { display: flex; gap: 6px; margin: 8px 0; }
details summary { cursor: pointer; font-weight: 700; }

/* tables */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; font-weight: 700; color: var(--muted); background: #fafafa; white-space: nowrap; }
tbody tr:hover { background: #fcfcfc; }
tfoot td { font-weight: 700; background: #fafafa; }
tr.grand td { font-size: 1.05rem; background: #f3f3f4; }
tr.voided td { color: #a0a1a6; text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
tr.voided td .badge, tr.voided td a { text-decoration: none; }
tr.row-late td { background: var(--late-bg); }
tr.row-soon td { background: var(--warn-bg); }
table.compact td, table.compact th { padding: 7px 8px; }
.card table.compact { margin-bottom: 8px; }
.row-actions { white-space: nowrap; text-align: end; }
.row-actions .btn { margin-inline-start: 4px; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: #eee; color: #444; white-space: nowrap; }
.b-draft { background: #eeeff1; color: #4b4d52; }
.b-sent { background: #e6efff; color: #1f4fae; }
.b-accepted { background: #e2f5e9; color: #126b37; }
.b-rejected { background: #fde7ea; color: #a0182a; }
.b-expired { background: #fff1d6; color: #8a5a00; }
.btn.b-accepted { border-color: #bfe3cc; }
.btn.b-rejected { border-color: #f2c4c9; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.kpi span { font-size: .82rem; color: var(--muted); font-weight: 500; }
.kpi strong { font-size: 1.45rem; font-variant-numeric: tabular-nums; direction: ltr; text-align: start; unicode-bidi: plaintext; }
.kpi strong.sm { font-size: 1.05rem; direction: rtl; }
.kpi small { color: var(--muted); font-size: .78rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid2 .card { margin: 0; }

.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.cat-head h2 small { font-weight: 400; color: var(--muted); font-size: .8rem; margin-inline-start: 6px; }
.empty { text-align: center; padding: 30px 16px; background: #fff; border: 1px dashed #d4d5d8; border-radius: var(--radius); color: var(--muted); margin-bottom: 16px; }
.info-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 20px; }
.info-list div { display: flex; flex-direction: column; }
.info-list span { font-size: .8rem; color: var(--muted); }
.status-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.danger-zone { margin-top: 30px; padding-top: 14px; border-top: 1px dashed var(--line); }
.logo-prev { display: flex; align-items: center; justify-content: center; background: #fafafa; border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.logo-prev img { max-height: 60px; max-width: 100%; }

/* quote editor */
table.items td { padding: 8px 6px; }
table.items input, table.items select, table.items textarea { padding: 6px 8px; }
table.items textarea { margin-top: 5px; font-size: .88rem; color: var(--ink-2); }
.w-name { min-width: 280px; width: 46%; }
.w-sm { width: 80px; }
.w-md { width: 120px; }
.totals-box { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-top: 14px; }
.totals-controls { display: flex; flex-direction: column; gap: 12px; min-width: 260px; }
.totals { display: grid; grid-template-columns: auto auto; gap: 6px 26px; margin: 0; min-width: 260px; align-self: start; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: left; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 1.15rem; color: var(--ink); border-top: 1px solid var(--line); padding-top: 6px; }

/* report bars */
.bar { display: inline-block; height: 6px; width: calc(var(--w) * .6); max-width: 60%; border-radius: 3px; margin-inline-end: 8px; vertical-align: middle; }
.bar.in { background: #7cc79a; }
.bar.out { background: #e5949c; }

/* auth */
body.auth { display: grid; place-items: center; min-height: 100vh; background: var(--ink); padding: 20px; }
.auth-box { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 30px 26px; display: grid; gap: 14px; }
.auth-box form { display: grid; gap: 14px; }
.auth-logo { height: 30px; justify-self: start; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .menu-btn { display: block; }
  .brand span { display: none; }
  .side { position: fixed; top: 58px; inset-inline-start: 0; z-index: 30; height: calc(100vh - 58px); transform: translateX(100%); transition: transform .2s; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
  body.nav-open .side { transform: none; }
  .main { padding: 16px 14px 60px; }
  .form-grid, .grid2 { grid-template-columns: 1fr; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
}
.w-bill { width: 120px; }
.who .role { font-size: .75rem; opacity: .6; margin-inline-start: 4px; }
fieldset.roles { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; display: grid; gap: 8px; margin: 0; }
fieldset.roles legend { font-weight: 700; font-size: .9rem; padding: 0 6px; }
.role-opt { flex-direction: row; align-items: flex-start; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.role-opt:hover { background: var(--bg); }
.role-opt input { width: auto; margin-top: 5px; }
.role-opt span { display: flex; flex-direction: column; }
.role-opt small { font-weight: 400; color: var(--muted); }
.ms-warn { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 0; padding: 9px 12px; border-radius: 8px; background: var(--late-bg); color: #8a1520; font-weight: 500; }
input.invalid { border-color: var(--neg); background: #fff7f8; }
.words-preview:empty { display: none; }

/* quote items as cards on phones (no sideways scrolling) */
@media (max-width: 700px) {
  #items thead { display: none; }
  #items, #items tbody { display: block; }
  #items tr.item { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px 8px; padding: 12px 10px; border-bottom: 1px solid var(--line); }
  #items tr.item td { display: flex; flex-direction: column; gap: 3px; padding: 0; border: 0; }
  #items tr.item td:first-child { grid-column: 1 / -1; }
  #items tr.item td[data-label]::before { content: attr(data-label); font-size: .75rem; color: var(--muted); font-weight: 500; }
  #items tr.item td.line-total { justify-content: flex-end; text-align: start; grid-column: 1 / -2; flex-direction: row; gap: 8px; align-items: baseline; }
  #items tr.item td:last-child { grid-row: 3; grid-column: -2 / -1; }
  #items + * { margin-top: 0; }
  .quote-form .table-wrap { overflow: visible; }
}
.filters input[type=checkbox] { min-width: 0; flex: none; }
.row-actions.under { margin-top: 6px; text-align: start; white-space: normal; }
.row-actions.under .btn { margin-inline-start: 0; margin-inline-end: 4px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 14px; }
.pager .current { background: var(--ink); color: #fff; border-color: var(--ink); cursor: default; }
.pager .muted.sm { margin-inline-start: 8px; }
