:root {
  --bg: #f6f1e8;
  --panel: rgba(255, 252, 247, 0.92);
  --line: rgba(62, 40, 16, 0.12);
  --ink: #22160d;
  --muted: #715b49;
  --accent: #b53f2f;
  --accent-dark: #7d2419;
  --success: #2e7d4b;
  --shadow: 0 20px 50px rgba(65, 39, 14, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top left, rgba(181, 63, 47, 0.16), transparent 32%),
    radial-gradient(circle at right, rgba(210, 171, 99, 0.18), transparent 28%),
    linear-gradient(180deg, #f7f1e7 0%, #efe4d3 100%);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.hero,
.panel {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 28px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
.tag-model,
.tag-main-price,
.tag-total {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3.2rem);
  line-height: 1;
}

.hero-copy,
.panel-header p,
.sheet-summary,
.empty-state {
  color: var(--muted);
}

.hero-copy {
  margin: 12px 0 0;
  max-width: 700px;
}

.hero-actions,
.action-row,
.memory-actions,
.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1.15fr) minmax(280px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.panel {
  padding: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
  margin-bottom: 18px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.panel-header p {
  margin: 0;
  text-align: right;
  font-size: 0.95rem;
}

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

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-grid label span {
  font-size: 0.9rem;
  font-weight: 700;
}

.form-grid .wide {
  grid-column: span 2;
}

.form-actions-row {
  display: flex;
  align-items: end;
}

.line-settings-modal {
  width: min(980px, calc(100% - 24px));
  max-height: min(88vh, 900px);
  padding: 0;
  border: 1px solid rgba(62, 40, 16, 0.12);
  border-radius: 28px;
  background: rgba(255, 252, 247, 0.98);
  box-shadow: 0 30px 80px rgba(32, 18, 6, 0.24);
}

.line-settings-modal::backdrop {
  background: rgba(34, 22, 13, 0.34);
  backdrop-filter: blur(4px);
}

.line-settings-modal__header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding: 24px 24px 0;
}

.line-settings-modal__header h3,
.line-settings-modal__header p {
  margin: 0;
}

.line-settings-modal__header p {
  margin-top: 4px;
  color: var(--muted);
}

.line-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  padding: 24px;
  overflow: auto;
}

.line-setting {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.line-setting span {
  font-size: 0.95rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(62, 40, 16, 0.16);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 2px solid rgba(181, 63, 47, 0.25);
  border-color: rgba(181, 63, 47, 0.35);
}

input[type="color"] {
  min-height: 52px;
  padding: 6px;
}

.logo-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.primary-button,
.ghost-button {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent) 0%, #d6743d 100%);
  color: #fff6f0;
  box-shadow: 0 12px 24px rgba(181, 63, 47, 0.22);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  border-color: rgba(62, 40, 16, 0.12);
}

.small {
  padding: 10px 14px;
}

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

.preview-stage {
  padding: 18px;
  border-radius: 24px;
  border: 1px dashed rgba(62, 40, 16, 0.18);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(250, 242, 232, 0.82)),
    repeating-linear-gradient(
      45deg,
      rgba(62, 40, 16, 0.03),
      rgba(62, 40, 16, 0.03) 12px,
      transparent 12px,
      transparent 24px
    );
  overflow: auto;
}

#previewTag {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 260px;
}

.memory-panel {
  grid-column: 2;
  grid-row: span 2;
}

.memory-list {
  display: grid;
  gap: 12px;
}

.memory-item {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid rgba(62, 40, 16, 0.12);
  background: rgba(255, 255, 255, 0.78);
}

.memory-item strong {
  font-size: 1rem;
}

.memory-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.sheet-panel {
  grid-column: 1 / -1;
}

.sheet-summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.sheet-editor {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.sheet-editor-item {
  display: grid;
  grid-template-columns: 72px minmax(180px, 1.4fr) minmax(160px, 1fr) minmax(120px, 140px) auto auto;
  gap: 10px;
  align-items: center;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(62, 40, 16, 0.12);
  background: rgba(255, 255, 255, 0.78);
}

.sheet-editor-item input {
  padding: 10px 12px;
  border-radius: 12px;
}

.sheet-editor-index {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tag-width, 60mm), var(--tag-width, 60mm)));
  gap: var(--sheet-gap, 6mm);
  align-content: start;
  min-height: 220px;
  justify-content: start;
}

.tag-shell {
  position: relative;
}

.tag-shell .sheet-tools {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.sheet-tool {
  flex: 1;
  border: 1px solid rgba(62, 40, 16, 0.12);
  border-radius: 999px;
  padding: 8px 10px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.88);
}

.tag-card {
  width: var(--tag-width, 60mm);
  height: var(--tag-height, 90mm);
  padding: 6mm 5mm 5mm;
  display: grid;
  grid-template-rows: auto auto auto auto auto 1fr auto;
  gap: 2.6mm;
  border: 1px dashed rgba(62, 40, 16, 0.2);
  overflow: hidden;
}

.tag-header {
  display: flex;
  align-items: start;
  min-height: 16mm;
}

.tag-brand {
  display: flex;
  align-items: center;
  justify-content: start;
  font-size: clamp(calc(10px * var(--brand-font-scale, 1)), calc(1.7mm * var(--brand-font-scale, 1)), calc(16px * var(--brand-font-scale, 1)));
  font-weight: var(--brand-font-weight, 800);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-brand img {
  max-width: 100%;
  max-height: 14mm;
  object-fit: contain;
}

.tag-model {
  margin: 0;
  position: relative;
  top: -10mm;
  margin-bottom: -10mm;
  font-size: clamp(calc(18px * var(--model-font-scale, 1)), calc(4.8mm * var(--model-font-scale, 1)), calc(33px * var(--model-font-scale, 1)));
  line-height: 1.05;
  font-weight: var(--model-font-weight, 700);
  text-transform: uppercase;
}

.tag-info {
  font-size: clamp(calc(11px * var(--info-font-scale, 1)), calc(2.5mm * var(--info-font-scale, 1)), calc(18px * var(--info-font-scale, 1)));
  font-weight: var(--info-font-weight, 400);
  line-height: 1.2;
}

.tag-main-price {
  margin-top: 2mm;
  text-align: center;
  font-size: clamp(calc(28px * var(--price-font-scale, 1)), calc(7.4mm * var(--price-font-scale, 1)), calc(50px * var(--price-font-scale, 1)));
  font-weight: var(--price-font-weight, 700);
  line-height: 1;
}

.tag-components {
  display: grid;
  gap: 1.5mm;
  align-self: end;
  font-size: clamp(calc(11px * var(--components-font-scale, 1)), calc(2.5mm * var(--components-font-scale, 1)), calc(18px * var(--components-font-scale, 1)));
  font-weight: var(--components-font-weight, 400);
  line-height: 1.2;
}

.component-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 2mm;
}

.tag-note {
  font-style: italic;
  min-height: 4mm;
  font-size: clamp(calc(11px * var(--note-font-scale, 1)), calc(2.5mm * var(--note-font-scale, 1)), calc(18px * var(--note-font-scale, 1)));
  font-weight: var(--note-font-weight, 400);
  line-height: 1.2;
}

.tag-total {
  padding-top: 2.5mm;
  padding-bottom: 3mm;
  font-size: clamp(calc(16px * var(--total-font-scale, 1)), calc(3.6mm * var(--total-font-scale, 1)), calc(26px * var(--total-font-scale, 1)));
  font-weight: var(--total-font-weight, 700);
}

.empty-state {
  padding: 24px;
  border: 1px dashed rgba(62, 40, 16, 0.18);
  border-radius: 20px;
  text-align: center;
}

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

  .memory-panel,
  .sheet-panel {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 12px;
  }

  .hero,
  .panel {
    border-radius: 22px;
    padding: 18px;
  }

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

  .panel-header {
    flex-direction: column;
    align-items: start;
  }

  .panel-header p {
    text-align: left;
  }

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

  .form-grid .wide {
    grid-column: auto;
  }

  .line-settings-modal {
    width: min(100% - 16px, 980px);
    border-radius: 22px;
  }

  .line-settings-modal__header,
  .line-settings-grid {
    padding: 18px;
  }

  .sheet-summary {
    flex-direction: column;
    align-items: start;
  }

  .sheet-editor-item {
    grid-template-columns: 1fr;
  }

  .sheet-grid {
    justify-content: center;
  }
}

@media print {
  @page {
    margin: 0;
  }

  body {
    background: #fff;
    margin: 0;
  }

  .no-print,
  .sheet-tools {
    display: none !important;
  }

  .page-shell {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .sheet-panel {
    padding: 8mm;
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  .sheet-grid {
    grid-template-columns: repeat(auto-fill, var(--tag-width, 60mm));
    gap: var(--sheet-gap, 6mm);
    justify-content: start;
  }

  .tag-shell {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .tag-card {
    box-shadow: none;
    width: var(--tag-width, 60mm) !important;
    height: var(--tag-height, 90mm) !important;
    min-height: 0;
    border: 1.4px dashed #2b1b11;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
