:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --brand: #0f766e; --brand-ink: #ffffff; --warn: #b45309; --pro: #a16207;
  --radius: 12px;
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --card: #111a2b; --text: #e5e7eb; --muted: #9ca3af; --line: #253046; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }
.logo-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 1.2rem; }
.top-actions { display: flex; gap: 8px; }
.hero { text-align: center; padding: 18px 16px 4px; color: var(--muted); max-width: 760px; margin: 0 auto; }

.btn { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 9px;
  cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.pro { border-color: var(--pro); color: var(--pro); font-weight: 600; }
.btn.pro.active { background: var(--pro); color: #fff; }
.btn.link { border: none; background: none; color: var(--brand); padding: 4px 6px; }
.btn.icon { padding: 4px 10px; font-size: 1.1rem; line-height: 1; }

.workspace { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px;
  padding: 16px 20px 32px; max-width: 1280px; margin: 0 auto; align-items: start; }
.editor { display: flex; flex-direction: column; gap: 14px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  padding: 12px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 700; padding: 0 6px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: .88rem; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: var(--bg); color: var(--text); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-row { display: grid; grid-template-columns: 1fr 64px 92px auto; gap: 6px; margin-bottom: 6px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
.logo-row { display: flex; align-items: end; gap: 8px; }
.logo-row .file { flex: 1; }
.colors { display: flex; align-items: center; gap: 10px; font-size: .88rem; color: var(--muted); flex-wrap: wrap; }
#swatches { display: flex; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; position: relative; }
.swatch.on { border-color: var(--text); }
.swatch.locked::after { content: "🔒"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.warn { color: var(--warn); font-size: .8rem; }
.muted { color: var(--muted); font-size: .85rem; }
.history { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.history summary { cursor: pointer; font-weight: 600; }
.history ul { list-style: none; padding: 0; margin: 8px 0 0; }
.history li { display: flex; justify-content: space-between; gap: 6px; padding: 6px 0; border-top: 1px solid var(--line); font-size: .9rem; }

/* ---------- the invoice paper (always light, like a printed page) ---------- */
.paper-wrap { position: sticky; top: 72px; }
.paper { --accent: #0f766e; background: #fff; color: #111827; border-radius: 6px; padding: 36px 40px;
  box-shadow: 0 6px 24px rgba(0,0,0,.08); min-height: 800px; font-size: 14px; }
.paper .lb { display: inline-flex; flex-direction: column; line-height: 1.15; }
.paper .lb b { font-weight: 600; }
.paper .lb i { font-style: normal; font-size: .75em; color: #6b7280; direction: ltr; }
.inv-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--accent); padding-bottom: 16px; }
.inv-head h2 { margin: 6px 0 4px; font-size: 1.25rem; color: var(--accent); }
.inv-head p { margin: 2px 0; color: #374151; }
.inv-logo { max-height: 70px; max-width: 160px; display: block; }
.title { text-align: end; }
.title h1 { margin: 0; font-size: 1.35rem; color: var(--accent); }
.title h1.en { font-size: .95rem; color: #6b7280; font-weight: 600; margin-bottom: 8px; }
.meta { margin-inline-start: auto; border-collapse: collapse; }
.meta td { padding: 3px 0 3px 12px; text-align: start; }
.meta td:last-child { font-weight: 600; }
.bill-to { margin: 18px 0 6px; padding: 10px 14px; background: #f9fafb; border-radius: 8px; }
.bill-to h4 { margin: 0 0 4px; color: var(--accent); }
.bill-to p { margin: 2px 0; }
.lines { width: 100%; border-collapse: collapse; margin-top: 18px; }
.lines th { background: var(--accent); color: #fff; padding: 8px; font-weight: 600; text-align: center; }
.lines th .lb i { color: rgba(255,255,255,.8); }
.lines td { padding: 8px; border-bottom: 1px solid #e5e7eb; text-align: center; }
.lines .d { text-align: start; width: 45%; }
.bottom { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-top: 18px; }
.qr-box { width: 140px; }
.qr-box img, .qr-box canvas { width: 120px; height: 120px; }
.totals { border-collapse: collapse; min-width: 300px; }
.totals td { padding: 7px 10px; border-bottom: 1px solid #e5e7eb; }
.totals td:last-child { text-align: end; white-space: nowrap; direction: ltr; }
.totals .grand td { background: var(--accent); color: #fff; font-weight: 700; font-size: 1.05rem; }
.totals .grand .lb i { color: rgba(255,255,255,.85); }
.notes { margin-top: 22px; padding-top: 10px; border-top: 1px dashed #d1d5db; white-space: pre-wrap; color: #374151; }
.mark { margin-top: 28px; text-align: center; font-size: 11px; color: #9ca3af; }

/* ---------- landing info ---------- */
.info { max-width: 1000px; margin: 0 auto; padding: 8px 20px 24px; }
.info h2 { text-align: center; }
.feats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.feat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.feat h3 { margin: 0 0 4px; font-size: 1rem; color: var(--brand); }
.feat p { margin: 0; color: var(--muted); font-size: .92rem; }
#faq details { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; }
#faq summary { cursor: pointer; font-weight: 600; }
footer { text-align: center; color: var(--muted); padding: 20px; font-size: .9rem; }

dialog { border: none; border-radius: 16px; padding: 24px; max-width: 380px; width: calc(100% - 32px);
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin-top: 0; color: var(--pro); }
dialog ul { padding-inline-start: 18px; }
dialog .btn.primary { width: 100%; text-align: center; margin: 6px 0 4px; }
.code-row { display: flex; gap: 6px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff;
  padding: 10px 18px; border-radius: 10px; z-index: 20; }

@media screen and (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; padding: 12px 16px 24px; }
  .paper-wrap { position: static; }
  .paper { padding: 20px 16px; min-height: 0; font-size: 12.5px; overflow-x: auto; }
  .inv-head, .bottom { flex-direction: column; }
  .title { text-align: start; }
  .meta { margin-inline-start: 0; }
  .totals { min-width: 0; width: 100%; }
}
@media screen and (max-width: 420px) {
  .item-row { grid-template-columns: 1fr 52px 76px auto; }
  .topbar { padding: 10px 16px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .no-print { display: none !important; }
  .workspace { display: block; padding: 0; }
  .paper-wrap { position: static; }
  .paper { box-shadow: none; padding: 0; min-height: 0; }
  .lines th, .totals .grand td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
