:root {
  --bg: #f3f6fb;
  --bg-soft: #eef3f9;
  --panel: #ffffff;
  --line: #d9e3ef;
  --text: #20324b;
  --muted: #6a7b90;
  --blue: #143453;
  --blue-2: #234a72;
  --orange: #f68b1f;
  --orange-2: #e97700;
  --green-bg: #edf8f1;
  --green-text: #17633d;
  --yellow-bg: #fff5dc;
  --yellow-text: #996300;
  --shadow: 0 24px 50px rgba(17, 43, 74, 0.08);
  --radius-lg: 28px;
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  font-family: "Manrope", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, #fff4e8 0, transparent 28%),
    linear-gradient(180deg, #e8eff8 0 180px, var(--bg) 180px 100%);
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input { font: inherit; }

.container {
  width: min(calc(100% - 40px), 1220px);
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(20, 52, 83, 0.08);
}

.topbar-row {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--blue);
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--muted);
  font-weight: 700;
}

.topnav a:hover {
  color: var(--blue);
}

.page {
  padding: 28px 0 52px;
}

.stack {
  display: grid;
  gap: 26px;
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid rgba(20, 52, 83, 0.08);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
}

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

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--blue-2);
  font-size: 14px;
  font-weight: 800;
}

.toyota-logo {
  width: 28px;
  height: 20px;
  object-fit: contain;
  border-radius: 3px;
}

body[data-page="search"] .page {
  padding-top: 18px;
}

body[data-page="search"] .stack {
  gap: 18px;
}

body[data-page="search"] .hero {
  gap: 18px;
}

body[data-page="search"] .hero .card {
  padding: 20px;
}

body[data-page="search"] h1 {
  font-size: 42px;
  line-height: 1.02;
}

body[data-page="search"] .lead {
  margin-top: 12px;
  font-size: 16px;
  line-height: 1.45;
}

body[data-page="search"] .field-input {
  min-height: 48px;
}

body[data-page="search"].has-search-result .catalog-intro-card { display: none; }
body[data-page="search"].has-search-result .hero { grid-template-columns: 1fr; }
body[data-page="search"].has-search-result .catalog-search-card { padding: 14px 18px; }
body[data-page="search"].has-search-result .catalog-search-card .form-grid {
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr) auto;
  align-items: end;
  gap: 12px;
}
body[data-page="search"].has-search-result .catalog-search-card > .stack { display: none; }
body[data-page="search"].has-search-result #search-results-section { padding: 16px 24px; }
body[data-page="search"].has-search-result #search-results-section > .card-header { margin-bottom: 10px; }
body[data-page="search"].has-search-result #search-results-section > .card-header h2 { font-size: 30px; }

@media (max-width: 760px) {
  body[data-page="search"].has-search-result .catalog-search-card .form-grid {
    grid-template-columns: 1fr;
  }
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: clamp(36px, 6vw, 62px);
  line-height: 0.94;
  letter-spacing: -0.04em;
  color: var(--blue);
}

h2 {
  font-size: clamp(28px, 3.2vw, 44px);
  line-height: 1.02;
  letter-spacing: -0.04em;
  color: var(--blue);
}

h3 {
  font-size: 22px;
  line-height: 1.1;
  color: var(--blue);
}

.lead {
  margin-top: 18px;
  max-width: 760px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field-label {
  display: block;
  margin: 0 0 8px;
  font-weight: 700;
  color: var(--blue-2);
}

.field-input {
  width: 100%;
  min-height: 56px;
  padding: 0 18px;
  border-radius: 22px;
  border: 1px solid #cbd9e8;
  background: #f8fbfe;
  outline: none;
}

.field-input:focus {
  border-color: #8bb1da;
  box-shadow: 0 0 0 4px rgba(139, 177, 218, 0.14);
}

.button-row,
.chips,
.mode-switch,
.page-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.mode-switch {
  justify-content: flex-end;
}

.button,
.chip,
.section-item,
.page-pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  transition: 0.18s ease;
}

.button,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

.button-primary {
  color: white;
  background: linear-gradient(135deg, var(--orange), var(--orange-2));
  border-color: transparent;
  box-shadow: 0 16px 28px rgba(246, 139, 31, 0.28);
}

.button-secondary {
  color: var(--blue);
  background: white;
}

.button-small {
  min-height: 44px;
  padding: 0 18px;
}

.chip {
  background: white;
  color: var(--blue);
}

.chip.active,
.page-pill.active {
  color: white;
  background: linear-gradient(135deg, var(--orange), var(--orange-2));
  border-color: transparent;
}

.results,
.units-layout,
.scheme-layout {
  display: grid;
  gap: 24px;
}

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

.unit-layout-left {
  min-width: 0;
}

.units-layout {
  grid-template-columns: minmax(0, 1fr) 260px;
  align-items: start;
}

.scheme-layout {
  grid-template-columns: minmax(0, 1fr) minmax(400px, 1fr);
  align-items: start;
}

.info-banner {
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid #cfe7d9;
  background: var(--green-bg);
  color: var(--green-text);
  font-weight: 700;
}

.warning-banner {
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid #f0dfb0;
  background: var(--yellow-bg);
  color: var(--yellow-text);
  font-weight: 700;
}

.not-applicable-banner {
  border-color: #f2b8b8;
  background: #fff1f1;
  color: #b42318;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat-box {
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: white;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 800;
  color: var(--blue);
}

.section-list {
  display: grid;
  gap: 4px;
}

.section-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 0;
  padding: 8px 10px;
  background: white;
  cursor: pointer;
  border-radius: 10px;
}

.section-item:hover {
  border-color: #a9c2db;
  background: #f5f7fa;
}

.section-item.active {
  color: white;
  background: linear-gradient(180deg, #21486f, #173858);
  border-color: transparent;
}

.section-item-title {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.25;
}

.section-item-count {
  margin-top: 0;
  min-width: 26px;
  text-align: center;
  font-size: 12px;
  color: var(--orange);
  font-weight: 700;
  border-radius: 999px;
  background: rgba(246, 139, 31, 0.12);
  padding: 2px 8px;
}

.section-item.active .section-item-count {
  color: #173858;
  background: #ffd08d;
}

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

.unit-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 20px;
  min-height: 320px;
}

.unit-card:hover {
  border-color: #9db9d7;
  box-shadow: 0 14px 24px rgba(24, 54, 86, 0.08);
}

.unit-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  padding: 4px;
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

.unit-preview img {
  max-height: 190px;
  max-width: 100%;
  object-fit: contain;
}

.unit-code {
  color: var(--orange);
  font-weight: 800;
  font-size: 14px;
}

.unit-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.28;
  color: var(--blue);
}

.unit-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.empty-state {
  padding: 20px;
  border-radius: 20px;
  border: 1px dashed #bfd0e1;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
}

.empty-state.not-applicable-state {
  border-color: #f2b8b8;
  color: #b42318;
  background: #fff7f7;
  font-weight: 700;
}

.catalog-access-banner {
  color: #8a2d17;
  background: #fff1ec;
  border-color: #f2b6a5;
}

.catalog-access-gate {
  padding: 30px 24px;
  text-align: center;
}

.catalog-access-gate__title {
  color: #14395e;
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
}

.catalog-access-gate__text { max-width: 520px; margin: 0 auto; }
.catalog-access-gate__actions { justify-content: center; margin-top: 20px; }

.scheme-stage {
  border-radius: 22px;
  border: 1px solid var(--line);
  background: white;
  padding: 10px;
}

.scheme-image-wrap {
  position: relative;
  overflow: auto;
  max-height: 75vh;
  border-radius: 16px;
  background: #fbfdff;
  padding: 8px;
}

.scheme-image {
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
}

.scheme-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.zone-rect {
  fill: transparent;
  stroke: transparent;
  stroke-width: 1;
  cursor: pointer;
  pointer-events: all;
  transition: fill 0.15s, stroke 0.15s;
}
/* Базовое состояние — очень слабая рамка чтобы видеть где зона */
.zone-rect {
  fill: transparent;
  stroke: rgba(33, 150, 243, 0.25);
  stroke-width: 1;
  cursor: pointer;
  pointer-events: all;
  transition: fill 0.15s, stroke 0.15s;
}
.zone-rect--hover {
  fill: rgba(255, 213, 79, 0.35);
  stroke: #f9a825;
  stroke-width: 2;
}
.zone-rect--selected {
  fill: rgba(229, 57, 53, 0.28);
  stroke: #c62828;
  stroke-width: 2.5;
}
/* legacy alias — старые inline onclick триггерят selectPnc → добавляет --selected; --highlight держим как alias для обратной совместимости */
.zone-rect--highlight {
  fill: rgba(229, 57, 53, 0.28);
  stroke: #c62828;
  stroke-width: 2.5;
}
.item-card {
  cursor: pointer;
  transition: background 0.15s;
}
.item-card--hover {
  background: rgba(255, 213, 79, 0.35) !important;
  box-shadow: inset 3px 0 0 #f9a825;
}
.item-card--selected {
  background: rgba(229, 57, 53, 0.18) !important;
  box-shadow: inset 3px 0 0 #c62828;
}
.item-card--highlight {
  background: rgba(229, 57, 53, 0.18) !important;
  box-shadow: inset 3px 0 0 #c62828;
}

.page-pills {
  margin-bottom: 14px;
}

.page-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  color: var(--blue);
  background: white;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.items-list {
  display: flex;
  flex-direction: column;
  max-height: 75vh;
  overflow-y: auto;
  font-size: 13px;
}

/* EPC table row */
.epc-row {
  display: grid;
  grid-template-columns: 90px 130px 1fr 32px 20px;
  gap: 4px;
  padding: 4px 6px;
  border-bottom: 1px solid #eef2f7;
  cursor: pointer;
  align-items: center;
  min-height: 26px;
  transition: background 0.12s;
}
.epc-row:hover {
  background: rgba(246, 139, 31, 0.08);
}
.epc-row--header {
  font-weight: 800;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--line);
  cursor: default;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}
.epc-row--header:hover { background: white; }
.epc-row--std {
  color: var(--muted);
  font-style: italic;
}
.epc-col-no {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}
.epc-col-pnc {
  color: var(--orange-2);
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}
.epc-col-part {
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
  font-family: monospace;
  white-space: nowrap;
}
.epc-part-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(21, 74, 120, 0.35);
  text-underline-offset: 3px;
}
.epc-part-link:hover {
  color: var(--orange-2);
  text-decoration-color: currentColor;
}

.scheme-loader-state {
  min-height: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.arimas-spinner {
  width: 58px;
  height: 58px;
  border: 6px solid rgba(10, 43, 87, 0.14);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: arimas-spin 0.85s linear infinite;
}

.arimas-spinner--paused {
  animation-play-state: paused;
}

.scheme-loader-title {
  color: var(--blue);
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.scheme-loader-note {
  max-width: 360px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

@keyframes arimas-spin {
  to { transform: rotate(360deg); }
}
.epc-col-name {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.epc-col-info {
  font-size: 14px;
  cursor: pointer;
  opacity: 0.4;
  text-align: center;
}
.epc-col-info:hover { opacity: 1; }
.epc-col-qty {
  font-size: 12px;
  color: var(--blue);
  text-align: center;
  font-weight: 700;
}
.item-variant {
  font-size: 10px;
  font-weight: 700;
  color: #999;
  margin-left: 2px;
}
/* Attributes popup */
.attr-popup {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 50;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 12px 14px;
  min-width: 280px;
  font-size: 13px;
}
.attr-popup-header {
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.attr-popup-close {
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
}
.attr-table { width: 100%; border-collapse: collapse; }
.attr-table td { padding: 3px 6px; vertical-align: top; }
.attr-table td:first-child { color: var(--muted); white-space: nowrap; width: 100px; }

/* Keep old classes for backward compat */
.item-card {
  padding: 5px 8px;
  border-bottom: 1px solid #eef2f7;
  cursor: pointer;
}
.epc-row {
  cursor: pointer;
  transition: background 0.12s;
}
.epc-row--hover {
  background: rgba(255, 213, 79, 0.35) !important;
  box-shadow: inset 3px 0 0 #f9a825;
}
.epc-row--selected {
  background: rgba(229, 57, 53, 0.18) !important;
  box-shadow: inset 3px 0 0 #c62828;
}
.epc-row--header,
.epc-row--header:hover {
  cursor: default;
  background: inherit !important;
  box-shadow: none !important;
}
/* legacy alias для inline onclick→highlightZone в старых рендерах */
.epc-row--highlight {
  background: rgba(229, 57, 53, 0.18) !important;
  box-shadow: inset 3px 0 0 #c62828;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .hero,
  .units-layout,
  .scheme-layout {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 20px;
  }

  .container {
    width: min(calc(100% - 24px), 1220px);
  }

  .mode-switch {
    justify-content: flex-start;
  }
}
