:root {
  --brand: #8e1b62;
  --brand-dark: #6f124b;
  --gold: #d89a22;
  --ink: #222;
  --muted: #667085;
  --line: #d0d5dd;
  --soft: #f7f5f7;
  --paper: #fff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Tahoma, Arial, sans-serif;
  background: #eef1f4;
  color: var(--ink);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 34px;
  background: linear-gradient(135deg, #fff, #f9f3f7);
  border-bottom: 1px solid #ddd;
}
.app-header h1 { margin: 3px 0; color: var(--brand); font-size: 30px; }
.app-header p { margin: 0; color: var(--muted); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 1.5px; color: var(--gold); }
.badge { background: var(--brand); color: white; padding: 9px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; }

.app-shell { width: min(1240px, 96vw); margin: 24px auto 50px; }
.control-card { background: white; border: 1px solid #d9dde3; border-radius: 16px; padding: 18px; box-shadow: 0 5px 20px rgba(30,40,50,.06); }
.control-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: end; }
.file-box { display: flex; flex-direction: column; gap: 7px; font-weight: 700; }
.file-box input { padding: 12px; border: 1px dashed var(--brand); border-radius: 10px; background: #fffafd; }
.file-box small { color: var(--muted); font-weight: 400; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
button { border: 0; border-radius: 10px; background: var(--brand); color: white; padding: 12px 17px; font-weight: 700; cursor: pointer; }
button:hover:not(:disabled) { background: var(--brand-dark); }
button.secondary { background: #3f4650; }
button:disabled { opacity: .45; cursor: not-allowed; }
.status { margin-top: 14px; padding: 10px 12px; border-radius: 9px; background: #f6f8fa; color: #344054; font-size: 14px; }
.status.ok { background: #ecfdf3; color: #027a48; }
.status.warn { background: #fffaeb; color: #b54708; }
.status.error { background: #fef3f2; color: #b42318; }
.notice { margin-top: 10px; color: #7a4b00; background: #fff8e7; border-left: 4px solid var(--gold); padding: 9px 12px; font-size: 13px; line-height: 1.5; }

.preview-wrap { margin-top: 24px; overflow-x: auto; padding-bottom: 18px; }
.invoice-page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: var(--paper);
  padding: 13mm 12mm 11mm;
  box-shadow: 0 10px 35px rgba(0,0,0,.14);
  font-size: 11px;
  color: #202124;
}
.invoice-page.empty-state { display: grid; place-items: center; color: var(--muted); }
.empty-message { display: flex; flex-direction: column; gap: 8px; text-align: center; }

.invoice-top { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 16px; align-items: center; }
.invoice-title-en { font-size: 19px; color: var(--gold); font-weight: 700; }
.invoice-title-ar { font-size: 20px; color: var(--gold); font-weight: 700; text-align: center; direction: rtl; }
.company-lockup { text-align: right; }
.company-mark { display: inline-flex; align-items: center; gap: 8px; color: var(--brand); font-weight: 900; font-size: 20px; }
.company-mark::before { content: "◆"; font-size: 29px; transform: rotate(20deg); }
.company-en { color: #4a4a4a; font-weight: 700; margin-top: 2px; }

.top-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 22px; }
.top-meta.single-column { grid-template-columns: 1fr; }
.customer-meta { margin-top: 12px; }
.meta-box { border-top: 2px solid var(--brand); padding-top: 8px; }
.meta-row { display: grid; grid-template-columns: 145px 1fr; gap: 8px; margin: 5px 0; align-items: baseline; }
.meta-row .label { color: #555; }
.meta-row .value { font-weight: 700; border-bottom: 1px solid #c8c8c8; padding: 2px 4px 4px; min-height: 20px; }
.meta-row.rtl { direction: rtl; grid-template-columns: 165px 1fr; }
.meta-row .value bdi[dir="ltr"] { direction: ltr; unicode-bidi: isolate; display: inline-block; width: 100%; text-align: right; }
.bilingual-label { display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.bilingual-label .label-en { direction: ltr; text-align: right; font-size: 9px; color: #6b7280; }
.bilingual-label .label-ar { direction: rtl; text-align: right; font-size: 11px; color: #444; }
.bilingual-row { align-items: center; }

.vehicle-grid { margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); border: 1px solid #333; }
.vehicle-cell { display: grid; grid-template-columns: 42% 58%; min-height: 39px; border-right: 1px solid #c9c9c9; border-bottom: 1px solid #c9c9c9; }
.vehicle-label { background: var(--brand); color: white; padding: 7px; font-weight: 700; text-align: center; }
.vehicle-value { padding: 8px; text-align: center; display: grid; place-items: center; }
.vehicle-label small { display: block; font-size: 9px; font-weight: 500; margin-top: 2px; }

.items-table { width: 100%; border-collapse: collapse; margin-top: 18px; table-layout: fixed; }
.items-table th, .items-table td { border: 1px solid #222; padding: 7px 5px; text-align: center; vertical-align: middle; }
.items-table thead th { background: #f1f1f1; font-size: 10px; }
.items-table .desc { width: 25%; }
.items-table td.desc { text-align: right; direction: rtl; }
.items-table .small-en { direction: ltr; text-align: left; color: #555; font-size: 9px; margin-top: 3px; }

.bottom-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 20px; margin-top: 18px; align-items: start; }
.summary-table { width: 100%; border-collapse: collapse; }
.summary-table td { border: 1px solid #222; padding: 7px 8px; }
.summary-table td:first-child { width: 47%; font-weight: 700; }
.amount-words { border: 1px solid #222; }
.words-row { display: grid; grid-template-columns: 1fr 150px; min-height: 47px; border-bottom: 1px solid #222; }
.words-row:last-child { border-bottom: 0; }
.words-value { padding: 8px; display: flex; align-items: center; }
.words-label { padding: 6px 8px; border-left: 1px solid #222; text-align: right; direction: rtl; font-size: 10px; }
.words-label strong { display: block; direction: ltr; text-align: left; margin-top: 4px; color: var(--brand); }

.signatures { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 36px; margin-top: 25px; }
.signature-box { min-height: 72px; }
.signature-title { display: flex; justify-content: space-between; font-weight: 700; }
.signature-line { border-bottom: 1px solid #999; margin-top: 28px; }

.invoice-footer { display: block; margin-top: 28px; padding-top: 12px; border-top: 3px solid var(--brand); }
.footer-text { text-align: center; color: #555; line-height: 1.55; }
.issue-stamp { text-align: right; margin-top: 10px; font-size: 9px; }

@media (max-width: 850px) {
  .app-header { flex-direction: column; align-items: flex-start; }
  .control-grid { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
}

@media print {
  body { background: white; }
  .app-header, .control-card { display: none !important; }
  .app-shell, .preview-wrap { width: auto; margin: 0; padding: 0; }
  .invoice-page { box-shadow: none; margin: 0; }
}

/* V4 bilingual labels: English + Arabic are always visible. */
.bilingual-label-inline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.15;
  text-align: right;
}
.label-en-inline {
  direction: ltr;
  text-align: right;
  font-size: 9px;
  color: #6b7280;
}
.label-ar-inline {
  direction: rtl;
  text-align: right;
  font-size: 11px;
  color: #444;
}
.label-divider { display: none; }
