:root {
  --bg: #f7f5ff;
  --panel: #ffffff;
  --ink: #18122b;
  --muted: #6b6478;
  --line: #e7e1f3;
  --primary: #5b21b6;
  --primary-dark: #44158f;
  --secondary: #f97316;
  --secondary-dark: #c94f08;
  --accent: #38bdf8;
  --accent-soft: #e8f7ff;
  --danger: #b42318;
  --success: #157347;
  --shadow: 0 24px 70px rgba(70, 45, 130, 0.14);
  --shadow-soft: 0 10px 30px rgba(91, 33, 182, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(91, 33, 182, 0.08), rgba(56, 189, 248, 0.08) 42%, rgba(249, 115, 22, 0.06)),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  background: var(--primary);
  color: #ffffff;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 1rem;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 3vw, 2.5rem);
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 35px rgba(91, 33, 182, 0.08);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.app-header h1,
.app-header p,
h2,
h3 {
  margin: 0;
}

.app-header h1 {
  color: var(--primary);
  font-size: clamp(1.45rem, 2vw, 2rem);
  font-weight: 850;
}

.eyebrow,
.preview-label {
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.header-actions,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.45fr);
  grid-template-areas:
    "editor side"
    "preview preview";
  gap: 1.5rem;
  padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 3rem;
}

.editor-panel {
  grid-area: editor;
}

.side-panel {
  grid-area: side;
  align-self: start;
  display: grid;
  gap: 1.25rem;
  position: sticky;
  top: 6rem;
}

.preview-panel {
  grid-area: preview;
}

.panel-section,
.summary-card,
.invoice-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.panel-section,
.summary-card {
  padding: 1.4rem;
  margin-bottom: 1.4rem;
}

.summary-card {
  margin-bottom: 0;
}

.section-heading {
  margin-bottom: 1.1rem;
}

.section-heading h2,
.summary-card h2 {
  color: var(--primary);
  font-size: 1.02rem;
  font-weight: 850;
}

.section-heading.compact {
  align-items: flex-start;
}

.badge {
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  background: var(--accent-soft);
  color: #075985;
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
}

.badge.saved {
  border-color: rgba(21, 115, 71, 0.25);
  background: #ecfdf3;
  color: var(--success);
}

.grid {
  display: grid;
  gap: 1rem;
}

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

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

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

label {
  display: grid;
  gap: 0.4rem;
  color: #514a64;
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefe;
  color: var(--ink);
  padding: 0.78rem 0.85rem;
  font-weight: 400;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(56, 189, 248, 0.32);
  outline-offset: 2px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.12);
}

.field-error {
  border-color: var(--danger);
}

.form-status {
  min-height: 1.5rem;
  color: var(--danger);
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.form-status.success {
  color: var(--success);
}

.button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 2.5rem;
  padding: 0.68rem 1.05rem;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 12px 28px rgba(91, 33, 182, 0.28);
}

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

.button-secondary {
  background: #f3edff;
  color: var(--primary);
  border-color: rgba(91, 33, 182, 0.16);
}

.button-secondary:hover {
  background: #ebe0ff;
}

.icon-button {
  min-height: 2.25rem;
  padding: 0.45rem 0.75rem;
  background: #fff7ed;
  color: var(--secondary-dark);
  border-color: rgba(249, 115, 22, 0.25);
}

.items-table {
  overflow-x: auto;
}

.items-head,
.item-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(76px, 0.35fr) minmax(110px, 0.45fr) minmax(110px, 0.45fr) 84px;
  gap: 0.75rem;
  align-items: end;
}

.items-head {
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0 0.25rem 0.55rem;
}

.item-row {
  min-width: 720px;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
}

.item-total {
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  color: var(--secondary-dark);
  font-weight: 700;
}

.remove-item {
  background: #fff7ed;
  color: var(--secondary-dark);
  border: 1px solid rgba(249, 115, 22, 0.26);
  border-radius: var(--radius);
  min-height: 2.75rem;
  padding: 0.55rem;
}

.totals-list,
.preview-totals,
.invoice-meta dl {
  margin: 0;
}

.totals-list div,
.preview-totals div,
.invoice-meta div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 0;
}

.totals-list dt,
.preview-totals dt,
.invoice-meta dt {
  color: var(--muted);
  font-weight: 700;
}

.totals-list dd,
.preview-totals dd,
.invoice-meta dd {
  margin: 0;
  font-weight: 800;
}

.grand-total {
  color: var(--secondary);
  font-size: 1.15rem;
  border-bottom: 0 !important;
}

.invoice-preview {
  max-width: 980px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: 0 30px 90px rgba(24, 18, 43, 0.12);
}

.invoice-preview-header {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 3px solid var(--primary);
}

.preview-logo {
  display: none;
  max-width: 150px;
  max-height: 80px;
  object-fit: contain;
  margin-bottom: 1rem;
}

.preview-logo.has-logo {
  display: block;
}

.preview-title {
  color: var(--primary);
  font-size: 2rem;
  font-weight: 800;
  margin: 0 0 1rem;
  text-transform: uppercase;
}

.bill-to {
  margin: 1.5rem 0;
}

.bill-to p,
.invoice-preview-header p {
  margin: 0.25rem 0;
  color: var(--muted);
  white-space: pre-line;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
}

.preview-table th,
.preview-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.8rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.preview-table th {
  background: #f6f1ff;
  color: var(--primary);
}

.preview-table th:not(:first-child),
.preview-table td:not(:first-child) {
  text-align: right;
}

.preview-totals {
  max-width: 360px;
  margin-left: auto;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "editor"
      "side"
      "preview";
  }

  .side-panel {
    position: static;
  }
}

@media (max-width: 700px) {
  .app-header,
  .invoice-preview-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .two-columns,
  .three-columns {
    grid-template-columns: 1fr;
  }

  .items-head {
    display: none;
  }

  .item-row {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .item-total {
    justify-content: flex-start;
  }

  .preview-table {
    display: block;
    overflow-x: auto;
  }
}

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

  .skip-link,
  .app-header,
  .editor-panel,
  .side-panel {
    display: none !important;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .preview-panel {
    display: block;
  }

  .invoice-preview {
    border: 0;
    box-shadow: none;
    max-width: none;
    padding: 0;
  }
}
