/* ================= رابط کاربری برنامه ================= */
:root {
  --bg: #eef1f6; --panel: #ffffff; --ink: #1f2937; --muted: #6b7280; --line: #e3e7ee;
  --brand: #4f46e5; --brand-d: #4338ca; --brand-l: #eef0ff; --ok: #059669; --bad: #dc2626;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Vazirmatn, Tahoma, sans-serif; font-size: 13.5px; line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg.i { width: 18px; height: 18px; flex: none; }

/* ---------- نوار بالا ---------- */
.topbar { height: 62px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 18px; padding: 0 18px; position: sticky; top: 0; z-index: 20; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; white-space: nowrap; }
.logo .mark { width: 36px; height: 36px; border-radius: 11px; background: linear-gradient(135deg, #4f46e5, #0ea5e9); display: grid; place-items: center; color: #fff; }
.tabs { display: flex; background: #f1f3f8; border-radius: 12px; padding: 4px; gap: 4px; }
.tabs button { border: 0; background: transparent; padding: 7px 16px; border-radius: 9px; display: flex; align-items: center; gap: 7px; font-weight: 700; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--brand); box-shadow: 0 1px 4px rgba(15, 23, 42, .1); }
.spacer { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; height: 38px; padding: 0 13px; display: inline-flex; align-items: center; gap: 7px; font-weight: 600; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: #f7f8fb; border-color: #cfd5df; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f1f3f8; }
.btn.danger { color: var(--bad); }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.split { display: inline-flex; border-radius: 9px; overflow: hidden; }
.split .btn { border-radius: 0; border-left-width: 0; }
.split .btn:first-child { border-radius: 0 9px 9px 0; }
.split .btn:last-child { border-radius: 9px 0 0 9px; border-left-width: 1px; }
.split .btn.primary + .btn.primary { border-right: 1px solid rgba(255, 255, 255, .25); }

/* ---------- چیدمان ---------- */
.layout { display: grid; grid-template-columns: 480px 1fr; height: calc(100vh - 62px); }
.formcol { overflow-y: auto; padding: 16px; border-left: 1px solid var(--line); background: #f6f7fb; }
.previewcol { overflow: auto; display: flex; flex-direction: column; }

/* ---------- کارت‌های فرم ---------- */
details.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; }
details.card > summary { list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 14px; user-select: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .ic { width: 30px; height: 30px; border-radius: 9px; background: var(--brand-l); color: var(--brand); display: grid; place-items: center; }
details.card > summary .chev { margin-right: auto; color: var(--muted); transition: transform .2s; }
details.card[open] > summary .chev { transform: rotate(180deg); }
details.card > summary .badge { font-size: 11px; background: #f1f3f8; color: var(--muted); padding: 1px 8px; border-radius: 20px; font-weight: 600; }
.card-body { padding: 2px 14px 14px; }

.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.c1 { grid-column: span 1; } .c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f > label, .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.in, .f input:not([type=checkbox]):not([type=file]), .f select, .f textarea {
  width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
.f textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; line-height: 1.8; }
.f input:focus, .f select:focus, .f textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
.f input.money, .f input.ltr { direction: ltr; text-align: left; }
.f input.money { font-variant-numeric: tabular-nums; }
.f input[type=time] { direction: ltr; text-align: center; }
.f .hint { font-size: 11px; color: var(--muted); }
.with-btn { display: flex; gap: 6px; }
.with-btn > :first-child { flex: 1; min-width: 0; }

.seg-ctrl { display: inline-flex; background: #f1f3f8; border-radius: 10px; padding: 3px; gap: 3px; }
.seg-ctrl button { border: 0; background: transparent; padding: 5px 14px; border-radius: 8px; font-weight: 700; color: var(--muted); font-size: 12.5px; }
.seg-ctrl button.on { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }

.sub-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-top: 10px; background: #fbfcfe; position: relative; }
.sub-card .sc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 800; }
.sub-card .sc-head .num { width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 12px; }
.sub-card .sc-head .tools { margin-right: auto; display: flex; gap: 4px; }
.sub-card .sc-head .total { font-size: 12.5px; color: var(--brand); font-weight: 800; }
.al-prev { height: 38px; min-width: 64px; max-width: 110px; border: 1px solid var(--line); border-radius: 9px; background: #fff; display: grid; place-items: center; padding: 3px 6px; overflow: hidden; }
.al-prev img { max-width: 100%; max-height: 30px; display: block; }
.al-prev .al-badge { width: 28px; height: 28px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; }

.pax { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 10px 0; border-top: 1px dashed var(--line); }
.pax:first-child { border-top: 0; padding-top: 2px; }
.pax .pn { width: 24px; height: 24px; border-radius: 50%; background: #f1f3f8; color: var(--muted); display: grid; place-items: center; font-size: 12px; font-weight: 700; margin-top: 26px; }

.addrow { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.addrow .btn { border-style: dashed; }

/* فیلترهای هزینه */
.fee { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid #f0f2f6; }
.fee:first-child { border-top: 0; }
.fee .fee-body { grid-column: 1 / -1; display: none; gap: 8px; }
.fee.on .fee-body { display: grid; grid-template-columns: repeat(6, 1fr); }
.fee .fee-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.fee .fee-title small { color: var(--muted); font-weight: 500; }
.switch { position: relative; width: 40px; height: 22px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #d5dae3; border-radius: 22px; transition: .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 3px; right: 3px; transition: .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { right: 21px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 3px 11px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.chips button:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-l); }

.svc { display: grid; grid-template-columns: 1fr 64px 120px 34px; gap: 6px; align-items: end; margin-top: 8px; }
.svc .tot { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); margin-top: -2px; }

.summary { background: linear-gradient(135deg, #312e81, #4f46e5); color: #fff; border-radius: 12px; padding: 12px 14px; margin-top: 12px; }
.summary .r { display: flex; justify-content: space-between; font-size: 12.5px; opacity: .9; }
.summary .r.big { font-size: 16px; font-weight: 800; opacity: 1; margin-top: 4px; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, .25); }
.summary .w { font-size: 11.5px; opacity: .8; margin-top: 4px; }

/* ---------- پیش‌نمایش ---------- */
.ptools { position: sticky; top: 0; z-index: 5; background: rgba(238, 241, 246, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 10px 18px; display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.ptools .grp { display: flex; align-items: center; gap: 8px; }
.ptools .grp > .lbl { white-space: nowrap; }
.tplbtns { display: flex; gap: 6px; }
.tplbtns button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 4px 10px 4px 6px; display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; }
.tplbtns button .sw { width: 22px; height: 26px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, .08); }
.tplbtns button.on { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(79, 70, 229, .2); color: var(--brand); }
.pals { display: flex; gap: 6px; align-items: center; }
.pals button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.pals button.on { box-shadow: 0 0 0 2px var(--brand); }
.pals button.auto { background: conic-gradient(#1e3a8a, #0f766e, #7f1d3a, #5b21b6, #1e3a8a); }
.ptools select { height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: #fff; }
.stage { flex: 1; padding: 24px; display: flex; justify-content: center; }
.paper-wrap { position: relative; flex: none; }
.paper { position: absolute; top: 0; left: 0; transform-origin: 0 0; box-shadow: 0 10px 40px rgba(15, 23, 42, .14); border-radius: 2px; }

/* میزبان خروجی تصویر (بیرون از صفحه) */
#export-host { position: absolute; top: 0; left: -12000px; width: 794px; pointer-events: none; }
#print-host { display: none; }

/* ---------- مودال ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: none; align-items: flex-start; justify-content: center; z-index: 50; padding: 40px 16px; overflow: auto; }
.modal.show { display: flex; }
.modal .box { background: #fff; border-radius: 16px; width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal .mh { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 800; font-size: 15px; }
.modal .mh .btn { margin-right: auto; }
.modal .mb { padding: 16px 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.logo-up { display: flex; align-items: center; gap: 12px; }
.logo-up .lp { width: 110px; height: 64px; border: 1px dashed #cfd5df; border-radius: 10px; display: grid; place-items: center; background: #fafbfc; overflow: hidden; color: var(--muted); font-size: 11px; }
.logo-up .lp img { max-width: 100%; max-height: 100%; }
.sep { height: 1px; background: var(--line); margin: 14px 0; }

/* ---------- تقویم شمسی ---------- */
.jdp { position: absolute; z-index: 100; display: none; width: 260px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 34px rgba(15, 23, 42, .18); padding: 10px; font-size: 12.5px; }
.jdp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.jdp-head button { border: 0; background: #f1f3f8; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.jdp-wd, .jdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jdp-wd span { color: var(--muted); font-size: 11.5px; padding: 3px 0; }
.jdp-grid button { border: 0; background: transparent; height: 31px; border-radius: 8px; }
.jdp-grid button:hover { background: var(--brand-l); }
.jdp-grid button.fri { color: var(--bad); }
.jdp-grid button.today { box-shadow: inset 0 0 0 1px var(--brand); }
.jdp-grid button.sel { background: var(--brand); color: #fff; }
.jdp-foot { text-align: center; margin-top: 6px; }
.jdp-foot button { border: 0; background: var(--brand-l); color: var(--brand); border-radius: 8px; padding: 3px 14px; font-weight: 700; }

/* ---------- پیام ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; transition: .25s; z-index: 200; pointer-events: none; font-weight: 600; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.busy { position: fixed; inset: 0; background: rgba(255, 255, 255, .6); display: none; align-items: center; justify-content: center; z-index: 150; font-weight: 800; font-size: 15px; }
.busy.show { display: flex; }

/* ---------- واکنش‌گرا ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .formcol { border-left: 0; overflow: visible; }
  .previewcol { overflow: visible; }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .c1, .c2, .c3, .c4, .c5, .c6 { grid-column: span 2; }
  .fee.on .fee-body { grid-template-columns: 1fr 1fr; }
  .fee.on .fee-body > * { grid-column: span 1 !important; }
  .svc { grid-template-columns: 1fr 1fr; }
  .stage { padding: 12px 8px; }
  .topbar .btn .t { display: none; }
}

/* ---------- چاپ ---------- */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body > *:not(#print-host) { display: none !important; }
  #print-host { display: block !important; }
  #print-host .inv { box-shadow: none; }
  #print-host .inv, #print-host .inv * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
