:root {
  --ui-bg: #eef1f5;
  --ui-panel: #ffffff;
  --ui-line: #d6dce5;
  --ui-text: #1c2430;
  --ui-muted: #66717f;
  --ui-accent: #193f72;
  --invoice-accent: #6c3bb8;
  --ui-accent-soft: #edf3fb;
  --ui-accent-strong: #102f58;
  --ui-danger: #9f3f3f;
  --ui-shadow: 0 18px 40px rgba(31, 39, 54, 0.08);
  --ui-shadow-soft: 0 10px 24px rgba(31, 39, 54, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ui-text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.75)),
    linear-gradient(135deg, #f3f6fb, #e8edf5);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  min-height: 100vh;
  max-width: 1680px;
  margin: 0 auto;
  padding: 24px;
}

.control-panel,
.preview-shell {
  background: var(--ui-panel);
  border: 1px solid var(--ui-line);
  box-shadow: var(--ui-shadow);
}

.control-panel {
  border-radius: 24px;
  padding: 24px;
}

.preview-shell {
  border-radius: 28px;
  padding: 24px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ui-accent);
}

.panel-head h1 {
  margin: 0;
  font-size: clamp(1.9rem, 4vw, 2.5rem);
  line-height: 1.08;
}

.panel-copy {
  margin: 12px 0 0;
  color: var(--ui-muted);
  line-height: 1.6;
}

.mobile-view-switch {
  display: none;
  gap: 10px;
  margin-top: 18px;
}

.active-switch {
  background: var(--ui-accent);
  color: #fff;
  border-color: var(--ui-accent);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 22px 0 24px;
  position: sticky;
  top: 10px;
  z-index: 2;
  padding: 12px;
  border: 1px solid rgba(214, 220, 229, 0.9);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  box-shadow: var(--ui-shadow-soft);
}

.primary-button,
.secondary-button,
.text-button,
.remove-item-button {
  border-radius: 12px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.text-button:hover,
.remove-item-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  padding: 11px 16px;
  background: var(--ui-accent);
  color: #fff;
  box-shadow: 0 12px 24px rgba(25, 63, 114, 0.2);
}

.secondary-button {
  padding: 11px 16px;
  background: #fff;
  color: var(--ui-text);
  border: 1px solid var(--ui-line);
}

.secondary-button:hover,
.primary-button:hover,
.text-button:hover,
.remove-item-button:hover {
  box-shadow: var(--ui-shadow-soft);
}

.text-button {
  padding: 8px 12px;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  font-weight: 700;
}

.remove-item-button {
  padding: 8px 12px;
  background: #f8eaea;
  color: var(--ui-danger);
  font-weight: 700;
}

.form-stack {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-card {
  border: 1px solid var(--ui-line);
  border-radius: 18px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 250, 255, 0.92));
  box-shadow: var(--ui-shadow-soft);
}

.wide-card {
  grid-column: 1 / -1;
}

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

.card-head h2 {
  margin: 0;
  font-size: 1rem;
}

.card-note {
  margin: 0;
  color: var(--ui-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.full-span {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 8px;
}

label span {
  font-size: 0.81rem;
  font-weight: 700;
  color: var(--ui-muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: #fff;
  color: var(--ui-text);
  padding: 11px 13px;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(25, 63, 114, 0.12);
  border-color: var(--ui-accent);
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--ui-line);
  background:
    radial-gradient(circle at top right, rgba(25, 63, 114, 0.08), transparent 35%),
    #fff;
  box-shadow: var(--ui-shadow-soft);
}

.stat-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ui-muted);
}

.stat-card strong {
  font-size: 1.1rem;
}

.style-picker {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--ui-line);
}

.style-label,
.save-title {
  margin: 0 0 10px;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--ui-text);
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--ui-line), inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.color-swatch[data-color="#6c3bb8"] { background: #6c3bb8; }
.color-swatch[data-color="#2356a5"] { background: #2356a5; }
.color-swatch[data-color="#1b6a52"] { background: #1b6a52; }
.color-swatch[data-color="#8a3b61"] { background: #8a3b61; }
.color-swatch[data-color="#8a5314"] { background: #8a5314; }

.color-swatch.active {
  transform: scale(1.08);
  box-shadow: 0 0 0 2px var(--ui-text), inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.custom-swatch {
  position: relative;
  background:
    linear-gradient(135deg, #ff6b6b, #feca57 24%, #48dbfb 50%, #1dd1a1 74%, #5f27cd);
}

.custom-swatch::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.saved-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.save-block {
  border: 1px solid var(--ui-line);
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #fafbfc, #f5f8fc);
}

.save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.accent-button {
  background: var(--ui-accent);
  color: #fff;
  border-color: var(--ui-accent);
}

.danger-button {
  border-color: rgba(159, 63, 63, 0.28);
  color: var(--ui-danger);
  background: #fff8f8;
}

.item-editor {
  display: grid;
  gap: 14px;
}

.item-card {
  border: 1px solid var(--ui-line);
  border-radius: 16px;
  padding: 14px;
  background: #fff;
}

.item-grid {
  grid-template-columns: 2fr 1fr repeat(5, minmax(0, 0.85fr));
  align-items: end;
}

.item-meta {
  min-width: 140px;
  padding: 12px;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: #fafbfc;
}

.item-meta p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ui-muted);
}

.item-meta p + p {
  margin-top: 8px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.preview-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
}

.preview-copy {
  margin: 8px 0 0;
  color: var(--ui-muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.draft-status {
  margin: 4px 0 0;
  color: var(--ui-muted);
  font-size: 0.85rem;
}

.invoice-sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  color: #000;
  padding: 10mm 10mm 12mm;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.14);
  font-family: Arial, Helvetica, sans-serif;
}

.preview-stage {
  padding: 18px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(18, 29, 43, 0.96), rgba(36, 46, 63, 0.96)),
    #1c2430;
  overflow-x: auto;
}

.sheet-title-row {
  border: 1px solid #000;
  padding: 8px 10px;
  text-align: center;
}

.sheet-title-row h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: #000;
}

.company-strip,
.invoice-meta-grid,
.summary-grid,
.footer-grid {
  display: grid;
  gap: 0;
}

.company-strip {
  grid-template-columns: 92px 1fr;
  border-left: 1px solid #000;
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
}

.brand-logo,
.brand-copy {
  min-height: 94px;
}

.brand-logo {
  display: grid;
  place-items: center;
  border-right: 1px solid #000;
  background: #fff;
  overflow: hidden;
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-copy {
  padding: 8px 10px;
}

.brand-name {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 700;
  text-transform: uppercase;
}

.muted-text,
.signatory-name,
.signatory-role {
  margin: 4px 0 0;
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: pre-line;
}

.invoice-meta-grid {
  grid-template-columns: 1.55fr 1fr;
  margin-top: 0;
}

.summary-grid {
  grid-template-columns: 1.25fr 0.75fr;
}

.footer-grid {
  grid-template-columns: repeat(3, 1fr);
}

.meta-box,
.totals-box {
  border: 1px solid #000;
  border-top: none;
  padding: 8px 10px;
  min-height: 100%;
}

.invoice-meta-grid .meta-box:first-child,
.summary-grid .meta-box:first-child,
.footer-grid .meta-box:first-child,
.summary-grid .totals-box {
  border-right: none;
}

.footer-grid .meta-box:nth-child(2) {
  border-right: none;
}

.box-title {
  margin: -8px -10px 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  background: var(--invoice-accent);
  border-bottom: 1px solid #000;
}

.strong-line {
  margin: 0;
  font-size: 0.93rem;
  font-weight: 700;
  line-height: 1.45;
}

.detail-list p,
.total-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 5px 0;
  border-bottom: 1px solid #c8c8c8;
  font-size: 0.84rem;
}

.detail-list p:last-child,
.total-line:last-child {
  border-bottom: none;
}

.table-card {
  margin-top: 0;
}

.invoice-table,
.mini-table {
  width: 100%;
  border-collapse: collapse;
}

.invoice-table th,
.invoice-table td,
.mini-table th,
.mini-table td {
  border: 1px solid #000;
  padding: 6px 6px;
  font-size: 0.8rem;
  vertical-align: top;
}

.invoice-table th,
.mini-table th {
  font-weight: 700;
  background: var(--invoice-accent);
  color: #fff;
}

.invoice-table td {
  height: 27px;
}

.invoice-table th:first-child,
.invoice-table td:first-child {
  width: 28px;
}

.tfoot-label {
  text-align: right;
  font-weight: 700;
}

.amount-words {
  margin-top: 10px;
}

.totals-box {
  align-self: start;
}

.grand {
  font-weight: 700;
}

.signatory-box {
  text-align: center;
}

.signature-stage {
  width: 100%;
  min-height: 92px;
  margin-top: 6px;
  display: grid;
  place-items: center;
}

.signature-wrap {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #fff;
}

.signature-wrap {
  width: min(100%, 260px);
  min-height: 84px;
  padding: 4px;
}

.signature-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.placeholder {
  border: 1px dashed #999;
}

.placeholder span {
  color: #777;
  font-size: 0.8rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.signatory-name {
  font-weight: 700;
}

.signatory-role {
  font-weight: 700;
  text-transform: capitalize;
}

@media (max-width: 1360px) {
  .preview-shell {
    overflow-x: auto;
  }

  .saved-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  body[data-mobile-view="preview"] .control-panel {
    display: none;
  }

  body[data-mobile-view="editor"] .preview-shell {
    display: none;
  }

  .control-panel,
  .preview-shell {
    border-radius: 20px;
    padding: 18px;
  }

  .mobile-view-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-stats,
  .saved-grid,
  .form-stack,
  .two-col,
  .item-grid {
    grid-template-columns: 1fr;
  }

  .action-row {
    position: static;
    padding: 0;
    border: none;
    box-shadow: none;
    background: transparent;
    backdrop-filter: none;
  }

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .preview-stage {
    padding: 12px;
  }

  .invoice-sheet {
    width: 100%;
    min-width: 780px;
  }
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  body {
    background: #fff;
  }

  .control-panel,
  .preview-toolbar {
    display: none;
  }

  .app-shell,
  .preview-shell {
    display: block;
    padding: 0;
    margin: 0;
    border: none;
    box-shadow: none;
    background: transparent;
  }

  .preview-stage {
    padding: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }

  .invoice-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    box-shadow: none;
  }
}
