:root {
  color-scheme: light;
  --ink: #191919;
  --muted: #64615d;
  --line: #d8d3ca;
  --panel: #fbfaf7;
  --surface: #ffffff;
  --red: #c91924;
  --red-dark: #a20f18;
  --green: #357663;
  --gold: #a47522;
  --focus: #1f6feb;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100vh;
  overflow: hidden;
  background: var(--panel);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #1d1b1a;
  color: #fff;
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.version-badge {
  display: inline-block;
  margin-left: 10px;
  color: #d8d0c6;
  font-size: 13px;
  font-weight: 700;
  vertical-align: middle;
}

.topbar p {
  margin: 4px 0 0;
  color: #cbc4ba;
  font-size: 13px;
}

.maker-credit {
  max-width: 620px;
  line-height: 1.35;
}

.header-notice {
  flex: 1 1 520px;
  max-width: 720px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid #5a5550;
  border-radius: 6px;
  background: #26231f;
  color: #f4eee6;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  white-space: pre-wrap;
}

.exports {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  max-width: 720px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.button.primary:hover {
  background: var(--red-dark);
}

.button.subtle {
  background: transparent;
  color: #fff;
  border-color: #5a5550;
}

.button.unlocked {
  border-color: var(--green);
  color: #dff5ee;
}

.button:focus,
input:focus,
select:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  flex: 1 1 auto;
  width: 100%;
  max-width: 100vw;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  padding: 10px 14px;
  overflow: hidden;
}

.toolbar {
  display: grid;
  grid-template-columns: 150px 120px minmax(0, 1fr) minmax(0, 1fr) 160px;
  gap: 10px;
  align-items: end;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.group-filter {
  display: none;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  padding: 8px 10px;
}

select {
  cursor: pointer;
}

.import-file-input {
  display: none;
}

output {
  flex: 1 0 100%;
  color: #cbc4ba;
  font-size: 13px;
  overflow-wrap: anywhere;
  text-align: right;
  white-space: pre-wrap;
}

.admin-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: start end;
  padding: 72px 24px 24px;
  background: rgb(0 0 0 / 18%);
  overflow: auto;
}

.admin-card {
  display: flex;
  flex-direction: column;
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 96px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 45px rgb(0 0 0 / 24%);
  overflow: hidden;
}

.admin-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.admin-head h2 {
  margin: 0;
  font-size: 18px;
}

.admin-close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.admin-login,
.admin-actions {
  display: grid;
  gap: 10px;
  padding: 16px;
  overflow: auto;
}

.admin-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 0;
}

.admin-notice-editor {
  grid-column: 1 / -1;
}

.admin-model-visibility {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfaf7;
}

.admin-model-visibility strong {
  font-size: 14px;
}

.admin-visibility-filters,
.visibility-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.visibility-models {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.visibility-model {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.25;
  text-transform: none;
}

.visibility-model input {
  width: auto;
  min-height: 0;
  margin-top: 1px;
}

.admin-notice-editor textarea {
  width: 100%;
  min-height: 94px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 10px;
  text-transform: none;
}

.admin-link {
  width: 100%;
  color: var(--ink);
  border-color: var(--line);
}

.admin-link.button.subtle {
  background: #fff;
  color: var(--ink);
}

.admin-link.button.subtle:hover {
  background: #f3f1ed;
}

.admin-link.button.primary {
  color: #fff;
}

.admin-link:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.admin-status {
  flex: 0 0 auto;
  display: block;
  max-height: 84px;
  min-height: 32px;
  padding: 0 16px 14px;
  color: var(--muted);
  font-size: 13px;
  overflow: auto;
  overflow-wrap: anywhere;
  text-align: left;
}

.category-tabs {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 0 8px 4px;
}

.category-tab {
  min-width: 160px;
  min-height: 39px;
  padding: 0 24px;
  border: 1px solid #5e5e5e;
  border-radius: 999px;
  background: #f9f9f9;
  color: #555;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.category-tab.active {
  border-color: #111;
  background: #111;
  color: #fff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(620px, 0.95fr);
  gap: 8px;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.diagram-pane,
.results-pane {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  overflow: hidden;
}

.results-pane {
  position: relative;
  display: flex;
  flex-direction: column;
}

.diagram-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.diagram-header {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--line);
}

.diagram-header span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.diagram-picker {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 12px;
}

.diagram-picker select {
  min-height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: #111;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
}

.diagram-picker span {
  min-height: 17px;
  padding: 0;
  overflow: visible;
  white-space: nowrap;
}

.quick-menu-hint {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  color: #111;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
}

.quick-menu-hint span {
  margin: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.quick-menu-arrow {
  position: relative;
  display: block;
  width: 32px;
  height: 16px;
}

.quick-menu-arrow::before,
.quick-menu-arrow::after {
  position: absolute;
  content: "";
  display: block;
}

.quick-menu-arrow::before {
  left: 5px;
  top: 7px;
  width: 24px;
  border-top: 4px solid #111;
}

.quick-menu-arrow::after {
  left: 0;
  top: 2px;
  width: 10px;
  height: 10px;
  border-left: 4px solid #111;
  border-bottom: 4px solid #111;
  transform: rotate(45deg);
}

.diagram-stage {
  position: relative;
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  padding: 0;
  background: #fff;
}

.diagram-stage.ktm-native {
  display: block;
  overflow: auto;
}

.diagram-canvas {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  place-items: center;
}

.diagram-canvas.ktm-native {
  display: block;
  width: max-content;
  height: max-content;
  min-width: 0;
  min-height: 0;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.hotspot-layer.ktm-native {
  inset: auto;
  top: 0;
  left: 0;
}

.hotspot-zone {
  position: absolute;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  pointer-events: auto;
}

.hotspot-marker {
  display: none;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #d90000;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 2px 7px rgb(0 0 0 / 22%);
}

.hotspot-zone:hover .hotspot-marker,
.hotspot-zone:focus-visible .hotspot-marker,
.hotspot-zone.active .hotspot-marker {
  display: block;
}

#diagramImage {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

#diagramImage.ktm-native {
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: fill;
}

.empty-detail {
  display: grid;
  min-height: 220px;
  place-items: center;
  color: var(--muted);
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.table-wrap::-webkit-scrollbar {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  min-width: 0;
  max-width: 100%;
  padding: 6px 8px;
  border-bottom: 1px solid #eee9df;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  overflow-wrap: anywhere;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0d0d0d;
  color: #fff;
  font-size: 12px;
  text-transform: uppercase;
  white-space: nowrap;
}

th:nth-child(4),
th:nth-child(5) {
  padding-right: 4px;
  padding-left: 4px;
  font-size: 11px;
}

tbody tr:nth-child(odd) {
  background: #f7f7f7;
}

tbody tr:nth-child(even) {
  background: #e9e9e9;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #fff4f2;
}

th:nth-child(1),
td:nth-child(1) {
  width: 38px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 142px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 68px;
  text-align: center;
  white-space: nowrap;
}

th:nth-child(5),
td:nth-child(5) {
  width: 68px;
  text-align: center;
  white-space: nowrap;
}

#partsTable:not(.show-ktm-qty) th:nth-child(5),
#partsTable:not(.show-ktm-qty) td:nth-child(5) {
  display: none;
}

th:nth-child(7),
td:nth-child(7) {
  width: 76px;
  text-align: right;
}

th:nth-child(6),
td:nth-child(6) {
  width: 90px;
  text-align: center;
  white-space: nowrap;
}

th:nth-child(8),
td:nth-child(8) {
  width: 44px;
  text-align: center;
}

.muted {
  color: var(--muted);
}

.code-cell,
.description-cell {
  min-width: 0;
}

.pos-cell strong,
.part-code {
  display: block;
  font-weight: 800;
  overflow-wrap: normal;
  word-break: normal;
  white-space: nowrap;
}

.superseded-original {
  color: #777;
  font-weight: 700;
  text-decoration: line-through;
}

.superseded-current {
  margin-top: 3px;
  color: #111;
}

.alternate-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #f6ead2;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  overflow-wrap: normal;
  text-transform: uppercase;
  white-space: nowrap;
  word-break: keep-all;
}

.part-description {
  display: block;
  margin-top: 0;
  color: #3f3b37;
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: normal;
}

.row-drawing {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.mru-qty-cell,
.ktm-qty-cell {
  color: #111;
  font-size: 13px;
}

.mru-qty,
.ktm-qty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff;
  color: #0d0d0d;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px #d7d0c6;
}

.ktm-qty {
  background: #fff4df;
  color: #7d570d;
}

.price-cell {
  font-weight: 800;
  white-space: nowrap;
  overflow-wrap: anywhere;
}

.qty-stepper {
  display: inline-grid;
  grid-template-columns: 28px 34px 28px;
  align-items: center;
  min-height: 34px;
  border: 1px solid #e4dfd6;
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}

.qty-adjust {
  display: grid;
  width: 28px;
  height: 32px;
  place-items: center;
  border: 0;
  background: #fff;
  color: var(--red);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.qty-adjust:disabled {
  color: #c9c1b6;
  cursor: not-allowed;
}

.qty-input {
  width: 34px;
  min-height: 32px;
  padding: 0;
  border: 0;
  border-radius: 0;
  text-align: center;
  font-size: 15px;
  appearance: textfield;
}

.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.add-cart,
.cart-toggle {
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: #d90000;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgb(0 0 0 / 18%);
}

.add-cart {
  width: 38px;
  height: 38px;
}

.cart-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 14px;
  border: 2px solid currentColor;
  border-top: 0;
  transform: translateY(1px);
}

.cart-icon::before {
  position: absolute;
  left: -4px;
  top: -7px;
  width: 8px;
  height: 8px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  content: "";
  transform: rotate(-20deg);
}

.cart-icon::after {
  position: absolute;
  left: 1px;
  bottom: -7px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 11px 0 0 currentColor;
  content: "";
}

.cart-toggle {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  grid-template-columns: 22px auto;
  gap: 7px;
  min-width: 74px;
  height: 44px;
  padding: 0 13px;
  font-weight: 800;
}

.cart-panel {
  position: absolute;
  right: 16px;
  bottom: 70px;
  z-index: 5;
  display: grid;
  width: min(430px, calc(100% - 32px));
  max-height: min(520px, calc(100% - 96px));
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 12px 36px rgb(0 0 0 / 18%);
}

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

.cart-head span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.cart-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #111;
  font-weight: 800;
  cursor: pointer;
}

.cart-items {
  min-height: 80px;
  overflow-y: auto;
}

.cart-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #eee9df;
}

.cart-item strong,
.cart-item span,
.cart-item small {
  display: block;
}

.cart-item small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.cart-item-total {
  text-align: right;
  white-space: nowrap;
}

.cart-empty {
  padding: 32px 14px;
  color: var(--muted);
  text-align: center;
}

.cart-foot {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.cart-clear {
  min-height: 38px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--red);
  font-weight: 800;
  cursor: pointer;
}

.filmstrip-shell {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  height: 0;
  min-height: 0;
  max-height: 0;
  overflow: visible;
  border-top: 0;
  background: transparent;
  box-shadow: none;
}

.filmstrip-shell.expanded {
  height: 180px;
  max-height: 180px;
  border-top: 1px solid var(--line);
  background: #f5f5f5;
  box-shadow: 0 -4px 18px rgb(0 0 0 / 12%);
}

.filmstrip-shell[hidden] {
  display: none;
}

.filmstrip-toggle {
  position: absolute;
  left: 50%;
  top: -28px;
  z-index: 3;
  width: 40px;
  height: 28px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 5px 5px 0 0;
  background: #fff;
  color: #111;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
}

.diagram-filmstrip {
  display: none;
  min-width: 0;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  height: 180px;
  padding: 16px;
  overscroll-behavior: contain;
  scroll-snap-type: x proximity;
}

.filmstrip-shell.expanded .diagram-filmstrip {
  display: flex;
}

.diagram-thumb {
  display: grid;
  flex: 0 0 150px;
  grid-template-rows: 96px minmax(34px, auto);
  gap: 6px;
  padding: 4px;
  border: 2px solid transparent;
  background: #fff;
  box-shadow: 0 4px 12px rgb(0 0 0 / 13%);
  color: #111;
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
  scroll-snap-align: start;
}

.diagram-thumb.active {
  border-color: var(--red);
}

.diagram-thumb img,
.thumb-placeholder {
  width: 100%;
  height: 96px;
  object-fit: contain;
  background: #fff;
}

.diagram-thumb span {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.25;
}

h2 {
  margin: 8px 0 14px;
  font-size: 18px;
  line-height: 1.3;
}

dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-size: 14px;
}

@media (max-width: 1220px) {
  .toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .workspace {
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .diagram-pane {
    min-height: 0;
  }

  .quick-menu-hint {
    display: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  dl {
    grid-template-columns: 1fr;
  }

  .exports {
    align-items: stretch;
    flex-direction: column;
    max-width: none;
  }

  .header-notice {
    flex-basis: auto;
    max-width: none;
    text-align: left;
  }

  .button {
    width: 100%;
  }

  output {
    text-align: left;
  }

  .diagram-pane {
    min-height: 0;
  }
}
