* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { height: 100dvh; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr) 400px; grid-template-rows: auto minmax(0, 1fr); background: var(--mfm-surface); color: var(--mfm-text); font-family: var(--mfm-font); }
[hidden] { display: none !important; }
button, select, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--mfm-primary-hover); }
#workspace-header { grid-column: 1 / -1; padding: 8px 24px 12px; background: var(--mfm-panel); border-bottom: 1px solid var(--mfm-border); }
#workspace-header nav { display: flex; align-items: center; gap: 20px; }
#workspace-header nav a { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; font-weight: 600; text-decoration: none; }
#workspace-header nav a:hover { text-decoration: underline; }
#workspace-header nav .mfm-brand { margin-right: auto; font-size: 16px; min-width: 44px; }
.heading-line { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
h1 { margin: 0; color: var(--mfm-ink); font-size: 24px; line-height: 1.25; letter-spacing: -.025em; }
#levels { padding: 4px; background: var(--mfm-surface); border: 1px solid var(--mfm-border); border-radius: var(--mfm-radius-control); gap: 4px !important; }
#levels a { min-width: 80px; justify-content: center; padding: 0 12px; border-radius: 8px; color: var(--mfm-muted); }
#levels a[aria-current="page"] { background: var(--mfm-primary-soft); color: var(--mfm-primary-hover); box-shadow: inset 0 0 0 1px var(--mfm-primary-border); }
#level-summary { margin: 6px 0 0; color: var(--mfm-muted); font-size: 13px; line-height: 1.5; }
main { position: relative; min-width: 0; min-height: 0; }
three-d-stage { display: block; width: 100%; height: 100%; --stage-bg: var(--mfm-surface); }
three-d-stage:not(:defined) { visibility: hidden; }
#loading { position: absolute; inset: 0; display: grid; place-content: center; padding: 24px; color: var(--mfm-muted); text-align: center; pointer-events: none; }
#model-tools { position: absolute; top: 16px; left: 16px; right: 16px; display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none; }
#model-tools button { pointer-events: auto; box-shadow: var(--mfm-shadow); }
#model-tools button[aria-pressed="true"] { background: var(--mfm-primary-soft); border-color: var(--mfm-primary-border); color: var(--mfm-primary-hover); }
aside { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--mfm-panel); border-left: 1px solid var(--mfm-border); padding: 16px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-shrink: 0; }
aside h2 { margin: 0; font-size: 18px; color: var(--mfm-ink); }
#sum { font-size: 13px; color: var(--mfm-muted); margin-bottom: 12px; line-height: 1.5; }
.tools { display: flex; gap: 6px; }
.tools button, .pagination button { border: 1px solid var(--mfm-border); border-radius: var(--mfm-radius-control); background: var(--mfm-panel); padding: 8px 12px; min-height: 44px; color: var(--mfm-text); font-size: 13px; }
.tools button:hover, .pagination button:not(:disabled):hover { background: var(--mfm-primary-soft); border-color: var(--mfm-primary-border); }
button:disabled { opacity: .45; cursor: default; }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
select, #search { width: 100%; padding: 10px 12px; min-height: 48px; border: 1px solid var(--mfm-border); border-radius: var(--mfm-radius-control); background: var(--mfm-panel); color: var(--mfm-text); font-size: 16px; flex-shrink: 0; }
#component-description { font-size: 16px; line-height: 1.6; background: var(--mfm-primary-soft); border-radius: var(--mfm-radius-control); padding: 16px; margin: 16px 0; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--mfm-surface); border-radius: var(--mfm-radius-control); margin-bottom: 12px; flex-shrink: 0; }
.tabs button { flex: 1; border: 0; border-radius: 8px; background: transparent; min-height: 44px; padding: 8px; color: var(--mfm-muted); font-size: 14px; font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--mfm-primary-soft); color: var(--mfm-primary-hover); }
#parts-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#components-panel { min-height: 0; overflow: auto; flex: 1; padding: 4px; }
#colors { display: flex; gap: 4px; margin-bottom: 10px; padding: 3px; overflow-x: auto; scrollbar-width: thin; flex-shrink: 0; }
.color-filter { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--mfm-muted); padding: 4px; flex-shrink: 0; font-size: 13px; font-weight: 600; }
.color-filter:hover { background: var(--mfm-surface); }
.color-filter[aria-pressed="true"] { border-color: var(--mfm-primary); background: var(--mfm-primary-soft); color: var(--mfm-primary-hover); }
.sw { display: inline-block; width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--mfm-muted); }
#results { font-size: 12px; line-height: 1.5; color: var(--mfm-muted); margin: 8px 0; min-height: 18px; flex-shrink: 0; }
#list { --part-row-height: 76px; --part-row-gap: 6px; display: flex; flex-direction: column; gap: var(--part-row-gap); flex: 1; min-height: 82px; overflow: hidden; padding: 3px; }
.part-row { height: var(--part-row-height); flex-shrink: 0; display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 4px; }
.part-row:not(:has(.catalog-link)) { grid-template-columns: 1fr; }
.card { width: 100%; min-width: 0; background: var(--mfm-panel); border: 1px solid var(--mfm-border); border-radius: var(--mfm-radius-control); padding: 8px; display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 4px 8px; height: var(--part-row-height); text-align: left; color: inherit; }
.card:hover { border-color: var(--mfm-primary-border); background: var(--mfm-surface); }
.card.on { border-color: var(--mfm-primary); background: var(--mfm-primary-soft); box-shadow: 0 0 0 1px var(--mfm-primary); }
.card img { width: 44px; height: 44px; object-fit: contain; grid-row: 1 / 3; }
.part-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.nm { font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.no { font-size: 12px; color: var(--mfm-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q { font-weight: 700; font-size: 12px; grid-column: 2; }
.catalog-link { display: flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; padding: 4px; border: 1px solid var(--mfm-border); border-radius: var(--mfm-radius-control); background: var(--mfm-panel); font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.catalog-link:hover { background: var(--mfm-primary-soft); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; flex-shrink: 0; }
#page-number { font-size: 12px; color: var(--mfm-muted); }
#empty { font-size: 14px; color: var(--mfm-muted); text-align: center; padding: 16px 4px; }
#hint { font-size: 12px; line-height: 1.5; color: var(--mfm-muted); margin: 10px 0 0; }
#selection { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 1.4; color: var(--mfm-primary-hover); background: var(--mfm-primary-soft); padding: 8px 12px; border: 1px solid var(--mfm-primary-border); border-radius: var(--mfm-radius-control); margin-top: 12px; flex-shrink: 0; }
#selection-text { flex: 1; }
#clear-selection { border: 0; background: transparent; color: var(--mfm-primary-hover); font-size: 24px; line-height: 1; min-width: 44px; min-height: 44px; padding: 8px; }
.error { color: var(--mfm-danger) !important; }
#mobile-nav, #view-component { display: none; }
@media (max-width: 1100px) { body { grid-template-columns: minmax(0, 1fr) 360px; } }
@media (max-width: 900px) and (min-width: 601px) and (min-height: 501px) { body { grid-template-columns: 1fr; grid-template-rows: auto minmax(200px, 40dvh) minmax(0, 1fr); } aside { border-left: 0; border-top: 1px solid var(--mfm-border); } }
@media (max-height: 720px) { aside { overflow-y: auto; } #parts-panel { flex: 1 0 280px; } }
@media (max-width: 600px), (max-width: 900px) and (max-height: 500px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; }
  #workspace-header { padding: calc(4px + env(safe-area-inset-top)) 16px 10px; }
  #workspace-header nav { gap: 12px; flex-wrap: wrap; }
  #workspace-header nav a { font-size: 12px; }
  #workspace-header nav .mfm-brand { font-size: 14px; }
  #workspace-header nav .mfm-brand span { display: none; }
  .heading-line { align-items: stretch; flex-direction: column; gap: 8px; }
  h1 { font-size: 20px; }
  #levels { flex-wrap: nowrap !important; }
  #levels a { flex: 1; min-width: 0; font-size: 14px !important; }
  #level-summary { font-size: 12px; }
  main, aside { grid-column: 1; grid-row: 2; }
  body[data-mobile-view="model"] aside { display: none; }
  body[data-mobile-view="parts"] main, body[data-mobile-view="components"] main { display: none; }
  aside { border: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px 10px; }
  .tabs { display: none; }
  #mobile-nav { grid-column: 1; grid-row: 3; display: flex; gap: 4px; padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); min-height: 60px; background: var(--mfm-panel); border-top: 1px solid var(--mfm-border); z-index: 2; }
  #mobile-nav button { flex: 1; min-height: 48px; border: 0; border-radius: var(--mfm-radius-control); background: transparent; color: var(--mfm-muted); font-size: 14px; font-weight: 600; }
  #mobile-nav button[aria-pressed="true"] { background: var(--mfm-primary-soft); color: var(--mfm-primary-hover); }
  #list { --part-row-height: 92px; }
  #selection { position: absolute; bottom: 104px; left: 16px; right: 16px; margin: 0; z-index: 1; box-shadow: var(--mfm-shadow); background: var(--mfm-panel); }
  #view-component { display: block; width: 100%; min-height: 48px; border: 0; border-radius: var(--mfm-radius-control); background: var(--mfm-primary); color: white; font-size: 15px; font-weight: 600; }
}
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  #workspace-header { padding: 4px 16px; display: flex; align-items: center; gap: 12px; }
  #workspace-header > nav { display: flex; flex-shrink: 0; }
  #workspace-header > nav .mfm-brand, #workspace-header > nav a:last-child { display: none; }
  .heading-line { flex: 1; flex-direction: row; align-items: center; justify-content: flex-end; }
  h1 { font-size: 18px; }
  #level-summary { display: none; }
  #levels a { min-width: 70px; }
  #model-tools { top: 8px; }
  #selection { top: 60px; bottom: auto; right: auto; width: min(340px, 45%); }
}
@media (max-width: 700px) and (max-height: 500px) and (orientation: landscape) { .heading-line h1 { display: none; } }
