:root {
  --orange: #F5A020;
  --orange-dark: #D4891A;
  --orange-soft: #FEF3E2;
  --dark: #0F1114;
  --charcoal: #333842;
  --logo-gray: #666666;
  --gray: #6B7280;
  --gray-light: #9CA3AF;
  --border: #E5E7EB;
  --border-light: #F1F2F4;
  --surface: #F7F8FA;
  --white: #FFFFFF;
  --green: #15803D; --green-soft: #DCFCE7;
  --blue: #1D4ED8;  --blue-soft: #DBEAFE;
  --red: #B91C1C;   --red-soft: #FEE2E2;
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-ar: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  --radius: 0.75rem;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); color: var(--dark); background: var(--surface);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.container { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

/* ---------- Top bar ---------- */
.topbar { background: var(--white); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 0.6rem 1rem; display: flex; align-items: center; gap: 1.25rem; }
.brand { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.brand img { height: 2rem; width: auto; }
.brand span { font-weight: 700; color: var(--gray); font-size: 0.8125rem; border-left: 1px solid var(--border); padding-left: 0.75rem; }
.mainnav { display: flex; gap: 0.25rem; flex: 1; overflow-x: auto; }
.mainnav a { padding: 0.45rem 0.85rem; border-radius: 999px; font-weight: 600; font-size: 0.8125rem; color: var(--gray); white-space: nowrap; }
.mainnav a:hover { color: var(--dark); background: var(--surface); }
.mainnav a.active { color: var(--orange-dark); background: var(--orange-soft); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--white); font-weight: 600; font-size: 0.8125rem; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--charcoal); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-dark { background: var(--dark); border-color: var(--dark); color: var(--white); }
.btn-dark:hover { background: var(--charcoal); }
.btn-orange { background: var(--orange); border-color: var(--orange); color: var(--white); }
.btn-orange:hover { background: var(--orange-dark); border-color: var(--orange-dark); }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: var(--red-soft); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.75rem; }
.icon-btn { border: none; background: none; cursor: pointer; padding: 0.25rem 0.4rem; border-radius: 6px; color: var(--gray); font-size: 0.9rem; line-height: 1; }
.icon-btn:hover { background: var(--surface); color: var(--dark); }
.icon-btn.del:hover { color: var(--red); background: var(--red-soft); }

/* ---------- Page headers ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.page-head .sub { color: var(--gray); font-size: 0.8125rem; margin-top: 0.15rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.card + .card { margin-top: 1rem; }
.card h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--gray); font-weight: 700; margin-bottom: 1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.stat { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat .label { font-size: 0.75rem; color: var(--gray); font-weight: 600; }
.stat .value { font-size: 1.35rem; font-weight: 800; margin-top: 0.2rem; letter-spacing: -0.01em; }
.stat .value small { font-size: 0.75rem; color: var(--gray); font-weight: 600; }
.stat .lines { font-size: 0.8125rem; color: var(--charcoal); margin-top: 0.2rem; font-weight: 600; }

/* ---------- Forms ---------- */
.grid { display: grid; gap: 0.9rem 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.field label { display: block; font-size: 0.75rem; font-weight: 700; color: var(--charcoal); margin-bottom: 0.3rem; }
.field .hint { font-size: 0.7rem; color: var(--gray); margin-top: 0.25rem; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 0.55rem;
  background: var(--white); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 2.4rem; }
input:focus, select:focus, textarea:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(245,160,32,.15); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface); color: var(--charcoal); }
.check { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 600; font-size: 0.8125rem; cursor: pointer; }
.check input { width: 1rem; height: 1rem; accent-color: var(--orange); }
.inline { display: flex; gap: 0.5rem; align-items: center; }
[dir=rtl], .rtl { font-family: var(--font-ar); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--gray); font-weight: 700; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.list td { padding: 0.75rem; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface); }
table.list .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list .muted { color: var(--gray); font-size: 0.8125rem; }
.qno { font-weight: 700; white-space: nowrap; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--gray); }
.empty strong { display: block; color: var(--dark); font-size: 1rem; margin-bottom: 0.25rem; }

.filters { display: flex; gap: 0.5rem; margin-bottom: 0.9rem; flex-wrap: wrap; }
.filters input { max-width: 320px; }
.filters select { width: auto; }

/* ---------- Status badges ---------- */
.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.st-draft { background: #EEF0F3; color: var(--charcoal); }
.st-sent { background: var(--blue-soft); color: var(--blue); }
.st-accepted { background: var(--green-soft); color: var(--green); }
.st-rejected { background: var(--red-soft); color: var(--red); }
.st-cancelled { background: #E5E7EB; color: var(--gray); text-decoration: line-through; }
.st-expired { background: var(--orange-soft); color: var(--orange-dark); }
.st-superseded { background: #F3F4F6; color: var(--gray-light); }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.side { position: sticky; top: 4.5rem; display: grid; gap: 1rem; }
.banner { background: var(--orange-soft); border: 1px solid #F8D49A; color: #7A4B06; border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1rem; font-weight: 600; font-size: 0.8125rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.banner.info { background: var(--blue-soft); border-color: #BFD3FB; color: #1E3A8A; }

table.items { width: 100%; border-collapse: collapse; }
table.items th { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--gray); font-weight: 700; padding: 0 0.35rem 0.5rem; text-align: left; }
table.items td { padding: 0.3rem 0.35rem; vertical-align: top; }
table.items tr.heading-row td { padding-top: 0.75rem; }
table.items tr.heading-row input { font-weight: 800; background: var(--surface); }
table.items .c-no { width: 2rem; color: var(--gray); font-weight: 700; padding-top: 0.85rem; text-align: center; }
table.items .c-unit { width: 6rem; }
table.items .c-qty { width: 6rem; }
table.items .c-price { width: 8.5rem; }
table.items .c-amt { width: 8.5rem; text-align: right; font-weight: 700; padding-top: 0.85rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.items .c-act { width: 5.5rem; white-space: nowrap; padding-top: 0.55rem; }
table.items input.num { text-align: right; }
table.items textarea { min-height: 2.4rem; }
.items-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

.totals { display: grid; gap: 0.45rem; font-size: 0.875rem; }
.totals .row { display: flex; justify-content: space-between; gap: 0.5rem; }
.totals .row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--border); padding-top: 0.6rem; margin-top: 0.2rem; font-size: 1.1rem; }
.totals .grand span:last-child { color: var(--orange-dark); font-weight: 800; }

.timeline { display: grid; gap: 0.6rem; font-size: 0.8rem; }
.timeline .ev { display: grid; gap: 0.05rem; padding-left: 0.75rem; border-left: 2px solid var(--border); }
.timeline .ev b { font-weight: 700; }
.timeline .ev span { color: var(--gray); font-size: 0.72rem; }
.revlist { display: grid; gap: 0.35rem; }
.revlist a { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem; border-radius: 0.5rem; font-weight: 600; font-size: 0.8rem; }
.revlist a:hover { background: var(--surface); }
.revlist a.current { background: var(--orange-soft); }

/* ---------- Modal & toast ---------- */
.modal { border: none; border-radius: 1rem; padding: 0; width: min(560px, calc(100vw - 2rem)); margin: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal::backdrop { background: rgba(15,17,20,.45); }
.modal .m-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 800; font-size: 1rem; }
.modal .m-body { padding: 1.25rem; max-height: 65vh; overflow: auto; }
.modal .m-foot { padding: 0.9rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.5rem; }
.pick { display: grid; gap: 0.35rem; }
.pick button { text-align: left; border: 1px solid var(--border); background: var(--white); border-radius: 0.6rem; padding: 0.6rem 0.75rem; cursor: pointer; display: flex; justify-content: space-between; gap: 1rem; }
.pick button:hover { border-color: var(--orange); background: var(--orange-soft); }
.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(150%); background: var(--dark); color: var(--white); padding: 0.65rem 1.1rem; border-radius: 999px; font-weight: 600; font-size: 0.8125rem; transition: transform .25s, opacity .25s; z-index: 50; max-width: calc(100vw - 2rem); opacity: 0; pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: var(--red); }

/* ---------- Sign in ---------- */
body.signed-out .topbar { display: none; }
.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 1rem; padding: 2rem; }
.login img { height: 2.75rem; width: auto; margin: 0 auto; }
.login h1 { text-align: center; font-size: 1rem; color: var(--gray); font-weight: 700; margin-top: -0.5rem; }
.login input[type=password] { width: 100%; padding: 0.65rem 0.75rem; border: 1px solid var(--border); border-radius: 0.55rem; outline: none; }
.login input[type=password]:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(245,160,32,.15); }
.login-err { color: var(--red); font-size: 0.8125rem; font-weight: 600; text-align: center; min-height: 1.2em; }

/* ---------- Printed quotation (A4) ---------- */
.print-bar { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; max-width: 210mm; margin: 0 auto 1rem; flex-wrap: wrap; }
.sheet {
  width: 210mm; min-height: 297mm; margin: 0 auto; background: var(--white);
  padding: 14mm 14mm 16mm; box-shadow: 0 6px 30px rgba(0,0,0,.08);
  color: #1F2328; font-size: 10pt; line-height: 1.45;
  display: flex; flex-direction: column;
}
.sheet[dir=rtl] { font-family: var(--font-ar); }
.lh { display: flex; justify-content: space-between; align-items: center; gap: 8mm; padding-bottom: 5mm; border-bottom: 2.5px solid var(--orange); }
.lh img { height: 17mm; width: auto; }
.lh .co { text-align: end; font-size: 8.5pt; color: #4B5058; line-height: 1.5; }
.lh .co b { display: block; font-size: 10.5pt; color: var(--dark); }
.doc-title { display: flex; justify-content: space-between; align-items: flex-end; margin: 7mm 0 5mm; gap: 6mm; }
.doc-title h1 { font-size: 20pt; font-weight: 800; letter-spacing: .06em; color: var(--dark); }
.sheet[dir=rtl] .doc-title h1 { letter-spacing: 0; }
.meta { display: grid; grid-template-columns: auto auto; gap: 1mm 5mm; font-size: 9pt; }
.meta dt { color: var(--gray); }
.meta dd { font-weight: 700; text-align: end; }
.parties { display: grid; grid-template-columns: 1.3fr 1fr; gap: 6mm; margin-bottom: 5mm; }
.box { border: 1px solid var(--border); border-radius: 2mm; padding: 3.5mm 4mm; }
.box .k { font-size: 7.5pt; text-transform: uppercase; letter-spacing: .08em; color: var(--orange-dark); font-weight: 800; margin-bottom: 1.5mm; }
.sheet[dir=rtl] .box .k { letter-spacing: 0; font-size: 8.5pt; }
.box .name { font-weight: 800; font-size: 11pt; }
.box p { white-space: pre-line; color: #3A3F47; font-size: 9pt; }
table.qt { width: 100%; border-collapse: collapse; margin-top: 1mm; font-size: 9pt; }
table.qt thead th { background: var(--dark); color: var(--white); font-weight: 700; padding: 2.4mm 2.5mm; text-align: start; font-size: 8.5pt; }
table.qt thead th:first-child { border-start-start-radius: 1.5mm; }
table.qt thead th:last-child { border-start-end-radius: 1.5mm; }
table.qt td { padding: 2.4mm 2.5mm; border-bottom: 1px solid #ECEDEF; vertical-align: top; }
table.qt td.desc { white-space: pre-line; }
table.qt .n { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.qt .c { text-align: center; }
table.qt tr.h td { background: var(--orange-soft); font-weight: 800; color: #7A4B06; }
table.qt tr { break-inside: avoid; }
.sum { display: flex; justify-content: flex-end; margin-top: 4mm; break-inside: avoid; }
.sum table { min-width: 78mm; border-collapse: collapse; font-size: 9.5pt; }
.sum td { padding: 1.6mm 2.5mm; }
.sum td:last-child { text-align: end; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum tr.g td { background: var(--orange); color: var(--white); font-weight: 800; font-size: 11pt; padding: 2.6mm 2.5mm; }
.sum tr.g td:first-child { border-start-start-radius: 1.5mm; border-end-start-radius: 1.5mm; }
.sum tr.g td:last-child { border-start-end-radius: 1.5mm; border-end-end-radius: 1.5mm; }
.blk { margin-top: 6mm; break-inside: avoid; }
.blk h3 { font-size: 8pt; text-transform: uppercase; letter-spacing: .08em; color: var(--orange-dark); font-weight: 800; margin-bottom: 1.5mm; }
.sheet[dir=rtl] .blk h3 { letter-spacing: 0; font-size: 9pt; }
.blk p { white-space: pre-line; font-size: 9pt; color: #3A3F47; }
.signs { display: grid; grid-template-columns: 1fr 1fr; gap: 12mm; margin-top: 12mm; break-inside: avoid; }
.signs .s { border-top: 1px solid #9CA3AF; padding-top: 2mm; font-size: 8.5pt; color: var(--gray); }
.signs .s b { display: block; color: var(--dark); font-size: 9.5pt; }
.sheet-foot { margin-top: auto; padding-top: 8mm; }
.sheet-foot div { border-top: 1px solid var(--border); padding-top: 2.5mm; display: flex; justify-content: space-between; gap: 4mm; font-size: 7.5pt; color: var(--gray); }

/* Page margins come from @page so long quotes keep margins on every page. */
@page { size: A4; margin: 12mm 0 14mm; }
@media print {
  body { background: var(--white); }
  .no-print, .print-bar { display: none !important; }
  .container { padding: 0; max-width: none; }
  .sheet { box-shadow: none; margin: 0; width: 210mm; min-height: 0; padding: 0 14mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Small screens ---------- */
@media (max-width: 960px) {
  .editor { grid-template-columns: 1fr; }
  .side { position: static; }
}
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 0.5rem 1rem; }
  .brand span { display: none; }
  .mainnav { order: 3; flex-basis: 100%; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  table.items, table.items tbody, table.items tr, table.items td { display: block; width: 100% !important; }
  table.items thead { display: none; }
  table.items tr { border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.4rem; margin-bottom: 0.5rem; display: grid; grid-template-columns: 1fr 1fr; }
  table.items td.c-desc, table.items td.c-act, table.items tr.heading-row td { grid-column: 1 / -1; }
  table.items .c-no { display: none !important; }
  table.items .c-amt { text-align: left; padding-top: 0.6rem; }
  .print-bar, .sheet { max-width: 100%; }
  .sheet-scroll { overflow-x: auto; }
}
