:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-2: #e7eefb;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --accent: #1f6feb;
  --accent-2: #103a80;
  --accent-soft: rgba(31, 111, 235, 0.12);
  --text: #172231;
  --muted: #62708a;
  --border: #dfe7f2;
  --danger: #c7372f;
  --danger-soft: #fff0ee;
  --success: #12715b;
  --success-soft: #e9fff5;
  --shadow: 0 18px 50px rgba(16, 40, 74, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(31, 111, 235, 0.14), transparent 30%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
}

h1,
h2,
h3,
p {
  margin: 0;
}

.mobile-tabs {
  display: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 500px) minmax(0, 1fr);
  align-items: start;
  gap: 24px;
  padding: 24px;
  min-height: 100vh;
}

.builder-panel,
.preview-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.builder-panel {
  padding: 24px;
}

.preview-panel {
  padding: 24px;
}

.panel-header,
.preview-header {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
}

.panel-copy {
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.6;
}

.utility-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.save-status {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.9rem;
  font-weight: 700;
}

.save-status.pending {
  background: #fff6df;
  color: #8a5b00;
}

.save-status.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.validation-summary {
  display: none;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(199, 55, 47, 0.18);
  line-height: 1.5;
}

form {
  display: grid;
  gap: 0;
}

fieldset {
  border: 1px solid rgba(223, 231, 242, 0.9);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 14px;
  background: rgba(255, 255, 255, 0.74);
}

legend {
  font-weight: 700;
  padding: 0 8px;
  color: var(--accent-2);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 0;
}

input,
textarea,
button,
select {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fdfefe;
  color: var(--text);
}

input[type="color"] {
  min-height: 48px;
  padding: 6px;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(31, 111, 235, 0.24);
  border-color: var(--accent);
}

.is-invalid,
.item-invalid {
  border-color: rgba(199, 55, 47, 0.55);
  background: #fff8f7;
}

.file-label input {
  padding: 8px 0;
  border: none;
  background: transparent;
}

.inline-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-grid-compact {
  grid-template-columns: minmax(120px, 160px) minmax(0, 1fr);
}

.items-editor,
.item-rows,
.summary-grid {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.item-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.item-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.item-field-wide {
  grid-column: 1 / -1;
}

.item-field-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.amount {
  background: #f4f8ff;
  font-weight: 700;
}

.item-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 700;
  background: var(--accent);
  color: white;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(31, 111, 235, 0.28);
}

button.secondary {
  background: #eaf1ff;
  color: var(--accent-2);
}

.ghost-button {
  padding: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.ghost-button:hover {
  transform: none;
  box-shadow: none;
  color: var(--accent-2);
}

.remove-item {
  background: #ffe8e8;
  color: #b42318;
}

.duplicate-item {
  background: #eff7ff;
  color: var(--accent-2);
}

.subtle-action {
  margin-top: 10px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(180deg, rgba(244, 247, 251, 0), rgba(244, 247, 251, 0.9) 30%, rgba(244, 247, 251, 0.9));
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
}

.summary-row strong {
  color: var(--text);
}

.summary-row.highlight {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--accent-2);
  font-size: 1.08rem;
}

.preview-panel {
  position: relative;
}

.invoice-preview {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(223, 231, 242, 0.9);
  border-radius: 24px;
  padding: 28px;
  background: var(--panel-solid);
  min-height: 100%;
}

.invoice-ribbon {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 10px;
  background: linear-gradient(90deg, var(--accent), #dbe8ff);
}

.invoice-top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0 24px;
  border-bottom: 1px solid var(--border);
}

.company-block {
  max-width: 360px;
}

.company-block h2 {
  font-family: "Cormorant Garamond", serif;
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 8px;
}

.logo-preview {
  max-width: 150px;
  max-height: 90px;
  object-fit: contain;
  display: none;
  margin-bottom: 14px;
  border-radius: 12px;
}

.invoice-meta {
  min-width: 260px;
  text-align: right;
}

.invoice-meta h1 {
  font-size: 2.5rem;
  line-height: 0.95;
  margin-bottom: 14px;
}

.invoice-meta p,
.bill-to p,
.notes-box p,
.signer-title-preview {
  margin-top: 6px;
  color: var(--muted);
}

.label {
  display: inline-block;
  min-width: 96px;
  margin-right: 12px;
  font-weight: 700;
  color: var(--text);
}

.bill-to {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.bill-to h3,
.notes-box h3 {
  margin-bottom: 8px;
}

.items-table {
  margin: 18px 0 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.totals {
  margin-top: 20px;
  margin-left: auto;
  max-width: 360px;
  padding: 16px 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fbfdff 0%, #f5f9ff 100%);
  border: 1px solid var(--border);
}

.notes-box {
  margin-top: 20px;
  padding: 18px;
  border-radius: 18px;
  background: #fbfdff;
  border: 1px solid var(--border);
}

.signature-box {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: none;
}

.signature-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.signature-preview {
  display: block;
  min-height: 54px;
  max-width: 320px;
  padding: 4px 0 8px;
  border-bottom: 1px solid var(--border);
  font-family: "Great Vibes", cursive;
  font-size: 2.3rem;
  line-height: 1.05;
  color: var(--accent);
}

.signer-title-preview {
  margin-top: 10px;
  font-size: 0.95rem;
}

.empty-items {
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .mobile-tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 14px 14px 0;
    background: linear-gradient(180deg, rgba(244, 247, 251, 0.97), rgba(244, 247, 251, 0.88));
    backdrop-filter: blur(10px);
  }

  .mobile-tab {
    background: rgba(255, 255, 255, 0.9);
    color: var(--muted);
    border: 1px solid var(--border);
  }

  .mobile-tab.active {
    background: var(--accent);
    color: #ffffff;
  }

  .app-shell {
    grid-template-columns: 1fr;
    padding-top: 14px;
  }

  .builder-panel[data-panel="edit"],
  .preview-panel[data-panel="preview"] {
    display: block;
  }

  body.mobile-preview .builder-panel,
  body.mobile-edit .preview-panel {
    display: none;
  }

  .invoice-top {
    flex-direction: column;
  }

  .invoice-meta {
    text-align: left;
    min-width: 0;
  }

}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .builder-panel,
  .preview-panel,
  .invoice-preview {
    border-radius: 20px;
  }

  .inline-grid,
  .inline-grid-compact,
  .item-row {
    grid-template-columns: 1fr;
  }

  .totals {
    max-width: none;
  }

  .actions {
    position: static;
    background: transparent;
  }

  .label {
    min-width: 82px;
  }
}

@media print {
  body {
    background: white;
  }

  .mobile-tabs,
  .builder-panel {
    display: none !important;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .preview-panel,
  .invoice-preview {
    border: none;
    box-shadow: none;
    padding: 0;
    background: white;
  }

  .invoice-ribbon {
    display: none;
  }
}

.invoice-meta {
  text-align: right;
  min-width: 220px;
}

.invoice-meta p,
.bill-to p,
.notes-box p {
  margin-top: 6px;
  color: var(--muted);
}

.label {
  display: inline-block;
  min-width: 90px;
  font-weight: 700;
  color: var(--text);
}

.bill-to {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.items-table {
  margin: 16px 0 0;
}

.items-table th {
  background: #f8fbff;
}

.totals {
  margin-top: 20px;
  max-width: 320px;
  margin-left: auto;
}

.notes-box {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.remove-item {
  background: #ffe8e8;
  color: #b42318;
  padding: 8px 10px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .invoice-top {
    flex-direction: column;
  }

  .invoice-meta {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .inline-grid {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: 1fr 1fr;
  }

  .app-shell {
    padding: 14px;
  }
}

@media print {
  body {
    background: white;
  }

  .builder-panel {
    display: none;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .preview-panel {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .invoice-preview {
    border: none;
    padding: 0;
  }
}
