:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #edf2f6;
  --ink: #15202b;
  --muted: #64717f;
  --line: #d7dee5;
  --blue: #0099d8;
  --blue-dark: #006d9b;
  --red: #d94b45;
  --red-dark: #b83631;
  --green: #1d8a62;
  --amber: #f7c948;
  --shadow: 0 12px 30px rgba(21, 32, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.brand-title {
  display: block;
  font-weight: 700;
  white-space: nowrap;
}

.brand-subtitle {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.global-search {
  position: relative;
  flex: 1 1 520px;
  max-width: 680px;
}

.global-search input {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
}

.global-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 153, 216, 0.14);
}

.global-search-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  z-index: 40;
  max-height: min(520px, calc(100vh - 92px));
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.global-search-menu[hidden] {
  display: none;
}

.global-search-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.global-search-result:last-child {
  border-bottom: 0;
}

.search-add-controls {
  display: flex;
  align-items: end;
  gap: 8px;
}

.search-add-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-add-controls input {
  width: 68px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-add-controls {
  display: grid;
  grid-template-columns: 56px 70px;
  align-items: end;
  gap: 8px;
  width: 134px;
}

.table-add-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.table-add-controls input {
  width: 56px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
}

.global-result-main {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 0;
  background: transparent;
  border: 0;
  color: inherit;
  text-align: left;
}

.global-result-main strong {
  color: var(--blue-dark);
  font-size: 18px;
}

.global-result-main span,
.global-result-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.global-result-main small,
.global-search-empty {
  color: var(--muted);
  font-size: 12px;
}

.global-search-empty {
  padding: 14px;
}

.cart-button,
.primary-button,
.secondary-button,
.danger-button,
.small-button,
.hotspot {
  border: 0;
  border-radius: 6px;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.cart-button,
.primary-button {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.cart-button {
  min-width: 146px;
  padding: 10px 14px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 44px;
  padding: 10px 16px;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  text-decoration: none;
}

.danger-button,
.small-button.add {
  background: var(--red);
  color: #fff;
}

.cart-button:hover,
.primary-button:hover {
  background: var(--blue-dark);
}

.danger-button:hover,
.small-button.add:hover {
  background: var(--red-dark);
}

.secondary-button:hover {
  background: #dfe7ee;
}

.cart-button:active,
.primary-button:active,
.secondary-button:active,
.danger-button:active,
.small-button:active,
.hotspot:active {
  transform: translateY(1px);
}

.page {
  width: min(1480px, calc(100% - 36px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--blue);
  font-size: 34px;
  font-weight: 500;
  line-height: 1.08;
}

h2,
h3 {
  margin: 0;
}

.lead {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
}

.engine-grid,
.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 22px;
}

.catalog-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 38px;
  align-items: start;
}

.catalog-sidebar {
  display: grid;
  background: var(--surface);
  border: 1px solid var(--line);
}

.catalog-sidebar button {
  min-height: 52px;
  padding: 12px 18px;
  background: #fff;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: #314151;
  text-align: left;
}

.catalog-sidebar button:last-child {
  border-bottom: 0;
}

.catalog-sidebar button.active {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.catalog-sidebar button:disabled:not(.active) {
  color: #314151;
  opacity: 1;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: #fff;
}

.category-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  gap: 10px;
  min-height: 298px;
  padding: 26px 16px 18px;
  background: #fff;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-align: center;
}

.category-card:not(.disabled):hover {
  background: #f7fbfe;
}

.category-card.disabled {
  cursor: not-allowed;
}

.category-card.disabled .category-media,
.category-card.disabled .category-status {
  opacity: 0.28;
}

.category-title {
  min-height: 56px;
  color: var(--blue);
  font-size: 23px;
  line-height: 1.12;
}

.category-media {
  width: 100%;
  max-width: 150px;
  height: 150px;
  object-fit: contain;
}

.category-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.engine-card,
.section-card {
  position: relative;
  display: grid;
  align-content: start;
  min-height: 330px;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: inherit;
  text-align: left;
}

.engine-card:not(.disabled):hover,
.section-card:hover {
  border-color: var(--blue);
  transform: translateY(-2px);
}

.engine-card.disabled {
  opacity: 0.58;
}

.card-ribbon {
  position: absolute;
  margin: 14px;
  padding: 8px 12px;
  background: var(--blue);
  color: #fff;
  border-radius: 4px;
  font-weight: 700;
  line-height: 1.1;
}

.card-media {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #fff;
}

.card-body {
  display: grid;
  gap: 6px;
  padding: 14px 16px 18px;
}

.card-title {
  font-size: 20px;
  font-weight: 700;
}

.card-copy {
  min-height: 44px;
  color: var(--muted);
  font-size: 14px;
}

.status-pill {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e7f7ef;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.status-pill.waiting {
  background: #fff6d8;
  color: #8b6b00;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(420px, 0.85fr);
  gap: 22px;
  align-items: start;
}

.diagram-panel,
.parts-panel,
.summary-panel,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.diagram-toolbar,
.parts-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.diagram-wrap {
  position: relative;
  overflow: auto;
  max-height: calc(100vh - 190px);
  background: #fff;
}

.diagram-stage {
  position: relative;
  min-width: 760px;
}

.diagram-stage img {
  display: block;
  width: 100%;
  height: auto;
}

.hotspot {
  position: absolute;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  background: transparent;
  color: transparent;
  border: 0;
  border-radius: 50%;
  box-shadow: none;
  font-size: 12px;
  font-weight: 700;
}

.hotspot:hover {
  background: transparent;
}

.hotspot:focus-visible {
  outline: 3px solid rgba(0, 153, 216, 0.45);
  outline-offset: 2px;
}

.hotspot.selected {
  background: transparent;
  color: transparent;
}

.parts-panel {
  position: sticky;
  top: 84px;
  overflow: hidden;
}

.search-field {
  width: min(260px, 100%);
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 280px);
}

table {
  width: 100%;
  min-width: 540px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fbfc;
  color: #263645;
  font-size: 13px;
}

td {
  font-size: 14px;
  vertical-align: middle;
}

.part-number {
  font-weight: 700;
  white-space: nowrap;
}

.part-thumb {
  display: block;
  width: 58px;
  height: 58px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.part-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.small-button {
  min-width: 70px;
  min-height: 34px;
  padding: 7px 10px;
  font-weight: 700;
}

.parts-panel th:last-child,
.parts-panel td:last-child {
  width: 150px;
}

.kit-actions {
  display: flex;
  justify-content: flex-end;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.selected-strip {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.selected-list,
.quote-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.selected-item,
.quote-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: var(--surface-2);
  border-radius: 6px;
}

.selected-item strong,
.quote-item strong {
  display: block;
}

.selected-meta {
  color: var(--muted);
  font-size: 12px;
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 7px;
}

.qty-controls input {
  width: 62px;
  height: 30px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
}

.qty-controls button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-weight: 700;
}

.checkout-item-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
}

.checkout-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(360px, 0.55fr);
  gap: 22px;
  align-items: start;
}

.form-panel,
.summary-panel {
  padding: 20px;
}

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

.field {
  display: grid;
  gap: 7px;
}

.field label {
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
}

.field textarea {
  min-height: 112px;
  resize: vertical;
}

.field-wide {
  grid-column: 1 / -1;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-field:focus {
  outline: 3px solid rgba(0, 153, 216, 0.18);
  border-color: var(--blue);
}

.control-number {
  margin: 0;
  color: var(--muted);
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

.result-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.quote-text {
  max-height: 380px;
  overflow: auto;
  margin: 0;
  padding: 16px;
  background: #101820;
  color: #e8f1f8;
  border-radius: 6px;
  font-size: 13px;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100% - 36px));
  padding: 12px 14px;
  background: #101820;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .detail-layout,
  .checkout-layout,
  .catalog-layout {
    grid-template-columns: 1fr;
  }

  .category-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .parts-panel {
    position: static;
  }

  .diagram-wrap,
  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    padding: 0 14px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .brand-subtitle {
    display: none;
  }

  .global-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .global-search-menu {
    max-height: min(440px, calc(100vh - 142px));
  }

  .page {
    width: min(100% - 24px, 1480px);
    padding-top: 20px;
  }

  .page-header,
  .diagram-toolbar,
  .parts-toolbar,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 28px;
  }

  .engine-grid,
  .section-grid,
  .category-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .catalog-layout {
    gap: 18px;
  }

  .cart-button {
    min-width: 112px;
    padding: 8px 10px;
  }

  .diagram-stage {
    min-width: 620px;
  }
}
