:root {
  --accent: #2563eb;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
}

* {
  box-sizing: border-box;
}

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

.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 20px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 12px;
}

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

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.brand-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

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

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.btn-primary:hover {
  filter: brightness(0.92);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover {
  background: #f3f4f6;
}

.btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  margin-top: 10px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 0;
  cursor: pointer;
  text-decoration: underline;
}

.full-width {
  width: 100%;
}

.main-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  padding-top: 24px;
  padding-bottom: 48px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.field input[type="number"],
.field input[type="file"],
.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

.field input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  background: #fff;
  cursor: pointer;
}

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

.ad-slot {
  background: #f9fafb;
}

.ad-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 6px;
}

.ad-text {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 12px;
}

.invoice-paper {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

.company-block {
  flex: 1;
}

.logo-preview-wrap {
  margin-bottom: 12px;
}

.logo-preview-wrap img {
  max-height: 64px;
  max-width: 180px;
  object-fit: contain;
}

.qr-preview-wrap {
  margin-top: 12px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.qr-preview-wrap img {
  width: 96px;
  height: 96px;
  object-fit: contain;
}

.qr-caption {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.hidden {
  display: none;
}

.invoice-meta {
  width: 240px;
  text-align: right;
}

.invoice-word {
  margin: 0 0 12px;
  font-size: 32px;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.editable {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 6px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  width: 100%;
  resize: vertical;
}

.editable:hover,
.editable:focus {
  border-color: var(--border);
  background: #f9fafb;
  outline: none;
}

.title-input {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.details-input {
  font-size: 13px;
  color: #374151;
}

.meta-input {
  width: 135px;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
}

.bill-to-section {
  margin-bottom: 28px;
  max-width: 380px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 6px;
}

.bill-name {
  font-size: 16px;
  font-weight: 600;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.items-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  padding: 10px 12px;
}

.items-table th:first-child {
  border-radius: 6px 0 0 6px;
}

.items-table th:last-child {
  border-radius: 0 6px 6px 0;
}

.items-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.col-qty, .col-rate, .col-amount {
  width: 100px;
  text-align: right;
}

.items-table th.col-qty,
.items-table th.col-rate,
.items-table th.col-amount {
  text-align: right;
}

.col-action {
  width: 36px;
  text-align: center;
}

.num-input {
  text-align: right;
}

.remove-btn {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.totals-section {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 32px;
  margin-top: 28px;
  align-items: start;
}

.totals-table {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.grand-total {
  border-top: 2px solid var(--accent);
  margin-top: 8px;
  padding-top: 10px;
  font-size: 18px;
  color: var(--accent);
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 20px 0 40px;
}

.seo-section {
  padding-bottom: 12px;
}

.seo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.seo-grid h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.seo-grid p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .seo-grid {
    grid-template-columns: 1fr;
  }
  .main-grid {
    grid-template-columns: 1fr;
  }
  .invoice-paper {
    padding: 20px;
  }
  .invoice-header,
  .totals-section {
    flex-direction: column;
    grid-template-columns: 1fr;
  }
  .invoice-meta {
    width: 100%;
    text-align: left;
  }
}

@media print {
  body {
    background: #fff;
  }
  .no-print {
    display: none !important;
  }
  .main-grid {
    display: block;
    padding: 0;
  }
  .container {
    max-width: 100%;
    padding: 0;
  }
  .invoice-paper {
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .editable {
    border: none !important;
    background: transparent !important;
    resize: none;
  }
  .items-table th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

:root {
  --bg: #edf3f1;
  --text: #172c29;
  --muted: #526962;
  --border: #d7e4df;
  --ui-accent: #126456;
}
body { font-family: "Segoe UI", system-ui, sans-serif; }
.topbar { box-shadow: 0 2px 10px #173c2910; }
.topbar .brand-badge, .btn-primary { background: var(--ui-accent); }
.btn { font-weight: 650; }
:focus-visible { outline: 2px solid #126456; outline-offset: 3px; }
.workspace-heading { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.workspace-heading h1, .workspace-heading p { margin: 0; }
.workspace-heading h1 { font-size: clamp(1.5rem, 3vw, 2.35rem); letter-spacing: -.04em; }
.workspace-heading p { color: var(--muted); }
.main-grid { grid-template-columns: 258px minmax(0, 1fr); }
.panel, .invoice-paper { border-radius: 16px; }
.invoice-paper { box-shadow: 0 16px 42px #18342d12; }
.invoice-paper[data-style="modern"] .invoice-header { border-top: 6px solid var(--accent); padding-top: 18px; }
.invoice-paper[data-style="modern"] .invoice-word { letter-spacing: -.045em; }
.invoice-paper[data-style="minimal"] .items-table th { color: var(--text); background: transparent; border-bottom: 2px solid var(--accent); }
.invoice-paper[data-style="minimal"] .invoice-word { color: var(--text); }
.signature-preview { margin-top: 25px; break-inside: avoid; }
.signature-preview img { display: block; max-width: 190px; max-height: 95px; object-fit: contain; }
.draft-dialog { width: min(540px, calc(100% - 24px)); max-height: 90dvh; padding: 24px; color: var(--text); border: 1px solid var(--border); border-radius: 18px; }
.draft-dialog::backdrop { background: #142d28a0; }
.draft-heading, .draft-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.draft-heading { justify-content: space-between; }
.draft-heading h2 { margin: 0; }
.draft-dialog p, #signature-status { color: var(--muted); font-size: .9rem; }
#draft-name { min-width: 0; flex: 1 1 150px; padding: 9px; font: inherit; border: 1px solid var(--border); border-radius: 8px; }
#draft-list { list-style: none; padding: 0; max-height: 34vh; overflow: auto; }
#draft-list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding: 8px 4px; overflow-wrap: anywhere; }
#draft-list .btn-sm { margin-top: 0; }
#signature-pad { display: block; width: 100%; height: auto; margin: 16px 0; border-radius: 10px; box-shadow: inset 0 0 0 1px var(--border); background: #f5f8f7; touch-action: none; }
button:disabled { opacity: .55; cursor: default; }
.print-value { display: none; }
.seo-landing { padding-block: clamp(24px, 5vw, 65px); max-width: 1020px; }
.seo-hero { padding: clamp(24px, 5vw, 62px); border: 1px solid var(--border); border-radius: 24px; background: linear-gradient(135deg, #fff 30%, #d9eee6); }
.seo-hero h1 { font-size: clamp(2rem, 5vw, 3.8rem); margin: 0 0 12px; line-height: 1.08; letter-spacing: -.045em; }
.seo-hero p { max-width: 65ch; color: var(--muted); margin: 0 0 24px; }
.seo-hero .btn { padding: 11px 18px; }
.seo-content { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.seo-content > section { padding: 22px; border: 1px solid var(--border); background: white; border-radius: 16px; }
.seo-content h2 { margin: 0 0 12px; font-size: 1.2rem; }
.seo-content li + li { margin-top: 9px; }
.seo-content details { border-top: 1px solid var(--border); padding: 10px 0; }
.seo-content summary { cursor: pointer; font-weight: 650; }
.seo-content details p { margin-bottom: 0; color: var(--muted); }
.seo-related a { color: #126456; }
.seo-support { display: inline-block; margin-top: 16px; }
@media screen and (max-width: 900px) {
  .main-grid, .seo-content { grid-template-columns: minmax(0, 1fr); }
}
@media screen and (max-width: 560px) {
  .container { padding-inline: 12px; }
  .topbar-inner { height: auto; min-height: 62px; flex-wrap: wrap; padding-block: 8px; }
  .topbar-actions { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; gap: 3px; }
  .topbar-actions .btn { padding: 7px 8px; font-size: 12px; }
  .invoice-paper { padding: 14px; }
  .invoice-header { gap: 8px; margin-bottom: 20px; }
  .items-table { table-layout: fixed; }
  .items-table th, .items-table td { padding-inline: 3px; font-size: 11px; }
  .items-table :is(.col-rate, .col-amount) { width: 20%; }
  .items-table .col-qty { width: 12%; }
  .items-table .col-action { width: 24px; }
  .items-table input { font-size: 12px; padding-inline: 1px; min-width: 0; }
  .items-table .col-amount { overflow-wrap: anywhere; }
  .field input, .field select { font-size: 16px; }
}
@media print {
  @page { margin: 13mm; }
  .invoice-paper { padding: 0; border: 0; border-radius: 0; box-shadow: none; }
  .invoice-header { display: flex; flex-direction: row; }
  .invoice-meta { width: auto; text-align: right; }
  .totals-section { grid-template-columns: minmax(0, 1fr) minmax(180px, .7fr); break-inside: avoid; }
  .items-table thead { display: table-header-group; }
  .items-table tr, .invoice-header, .bill-to { break-inside: avoid; }
  .invoice-paper .editable:has(+ .print-value) { display: none; }
  .print-value { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
  .print-value.meta-input { display: inline-block; width: auto; }
  .print-value.num-input { text-align: right; }
}


#editor-ui { padding: 7px; border: 1px solid var(--border); border-radius: 8px; background: white; }
.workspace-heading label, #trade-panel p, #trade-panel details { font-size: .86rem; color: var(--muted); }
#trade-panel a { color: var(--ui-accent); }
#trade-panel .btn { padding: 6px 9px; font-size: .79rem; }
#trade-panel details { margin-top: 12px; }
#trade-panel summary { cursor: pointer; }
#invoice-paper[data-document="packing"] :is(.col-rate, .col-amount, .totals-table) { display: none; }
#invoice-paper[data-document="packing"] .totals-section { grid-template-columns: 1fr; }
@media screen and (max-width: 560px) {
  .workspace-heading { align-items: flex-start; flex-direction: column; }
}

