:root {
    color-scheme: light;
    --ink: #102d2a;
    --muted: #647672;
    --paper: #f4f8f7;
    --card: #ffffff;
    --line: #d8e4e1;
    --accent: #087f72;
    --accent-dark: #05665c;
    --accent-soft: #e1f3ef;
    --warning: #b97519;
    --shadow: 0 18px 50px rgba(25, 62, 57, .10);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; margin: 0; color: var(--ink); background: radial-gradient(circle at 85% 0, #dff1ed 0, transparent 28rem), var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; padding: 12px max(20px, calc((100vw - 1240px) / 2)); background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; color: white; background: var(--accent); font-size: 32px; line-height: 1; transform: rotate(90deg); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: 12px; }
.database-status { max-width: 48%; padding: 7px 11px; border-radius: 99px; color: var(--accent-dark); background: var(--accent-soft); font-size: 12px; font-weight: 700; text-align: right; }

.shell { width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 54px 0 72px; }
.hero { max-width: 790px; }
.hero h1 { margin: 5px 0 14px; font-size: clamp(34px, 6vw, 66px); line-height: .98; letter-spacing: -.055em; }
.hero > p:last-child { max-width: 720px; color: var(--muted); font-size: clamp(16px, 2vw, 20px); line-height: 1.55; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .18em; }

.tabs { display: flex; gap: 6px; margin-top: 34px; padding: 6px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.75); overflow-x: auto; }
.tab { flex: 1; min-width: max-content; padding: 12px 18px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; font-weight: 750; }
.tab.active { color: white; background: var(--accent); box-shadow: 0 8px 20px rgba(8,127,114,.25); }

.panel { margin-top: 16px; padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,255,255,.92); box-shadow: var(--shadow); }
.search-form { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto; align-items: end; gap: 14px; }
#numberForm { grid-template-columns: 1fr auto; }
.measure-form { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)) auto; align-items: end; gap: 12px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
input { width: 100%; min-height: 49px; padding: 11px 14px; border: 1px solid #bfd0cc; border-radius: 12px; outline: none; color: var(--ink); background: #fff; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(8,127,114,.12); }
.primary, .ghost { min-height: 49px; padding: 11px 19px; border-radius: 12px; font-weight: 800; }
.primary { border: 1px solid var(--accent); color: white; background: var(--accent); }
.primary:hover { background: var(--accent-dark); }
.ghost { border: 1px solid var(--line); color: var(--accent-dark); background: white; }

.autocomplete { position: relative; }
.suggestions { position: absolute; z-index: 15; top: calc(100% + 6px); left: 0; right: 0; max-height: 330px; padding: 6px; border: 1px solid var(--line); border-radius: 13px; background: white; box-shadow: var(--shadow); overflow-y: auto; }
.suggestion { display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 10px 11px; border: 0; border-radius: 9px; color: var(--ink); background: transparent; text-align: left; }
.suggestion:hover, .suggestion:focus { background: var(--accent-soft); }
.suggestion small { color: var(--muted); }

.results-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 42px 0 15px; }
.results-head h2 { margin: 4px 0 0; font-size: clamp(24px, 3vw, 36px); letter-spacing: -.035em; }
.loading { display: flex; align-items: center; gap: 10px; padding: 20px; color: var(--muted); }
.loading span { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { display: grid; justify-items: center; gap: 6px; padding: 58px 20px; border: 1px dashed #b8cbc7; border-radius: 22px; color: var(--muted); text-align: center; background: rgba(255,255,255,.55); }
.empty-state span { color: var(--accent); font-size: 54px; }
.empty-state strong { color: var(--ink); font-size: 19px; }
.empty-state p { margin: 0; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 14px; }
.result-card { display: grid; grid-template-columns: 92px 1fr; gap: 14px; min-height: 132px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; color: inherit; background: var(--card); box-shadow: 0 8px 24px rgba(25,62,57,.06); text-align: left; transition: transform .15s, border-color .15s; }
.result-card:hover { transform: translateY(-2px); border-color: #9dbeb7; }
.result-card img { width: 92px; height: 100px; border-radius: 12px; object-fit: contain; background: #edf3f1; }
.result-card .brand-name { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.result-card h3 { margin: 4px 0 5px; font-size: 21px; letter-spacing: -.025em; overflow-wrap: anywhere; }
.result-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.result-card .aliases { margin-top: 5px; color: var(--accent-dark); font-size: 11px; }
.result-card .depth { display: inline-block; margin-top: 7px; color: var(--warning); font-size: 11px; font-weight: 800; }
.result-card .depth.direct { color: var(--accent-dark); }
.result-card .depth.connected { color: var(--warning); }
.category-badge { display: inline-flex; margin-bottom: 6px; padding: 3px 7px; border-radius: 99px; color: #175b51; background: #dff0eb; font-size: 10px; font-weight: 800; }
.oem-reference { display: grid; gap: 2px; margin: 0 0 9px; padding: 8px 9px; border-left: 3px solid var(--accent); border-radius: 8px; color: var(--ink); background: #edf7f4; }
.oem-reference small { color: var(--accent-dark); font-size: 9px; font-weight: 900; letter-spacing: .05em; }
.oem-reference strong { font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.oem-reference em { color: var(--muted); font-size: 10px; font-style: normal; }
#results.equipment-mode { display: block; }
.equipment-tabs { display: flex; gap: 8px; margin-bottom: 16px; padding: 5px 2px 10px; overflow-x: auto; scrollbar-width: thin; }
.equipment-tab { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; min-height: 40px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: white; font-weight: 800; }
.equipment-tab b { display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 99px; color: var(--accent-dark); background: var(--accent-soft); font-size: 10px; }
.equipment-tab.active { border-color: var(--accent); color: white; background: var(--accent-dark); }
.equipment-tab.active b { color: var(--ink); background: white; }
.equipment-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }

.detail-dialog { width: min(1060px, calc(100% - 26px)); max-height: calc(100vh - 30px); padding: 0; border: 0; border-radius: 24px; color: var(--ink); background: white; box-shadow: 0 24px 80px rgba(0,0,0,.24); overflow: auto; }
.detail-dialog::backdrop { background: rgba(7,28,25,.55); backdrop-filter: blur(5px); }
.dialog-close { position: sticky; z-index: 4; top: 12px; float: right; width: 42px; height: 42px; margin: 12px 12px -54px 0; border: 0; border-radius: 50%; color: var(--ink); background: rgba(255,255,255,.9); font-size: 28px; }
.detail { padding: 28px; }
.detail-hero { display: grid; grid-template-columns: 260px 1fr; gap: 28px; align-items: center; padding-bottom: 25px; border-bottom: 1px solid var(--line); }
.detail-media { min-width: 0; }
.detail-main-image { width: 100%; height: 230px; object-fit: contain; border-radius: 18px; background: var(--paper); }
.detail-gallery { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; padding: 2px 2px 8px; }
.detail-thumb { flex: 0 0 64px; width: 64px; height: 64px; padding: 3px; border: 2px solid transparent; border-radius: 10px; background: var(--paper); cursor: pointer; }
.detail-thumb.active { border-color: var(--accent); }
.detail-thumb img { width: 100%; height: 100%; object-fit: contain; }
.detail-hero h2 { margin: 3px 0 8px; font-size: clamp(32px, 5vw, 54px); letter-spacing: -.05em; overflow-wrap: anywhere; }
.detail-hero p { color: var(--muted); line-height: 1.55; }
.reference-notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; margin-top: 14px; padding: 11px 14px; border: 1px solid #b8d9d2; border-radius: 12px; color: var(--accent-dark); background: var(--accent-soft); text-align: left; }
.reference-notice strong, .reference-notice span { display: block; }
.reference-notice span { color: var(--muted); }
.detail-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 24px; }
.detail-section { min-width: 0; }
.detail-section h3 { margin: 0 0 10px; }
.data-list { display: grid; gap: 7px; }
.data-row { display: grid; grid-template-columns: minmax(110px, .45fr) 1fr; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--paper); font-size: 13px; }
.data-row strong { color: var(--muted); }
.equivalent-section { grid-column: 1 / -1; }
.xref-matrix { display: grid; gap: 10px; }
.xref-selected { overflow: hidden; border: 1px solid #b8d9d2; border-radius: 14px; background: #f5faf8; }
.xref-selected > header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 14px; color: white; background: var(--ink); }
.xref-selected > header span:first-child { display: grid; gap: 2px; }
.xref-selected > header small { color: #bcd2cd; font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.xref-selected > header strong { font-size: 18px; }
.xref-selected-count { flex: 0 0 auto; padding: 5px 9px; border-radius: 99px; color: var(--ink); background: #d8ebe6; font-size: 11px; font-weight: 800; }
.xref-selected-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--line); }
.xref-selected-facts > div { display: grid; gap: 4px; min-width: 0; padding: 11px 13px; background: #f8fbfa; }
.xref-selected-facts small { color: var(--muted); font-size: 10px; font-weight: 700; }
.xref-selected-facts strong { overflow-wrap: anywhere; font-size: 12px; }
.xref-selected-facts p { margin: 0; padding: 14px; color: var(--muted); background: #f8fbfa; }
.xref-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 13px; border-radius: 14px; color: white; background: linear-gradient(135deg, var(--accent-dark), var(--accent)); }
.xref-toolbar > div { display: grid; gap: 3px; }
.xref-toolbar small { color: rgba(255,255,255,.78); }
.xref-toolbar label { min-width: min(330px, 44%); color: white; }
.xref-toolbar input { min-height: 42px; border: 0; }
.xref-tier { display: block; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fbfdfc; }
.xref-tier > header, .xref-tier > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--ink); }
.xref-tier > header span, .xref-tier > summary span { display: grid; gap: 2px; }
.xref-tier > header small, .xref-tier > summary small { color: var(--muted); font-weight: 500; }
.xref-tier > header b, .xref-tier > summary b { display: grid; place-items: center; min-width: 34px; height: 28px; padding: 0 8px; border-radius: 99px; color: var(--accent-dark); background: var(--accent-soft); }
.xref-tier > summary { cursor: pointer; font-weight: 700; }
.xref-table-wrap { margin-top: 11px; border: 1px solid var(--line); border-radius: 11px; overflow: auto; }
.xref-table { width: 100%; min-width: 850px; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.xref-table th { position: sticky; top: 0; z-index: 1; padding: 9px 10px; color: var(--muted); background: #eef5f3; text-align: left; white-space: nowrap; }
.xref-table td { padding: 9px 10px; border-top: 1px solid #e6efed; vertical-align: middle; }
.xref-table tbody tr:nth-child(even) { background: #f8fbfa; }
.xref-table tr.selected { background: #e8f5f1; }
.xref-table code { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; font-weight: 800; }
.xref-relation { display: inline-flex; padding: 4px 7px; border-radius: 99px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.xref-relation.selected { color: #fff; background: var(--ink); }
.xref-relation.direct { color: var(--accent-dark); background: var(--accent-soft); }
.xref-relation.connected { color: #8b570e; background: #fff1dc; }
.xref-open { padding: 6px 10px; border: 1px solid var(--accent); border-radius: 8px; color: var(--accent-dark); background: white; font-size: 11px; font-weight: 800; }
.xref-current { color: var(--muted); font-size: 11px; font-weight: 700; }
.xref-visible-count { margin: 0; color: var(--muted); font-size: 11px; text-align: right; }
.xref-empty { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.application-list { max-height: 420px; overflow: auto; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 24px max(20px, calc((100vw - 1240px) / 2)); border-top: 1px solid var(--line); color: var(--muted); background: white; font-size: 12px; }

@media (max-width: 900px) {
    .measure-form { grid-template-columns: repeat(2, 1fr); }
    .search-form { grid-template-columns: 1fr 1fr; }
    .search-form .primary { grid-column: 1 / -1; }
    .detail-columns { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
    .shell { width: min(100% - 20px, 1240px); padding-top: 30px; }
    .database-status { display: none; }
    .panel { padding: 13px; border-radius: 16px; }
    #numberForm, .search-form, .measure-form { grid-template-columns: 1fr; }
    .search-form .primary { grid-column: auto; }
    .result-grid { grid-template-columns: 1fr; }
    .detail { padding: 16px; }
    .detail-hero { grid-template-columns: 1fr; gap: 12px; }
    .detail-main-image { height: 180px; }
    .xref-toolbar { align-items: stretch; flex-direction: column; }
    .xref-toolbar label { min-width: 0; }
    .xref-selected-facts { grid-template-columns: 1fr 1fr; }
    footer { flex-direction: column; }
}
@media (max-width: 420px) {
    .xref-selected > header { align-items: flex-start; flex-direction: column; }
    .xref-selected-facts { grid-template-columns: 1fr; }
}
