/* ================= Design tokens ================= */
:root {
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --text: #1a202e;
  --muted: #67708b;
  --border: #e3e6f0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 46, 0.05), 0 8px 24px rgba(20, 24, 46, 0.07);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ================= Header ================= */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 19px; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.brand strong { color: var(--accent); }
.header-nav { display: flex; align-items: center; gap: 20px; }
.header-nav a { color: var(--muted); text-decoration: none; font-size: 14.5px; font-weight: 500; }
.header-nav a:hover { color: var(--text); }

/* ================= Hero ================= */
.hero { padding: 42px 0 10px; text-align: center; }
.hero h1 { font-size: clamp(28px, 4.5vw, 42px); margin: 0 0 10px; letter-spacing: -0.02em; }
.hero p { max-width: 640px; margin: 0 auto; color: var(--muted); font-size: 16.5px; }

/* ================= Layout ================= */
.app-layout {
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  gap: 28px;
  align-items: start;
  padding-top: 30px;
  padding-bottom: 40px;
}
@media (max-width: 980px) {
  .app-layout { grid-template-columns: 1fr; }
  .preview-wrap { order: -1; }
}

/* ================= Editor panels ================= */
.editor { display: flex; flex-direction: column; gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow);
}
.panel-title h2 { margin: 0 0 14px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.span-2 { grid-column: span 2; }
.field span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, textarea, select {
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: #fbfbfe;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
textarea { resize: vertical; min-height: 40px; }

/* Logo upload */
.logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.logo-upload {
  width: 88px; height: 60px;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600;
  overflow: hidden; background: #fbfbfe;
  transition: border-color .15s;
}
.logo-upload:hover { border-color: var(--accent); color: var(--accent); }
.logo-upload img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Items */
.items-head, .item-row {
  display: grid;
  grid-template-columns: 1fr 64px 92px 84px 30px;
  gap: 8px;
  align-items: center;
}
.items-head { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; padding: 0 2px; }
.item-row { margin-bottom: 8px; }
.item-amount { font-size: 13.5px; font-weight: 600; text-align: right; padding-right: 2px; white-space: nowrap; overflow: hidden; }
.item-remove {
  border: none; background: none; color: #b6bdd1; font-size: 16px; cursor: pointer;
  border-radius: 6px; height: 30px;
}
.item-remove:hover { color: #e5484d; background: #fdf0f0; }
.add-item { margin-top: 4px; }

.totals-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
@media (max-width: 460px) { .totals-controls { grid-template-columns: 1fr 1fr; } }

/* Swatches */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  outline-offset: 2px;
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { border-color: var(--text); }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; font-size: 14.5px;
  border-radius: 9px; padding: 10px 18px;
  cursor: pointer; border: 1px solid transparent;
  transition: background .15s, transform .05s;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-subtle { background: #fff; color: var(--text); border-color: var(--border); }
.btn-subtle:hover { background: #f5f6fb; }
.btn-ghost-accent { background: var(--accent-soft); color: var(--accent); border: none; }
.btn-ghost-accent:hover { background: color-mix(in srgb, var(--accent) 18%, white); }
.btn-wide { width: 100%; padding: 12px; font-size: 15.5px; }

.editor-actions { display: flex; gap: 12px; }
.editor-actions .btn-primary { flex: 1; padding: 13px; font-size: 15.5px; }

/* ================= Invoice preview ================= */
.preview-sticky { position: sticky; top: 76px; }
.invoice-sheet {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(20,24,46,.08), 0 18px 50px rgba(20,24,46,.12);
  padding: 44px 48px;
  min-height: 700px;
  aspect-ratio: 210 / 297;
  overflow: hidden;
  display: flex; flex-direction: column;
  font-size: 13.5px;
}
@media (max-width: 640px) { .invoice-sheet { padding: 26px 24px; aspect-ratio: auto; } }

.inv-top { display: flex; justify-content: space-between; gap: 24px; }
.inv-logo { max-height: 56px; max-width: 170px; object-fit: contain; margin-bottom: 10px; display: block; }
.inv-from-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.inv-muted { color: var(--muted); white-space: pre-line; font-size: 12.5px; }
.inv-meta { text-align: right; min-width: 200px; }
.inv-title { font-size: 26px; font-weight: 800; letter-spacing: 0.12em; color: var(--accent); margin-bottom: 10px; }
.inv-meta-row { display: flex; justify-content: space-between; gap: 18px; font-size: 12.5px; padding: 2px 0; }
.inv-meta-row span { color: var(--muted); }

.inv-billto { margin-top: 28px; }
.inv-label { font-size: 10.5px; font-weight: 800; letter-spacing: 0.1em; color: var(--accent); margin-bottom: 4px; }
.inv-billto-name { font-weight: 700; font-size: 14.5px; }

.inv-table { width: 100%; border-collapse: collapse; margin-top: 22px; }
.inv-table th {
  text-align: left; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: #fff; background: var(--accent);
  padding: 8px 10px;
}
.inv-table th:first-child { border-radius: 6px 0 0 6px; }
.inv-table th:last-child { border-radius: 0 6px 6px 0; }
.inv-table th.num, .inv-table td.num { text-align: right; }
.inv-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.inv-table td:nth-child(2), .inv-table td:nth-child(3) { white-space: nowrap; color: var(--muted); }
.inv-table td.num { font-weight: 600; white-space: nowrap; }
.inv-item-desc { font-weight: 500; }

.inv-totals { margin-top: 16px; margin-left: auto; width: 260px; max-width: 100%; }
.inv-total-row { display: flex; justify-content: space-between; padding: 4px 10px; font-size: 13px; }
.inv-total-row span:first-child { color: var(--muted); }
.inv-grand {
  border-top: 2px solid var(--text);
  margin-top: 6px; padding-top: 8px;
  font-size: 15.5px; font-weight: 800;
}
.inv-grand span:first-child { color: var(--text); }
.inv-due { font-weight: 800; color: var(--accent); }
.inv-due span:first-child { color: var(--accent); }

.inv-notes { margin-top: 22px; }
.inv-notes div:last-child { white-space: pre-line; font-size: 12.5px; color: var(--text); }

.inv-watermark {
  margin-top: auto; padding-top: 26px;
  font-size: 10.5px; color: #a6adc4; text-align: center;
}
body.premium .inv-watermark { display: none; }

/* ================= Rate calculator ================= */
.calc-layout {
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  gap: 28px;
  align-items: start;
  padding-top: 30px;
  padding-bottom: 40px;
}
@media (max-width: 980px) { .calc-layout { grid-template-columns: 1fr; } }
input[type="range"] { padding: 0; height: 32px; accent-color: var(--accent); background: transparent; border: none; }
input[type="range"]:focus { box-shadow: none; }
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 30px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.result-label { color: var(--muted); font-weight: 600; font-size: 14px; }
.result-big { font-size: clamp(44px, 7vw, 64px); font-weight: 800; letter-spacing: -0.03em; color: var(--accent); line-height: 1.1; margin-top: 4px; }
.result-unit { color: var(--muted); margin-bottom: 20px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; margin-bottom: 16px; }
.result-cell { background: var(--bg); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.result-cell span { font-size: 12px; color: var(--muted); font-weight: 600; }
.result-cell b { font-size: 16.5px; }
.result-note { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.site-footer a { color: var(--muted); }

/* ================= Ad slots ================= */
.ad-slot { margin: 18px auto; text-align: center; }

/* ================= Content sections ================= */
.content-section { padding: 56px 0; }
.content-alt { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.content-section h2 { font-size: 26px; letter-spacing: -0.02em; margin: 0 0 26px; }
.content-section h2:not(:first-child) { margin-top: 52px; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 800px) { .steps { grid-template-columns: 1fr; } }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.step-num {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 800;
  display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.step h3 { margin: 0 0 6px; font-size: 16.5px; }
.step p { margin: 0; color: var(--muted); font-size: 14.5px; }

.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 800px) { .features { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .features { grid-template-columns: 1fr; } }
.feature h3 { margin: 0 0 4px; font-size: 15.5px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }

#faq details {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 10px;
}
#faq summary { font-weight: 600; cursor: pointer; font-size: 15px; }
#faq details p { color: var(--muted); margin: 10px 0 2px; font-size: 14.5px; }

.site-footer { padding: 28px 0 36px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ================= Premium modal ================= */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 18, 34, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: #fff; border-radius: 16px; padding: 30px 30px 26px;
  width: 100%; max-width: 420px; position: relative;
  box-shadow: 0 24px 80px rgba(0,0,0,.3);
}
.modal h2 { margin: 0 0 4px; font-size: 22px; }
.modal-sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.modal-close {
  position: absolute; top: 14px; right: 14px;
  border: none; background: #f1f2f8; color: var(--muted);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 13px;
}
.premium-perks { margin: 0 0 18px; padding: 0 0 0 2px; list-style: none; }
.premium-perks li { padding: 5px 0 5px 26px; position: relative; font-size: 14.5px; }
.premium-perks li::before { content: "✓"; position: absolute; left: 2px; color: var(--accent); font-weight: 800; }
.premium-price { text-align: center; margin-bottom: 14px; }
.premium-price b { font-size: 34px; letter-spacing: -0.02em; }
.premium-price span { color: var(--muted); font-size: 14px; }
.license-row { display: flex; gap: 8px; margin-top: 16px; }
.license-status { font-size: 13px; margin: 8px 0 0; min-height: 18px; }
.license-status.ok { color: #18794e; }
.license-status.err { color: #e5484d; }

/* ================= Toast ================= */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 11px 20px; border-radius: 10px; font-size: 14px; font-weight: 500;
  z-index: 120; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

/* ================= Print (PDF export) ================= */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .site-header, .hero, .editor, .ad-slot, .content-section, .site-footer,
  .modal-backdrop, .toast { display: none !important; }
  .app-layout { display: block; padding: 0; max-width: none; margin: 0; }
  .preview-sticky { position: static; }
  .invoice-sheet {
    box-shadow: none; border-radius: 0;
    width: 210mm; min-height: 287mm; aspect-ratio: auto;
    padding: 18mm 16mm;
    margin: 0 auto;
    font-size: 12.5px;
  }
  .inv-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-title, .inv-label, .inv-due, .step-num { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
