/* ══════════════════════════════════════════════════════════════════════════
   QuotePro UI — light/dark, RTL/LTR. Everything uses logical properties so
   flipping `dir` on <html> mirrors the whole layout with no extra rules.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  --accent: #AE1B1F;
  --accent-2: #d13036;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-1: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-2: 0 4px 12px rgba(16,24,40,.08), 0 2px 4px rgba(16,24,40,.05);
  --shadow-3: 0 24px 60px rgba(16,24,40,.22);
  --font: 'Cairo', 'Inter', 'Segoe UI', system-ui, sans-serif;
  --speed: .16s;
}

html[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-2: #eaecef;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --surface-3: #f1f3f5;
  --text: #16191d;
  --text-2: #565d66;
  --text-3: #868e98;
  --line: #e2e5e9;
  --line-2: #d3d8de;
  --field: #ffffff;
  --field-line: #d8dce1;
}

html[data-theme="dark"] {
  --bg: #0e1116;
  --bg-2: #070910;
  --surface: #161a21;
  --surface-2: #1b2029;
  --surface-3: #212832;
  --text: #e7eaee;
  --text-2: #a3acb8;
  --text-3: #79828f;
  --line: #262d38;
  --line-2: #313a47;
  --field: #11151b;
  --field-line: #2c3542;
  --shadow-3: 0 24px 60px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .01em; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor;
      stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.app { display: flex; flex-direction: column; height: 100%; }
.spacer { flex: 1; }

/* ═══ top bar ═══ */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-1);
  z-index: 20; flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { height: 26px; width: auto; }
.brand-text { display: flex; align-items: baseline; gap: 6px; }
.brand-text b { font-size: 15px; letter-spacing: -.01em; }
.ver { font-size: 10px; color: var(--text-3); }

.doc-chip {
  display: flex; align-items: center; gap: 7px;
  margin-inline-start: 8px; padding: 5px 12px;
  background: var(--surface-3); border-radius: 20px;
  font-size: 12px; color: var(--text-2); max-width: 340px;
}
.doc-chip .dc-num { font-weight: 700; color: var(--text); direction: ltr; }
.doc-chip .dc-sep { color: var(--text-3); }
.doc-chip .dc-client { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seg { display: flex; background: var(--surface-3); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2);
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 5px 12px; border-radius: 6px; cursor: pointer;
  transition: var(--speed);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* ═══ buttons ═══ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: var(--speed); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(174,27,31,.28);
}
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.icon { padding: 8px; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.file { cursor: pointer; }
.btn.danger-ghost { border-color: transparent; background: transparent; color: var(--text-3); }
.btn.danger-ghost:hover { background: rgba(220,38,38,.1); color: #dc2626; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.mini {
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--text-2); font-family: inherit; font-size: 11.5px; font-weight: 600;
  padding: 4px 9px; border-radius: 7px; cursor: pointer; transition: var(--speed);
  white-space: nowrap;
}
.mini:hover { background: var(--surface-3); color: var(--text); }
.mini.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.mini.accent:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ═══ workspace ═══ */
.workspace { flex: 1; display: flex; min-height: 0; }

/* ── editor panel ── */
.panel {
  width: 460px; flex: none; display: flex; flex-direction: column;
  background: var(--surface); border-inline-end: 1px solid var(--line);
  min-height: 0;
}
.tabs {
  display: flex; gap: 2px; padding: 8px 8px 0;
  border-bottom: 1px solid var(--line); flex: none; overflow-x: auto;
}
.tabs::-webkit-scrollbar { height: 0; }
.tabs button {
  position: relative; border: 0; background: transparent; color: var(--text-2);
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 9px 11px; border-radius: 8px 8px 0 0; cursor: pointer;
  white-space: nowrap; transition: var(--speed);
  display: inline-flex; align-items: center; gap: 5px;
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.on { color: var(--accent); }
.tabs button.on::after {
  content: ""; position: absolute; inset-inline: 8px; bottom: -1px;
  height: 2px; background: var(--accent); border-radius: 2px 2px 0 0;
}
.tabs .count {
  font-style: normal; font-size: 10px; font-weight: 700;
  background: var(--surface-3); color: var(--text-2);
  padding: 1px 6px; border-radius: 10px;
}
.tabs button.on .count { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.panel-body { flex: 1; overflow-y: auto; padding: 14px; }
.pane { display: none; }
.pane.on { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.group {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px; margin-bottom: 12px;
}
.group-head { display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px; }
.group > h3 { margin-bottom: 10px; }
.hint { margin: 8px 0 0; font-size: 11.5px; color: var(--text-3); line-height: 1.5; }

label { display: block; margin-bottom: 9px; }
label > span { display: block; font-size: 11.5px; font-weight: 600;
  color: var(--text-2); margin-bottom: 4px; }
label:last-child { margin-bottom: 0; }

input, select, textarea {
  width: 100%; padding: 8px 10px;
  background: var(--field); color: var(--text);
  border: 1px solid var(--field-line); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13px; transition: var(--speed);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { resize: vertical; line-height: 1.6; }
select { cursor: pointer; }
.color-input { padding: 3px; height: 36px; cursor: pointer; }
.row > .color-input { width: 72px; flex: none; }

.row { display: flex; gap: 9px; align-items: flex-end; margin-bottom: 9px; }
.row:last-child { margin-bottom: 0; }
.row.tight { gap: 6px; margin-bottom: 0; align-items: center; }
.row > label { margin-bottom: 0; }
.grow { flex: 1; min-width: 0; }

.check { display: flex; align-items: center; gap: 8px; margin: 0; }
.check input { width: auto; margin: 0; accent-color: var(--accent); }
.check span { margin: 0; font-size: 12.5px; color: var(--text); font-weight: 500; }

/* ── items editor ── */
.items-editor { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px;
  transition: var(--speed);
}
.item-row.dragging { opacity: .45; }
.item-row.drop-target { border-color: var(--accent); }
.ir-top { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
.ir-handle { cursor: grab; color: var(--text-3); display: flex; padding: 2px; }
.ir-handle:active { cursor: grabbing; }
.ir-index {
  font-size: 11px; font-weight: 700; color: var(--text-3);
  min-width: 17px; text-align: center;
}
.ir-desc { flex: 1; min-width: 0; }
.ir-del { flex: none; }
.ir-details { margin-bottom: 7px; }
.ir-details input { font-size: 12px; padding: 6px 9px; }
.ir-grid { display: grid; grid-template-columns: 1.1fr .8fr 1.2fr .75fr; gap: 6px; }
.ir-grid label { margin: 0; }
.ir-grid label > span { font-size: 10px; margin-bottom: 3px; }
.ir-grid input, .ir-grid select { padding: 6px 8px; font-size: 12.5px; }
.ir-total {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line);
  font-size: 12px; color: var(--text-2);
}
.ir-total b { font-size: 13.5px; color: var(--text); direction: ltr; }

.empty {
  text-align: center; padding: 22px 14px; color: var(--text-3);
  font-size: 12.5px; border: 1px dashed var(--line-2); border-radius: var(--radius-sm);
}

/* ── extras & terms ── */
.extras, .terms { display: flex; flex-direction: column; gap: 7px; }
.extra-row, .term-row { display: flex; gap: 7px; align-items: center; }
.extra-row input, .term-row input { padding: 7px 9px; font-size: 12.5px; }
.term-row .tr-no {
  font-size: 11px; font-weight: 700; color: var(--text-3);
  min-width: 16px; text-align: center; flex: none;
}

/* ── chips ── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 18px; font-size: 12px;
  background: var(--surface); border: 1px solid var(--line-2);
  color: var(--text-2); cursor: pointer; transition: var(--speed);
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip .x { color: var(--text-3); display: flex; }
.chip .x:hover { color: #dc2626; }

/* ── template grid ── */
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.tpl-card {
  border: 1.5px solid var(--line-2); border-radius: var(--radius-sm);
  padding: 10px; cursor: pointer; background: var(--surface);
  transition: var(--speed); text-align: start;
}
.tpl-card:hover { border-color: var(--text-3); transform: translateY(-1px); }
.tpl-card.on { border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.tpl-thumb {
  height: 58px; border-radius: 6px; margin-bottom: 8px;
  background: var(--surface-3); overflow: hidden; position: relative;
  display: flex; flex-direction: column; padding: 6px; gap: 3px;
}
.tt-bar { height: 8px; border-radius: 2px; background: var(--accent); width: 45%; }
.tt-bar.wide { width: 100%; }
.tt-line { height: 3px; border-radius: 2px; background: var(--line-2); }
.tt-line.short { width: 60%; }
.tt-block { height: 14px; border-radius: 2px; background: var(--line-2); margin-top: auto; }
.tpl-name { font-size: 12.5px; font-weight: 700; }
.tpl-desc { font-size: 10.5px; color: var(--text-3); line-height: 1.45; margin-top: 2px; }

.swatches { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.swatch {
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent; transition: var(--speed);
}
.swatch:hover { transform: scale(1.08); }
.swatch.on { border-color: var(--text); }

.toggles { display: flex; flex-direction: column; gap: 8px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.toggle span { font-size: 12.5px; color: var(--text); }
.switch { position: relative; width: 38px; height: 21px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%;
  margin: 0; cursor: pointer; z-index: 1; }
.switch .track {
  position: absolute; inset: 0; background: var(--line-2);
  border-radius: 12px; transition: var(--speed);
}
.switch .track::after {
  content: ""; position: absolute; inset-inline-start: 2px; top: 2px;
  width: 17px; height: 17px; background: #fff; border-radius: 50%;
  transition: var(--speed); box-shadow: var(--shadow-1);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { inset-inline-start: 19px; }

.logo-box { display: flex; align-items: center; gap: 12px; }
.logo-box img {
  height: 44px; max-width: 170px; object-fit: contain;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 5px;
}

/* ═══ preview ═══ */
.preview { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-2); }
.preview-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: var(--surface);
  border-bottom: 1px solid var(--line); flex: none;
}
.tpl-chips { display: flex; gap: 5px; overflow-x: auto; }
.tpl-chips::-webkit-scrollbar { height: 0; }
.tpl-chip {
  border: 1px solid var(--line-2); background: transparent; color: var(--text-2);
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 5px 11px; border-radius: 16px; cursor: pointer;
  white-space: nowrap; transition: var(--speed);
}
.tpl-chip:hover { color: var(--text); border-color: var(--text-3); }
.tpl-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.zoom { display: flex; align-items: center; gap: 5px; }
.zoom span { font-size: 11.5px; color: var(--text-2); min-width: 40px;
  text-align: center; font-variant-numeric: tabular-nums; }

.preview-scroll { flex: 1; overflow: auto; padding: 22px; position: relative;
  display: flex; justify-content: center; align-items: flex-start; }
.paper-wrap {
  transform-origin: top center; transition: transform .18s ease;
  box-shadow: var(--shadow-3); border-radius: 3px; background: #fff;
  flex: none;
}
#paper { width: 210mm; height: 297mm; border: 0; display: block; border-radius: 3px; }

.preview-loading {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg-2) 55%, transparent);
  backdrop-filter: blur(1px);
}
.preview-loading.on { display: flex; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.totals-bar {
  display: flex; gap: 4px; padding: 9px 14px; flex: none;
  background: var(--surface); border-top: 1px solid var(--line);
}
.tb-cell {
  flex: 1; display: flex; flex-direction: column; gap: 1px;
  padding: 4px 10px; border-radius: 8px; min-width: 0;
}
.tb-cell span { font-size: 10.5px; color: var(--text-3); font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; }
.tb-cell b { font-size: 14px; direction: ltr; text-align: start;
  font-variant-numeric: tabular-nums; }
.tb-cell.total { background: var(--accent); }
.tb-cell.total span { color: rgba(255,255,255,.75); }
.tb-cell.total b { color: #fff; font-size: 16px; }
.tb-cell.hidden { display: none; }

/* ═══ modals ═══ */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(9,12,17,.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade .15s ease;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-3);
  width: min(640px, 100%); max-height: 82vh; display: flex; flex-direction: column;
  border: 1px solid var(--line);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); flex: none;
}
.modal-body { overflow-y: auto; padding: 14px 16px; }

.hist-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  margin-bottom: 8px; cursor: pointer; transition: var(--speed);
}
.hist-row:hover { border-color: var(--accent); background: var(--surface-2); }
.hist-main { flex: 1; min-width: 0; }
.hist-num { font-size: 13px; font-weight: 700; direction: ltr; }
.hist-sub { font-size: 11.5px; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-total { font-size: 13.5px; font-weight: 700; direction: ltr;
  font-variant-numeric: tabular-nums; }
.hist-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px;
  background: var(--surface-3); color: var(--text-2); text-transform: uppercase;
}

.cat-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  margin-bottom: 7px; cursor: pointer; transition: var(--speed);
}
.cat-row:hover { border-color: var(--accent); background: var(--surface-2); }
.cat-main { flex: 1; min-width: 0; }
.cat-desc { font-size: 13px; font-weight: 600; }
.cat-sub { font-size: 11.5px; color: var(--text-3); }
.cat-price { font-size: 13px; font-weight: 700; direction: ltr; }

/* ═══ toasts ═══ */
#toasts {
  position: fixed; inset-block-end: 20px; inset-inline-end: 20px;
  z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 15px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-2); font-size: 13px; font-weight: 500;
  max-width: 380px; animation: toastin .22s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes toastin { from { opacity: 0; transform: translateY(10px) scale(.97); } }
.toast.ok { border-inline-start: 3px solid #16a34a; }
.toast.err { border-inline-start: 3px solid #dc2626; }
.toast.info { border-inline-start: 3px solid var(--accent); }
.toast .ti { flex: none; }
.toast.ok .ti { color: #16a34a; }
.toast.err .ti { color: #dc2626; }
.toast.info .ti { color: var(--accent); }

/* ═══ scrollbars ═══ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px;
  border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ═══ narrow screens ═══ */
@media (max-width: 1180px) {
  .panel { width: 400px; }
  .doc-chip { display: none; }
}
@media (max-width: 940px) {
  body { overflow: auto; }
  .workspace { flex-direction: column; }
  .panel { width: 100%; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .preview { min-height: 70vh; }
  .topbar { flex-wrap: wrap; }
}

/* ── client price list ── */
.pl-items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.pl-item-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  transition: border-color var(--speed), box-shadow var(--speed);
}

.pl-item-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
}

.pl-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.pl-item-info {
  flex: 1;
  min-width: 0;
}

.pl-item-desc {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.pl-item-details {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 2px;
}

.pl-item-action {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.pl-item-price {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  direction: ltr;
  display: inline-block;
}

.pl-item-price small {
  font-size: 10.5px;
  color: var(--text-3);
  font-weight: normal;
}

.pl-item-history-toggle {
  margin-top: 4px;
}

.pl-history-table {
  width: 100%;
  font-size: 11.5px;
  border-collapse: collapse;
  text-align: start;
}

.pl-history-table th {
  font-weight: 600;
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
}

.pl-history-table td {
  padding: 6px 6px;
}

/* ── status badges ── */
.status-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status-badge.draft {
  background: var(--surface-3);
  color: var(--text-2);
}

.status-badge.sent {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.status-badge.approved {
  background: rgba(22, 163, 74, 0.15);
  color: #16a34a;
}

.status-badge.declined {
  background: rgba(220, 38, 38, 0.15);
  color: #dc2626;
}

.status-badge.expired {
  background: rgba(217, 119, 6, 0.15);
  color: #d97706;
}

/* ── BOM Costing ── */
.costing-materials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding-inline-end: 6px;
  margin-top: 10px;
}

.cost-mat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cost-mat-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cost-mat-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.cost-mat-row label {
  margin-bottom: 0 !important;
  flex: 1;
  min-width: 0;
}

.cost-mat-row label > span {
  font-size: 9px;
  margin-bottom: 2px;
  color: var(--text-3);
  text-transform: uppercase;
}

.cost-mat-row input {
  padding: 4px 6px;
  font-size: 11.5px;
  border-radius: 6px;
}

.costing-products-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.cost-prod-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  transition: border-color var(--speed);
}

.cost-prod-card:hover {
  border-color: var(--accent);
}

.cost-prod-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.cost-prod-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

.cost-prod-totals {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.cost-prod-calc {
  text-align: end;
}

.cost-prod-val {
  font-size: 11.5px;
  color: var(--text-2);
}

.cost-prod-val b {
  font-size: 13px;
  color: var(--text);
}

.cost-prod-markup {
  width: 70px;
  margin-bottom: 0 !important;
}

.cost-prod-markup input {
  padding: 5px 6px;
  font-size: 12px;
  text-align: center;
}

.cost-prod-bom-toggle {
  margin-top: 8px;
}

.cost-prod-bom-table {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
  margin-top: 8px;
  border-top: 1px dashed var(--line);
}

.cost-prod-bom-table th {
  padding: 4px;
  text-align: start;
  color: var(--text-3);
  border-bottom: 1px solid var(--line);
}

.cost-prod-bom-table td {
  padding: 5px 4px;
  border-bottom: 1px solid var(--surface-3);
}

/* ── Material Cost History dropdowns ── */
.cost-mat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.btn-mat-hist {
  padding: 2px;
  background: transparent;
  border: 0;
  color: var(--text-3);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--speed), background-color var(--speed);
}

.btn-mat-hist:hover {
  color: var(--accent);
  background-color: var(--surface-3);
}

.btn-mat-hist svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.cost-mat-hist-div {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  overflow-x: auto;
}

.cost-mat-hist-table {
  width: 100%;
  font-size: 10px;
  border-collapse: collapse;
}

.cost-mat-hist-table th {
  padding: 2px 4px;
  text-align: start;
  color: var(--text-3);
  border-bottom: 1px solid var(--line);
}

.cost-mat-hist-table td {
  padding: 3px 4px;
  border-bottom: 1px solid var(--surface-3);
}

/* ── Orders & Invoices ── */
.orders-list, .invoices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.order-card, .invoice-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color var(--speed);
}

.order-card:hover, .invoice-card:hover {
  border-color: var(--accent);
}

.order-header, .invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.order-num, .invoice-num {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

.order-sub, .invoice-sub {
  font-size: 11.5px;
  color: var(--text-2);
}

.order-actions, .invoice-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.status-badge.pending {
  background: rgba(234, 179, 8, 0.15);
  color: #ca8a04;
}

.status-badge.in_production {
  background: rgba(37, 99, 235, 0.15);
  color: #2563eb;
}

.status-badge.completed {
  background: rgba(22, 163, 74, 0.15);
  color: #16a34a;
}

.status-badge.invoiced {
  background: rgba(147, 51, 234, 0.15);
  color: #9333ea;
}

.status-badge.issued {
  background: rgba(37, 99, 235, 0.15);
  color: #2563eb;
}

.status-badge.paid {
  background: rgba(22, 163, 74, 0.15);
  color: #16a34a;
}

.status-badge.partially_paid {
  background: rgba(234, 179, 8, 0.15);
  color: #ca8a04;
}

/* ── BOM Requisition Table ── */
.bom-req-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
  margin-top: 10px;
}

.bom-req-table th {
  padding: 8px 6px;
  text-align: start;
  background: var(--surface-2);
  color: var(--text-2);
  border-bottom: 2px solid var(--line);
}

.bom-req-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}

/* ── Dashboard ── */
.dash-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.dash-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dash-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-2);
  font-weight: 600;
}

.dash-icon {
  font-size: 14px;
}

.dash-val {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
}

.dash-sub {
  font-size: 10px;
  color: var(--text-3);
}

.dash-pipeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pipe-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pipe-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
}

.pipe-bar-bg {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}

.pipe-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.dash-activity {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.act-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 11.5px;
}

/* ── PO Stepper Line & Status Log ── */
.po-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  position: relative;
}

.po-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  position: relative;
  z-index: 1;
}

.po-step-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
  color: var(--text-3);
}

.po-step.done .po-step-dot {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.po-step.active .po-step-dot {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.po-step-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
}

.po-step.done .po-step-label, .po-step.active .po-step-label {
  color: var(--text);
}

/* ══════════════════════════════════════════════════════════════════════════
   Module rail and layout modes
   The app outgrew a single tab strip: 11 tabs overflowed a 460px panel with
   the scrollbar hidden, so half the app was invisible. Navigation is now two
   levels — a module rail for "what am I working on", and sub-tabs only inside
   the quote editor for "which part of this document".
   ══════════════════════════════════════════════════════════════════════════ */

.rail {
  width: 82px; flex: none; display: flex; flex-direction: column; gap: 2px;
  padding: 10px 7px; background: var(--surface);
  border-inline-end: 1px solid var(--line); overflow-y: auto;
}
.rail::-webkit-scrollbar { width: 0; }

.rail-btn {
  position: relative; border: 0; background: transparent; color: var(--text-3);
  font-family: inherit; font-size: 10.5px; font-weight: 600; line-height: 1.25;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 9px 3px; border-radius: 10px; cursor: pointer;
  transition: background var(--speed), color var(--speed); text-align: center;
}
.rail-btn svg { width: 19px; height: 19px; }
.rail-btn:hover { background: var(--surface-3); color: var(--text); }
.rail-btn.on { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.rail-btn.on::before {
  content: ""; position: absolute; inset-inline-start: -7px; top: 50%;
  transform: translateY(-50%); width: 3px; height: 22px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}
html[dir="rtl"] .rail-btn.on::before { border-radius: 3px 0 0 3px; }

.rail-badge {
  position: absolute; top: 4px; inset-inline-end: 8px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 9.5px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
}
.rail-badge.on { display: flex; }

.rail-sep { height: 1px; background: var(--line); margin: 7px 6px; flex: none; }

/* ── layout modes ──
   'split' = document editor beside the live A4 preview.
   'full'  = business views get the entire window instead of a narrow column
             sitting next to an irrelevant blank quote. */
.workspace[data-layout="full"] .preview { display: none; }
.workspace[data-layout="full"] .panel { width: 100%; border-inline-end: 0; }
.workspace[data-layout="full"] .panel-body { padding: 18px 20px 26px; }
.workspace[data-layout="full"] .panel-body > .pane { max-width: 1180px; margin-inline: auto; }
.workspace[data-layout="full"] .dash-widgets-grid { grid-template-columns: 1fr 1fr 1fr; }

.tabs.hidden { display: none; }
.tabs button.hidden { display: none; }

/* ── top-bar overflow menu ── */
.menu-wrap { position: relative; }
.menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 7px);
  min-width: 216px; padding: 6px; z-index: 60; display: none;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-2);
}
.menu.on { display: block; animation: fade .13s ease; }
.menu button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 0; background: transparent; color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 500;
  border-radius: 8px; cursor: pointer; text-align: start;
}
.menu button:hover { background: var(--surface-3); }
.menu button svg { flex: none; color: var(--text-3); }
.menu button:hover svg { color: var(--accent); }
.menu .sep { height: 1px; background: var(--line); margin: 5px 3px; }
.menu .k {
  margin-inline-start: auto; font-size: 10.5px; color: var(--text-3);
  font-weight: 600; letter-spacing: .02em;
}

.topbar .group-actions { display: flex; align-items: center; gap: 8px; }
.topbar .group-actions.hidden { display: none; }

/* ── richer empty states ── */
.empty-rich {
  text-align: center; padding: 34px 20px; color: var(--text-3);
  border: 1px dashed var(--line-2); border-radius: var(--radius);
}
.empty-rich svg { width: 30px; height: 30px; margin-bottom: 10px; color: var(--line-2); }
.empty-rich .et { font-size: 13.5px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.empty-rich .es { font-size: 12px; line-height: 1.6; max-width: 340px; margin: 0 auto; }
.empty-rich .btn { margin-top: 14px; }

/* ── module heading shown above full-width views ── */
.module-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.module-head h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.module-head .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

@media (max-width: 1100px) {
  .rail { width: 62px; }
  .rail-btn { font-size: 0; gap: 0; padding: 11px 3px; }
  .rail-btn svg { width: 20px; height: 20px; }
}

.dash-icon { display: inline-flex; color: var(--text-3); }
.dash-icon svg { width: 15px; height: 15px; }
.dash-card:hover .dash-icon { color: var(--accent); }
