:root {
  --bg: #f6f0e7;
  --bg-soft: #efe4d4;
  --card: #fffaf3;
  --ink: #201c1a;
  --muted: #6c625c;
  --accent: #d3112e; /* Красный цвет ASKO */
  --accent-dark: #8f131a;
  --line: #dacbb7;
  --shadow: 0 22px 50px rgba(47, 27, 8, 0.17);
  --radius: 20px;
  --mono: "IBM Plex Mono", "Consolas", monospace;
  --sans: "Arial", "Helvetica", sans-serif;
  --condensed: "Oswald", "Arial Narrow", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(circle at 80% -10%, #ffe6bf, transparent 45%),
    radial-gradient(circle at 10% 30%, #fff4de, transparent 35%), var(--bg);
  min-height: 100vh;
}

.page-bg {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(111, 83, 43, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(111, 83, 43, 0.035) 1px, transparent 1px);
  background-size: 26px 26px;
  pointer-events: none;
}

.layout {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
  grid-template-columns: 1.1fr 1.3fr 0.8fr;
  align-items: start;
}

.panel {
  background: color-mix(in srgb, var(--card) 94%, white 6%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-head h1,
.panel-head h2,
.preview-head h2 {
  margin: 0;
  font-family: var(--condensed);
  letter-spacing: 0.02em;
}

.panel-head p,
.preview-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
}

/* --- Modes Switcher --- */
.mode-switch {
  display: flex;
  background: #ebe0d3;
  border-radius: 12px;
  padding: 4px;
  margin-top: 14px;
  gap: 4px;
}

.mode-btn {
  flex: 1;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  padding: 8px;
  border-radius: 9px;
  box-shadow: none;
  font-size: 0.9rem;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.5);
  transform: none;
}

.mode-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.mode-content {
  display: none;
  margin-top: 14px;
}

.mode-content.active {
  display: block;
}

/* --- Form --- */
.form-grid {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 5px;
  font-size: 0.86rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input,
button {
  font: inherit;
}

input {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 11px;
  color: var(--ink);
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, white 35%);
  outline-offset: 1px;
}

.specs-wrap {
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.specs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.specs-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-family: var(--condensed);
}

.spec-rows {
  display: grid;
  gap: 7px;
}

.spec-row {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr 1fr auto;
}

button {
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.17s ease, background 0.2s ease;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.remove-spec,
.small-btn,
.ghost-btn {
  background: #fbefe9;
  color: #68252a;
  border: 1px solid #d9aaa8;
}

.remove-spec:hover,
.small-btn:hover,
.ghost-btn:hover {
  background: #f4dad2;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

/* --- Auto Mode --- */
.auto-search-box {
  background: #fff8ed;
  border: 1px dashed #d3bea7;
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}

.auto-search-box input {
  width: 100%;
  font-size: 1.1rem;
  padding: 12px;
  text-align: center;
  margin-bottom: 10px;
}

.auto-search-box button {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}

.results-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.result-item {
  text-align: left;
  background: #fff;
  border: 1px solid #e7d9c5;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.2s;
}

.result-item:hover {
  border-color: var(--accent);
  background: #fffcf5;
}

.result-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.result-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

/* --- Import Attributes --- */
.import-attrs {
  margin-top: 10px;
  border: 1px solid #dbc8ad;
  border-radius: 10px;
  padding: 8px;
  background: #fffcf5;
}

.is-hidden {
  display: none !important;
}

.import-attrs-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.import-attrs-actions {
  display: flex;
  gap: 6px;
}

.import-attrs-list {
  margin-top: 8px;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.attr-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  padding: 6px 7px;
  border-radius: 8px;
  border: 1px solid #e7d9c5;
  background: #fff;
}

.attr-item-label {
  font-size: 0.82rem;
  color: #564d47;
  margin: 0;
}

.attr-item-value {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 2px 0 0;
}

.status-line {
  min-height: 22px;
  margin: 8px 0 0;
  color: #0f5f43;
  font-weight: 700;
}

/* --- TAG DESIGN (Technoklass Style) --- */

.preview-shell {
  margin-top: 14px;
  display: grid;
  place-items: center;
  overflow-x: auto;
}

/* A6 Landscape: 148mm x 105mm */
.tag-card {
  width: 148mm;
  height: 105mm;
  background: #fff;
  border: 1px solid #bbb0a0;
  box-shadow: 0 10px 30px rgba(19, 14, 10, 0.18);
  display: flex;
  overflow: hidden;
  color: #000;
  font-family: "Arial", "Helvetica", sans-serif;
  position: relative;
  line-height: 1.2;
}

/* Main Body */
.tag-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
}

/* Header: Logo, Category, Model, QR */
.tag-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 12px;
}

.header-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.header-right {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

/* Brand Logo над названием */
.brand-logo-wrapper {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 6px;
}

.brand-logo-img {
  max-height: 18mm;
  max-width: 45mm;
  object-fit: contain;
}

.brand-logo-text {
  font-size: 20pt;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tag-category {
  font-size: 13pt;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
  color: #000;
}

.tag-model {
  font-size: 18pt;
  font-weight: 800;
  margin: 2px 0 0;
  line-height: 1.05;
  color: #000;
  letter-spacing: -0.01em;
}

/* QR в правом верхнем углу */
.qr {
  width: 24mm;
  height: 24mm;
  object-fit: contain;
}

/* Specs Table */
.spec-list {
  flex: 1;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2.5px 10px;
  font-size: 8.5pt;
  align-content: start;
  padding-top: 6px;
  margin-top: 2px;
}

.spec-item {
  display: contents;
}

.spec-label {
  color: #000;
  line-height: 1.15;
  white-space: normal;
}

.spec-value {
  font-weight: 700;
  line-height: 1.15;
  white-space: normal;
  text-align: right;
  color: #000;
}

/* Footer: Info & Price */
.tag-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: auto;
  padding-top: 8px;
  gap: 12px;
}

.footer-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.footer-right {
  display: flex;
  align-items: flex-end;
}

.price {
  font-size: 34pt;
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: #000;
}

.footer-website {
  font-size: 9pt;
  font-weight: 700;
  color: #000;
  line-height: 1.2;
  text-align: left;
}

.footer-warranty {
  font-size: 8pt;
  color: #000;
  line-height: 1.2;
  text-align: left;
}

/* History */
.history-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.history-btn {
  width: 100%;
  text-align: left;
  background: #fff4e4;
  color: #302a25;
  border: 1px solid #dbc8ad;
  border-radius: 12px;
  padding: 9px;
}

.history-btn.active {
  border-color: #c55053;
  box-shadow: inset 0 0 0 1px #d17173;
}

.history-meta {
  display: block;
  color: #736860;
  font-size: 0.77rem;
  margin-top: 3px;
  font-family: var(--mono);
}

.stagger {
  opacity: 0;
  transform: translateY(16px);
  animation: rise 0.6s ease forwards;
  animation-delay: var(--delay, 0s);
}

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

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

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

  .spec-row {
    grid-template-columns: 1fr;
  }

  .mode-switch {
    flex-wrap: wrap;
  }

  .tag-card {
    width: 100%;
    height: auto;
    aspect-ratio: 1.41 / 1;
  }

  .spec-list { font-size: 2.3vw; }
  .tag-model { font-size: 4.5vw; }
  .tag-category { font-size: 3.3vw; }
  .brand-logo-text { font-size: 5vw; }
  .price { font-size: 8.5vw; }
  .qr { width: 16%; height: auto; }
  .footer-website { font-size: 2.2vw; }
  .footer-warranty { font-size: 2vw; }
}

@media print {
  @page {
    size: 148mm 105mm; /* A6 Landscape */
    margin: 0; /* Important for Firefox to hide headers */
  }

  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff;
    width: 148mm;
    height: 105mm;
    overflow: hidden;
  }

  body > * {
    display: none !important;
  }

  /* Show layout but hide everything inside except preview */
  .layout {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }

  .page-bg,
  .form-panel,
  .history-panel,
  .mode-switch,
  .preview-head,
  .status-line {
    display: none !important;
  }

  .preview-panel {
    display: block !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 148mm !important;
    height: 105mm !important;
  }

  .preview-shell {
    display: block !important;
    margin: 0 !important;
    width: 148mm !important;
    height: 105mm !important;
    padding: 0 !important;
  }

  .tag-card {
    display: flex !important; /* Ensure flex works */
    width: 148mm !important;
    height: 105mm !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    
    /* Avoid page breaks inside the card */
    break-inside: avoid;
    page-break-inside: avoid;
  }
  
  /* Hide scrollbars just in case */
  ::-webkit-scrollbar {
    display: none;
  }
}
