:root {
  --navy: #1b3f94;
  --navy-dark: #0d0f39;
  --orange: #f37321;
  --orange-dark: #ea580c;
  --bg: #f3f4f8;
  --card: #ffffff;
  --line: #e3e6ef;
  --text: #1c2233;
  --muted: #6b7280;
  --soft: #fff4ec;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Poppins, system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
[dir="rtl"], .ar { font-family: Cairo, Poppins, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar .brand { height: 30px; }
.app-name { font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); padding-left: 12px; }
.spacer { flex: 1; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--navy); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--orange-dark); }
.btn.ai { background: linear-gradient(135deg, #1b3f94, #5b3fd6); border: 0; color: #fff; }
.btn.ai:hover { opacity: .92; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: wait; }

/* Layout */
.layout { display: grid; grid-template-columns: 460px 1fr; min-height: calc(100vh - 53px); }
.editor { border-right: 1px solid var(--line); padding: 16px; overflow-y: auto; height: calc(100vh - 53px); position: sticky; top: 53px; }
.preview-wrap { padding: 28px; overflow-x: auto; }
.mobile-tabs { display: none; }

/* Editor cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h2 .step { width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: #fff; font-size: 12px; display: grid; place-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label.f { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label.f input, label.f select, label.f textarea { display: block; width: 100%; margin-top: 3px; }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px #1b3f9420; }
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); }

/* Service tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 6px; background: #fff; cursor: pointer; text-align: center; font-size: 12px; font-weight: 500; line-height: 1.3; }
.tile .ic { display: block; font-size: 22px; margin-bottom: 4px; }
.tile.on { border-color: var(--orange); background: var(--soft); color: var(--orange-dark); }

/* Service editor */
.svc { border: 1px solid var(--line); border-left: 4px solid var(--orange); border-radius: 12px; padding: 12px; margin-top: 12px; }
.svc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 600; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pill { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 12px; }
.pill.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.pill small { opacity: .75; }
.items { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.item { display: flex; align-items: center; gap: 6px; }
.item input[type=text] { flex: 1; padding: 5px 8px; font-size: 13px; }
.item.off input[type=text] { color: #aab; text-decoration: line-through; }
.item input[type=checkbox] { accent-color: var(--orange); width: 16px; height: 16px; }
.x { border: 0; background: none; color: #b0b5c3; cursor: pointer; font-size: 16px; padding: 0 4px; }
.x:hover { color: #e11d48; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.suggest button { border: 1px dashed #5b3fd6; color: #5b3fd6; background: #f5f3ff; border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 12px; text-align: left; }
.price-row { display: grid; grid-template-columns: 1.3fr 1fr .8fr; gap: 6px; margin-top: 10px; align-items: end; }
.calc-total { white-space: nowrap; margin-top: 3px; padding: 8px 10px; border-radius: 8px; background: var(--soft); color: var(--orange-dark); font-weight: 700; font-size: 13px; }
.models-box { margin-top: 10px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px; }
.models-box.on { border-color: var(--orange); background: #fffaf6; }
.qty-line { margin-top: 10px; font-size: 13px; background: #f6f8fd; border-radius: 8px; padding: 8px 12px; }
.models-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 10px; font-size: 13px; border: 1px solid #f3732155; background: #fffaf6; border-radius: 8px; padding: 8px 12px; }
table.inv tr.sub td { color: var(--muted); font-size: 12.5px; padding-top: 6px; }
.section-ed { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-top: 8px; }
.section-ed input { width: 100%; font-weight: 600; margin-bottom: 6px; }
.section-ed textarea { width: 100%; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* ================= Proposal paper ================= */
.paper { width: 794px; margin: 0 auto; background: #fff; box-shadow: 0 10px 40px #0d0f391a; border-radius: 6px; overflow: hidden; color: #1c2233; }
.cover { background: var(--navy-dark); color: #fff; padding: 44px 50px 40px; position: relative; overflow: hidden; }
.cover::after { content: ""; position: absolute; right: -80px; top: -80px; width: 280px; height: 280px; border-radius: 50%; background: radial-gradient(circle, #f3732155, transparent 70%); }
.cover img { height: 38px; }
.cover .kicker { margin-top: 46px; color: var(--orange); font-weight: 600; letter-spacing: 3px; font-size: 12px; text-transform: uppercase; }
.cover h1 { margin: 6px 0 4px; font-size: 34px; line-height: 1.15; }
.cover .for { color: #c9d9f5; font-size: 15px; }
.cover .meta { display: flex; gap: 34px; margin-top: 30px; font-size: 12px; color: #c9d9f5; }
.cover .meta b { display: block; color: #fff; font-size: 13px; }
.chipline { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.chipline span { border: 1px solid #ffffff40; border-radius: 999px; padding: 3px 10px; font-size: 11px; }
.pbody { padding: 34px 50px 20px; }
.psec { margin-bottom: 28px; }
.psec h3 { font-size: 18px; color: var(--navy); margin: 0 0 10px; display: flex; align-items: center; gap: 10px; }
.psec h3::before { content: ""; width: 5px; height: 20px; background: var(--orange); border-radius: 3px; }
.psec p { margin: 0 0 8px; line-height: 1.7; white-space: pre-line; }
.muted { color: var(--muted); }
.pservice { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 18px; break-inside: avoid; }
.pservice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; background: #f6f8fd; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.pservice-head h4 { margin: 0; font-size: 17px; color: var(--navy); }
.pservice-head .pk { color: var(--orange-dark); font-weight: 600; font-size: 13px; }
.pservice-head .amt { text-align: right; white-space: nowrap; }
.pservice-head .amt b { display: block; font-size: 22px; color: var(--navy-dark); }
.pservice-head .amt span { font-size: 12px; color: var(--muted); }
.pservice-body { padding: 14px 20px 16px; }
.checks { list-style: none; padding: 0; margin: 10px 0 0; columns: 2; column-gap: 24px; }
.checks li { break-inside: avoid; padding: 4px 0 4px 24px; position: relative; font-size: 13px; line-height: 1.45; }
.checks li::before { content: "✓"; position: absolute; left: 0; top: 3px; color: var(--orange); font-weight: 800; }
.checks li[dir=rtl] { padding: 4px 24px 4px 0; }
.checks li[dir=rtl]::before { left: auto; right: 0; }
.pbody [dir=rtl] { font-family: Cairo, Poppins, sans-serif; }
.tl { margin-top: 10px; font-size: 12px; background: var(--soft); border-radius: 8px; padding: 8px 12px; }
.tl b { color: var(--orange-dark); }
table.inv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.inv th { text-align: left; background: var(--navy-dark); color: #fff; padding: 9px 12px; font-weight: 500; }
table.inv th:last-child, table.inv td:last-child { text-align: right; }
table.inv td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
table.inv tr.tot td { border: 0; padding: 5px 12px; }
table.inv tr.grand td { font-size: 17px; font-weight: 700; color: var(--navy-dark); border-top: 2px solid var(--navy-dark); padding-top: 10px; }
.why { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.why div { background: #f6f8fd; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.why div::before { content: "★ "; color: var(--orange); }
ol.terms { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.7; }
.sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 10px; }
.sign div { border-top: 1px solid #9aa; padding-top: 6px; font-size: 12px; color: var(--muted); margin-top: 50px; }
.pfoot { background: var(--navy-dark); color: #c9d9f5; padding: 16px 50px; display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.pfoot img { height: 24px; }
.empty { padding: 60px 50px; text-align: center; color: var(--muted); }

/* Dialog + toast */
dialog { border: 0; border-radius: 16px; padding: 20px; width: min(520px, 92vw); box-shadow: 0 20px 60px #0004; }
dialog h3 { margin-top: 0; }
.saved-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--navy-dark); color: #fff; padding: 10px 18px; border-radius: 10px; transition: transform .25s; z-index: 50; }
.toast.show { transform: translateX(-50%) translateY(0); }

/* Account menu, team, login */
.usermenu { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 30px #0d0f3922; padding: 6px; min-width: 200px; z-index: 30; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--bg); }
dialog.wide { width: min(760px, 94vw); }
.scroll-list { max-height: 55vh; overflow-y: auto; }
.add-user { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; margin-bottom: 12px; }
.add-user > * { min-width: 0; }
.role { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); margin-left: 6px; }
.role.sa { background: var(--soft); color: var(--orange-dark); }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 80% 10%, #f3732133, transparent 40%), var(--navy-dark); }
.login-card { background: #fff; border-radius: 18px; padding: 28px; width: min(380px, 100%); box-shadow: 0 30px 80px #0006; }
.login-card img { height: 34px; }
.login-card h1 { font-size: 20px; margin: 16px 0 2px; }
.login-card input { padding: 10px 12px; }
.err { color: #e11d48; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* Responsive */
@media (max-width: 1000px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .app-name { display: none; }
  .topbar .spacer { flex-basis: 100%; height: 0; }
  .topbar .btn { flex: 1; padding: 8px 6px; font-size: 12px; }
  .layout { grid-template-columns: 1fr; }
  .editor { position: static; height: auto; border-right: 0; }
  .preview-wrap { padding: 0 16px 16px; }
  .mobile-tabs { display: flex; position: sticky; top: 0; gap: 6px; margin: 0 -16px; padding: 10px 16px; background: var(--bg); z-index: 5; }
  .mobile-tabs button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px; }
  .mobile-tabs button.active { background: var(--navy); color: #fff; }
  body.m-edit .paper { display: none; }
  body.m-preview .editor { display: none; }
  .paper { width: 100%; }
  .cover, .pbody, .pfoot { padding-left: 20px; padding-right: 20px; }
  .checks { columns: 1; }
  .why { grid-template-columns: 1fr; }
  .editor .mobile-tabs { display: none; }
}
@media (max-width: 1000px) { .layout > .editor { order: 2; } .preview-wrap { order: 1; } }

/* Print → PDF */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print { display: none !important; }
  .layout { display: block; }
  .preview-wrap { padding: 0; }
  .paper, body.m-edit .paper { display: block; width: 100%; box-shadow: none; border-radius: 0; }
  .checks { columns: 2; }
  .psec, .pservice, table.inv tr { break-inside: avoid; }
}
