:root {
  color-scheme: light;
  --ink: #141414;
  --muted: #64686f;
  --line: #d9dce1;
  --surface: #ffffff;
  --canvas: #eef0f3;
  --accent: #e73a3f;
  --accent-dark: #bd2429;
  --success: #0d9d68;
  --warning: #a96600;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(231, 58, 63, .15), transparent 33%),
    linear-gradient(135deg, #080808 0%, #242426 56%, #0d0d0e 100%);
}

.login-shell, .setup-shell { width: min(100%, 460px); }
.setup-shell { width: min(100%, 720px); }

.login-card, .setup-card {
  padding: clamp(26px, 5vw, 42px);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 22px;
  color: #fff;
  background: rgba(22, 22, 24, .96);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .45);
}

.login-card h1, .setup-card h1 { margin-bottom: 10px; }
.login-copy { margin-bottom: 26px; color: #bfc1c6; line-height: 1.55; }
.login-form, .setup-form { display: grid; gap: 16px; }
.login-form label, .setup-form label { display: grid; gap: 7px; color: #e7e7e9; font-size: 13px; font-weight: 750; }
.login-form input, .setup-form input {
  width: 100%;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid #505158;
  border-radius: 10px;
  color: #fff;
  background: #111113;
}
.login-form input:focus, .setup-form input:focus { outline: 3px solid rgba(231, 58, 63, .24); border-color: #f05a5f; }
.login-form .primary-button, .setup-form .primary-button { margin-top: 4px; }
.setup-form fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 18px;
  border: 1px solid #3c3d42;
  border-radius: 13px;
}
.setup-form legend { padding: 0 8px; color: #ff8589; font-size: 12px; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.setup-form .full-field { grid-column: 1 / -1; }
.form-alert {
  margin-bottom: 18px;
  padding: 11px 13px;
  border: 1px solid rgba(255, 112, 117, .45);
  border-radius: 10px;
  color: #ffd6d8;
  background: rgba(170, 29, 36, .25);
  font-size: 13px;
  line-height: 1.45;
}

.app-header {
  min-height: 118px;
  padding: 24px clamp(24px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #fff;
  background: linear-gradient(112deg, #090909 0%, #1c1c1d 56%, #343436 100%);
  border-bottom: 4px solid var(--accent);
}

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.logout-form { margin: 0; }
.logout-button {
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid rgba(255,255,255,.23);
  border-radius: 10px;
  color: #fff;
  background: rgba(255,255,255,.07);
  font-weight: 750;
}
.logout-button:hover { border-color: rgba(255,255,255,.48); background: rgba(255,255,255,.12); }

.app-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 18px 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.app-tab {
  padding: 11px 16px 12px;
  border: 0;
  border-bottom: 3px solid transparent;
  color: #696c73;
  background: transparent;
  font-weight: 800;
}
.app-tab:hover { color: #292b2f; }
.app-tab.is-active { color: var(--accent-dark); border-bottom-color: var(--accent); }

.app-notice {
  position: fixed;
  z-index: 100;
  right: 22px;
  bottom: 22px;
  max-width: min(440px, calc(100vw - 44px));
  padding: 13px 16px;
  border-radius: 11px;
  color: #fff;
  background: #14805a;
  box-shadow: 0 16px 45px rgba(0, 0, 0, .22);
  font-size: 13px;
  font-weight: 750;
}
.app-notice.error { background: #a8242b; }

.eyebrow {
  margin: 0 0 5px;
  color: #ff777b;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(25px, 3vw, 36px); letter-spacing: -.035em; }
h2 { margin-bottom: 4px; font-size: 20px; letter-spacing: -.02em; }
.header-copy, .section-heading p { margin-bottom: 0; color: #bfc1c6; }

.primary-button, .quiet-button, .icon-button {
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 750;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.primary-button {
  min-height: 44px;
  padding: 0 19px;
  color: white;
  background: var(--accent);
  box-shadow: 0 9px 24px rgba(231, 58, 63, .24);
}

.primary-button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.quiet-button { padding: 8px 11px; color: #35383d; background: #fff; border-color: var(--line); }
.quiet-button:hover { border-color: #aeb2b9; background: #f8f8f9; }
.icon-button { width: 38px; height: 38px; color: #555; background: transparent; font-size: 28px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(520px, .9fr) minmax(600px, 1.1fr);
  gap: 18px;
  padding: 18px;
  align-items: start;
}

.history-view { padding: 18px; }
.history-panel {
  overflow: hidden;
  background: #fff;
  border: 1px solid #e1e3e7;
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(25, 30, 40, .07);
}
.history-table-wrap { overflow: auto; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 13px 15px; border-bottom: 1px solid #e7e9ec; text-align: left; vertical-align: middle; }
.history-table th { color: #5d6067; background: #f7f7f8; font-size: 11px; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.history-table td { color: #292b2f; font-size: 13px; }
.history-table tbody tr:hover { background: #fbfbfc; }
.history-table tbody tr:last-child td { border-bottom: 0; }
.history-brands { max-width: 360px; color: var(--muted) !important; line-height: 1.45; }
.history-message { padding: 34px !important; color: var(--muted) !important; text-align: center !important; }
.history-message.error { color: #a8242b !important; }
.history-status { min-width: 142px; min-height: 34px; padding: 5px 30px 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.history-status.status-in_progress { color: #805500; border-color: #eccb83; background: #fff3d5; }
.history-status.status-accepted { color: #08744d; border-color: #99d9bf; background: #e2f7ee; }
.history-status.status-rejected { color: #962229; border-color: #e9a6aa; background: #ffe9ea; }
.history-status.status-test { color: #4e5360; border-color: #c7cbd3; background: #f0f1f4; }
.download-offer { color: var(--accent-dark); font-weight: 850; text-decoration: none; white-space: nowrap; }
.download-offer:hover { text-decoration: underline; }
.download-offer.secondary { color: #5f636a; }
.history-file-actions { display: flex; align-items: center; gap: 12px; }

.catalog-panel, .preview-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid #e1e3e7;
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(25, 30, 40, .07);
}

.catalog-panel { overflow: hidden; }
.preview-panel { position: sticky; top: 18px; padding-bottom: 18px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.section-heading p { color: var(--muted); font-size: 13px; }
.heading-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.filters {
  display: grid;
  grid-template-columns: 1.45fr .8fr .9fr;
  gap: 10px;
  padding: 14px 20px;
  background: #fafafa;
  border-bottom: 1px solid var(--line);
}

.filters label:not(.toggle-field) span {
  display: block;
  margin-bottom: 5px;
  color: #565a61;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

input[type="search"], input[type="number"], select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cfd2d7;
  border-radius: 9px;
  padding: 7px 10px;
  color: var(--ink);
  background: white;
}

input:focus, select:focus { outline: 3px solid rgba(231, 58, 63, .16); border-color: var(--accent); }

.toggle-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #44484e;
  font-size: 13px;
  font-weight: 700;
}

.toggle-field input { width: 17px; height: 17px; accent-color: var(--accent); }

.item-list {
  max-height: calc(100vh - 340px);
  min-height: 320px;
  overflow: auto;
}

.item-row {
  display: grid;
  grid-template-columns: 28px minmax(180px, 1fr) 92px 86px;
  gap: 10px;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid #eceef1;
}

.item-row:hover { background: #fbfbfc; }
.item-row.is-selected { background: #fff6f6; }
.item-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.item-name { min-width: 0; }
.item-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.item-meta { margin-top: 3px; color: var(--muted); font-size: 11px; }
.status-pill { display: inline-flex; align-items: center; width: fit-content; padding: 4px 7px; border-radius: 999px; font-size: 10px; font-weight: 850; text-transform: uppercase; }
.status-pill.ready { color: #08744d; background: #e2f7ee; }
.status-pill.warning { color: #8a5700; background: #fff0cb; }
.status-pill.missing { color: #8a5700; background: #fff0cb; }
.discount-cell { display: flex; align-items: center; gap: 4px; }
.discount-cell input { width: 54px; min-height: 34px; padding: 5px 6px; text-align: right; }
.discount-cell span { color: var(--muted); font-weight: 750; }
.edit-prices { padding: 6px 8px; font-size: 11px; }

.screen-preview {
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 18px;
  background: #cfd2d7;
  border-radius: 0 0 16px 16px;
}

.empty-preview {
  min-height: 380px;
  display: grid;
  place-items: center;
  padding: 50px;
  color: #6a6e75;
  text-align: center;
  background: white;
  border: 1px dashed #aeb2b9;
  border-radius: 12px;
}

.offer-page {
  position: relative;
  width: 210mm;
  height: 297mm;
  margin: 0 auto 20px;
  padding: 8.5mm 0;
  overflow: hidden;
  background: linear-gradient(90deg, #070707 0%, #fff 100%);
  box-shadow: 0 8px 28px rgba(15, 18, 24, .22);
  break-after: page;
  page-break-after: always;
}

.offer-page:last-child { break-after: auto; page-break-after: auto; }

.offer-card {
  position: relative;
  width: 210mm;
  height: 46.66mm;
  overflow: hidden;
  break-inside: avoid;
  page-break-inside: avoid;
}

.contact-page { padding: 3.5mm 0; background: #171817; }
.contact-page img { display: block; width: 210mm; height: 290mm; object-fit: fill; }

.table-card {
  display: grid;
  grid-template-columns: 57mm 1fr;
  align-items: center;
  padding: 4mm 7mm 4mm 6mm;
  isolation: isolate;
  color: #fff;
}

.table-card::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 1.8mm 0;
  background: #171717;
  border-radius: 0 10mm 10mm 0;
}

.table-card.light { color: #111; }
.table-card.light::before {
  left: 5mm;
  background: #fff;
  border-radius: 10mm 0 0 10mm;
}

.product-identity {
  position: relative;
  height: 38.6mm;
  display: grid;
  grid-template-columns: 38mm 14mm;
  align-items: center;
  gap: 1mm;
  padding-right: 3mm;
}

.brand-logo {
  width: 34mm;
  height: 34mm;
  display: grid;
  place-items: center;
  overflow: visible;
  border-radius: 50%;
  background: transparent;
}

.brand-logo img { display: block; width: 100%; height: 100%; object-fit: contain; }
.brand-fallback { padding: 2mm; color: #111; font-size: 3.3mm; font-weight: 850; line-height: 1.05; text-align: center; }

.product-codes {
  height: 34mm;
  display: grid;
  grid-template-rows: 11mm 1fr;
  align-items: center;
  justify-items: center;
}

.product-icons {
  width: 11mm;
  height: 21mm;
  object-fit: contain;
}

.grade-mark { font-size: 8.5mm; font-weight: 950; line-height: 1; }
.grade-A { color: #08b574; }
.grade-B { color: #ff8746; }
.grade-C { color: #55c9d5; }
.grade-U { color: #777; }
.category-mark { max-width: 14mm; font-size: 2.55mm; font-weight: 800; line-height: 1.08; text-align: center; text-transform: uppercase; overflow-wrap: anywhere; }

.price-grid {
  width: 100%;
  height: 38.6mm;
  table-layout: fixed;
  border-collapse: collapse;
  border: .65mm solid currentColor;
  color: inherit;
}

.price-grid th, .price-grid td {
  padding: 0;
  border-right: .5mm solid currentColor;
  text-align: center;
  vertical-align: middle;
}

.price-grid th:last-child, .price-grid td:last-child { border-right: 0; }
.price-grid thead { height: 15.2mm; border-bottom: .5mm solid currentColor; }
.price-grid tbody { height: 22.2mm; }
.price-grid thead th { font-size: 3.15mm; font-weight: 850; }
.price-grid .unit-cell { width: 17mm; font-size: 3.2mm; }
.currency-cell { width: 17mm; font-size: 6.2mm; font-weight: 400; }

.price-stack {
  min-height: 20mm;
  display: grid;
  grid-template-rows: 8.4mm 9.6mm;
  place-items: center;
  padding-top: .8mm;
}

.old-price {
  position: relative;
  min-width: 11mm;
  color: #5d6066;
  font-size: 3mm;
  font-weight: 450;
  line-height: 1;
}

.table-card.dark .old-price { color: #c2c4c8; }

.old-price::after {
  content: "";
  position: absolute;
  left: -.8mm;
  right: -.8mm;
  top: 50%;
  height: .2mm;
  background: currentColor;
  opacity: .82;
}

.discounted-price { font-size: 4mm; font-weight: 950; line-height: 1; letter-spacing: -.02em; }
.price-grade-a { color: #08b574; }
.price-grade-other { color: #ff7838; }

.discount-badge {
  position: absolute;
  left: 32.5mm;
  top: 0;
  z-index: 3;
  width: 11.3mm;
  height: 11.3mm;
  object-fit: contain;
  filter: drop-shadow(0 .8mm .8mm rgba(0, 0, 0, .2));
}

.discount-badge-fallback {
  display: grid;
  place-items: center;
  width: auto;
  height: auto;
  min-width: 15mm;
  padding: .75mm 1.4mm;
  border-radius: 4mm;
  color: #fff;
  background: #ed3037;
  box-shadow: 0 1mm 2mm rgba(0, 0, 0, .18);
  font-size: 3.65mm;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  letter-spacing: -.02em;
}

.new-price, .strike {
  position: absolute;
  z-index: 4;
  left: var(--x);
  transform: translateX(-50%);
  pointer-events: none;
}

.new-price {
  bottom: 1.7mm;
  min-width: 13mm;
  color: #ff3038;
  font-size: 3.6mm;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-shadow: 0 .25mm .25mm rgba(255, 255, 255, .9), 0 0 1mm rgba(255,255,255,.9);
}

.strike {
  top: 73.4%;
  width: 10mm;
  height: .38mm;
  background: #e12d34;
  box-shadow: 0 0 .3mm rgba(255, 255, 255, .7);
}

.generic-card {
  display: grid;
  grid-template-columns: 39mm 1fr;
  align-items: stretch;
  padding: 4mm 7mm 4mm 6mm;
  background: #171717;
  color: #fff;
}

.generic-card.light { color: #111; background: white; }
.generic-brand { display: grid; align-content: center; justify-items: center; padding-right: 4mm; text-align: center; }
.generic-brand strong { font-size: 4mm; line-height: 1.05; }
.generic-brand span { margin-top: 1.5mm; color: #ff7d43; font-size: 7mm; font-weight: 900; }
.generic-table { display: grid; grid-template-columns: repeat(6, 1fr); border: .55mm solid currentColor; }
.generic-cell { display: grid; place-items: center; grid-template-rows: 1fr 1fr 1fr; border-right: .35mm solid currentColor; padding: .8mm 0; font-size: 3.4mm; font-weight: 800; }
.generic-cell:last-child { border-right: 0; }
.generic-cell small { font-size: 2.8mm; }
.generic-cell s { color: currentColor; font-size: 2.8mm; font-weight: 500; opacity: .75; }
.generic-cell b { color: #ff3038; }

.print-root { display: none; }

dialog {
  width: min(620px, calc(100vw - 32px));
  border: 0;
  border-radius: 16px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); backdrop-filter: blur(3px); }
dialog form { padding: 22px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.dialog-copy { color: var(--muted); }
.price-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.price-fields label span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 750; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 22px 0 0; padding: 0; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .item-list, .screen-preview { max-height: none; }
}

@media (max-width: 700px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .app-tabs { padding-inline: 10px; }
  .workspace { padding: 10px; }
  .history-view { padding: 10px; }
  .filters { grid-template-columns: 1fr; }
  .filters .toggle-field { grid-column: auto; }
  .item-row { grid-template-columns: 26px 1fr 68px; }
  .stock-cell, .status-cell { display: none; }
  .preview-heading { align-items: flex-start; flex-direction: column; }
  .screen-preview { padding: 8px; }
  .offer-page { transform-origin: top left; }
  .price-fields { grid-template-columns: repeat(2, 1fr); }
  .setup-form fieldset { grid-template-columns: 1fr; }
  .setup-form .full-field { grid-column: auto; }
  .history-table thead { display: none; }
  .history-table, .history-table tbody, .history-table tr, .history-table td { display: block; width: 100%; }
  .history-table tr { padding: 11px 15px; border-bottom: 1px solid #e7e9ec; }
  .history-table td { display: grid; grid-template-columns: 95px minmax(0, 1fr); gap: 10px; padding: 6px 0; border: 0; }
  .history-table .history-file-actions { display: grid; }
  .history-table td::before { content: attr(data-label); color: #777b83; font-size: 10px; font-weight: 850; letter-spacing: .04em; text-transform: uppercase; }
  .history-message { display: block !important; padding: 25px 0 !important; }
  .history-message::before { content: none !important; }
}

@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { width: 210mm; margin: 0; padding: 0; background: white; }
  .no-print, dialog { display: none !important; }
  .print-root { display: block; }
  .offer-page {
    margin: 0;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
