:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #283548;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: #0b1120;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  font-size: 1.5rem;
}

.brand strong {
  display: block;
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.mode-switch {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.mode-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 7px 14px;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
}

.pro-pill {
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
}

.pro-pill.unlocked {
  background: var(--accent);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 1.05fr;
  gap: 24px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: #e2e8f0;
}

.card-head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head-row h2 {
  margin: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.82rem;
  color: #cbd5e1;
}

.field.hidden {
  display: none;
}

.field input,
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 0.9rem;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.items-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: grid;
  grid-template-columns: 2fr 70px 100px 34px;
  gap: 8px;
  align-items: center;
}

.item-row input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.btn-remove {
  background: rgba(239, 68, 68, 0.16);
  color: #f87171;
  border: none;
  border-radius: 8px;
  height: 34px;
  cursor: pointer;
  font-weight: 700;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: #e2e8f0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}

.btn-outline {
  background: transparent;
  color: #fbbf24;
  border: 1px solid #f59e0b;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
}

.actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* A4 Live Preview */
.preview-panel {
  position: sticky;
  top: 16px;
}

.a4-sheet {
  position: relative;
  background: #ffffff;
  color: #0f172a;
  border-radius: 8px;
  padding: 36px 38px;
  min-height: 760px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.watermark {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-28deg);
  font-size: 2rem;
  font-weight: 800;
  color: rgba(15, 23, 42, 0.08);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.watermark.hidden,
.doc-footer-wm.hidden {
  display: none;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.doc-tag {
  display: inline-block;
  background: #1d4ed8;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 4px;
  margin-bottom: 6px;
}

.doc-header h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

.doc-meta {
  margin: 0;
  color: #475569;
  font-size: 0.84rem;
}

.doc-number-box {
  text-align: right;
  font-size: 0.9rem;
}

.client-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.client-box .label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #64748b;
  letter-spacing: 0.06em;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 0.88rem;
}

.doc-table th {
  text-align: left;
  background: #f1f5f9;
  color: #334155;
  padding: 9px 10px;
  border-bottom: 2px solid #cbd5e1;
}

.doc-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e2e8f0;
}

.doc-table th.num,
.doc-table td.num {
  text-align: right;
  white-space: nowrap;
}

.doc-totals {
  margin-left: auto;
  width: min(100%, 260px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.tot-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: #475569;
}

.tot-row.hidden {
  display: none;
}

.tot-grand {
  border-top: 2px solid #0f172a;
  padding-top: 6px;
  color: #0f172a;
  font-size: 1.08rem;
}

.pix-box {
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  color: #065f46;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.pix-box.hidden,
.notes-box.hidden {
  display: none;
}

.notes-box {
  background: #f8fafc;
  border-left: 3px solid #94a3b8;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.notes-box p {
  margin: 4px 0 0;
  color: #334155;
}

.signature-area {
  margin-top: auto;
  padding-top: 34px;
  display: flex;
  justify-content: flex-end;
}

.sig-line {
  width: 240px;
  border-top: 1px solid #334155;
  text-align: center;
  padding-top: 6px;
  font-size: 0.82rem;
  color: #475569;
}

.doc-footer-wm {
  margin-top: 18px;
  text-align: center;
  font-size: 0.74rem;
  color: #94a3b8;
}

.seo-faq {
  max-width: 1360px;
  margin: 8px auto 40px;
  padding: 0 24px;
}

.seo-faq h2 {
  font-size: 1.15rem;
  margin-bottom: 12px;
}

.faq-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.faq-item h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.faq-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.pro-modal {
  width: min(94vw, 460px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
}

.pro-modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.pro-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pro-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pro-modal-head h3 {
  margin: 0;
}

.icon-btn {
  background: var(--surface-2);
  color: var(--text);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.pro-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.pro-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.btn-pix {
  display: block;
  text-align: center;
  text-decoration: none;
  background: var(--accent);
  color: #022c22;
  font-weight: 800;
  padding: 12px;
  border-radius: 10px;
}

.unlock-box {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.unlock-row {
  display: flex;
  gap: 8px;
}

.unlock-msg {
  margin: 6px 0 0;
  font-size: 0.84rem;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .preview-panel {
    position: static;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .item-row {
    grid-template-columns: 1fr 62px 88px 34px;
  }
}

@media print {
  body {
    background: #ffffff;
  }
  .no-print {
    display: none !important;
  }
  .workspace {
    display: block;
    padding: 0;
    margin: 0;
    max-width: none;
  }
  .preview-panel {
    position: static;
  }
  .a4-sheet {
    box-shadow: none;
    border-radius: 0;
    padding: 10mm 12mm;
    min-height: auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
