:root {
  color-scheme: light;
  --ink: #1d120f;
  --ink-soft: #4a342a;
  --cream: #f7f1ea;
  --gold: #c08a2e;
  --shadow: 0 24px 50px rgba(35, 18, 8, 0.14);
  --radius: 24px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 150%;
}

body {
  font-family: "Georgia", "Times New Roman", serif;
  background-color: #f1ebe3;
  background-image: linear-gradient(120deg, #f3ede6, #eee6de 60%, #f7f1ea);
  background-size: 200% 200%;
  animation: drift 24s ease-in-out infinite;
  color: #1d120f;
  color: var(--ink);
  min-height: 100vh;
  padding: 2rem 1.5rem 3.5rem;
  position: relative;
  overflow-x: hidden;
  font-size: 1rem;
}

.glow {
  position: absolute;
  inset: -120px auto auto -120px;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(192, 138, 46, 0.28), rgba(192, 138, 46, 0));
  filter: blur(10px);
  pointer-events: none;
}

.hero {
  display: grid;
  gap: 32px;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  align-items: stretch;
  margin-bottom: 40px;
}

.eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #4a342a;
  color: var(--ink-soft);
  margin-bottom: 0.9rem;
}

h1 {
  font-size: 1.8rem;
  line-height: 1.2;
  margin-bottom: 0.9rem;
}

.subtitle {
  font-size: 0.95rem;
  color: #4a342a;
  color: var(--ink-soft);
  max-width: 520px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
  margin-top: 1rem;
}

.hero-actions {
  margin-top: 0.9rem;
}

.hero-actions .button {
  display: inline-block;
  text-decoration: none;
}

.pill {
  background: rgba(29, 18, 15, 0.1);
  color: #1d120f;
  color: var(--ink);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.7rem;
}

.pill.good {
  background: rgba(22, 90, 46, 0.15);
  color: #195227;
}

.pill.warn {
  background: rgba(155, 38, 38, 0.15);
  color: #7b1f1f;
}

.meta-text {
  font-size: 0.7rem;
  color: #4a342a;
  color: var(--ink-soft);
}

.hero-card {
  background: #fbf6f0;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 24px;
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: 0 24px 50px rgba(35, 18, 8, 0.14);
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #4a342a;
  color: var(--ink-soft);
  margin-bottom: 0.9rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem 1.2rem;
}

.kpi-title {
  font-size: 0.7rem;
  color: #4a342a;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.kpi-value {
  font-size: 1.05rem;
  font-weight: 600;
}

.section {
  margin-top: 2.1rem;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
  margin-bottom: 0.9rem;
}

.section-title h2 {
  font-size: 1.2rem;
}

.section-title p {
  font-size: 0.7rem;
  color: #4a342a;
  color: var(--ink-soft);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.card {
  background: #f7f1ea;
  background: var(--cream);
  border-radius: 18px;
  padding: 0.8rem 0.9rem;
  box-shadow: 0 16px 30px rgba(35, 18, 8, 0.12);
  display: grid;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-icon-text {
  min-width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: #c08a2e;
  border-radius: 999px;
  background: rgba(192, 138, 46, 0.12);
  flex-shrink: 0;
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 18px;
  border: 1px solid rgba(192, 138, 46, 0.3);
  pointer-events: none;
}

.card-title {
  font-size: 0.78rem;
  font-weight: 600;
}

.card-subtitle {
  font-size: 0.6rem;
  color: #4a342a;
  color: var(--ink-soft);
}

.card-price {
  font-size: 0.95rem;
  font-weight: 600;
}

.change {
  font-size: 0.6rem;
  color: #195227;
}

.change.negative {
  color: #7b1f1f;
}

.footer {
  margin-top: 3rem;
  text-align: center;
  font-size: 0.75rem;
  color: #4a342a;
  color: var(--ink-soft);
}

.footer p + p {
  margin-top: 0.4rem;
}

.invoice-hero .hero-card {
  display: flex;
  align-items: center;
}

.invoice-hint {
  font-size: 0.75rem;
  color: #4a342a;
  color: var(--ink-soft);
  line-height: 1.6;
}

.invoice-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  align-items: flex-start;
}

.invoice-panel {
  background: #fbf6f0;
  border-radius: 18px;
  padding: 1.2rem;
  box-shadow: 0 16px 30px rgba(35, 18, 8, 0.12);
  flex: 1 1 320px;
  min-width: 280px;
}

.field-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.field-group {
  flex: 1 1 180px;
  margin-bottom: 0.8rem;
}

.field-group label {
  display: block;
  font-size: 0.7rem;
  margin-bottom: 0.3rem;
  color: #4a342a;
  color: var(--ink-soft);
}

.field-group input,
.field-group textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid #e1d3c6;
  border-radius: 10px;
  font-size: 0.85rem;
  background: #fff;
}

.price-picker {
  margin-bottom: 0.8rem;
}

.price-picker label {
  display: block;
  font-size: 0.7rem;
  margin-bottom: 0.3rem;
  color: #4a342a;
  color: var(--ink-soft);
}

.price-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.price-picker select {
  flex: 1 1 220px;
  padding: 0.5rem 0.6rem;
  border: 1px solid #e1d3c6;
  border-radius: 10px;
  font-size: 0.8rem;
  background: #fff;
}

.items-block {
  margin: 1rem 0;
}

.items-head {
  display: flex;
  gap: 0.6rem;
  font-size: 0.7rem;
  color: #4a342a;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.items-head span {
  flex: 1;
}

.items-head span:last-child {
  flex: 0 0 3.5rem;
}

.item-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  align-items: center;
}

.item-row input {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border: 1px solid #e1d3c6;
  border-radius: 8px;
  font-size: 0.8rem;
}

.item-row .item-qty,
.item-row .item-price {
  max-width: 7rem;
}

.item-remove {
  background: #f1e2d6;
  border: none;
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.7rem;
  cursor: pointer;
  color: #7b4d2a;
}

.button {
  background: #c08a2e;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.button.secondary {
  background: #ead8c7;
  color: #5a3a1f;
  margin-top: 0.5rem;
}

.section-title-inline {
  font-size: 1rem;
  margin-bottom: 0.8rem;
}

.invoice-preview {
  background: #fff;
  border-radius: 16px;
  padding: 1rem;
  border: 1px solid #e6d9cd;
}

.invoice-sheet h2 {
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.invoice-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  border-bottom: 1px solid #eee1d4;
  padding-bottom: 0.8rem;
  margin-bottom: 0.8rem;
}

.invoice-store p,
.invoice-meta p,
.invoice-customer p {
  font-size: 0.75rem;
  color: #4a342a;
  color: var(--ink-soft);
  margin-top: 0.3rem;
}

.invoice-meta span,
.invoice-customer span {
  color: #1d120f;
  color: var(--ink);
  font-weight: 600;
}

.invoice-customer {
  margin-bottom: 0.6rem;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.6rem;
  font-size: 0.75rem;
}

.invoice-table th,
.invoice-table td {
  border: 1px solid #eee1d4;
  padding: 0.45rem;
  text-align: center;
}

.invoice-table th {
  background: #f8f2ec;
}

.invoice-table .empty {
  text-align: center;
  color: #4a342a;
  color: var(--ink-soft);
}

.invoice-totals {
  margin-top: 0.8rem;
  font-size: 0.78rem;
}

.invoice-totals div {
  margin-top: 0.3rem;
}

.invoice-total {
  font-size: 0.85rem;
  color: #1d120f;
  color: var(--ink);
}

.invoice-notes {
  margin-top: 0.8rem;
  font-size: 0.75rem;
  color: #4a342a;
  color: var(--ink-soft);
}

.invoice-print {
  display: none;
}

.invoice-actions {
  text-align: left;
  margin-bottom: 0.8rem;
}

.invoice-error {
  padding: 1rem;
  background: #fff3f3;
  border-radius: 12px;
  color: #7b1f1f;
}

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

  .glow,
  .hero,
  #builder-view,
  .invoice-actions {
    display: none !important;
  }

  .invoice-preview {
    border: none;
    box-shadow: none;
  }
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }

  body {
    padding: 1.4rem 1rem 2.4rem;
    font-size: 1rem;
  }

  h1 {
    font-size: 1.5rem;
  }
}

@keyframes drift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .card {
    animation: rise 0.6s ease both;
  }

  .card:nth-child(2) { animation-delay: 0.05s; }
  .card:nth-child(3) { animation-delay: 0.1s; }
  .card:nth-child(4) { animation-delay: 0.15s; }
  .card:nth-child(5) { animation-delay: 0.2s; }
  .card:nth-child(6) { animation-delay: 0.25s; }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
