:root {
    --bg: #0d1117; --surface: #161b22; --border: #30363d;
    --text: #e6edf3; --text2: #8b949e; --accent: #58a6ff;
    --green: #3fb950; --red: #f85149; --orange: #d29922;
    --radius: 8px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }

/* Mobile elements hidden on desktop */
.mobile-header { display: none; }
.mobile-bottom-nav { display: none; }
.mobile-menu { display: none; }
.mobile-menu-backdrop { display: none; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg); color: var(--text); line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1400px; margin: 0 auto; padding: 16px 24px; }

/* Header */
header {
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 12px 0; position: sticky; top: 0; z-index: 100;
}
header .container { display: flex; align-items: center; gap: 24px; }
header h1 { font-size: 18px; font-weight: 600; white-space: nowrap; }
header h1 a { color: var(--text); }
.search-box {
    flex: 1; max-width: 600px; position: relative;
}
.search-box form { position: relative; }
.search-box input {
    width: 100%; padding: 8px 28px 8px 12px; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--bg);
    color: var(--text); font-size: 14px; outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-clear {
    display: none; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text2); font-size: 18px;
    cursor: pointer; padding: 0 4px; line-height: 1;
}
.search-clear:hover { color: var(--text); }
.nav-links { display: flex; gap: 16px; font-size: 14px; }

/* User dropdown */
.user-dropdown {
    position: relative; margin-left: auto;
}
.user-dropdown-btn {
    display: flex; align-items: center; gap: 8px; cursor: pointer;
    background: none; border: 1px solid transparent; border-radius: var(--radius);
    padding: 4px 8px; color: var(--text); font-size: 13px;
    transition: border-color 0.2s;
}
.user-dropdown-btn:hover { border-color: var(--border); }
.user-avatar {
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
    flex-shrink: 0;
}
.user-dropdown-name { font-weight: 500; }
.user-dropdown-caret { font-size: 10px; color: var(--text2); }
.user-dropdown-menu {
    display: none; position: absolute; right: 0; top: calc(100% + 4px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); min-width: 220px; padding: 4px 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3); z-index: 200;
}
.user-dropdown.open .user-dropdown-menu { display: block; }
.user-dropdown-header {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}
.user-dropdown-header strong { font-size: 14px; }
.user-dropdown-menu a {
    display: block; padding: 8px 16px; font-size: 13px;
    color: var(--text); text-decoration: none;
}
.user-dropdown-menu a:hover { background: var(--border); }
.user-dropdown-menu hr {
    border: none; border-top: 1px solid var(--border); margin: 4px 0;
}

/* Stats cards */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px; margin: 20px 0;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
}
.stat-card .label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 600; margin-top: 4px; }

/* Category sidebar */
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; margin-top: 20px; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }
.sidebar {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; height: fit-content;
    position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto;
}
.sidebar h3 { font-size: 13px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }
.cat-list { list-style: none; }
.cat-list li { margin-bottom: 2px; }
.cat-list a {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 10px; border-radius: 6px; font-size: 13px;
    color: var(--text); transition: background 0.15s;
}
.cat-list a:hover { background: var(--border); text-decoration: none; }
.cat-list a.active { background: rgba(88,166,255,0.15); color: var(--accent); }
.cat-count { font-size: 11px; color: var(--text2); background: var(--bg); padding: 2px 8px; border-radius: 10px; }

/* Component table */
.comp-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.comp-table th {
    text-align: left; padding: 10px 12px; font-size: 12px;
    color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0;
    background: var(--bg);
}
.comp-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.comp-table .desc-cell { max-width: 300px; }
.comp-table tr:hover td { background: var(--surface); }
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 11px; font-weight: 500;
}
.badge-basic { background: rgba(139,148,158,0.2); color: var(--text2); }
.badge-expand { background: rgba(63,185,80,0.15); color: var(--green); }
.badge-rohs { background: rgba(63,185,80,0.15); color: var(--green); }
.thumb { width: 40px; height: 40px; object-fit: contain; border-radius: 4px; background: #fff; }

/* Pagination */
.pagination {
    display: flex; justify-content: center; align-items: center;
    gap: 8px; margin: 20px 0; font-size: 14px;
}
.pagination a, .pagination span {
    padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border);
}
.pagination a:hover { background: var(--surface); text-decoration: none; }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Detail page */
.detail-header { margin: 16px 0 12px; }
.detail-header h2 { font-size: 22px; margin-bottom: 2px; }
.detail-header .subtitle { color: var(--text2); font-size: 14px; }

/* Top area: image | description | info */
.detail-top {
    display: grid; grid-template-columns: 300px 1fr 320px; gap: 16px; margin-bottom: 16px;
    align-items: stretch;
}
@media (max-width: 1000px) { .detail-top { grid-template-columns: 1fr; } }
.detail-top .images-col {
    display: flex; flex-direction: column; gap: 8px;
}
.detail-top .images-pane {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px;
    aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
    overflow: hidden; cursor: pointer;
}
.detail-top .images-pane img {
    max-width: 100%; max-height: 100%; object-fit: contain;
}
.detail-top .images-pane svg {
    width: 100%; height: auto; max-height: 100%;
}
.detail-top .images-pane { position: relative; }
.img-pane-grid-btn {
    position: absolute; top: 8px; right: 8px; z-index: 2;
    font-size: 11px; padding: 2px 8px; cursor: pointer;
    background: rgba(88,166,255,0.15); color: var(--accent);
    border: 1px solid var(--accent); border-radius: 4px;
    transition: background 0.15s;
}
.img-pane-grid-btn:hover { background: rgba(88,166,255,0.3); }
.img-pane-grid-btn.off { opacity: 0.5; background: transparent; }
.thumb-strip {
    display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
}
.thumb-strip img {
    width: 48px; height: 48px; object-fit: contain;
    border: 2px solid var(--border); border-radius: 4px;
    cursor: pointer; background: #fff; padding: 2px;
    transition: border-color 0.15s;
}
.thumb-strip img.svg-thumb {
    background: var(--surface); padding: 4px;
}
.thumb-strip img:hover { border-color: var(--accent); }
.thumb-strip img.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb-strip .thumb-3d:hover { border-color: var(--accent); }
.thumb-strip .thumb-3d.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.detail-top .desc-pane {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    overflow-y: auto;
}
.detail-top .info-pane {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    overflow-y: auto;
}

/* Bottom area: description + params + pricing + timestamps */
.detail-bottom {
    display: grid; grid-template-columns: 1fr 1fr 280px; gap: 16px; margin-bottom: 16px;
}
@media (max-width: 1000px) { .detail-bottom { grid-template-columns: 1fr; } }

.detail-section {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
}
.detail-section + .detail-section { margin-top: 16px; }
.detail-section h3 { font-size: 13px; color: var(--text2); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.detail-layout { display: grid; gap: 24px; }
@media (max-width: 900px) { .detail-layout { grid-template-columns: 1fr !important; } }
.detail-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--text2); white-space: nowrap; margin-right: 12px; }
.detail-row .val { text-align: right; max-width: 60%; word-break: break-all; }

/* Substitutions + EDA section */
.subs-eda-section {
    display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px;
}
.subs-header {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 8px;
}
.subs-actions {
    display: flex; gap: 8px; flex-wrap: wrap;
}

/* Substitution results table */
.subs-table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    margin-top: 4px;
}
.subs-table {
    width: 100%; border-collapse: collapse; font-size: 13px;
    table-layout: fixed;
}
.subs-table th {
    text-align: left; padding: 6px 8px; color: var(--text2);
    border-bottom: 1px solid var(--border); font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.3px;
    white-space: nowrap;
}
.subs-table td {
    padding: 8px 8px; border-bottom: 1px solid var(--border);
    vertical-align: top; word-wrap: break-word; overflow-wrap: break-word;
}
.subs-table .col-mpn { width: 12%; }
.subs-table .col-mfr { width: 10%; }
.subs-table .col-reason { width: 23%; }
.subs-table .col-diff { width: 19%; }
.subs-table .col-price { width: 9%; }
.subs-table .col-buy { width: 7%; }
.subs-table .col-local { width: 15%; }
.subs-table .col-del { width: 5%; text-align: center; }

/* Detail page footer (metadata + history — always last) */
.detail-footer {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
@media (max-width: 1000px) { .detail-footer { grid-template-columns: 1fr; } }

/* Images (browse grid) */
.images-grid { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.img-card {
    background: #fff; border-radius: var(--radius); padding: 4px;
    text-align: center; width: 100%; height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer;
}
.img-card img { max-width: 100%; max-height: 100%; object-fit: contain; }
.img-card .img-label { font-size: 10px; color: #666; margin-top: 4px; flex-shrink: 0; }
#zoom-overlay {
    position: fixed; z-index: 1000; pointer-events: none;
    background: #fff; border-radius: 12px; padding: 10px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    opacity: 0; transition: opacity 0.2s ease;
    transform: translate(20px, -50%);
}
#zoom-overlay.visible { opacity: 1; }
#zoom-overlay img {
    max-width: 450px; max-height: 450px; object-fit: contain; display: block;
}
/* Image lightbox (click to enlarge) */
#img-lightbox {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0,0,0,0.85);
    display: none; align-items: center; justify-content: center;
    cursor: zoom-out;
}
#img-lightbox.open { display: flex; }
#img-lightbox img {
    max-width: 92vw; max-height: 92vh; object-fit: contain;
    border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    background: #fff; padding: 4px;
}
#img-lightbox .lb-close {
    position: absolute; top: 16px; right: 20px;
    color: #fff; font-size: 28px; cursor: pointer;
    background: rgba(0,0,0,0.4); border: none;
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
#img-lightbox .lb-close:hover { background: rgba(255,255,255,0.2); }
/* Barcode scanner modal */
#barcode-modal {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0,0,0,0.85);
    display: none; flex-direction: column; align-items: center; justify-content: center;
    padding: 16px 0;
}
#barcode-modal.open { display: flex; }
#barcode-modal .bc-inner {
    background: var(--surface); border-radius: 12px; padding: 24px;
    max-width: 480px; width: 90%; text-align: center; position: relative;
    display: flex; flex-direction: column;
    max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
    overflow: hidden;
}
#barcode-modal .bc-close {
    position: absolute; top: 10px; right: 14px;
    color: var(--text); font-size: 22px; cursor: pointer;
    background: none; border: none; line-height: 1; z-index: 1;
}
#barcode-modal video {
    width: 100%; max-height: 300px; border-radius: 8px;
    background: #000; margin: 8px 0; flex-shrink: 1; object-fit: cover;
}
#bc-reader { border-radius: 8px; overflow: hidden; margin: 8px 0; flex-shrink: 0; }
#bc-reader video { width: 100% !important; border-radius: 8px; }
#barcode-modal .bc-status {
    font-size: 13px; color: var(--text2); margin-top: 4px; min-height: 18px; flex-shrink: 0;
}
#barcode-modal .bc-result {
    font-size: 14px; color: var(--accent); font-weight: 600; margin-top: 4px; flex-shrink: 0;
}
#barcode-modal .bc-manual {
    margin-top: 8px; display: flex; gap: 8px; justify-content: center; flex-shrink: 0;
}
#barcode-modal .bc-manual input {
    padding: 6px 10px; border-radius: var(--radius); border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 14px; width: 180px;
    text-align: center;
}
/* Scanner mode tabs */
.scanner-tabs { display: flex; gap: 0; margin-bottom: 8px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); flex-shrink: 0; }
.scanner-tabs button { flex: 1; padding: 7px 12px; font-size: 13px; border: none; background: var(--bg); color: var(--text2); cursor: pointer; transition: background 0.15s, color 0.15s; }
.scanner-tabs button.active { background: var(--accent); color: #fff; font-weight: 600; }
/* OCR controls */
.ocr-controls { margin: 6px 0; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; flex-shrink: 0; }
#ocr-canvas { display: none; max-width: 100%; border-radius: 8px; margin: 4px 0; flex-shrink: 1; align-self: center; }
/* Scrollable results area */
#ocr-tokens-area, #ocr-matches-area { flex-shrink: 1; }
.bc-results-scroll { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.ocr-tokens { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 6px 0; }
.ocr-token { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-family: monospace; background: var(--bg); border: 1px solid var(--border); cursor: pointer; transition: background 0.15s; }
.ocr-token:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.ocr-matches { text-align: left; margin-top: 6px; }
.ocr-match { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; border-bottom: 1px solid var(--border); font-size: 12px; }
.ocr-match:last-child { border-bottom: none; }
.ocr-match a { color: var(--accent); text-decoration: none; font-weight: 600; }
.ocr-match .match-meta { color: var(--text2); font-size: 11px; }
/* EDA SVG scaling — force inline SVGs to fit containers */
#add-eda-svg-area svg, .vision-enrich svg { max-width: 100%; max-height: 100%; height: auto; width: auto; display: block; margin: 0 auto; }
#add-eda-svg-area > div > div:last-child { display: flex; align-items: center; justify-content: center; }
/* Vision result card (compact) */
.vision-result-card { display: flex; gap: 10px; align-items: flex-start; padding: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); margin: 8px 0 6px; text-align: left; }
.vision-thumb { flex-shrink: 0; width: 56px; height: 56px; border-radius: 6px; overflow: hidden; background: var(--bg2); }
.vision-thumb img { width: 100%; height: 100%; object-fit: contain; }
.vision-info { flex: 1; min-width: 0; }
.vision-part-name { font-size: 14px; font-weight: 700; color: var(--text); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vision-meta { font-size: 11px; color: var(--text2); line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vision-enrich { font-size: 10px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vision-enrich a { font-size: 10px; }
.vision-actions { display: flex; gap: 6px; margin: 4px 0; }
.vision-actions .btn { font-size: 13px; padding: 6px 14px; }
/* Collapsible matches toggle */
.matches-toggle { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text2); cursor: pointer; padding: 4px 0; border: none; background: none; width: 100%; text-align: left; }
.matches-toggle:hover { color: var(--accent); }
.matches-toggle .chevron { transition: transform 0.2s; display: inline-block; }
.matches-toggle.open .chevron { transform: rotate(90deg); }
/* Mobile: tighter layout to fit everything on screen */
@media (max-width: 600px) {
    #barcode-modal { padding: 0; }
    #barcode-modal .bc-inner { border-radius: 0; padding: 14px 12px; width: 100%; max-width: 100%; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; }
    #barcode-modal video { max-height: none; flex: 1 1 40%; min-height: 200px; margin: 6px 0; }
    #ocr-canvas { flex: 0 0 auto; max-height: 20vh !important; width: auto !important; }
    .scanner-tabs { margin-bottom: 6px; }
    .scanner-tabs button { padding: 6px 8px; font-size: 12px; }
    .ocr-controls { margin: 4px 0; }
    .vision-thumb { width: 44px; height: 44px; }
    .vision-part-name { font-size: 13px; }
    .vision-actions .btn { font-size: 12px; padding: 6px 10px; }
    .vision-result-card { padding: 6px; gap: 8px; }
}
.no-images { color: var(--text2); font-size: 13px; font-style: italic; padding: 10px 0; text-align: center; }

/* Pricing */
.price-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.price-table th { text-align: left; padding: 4px 6px; color: var(--text2); border-bottom: 1px solid var(--border); font-size: 11px; }
.price-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); }

.param-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.param-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.param-table td:first-child { color: var(--text2); width: 40%; }

/* EDA preview cards */
.eda-previews {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
@media (max-width: 1000px) { .eda-previews { grid-template-columns: 1fr; } }
.eda-preview-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; text-align: center;
}
.eda-preview-card h3 {
    font-size: 13px; color: var(--text2); margin-bottom: 10px;
    text-transform: uppercase; letter-spacing: 0.5px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.eda-preview-card svg {
    width: 100%; max-height: 340px; height: auto;
}
/* Footprint grid toggle */
.fp-grid-toggle {
    font-size: 11px; padding: 2px 8px; cursor: pointer;
    background: rgba(88,166,255,0.15); color: var(--accent);
    border: 1px solid var(--accent); border-radius: 4px;
    text-transform: none; letter-spacing: 0;
    line-height: 1.4; display: inline-flex; align-items: center; gap: 3px;
}
.fp-grid-toggle:hover { background: rgba(88,166,255,0.3); }
.fp-grid-toggle.off { opacity: 0.5; background: transparent; }
.fp-grid-hidden .fp-grid { display: none; }

.ds-link {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; background: rgba(88,166,255,0.1); border: 1px solid var(--accent);
    border-radius: var(--radius); font-size: 13px; margin-top: 6px;
}
.ds-link:hover { background: rgba(88,166,255,0.2); text-decoration: none; }

.breadcrumb { font-size: 13px; color: var(--text2); margin-bottom: 4px; }
.breadcrumb a { color: var(--text2); }

.ts-row { font-size: 12px; padding: 3px 0; color: var(--text2); }
.ts-row .ts-label { color: var(--text2); margin-right: 6px; }
.breadcrumb a:hover { color: var(--accent); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }

/* Filter bar */
.filter-bar {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    padding: 10px 16px; margin-top: 16px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 13px;
}
.filter-bar .filter-label { color: var(--text2); font-weight: 500; white-space: nowrap; }
.filter-bar label {
    display: inline-flex; align-items: center; gap: 6px;
    cursor: pointer; user-select: none; color: var(--text);
    padding: 4px 10px; border-radius: 6px; transition: background 0.15s;
}
.filter-bar label:hover { background: var(--border); }
.filter-bar input[type="checkbox"] {
    accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer;
}
.filter-bar .filter-sep {
    width: 1px; height: 20px; background: var(--border);
}
.filter-row {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    width: 100%;
}
.filter-bar .filter-group {
    display: flex; align-items: center; gap: 6px;
}
.filter-bar select,
.filter-bar input[type="text"],
.filter-bar input[type="number"] {
    padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 13px; outline: none;
}
.filter-bar select:focus,
.filter-bar input[type="text"]:focus,
.filter-bar input[type="number"]:focus {
    border-color: var(--accent);
}
.filter-bar input[type="number"] { width: 70px; }
.filter-bar input[type="text"] { width: 140px; }
.filter-bar select { cursor: pointer; }
.filter-row-params {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 4px;
}
.filter-row-params .filter-label:first-child {
    min-width: 100px;
}
.pf-select {
    max-width: 200px;
    min-width: 100px;
}

/* Parametric filter active chips */
.filter-row-chips {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 4px;
    gap: 6px;
}
.pf-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--accent);
    color: #fff;
    border-radius: 12px;
    font-size: 12px;
    white-space: nowrap;
}
.pf-chip strong { font-weight: 600; }
.pf-chip-x {
    background: none;
    border: none;
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    opacity: 0.8;
}
.pf-chip-x:hover { opacity: 1; }

/* ---- Mobile-responsive overrides ---- */
@media (max-width: 600px) {
    /* Container */
    .container { padding: 10px 12px; }

    /* Header: stack vertically */
    header .container {
        flex-wrap: wrap; gap: 8px;
    }
    header h1 { font-size: 16px; }
    .search-box { max-width: 100%; order: 3; flex-basis: 100%; }
    .nav-links { gap: 12px; font-size: 13px; }

    /* Layout: sidebar above content, not sticky */
    .layout { grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
    .sidebar {
        position: static; max-height: none;
        padding: 12px; overflow-y: visible;
    }
    /* Collapse categories behind a toggle by default */
    .sidebar .cat-list { max-height: 200px; overflow-y: auto; }

    /* Filter bar: stack rows, full-width inputs */
    .filter-bar {
        padding: 8px 10px; gap: 8px; font-size: 12px;
    }
    .filter-row {
        gap: 6px 10px;
    }
    .filter-bar label { padding: 3px 6px; font-size: 12px; }
    .filter-bar input[type="number"] { width: 55px; font-size: 12px; }
    .filter-bar input[type="text"] { width: 100px; font-size: 12px; }
    .filter-bar select { font-size: 12px; }
    .filter-bar .filter-group { flex-wrap: wrap; }
    .filter-row-params { padding-top: 6px; margin-top: 2px; }
    .filter-row-params .filter-label:first-child { min-width: auto; }
    .pf-select { max-width: 150px; min-width: 80px; font-size: 12px; }
    .pf-chip { font-size: 11px; padding: 2px 6px; }

    /* Browse table → card layout on mobile */
    .comp-table thead { display: none; }
    .comp-table,
    .comp-table tbody,
    .comp-table tr,
    .comp-table td { display: block; width: 100%; }
    .comp-table tr {
        background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 10px 12px;
        margin-bottom: 8px;
    }
    .comp-table td {
        padding: 2px 0; border-bottom: none; font-size: 13px;
        display: flex; justify-content: space-between; align-items: center;
    }
    .comp-table td::before {
        font-size: 11px; color: var(--text2); text-transform: uppercase;
        letter-spacing: 0.4px; font-weight: 500; margin-right: 8px;
        white-space: nowrap;
    }
    /* Label each cell via nth-child */
    .comp-table td:nth-child(1) { justify-content: center; padding-bottom: 6px; }
    .comp-table td:nth-child(1)::before { content: none; }
    .comp-table td:nth-child(2)::before { content: 'Code'; }
    .comp-table td:nth-child(3)::before { content: 'Model'; }
    .comp-table td:nth-child(4)::before { content: 'Category'; }
    .comp-table td:nth-child(5)::before { content: 'Description'; }
    .comp-table td:nth-child(5) { max-width: none; }
    .comp-table td:nth-child(6)::before { content: 'Stock'; }
    .comp-table td:nth-child(7)::before { content: 'Type'; }
    .comp-table tr:hover td { background: transparent; }
    .thumb { width: 60px; height: 60px; }

    /* Pagination */
    .pagination { flex-wrap: wrap; gap: 4px; }
    .pagination a, .pagination span { padding: 6px 10px; font-size: 13px; }

    /* Detail page */
    .detail-header h2 { font-size: 18px; }
    .detail-header .btn-group { flex-wrap: wrap; gap: 6px; }
    .detail-top { grid-template-columns: 1fr; gap: 12px; }
    .detail-top .images-pane { max-width: 280px; margin: 0 auto; }
    .detail-bottom { grid-template-columns: 1fr; gap: 12px; }
    .detail-footer { grid-template-columns: 1fr; gap: 12px; }
    .eda-previews { grid-template-columns: 1fr; gap: 12px; }
    .detail-section { padding: 12px; }
    .detail-row { font-size: 12px; flex-wrap: wrap; }
    .detail-row .val { max-width: 100%; text-align: left; }
    .price-table { font-size: 11px; }
    .param-table { font-size: 12px; }

    /* Substitutions: stack header + buttons vertically */
    .subs-header { flex-direction: column; align-items: flex-start; }
    .subs-actions { width: 100%; }
    .subs-actions .btn { font-size: 11px !important; flex: 1; text-align: center; min-width: 0; }

    /* Substitution results: card layout on mobile */
    .subs-table { table-layout: auto; }
    .subs-table thead { display: none; }
    .subs-table, .subs-table tbody, .subs-table tr, .subs-table td { display: block; width: 100%; }
    .subs-table tr {
        background: var(--bg); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 10px 12px;
        margin-bottom: 8px;
    }
    .subs-table td {
        padding: 3px 0; border-bottom: none; font-size: 13px;
        display: flex; gap: 8px;
    }
    .subs-table td::before {
        font-size: 11px; color: var(--text2); text-transform: uppercase;
        letter-spacing: 0.3px; font-weight: 500; white-space: nowrap;
        min-width: 80px; flex-shrink: 0;
    }
    .subs-table td:nth-child(1)::before { content: 'Part'; }
    .subs-table td:nth-child(2)::before { content: 'Mfr'; }
    .subs-table td:nth-child(3)::before { content: 'Why'; }
    .subs-table td:nth-child(4)::before { content: 'Diff'; }
    .subs-table td:nth-child(5)::before { content: 'Price'; }
    .subs-table td:nth-child(6)::before { content: 'Buy'; }
    .subs-table td:nth-child(7)::before { content: 'In DB'; }
    .subs-table td:nth-child(8)::before { content: ''; }
    .subs-table td:nth-child(8) { text-align: right; }

    /* Zoom overlay: hide on mobile (no hover) */
    #zoom-overlay { display: none !important; }
}

/* Tablet tweaks (600-900px) */
@media (min-width: 601px) and (max-width: 900px) {
    .container { padding: 14px 16px; }
    .comp-table td { padding: 8px 8px; font-size: 13px; }
    .comp-table th { font-size: 11px; padding: 8px 8px; }
    .comp-table td:nth-child(5) { max-width: 200px; }
    .detail-top { grid-template-columns: 1fr 1fr; }
    .detail-bottom { grid-template-columns: 1fr 1fr; }
    .detail-footer { grid-template-columns: 1fr 1fr; }
    .filter-bar input[type="text"] { width: 120px; }
    #zoom-overlay img { max-width: 300px; max-height: 300px; }
}

/* ---- Inventory-specific styles ---- */
.inv-form { max-width: 900px; }
.inv-form .form-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; margin-bottom: 16px;
}
@media (max-width: 600px) { .inv-form .form-grid { grid-template-columns: 1fr; } }
.inv-form .form-group { display: flex; flex-direction: column; gap: 4px; }
.inv-form .form-group.full-width { grid-column: 1 / -1; }
.inv-form label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 500; }
.inv-form input, .inv-form select, .inv-form textarea {
    padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 14px; outline: none;
    font-family: inherit;
}
.inv-form input:focus, .inv-form select:focus, .inv-form textarea:focus { border-color: var(--accent); }
.inv-form textarea { min-height: 80px; resize: vertical; }
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius); font-size: 14px;
    cursor: pointer; border: 1px solid var(--border); transition: background 0.15s;
    font-family: inherit; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #4a96ea; }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: #36a347; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #e04640; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 6px; font-size: 11px; line-height: 1.2; vertical-align: middle; }
.ds-refetch-btn { opacity: 0.6; transition: opacity 0.15s; }
.ds-refetch-btn:hover { opacity: 1; }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface); }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.form-actions { display: flex; gap: 12px; margin-top: 16px; align-items: center; }

/* Edit page image gallery */
.edit-img-gallery {
    display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0;
}
.edit-img-card {
    position: relative; width: 110px; height: 110px;
    border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; background: var(--bg2);
}
.edit-img-card img {
    width: 100%; height: 100%; object-fit: contain; display: block;
}
.edit-img-badge {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,.65); color: #fff; font-size: 10px;
    padding: 2px 6px; text-align: center; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.edit-img-del {
    position: absolute; top: 4px; right: 4px;
    background: rgba(248,81,73,.85); color: #fff;
    width: 20px; height: 20px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    font-size: 12px; line-height: 1; text-decoration: none;
    cursor: pointer;
}
.edit-img-card:hover .edit-img-del { display: flex; }

.flash-success {
    background: rgba(63,185,80,0.15); border: 1px solid var(--green);
    color: var(--green); padding: 10px 16px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px;
}
.flash-error {
    background: rgba(248,81,73,0.15); border: 1px solid var(--red);
    color: var(--red); padding: 10px 16px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px;
}

/* Maintenance banner (pre-maintenance warning) */
.maintenance-banner {
    background: rgba(210,153,34,0.15); border: 1px solid var(--orange);
    color: var(--orange); padding: 12px 20px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px; display: flex; align-items: center; gap: 10px;
}
.maintenance-banner .maint-icon { font-size: 20px; flex-shrink: 0; }
.maintenance-banner strong { color: var(--text); }

/* Maintenance landing page */
.maintenance-page {
    text-align: center; padding: 80px 20px; max-width: 600px; margin: 0 auto;
}
.maintenance-page .maint-icon-lg { font-size: 64px; margin-bottom: 24px; display: block; }
.maintenance-page h2 { font-size: 24px; margin-bottom: 12px; color: var(--text); }
.maintenance-page p { color: var(--text2); font-size: 15px; margin-bottom: 8px; line-height: 1.6; }
.maintenance-page .maint-detail {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin-top: 24px;
    text-align: left; font-size: 14px;
}
.maintenance-page .maint-detail dt { color: var(--text2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 12px; }
.maintenance-page .maint-detail dt:first-child { margin-top: 0; }
.maintenance-page .maint-detail dd { color: var(--text); margin: 2px 0 0 0; }
.maintenance-page .maint-links { margin-top: 28px; }
.maintenance-page .maint-links a { margin: 0 12px; }
/* Collapsible project sections */
details.collapsible-section { border-radius: var(--radius); }
details.collapsible-section > summary.section-toggle {
    cursor: pointer; list-style: none; user-select: none;
    display: flex; align-items: center; gap: 6px;
    padding: 0; margin: 0;
}
details.collapsible-section > summary.section-toggle::-webkit-details-marker { display: none; }
details.collapsible-section > summary.section-toggle::before {
    content: '▶'; font-size: 10px; color: var(--text2); transition: transform 0.2s;
    display: inline-block; width: 14px; flex-shrink: 0;
}
details.collapsible-section[open] > summary.section-toggle::before { transform: rotate(90deg); }
details.collapsible-section > summary.section-toggle h3 { margin: 0; }
details.collapsible-section > summary.section-toggle:hover { opacity: 0.8; }
.inv-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.inv-table th {
    text-align: left; padding: 8px 10px; font-size: 11px;
    color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0;
    background: var(--bg); white-space: nowrap;
}
.inv-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.inv-table .col-ref { font-size: 11px; font-family: monospace; color: var(--text2); word-break: break-all; max-width: 180px; }
.inv-table .col-mono { font-family: monospace; font-size: 12px; }
.inv-table .col-num { text-align: center; white-space: nowrap; }
.inv-table .col-stock { text-align: right; white-space: nowrap; font-size: 12px; color: var(--text2); }
.inv-table .col-status { width: 28px; text-align: center; }
.inv-table tr:hover td { background: var(--surface); }
.stock-badge {
    display: inline-block; padding: 2px 10px; border-radius: 10px;
    font-size: 12px; font-weight: 500;
}
.stock-ok { background: rgba(63,185,80,0.15); color: var(--green); }
.stock-low { background: rgba(210,153,34,0.15); color: var(--orange); }
.stock-out { background: rgba(248,81,73,0.15); color: var(--red); }
.fav-star { cursor: pointer; font-size: 18px; }
.fav-star.active { color: var(--orange); }
.catalog-fav { cursor: pointer; font-size: 16px; color: var(--text2); transition: color 0.15s; vertical-align: middle; }
.catalog-fav:hover { color: var(--orange); }
.catalog-fav.on { color: var(--orange); }
.loc-tree { list-style: none; }
.loc-tree li { margin-bottom: 2px; display: flex; align-items: center; }
.loc-tree li[data-parent] { display: none; }
.loc-tree li.loc-expanded-child { display: flex; }
.loc-tree a {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 10px; border-radius: 6px; font-size: 13px;
    color: var(--text); transition: background 0.15s; flex: 1; min-width: 0;
}
.loc-tree a:hover { background: var(--border); text-decoration: none; }
.loc-tree a.active { background: rgba(88,166,255,0.15); color: var(--accent); }
.loc-toggle {
    cursor: pointer; font-size: 9px; padding: 4px 4px 4px 0; color: var(--text2);
    user-select: none; flex-shrink: 0; width: 16px; text-align: center;
    transition: transform 0.15s;
}
.loc-toggle.collapsed { transform: rotate(-90deg); }
.loc-toggle:hover { color: var(--text); }
.loc-toggle-spacer { width: 16px; flex-shrink: 0; }
.loc-tbl-toggle {
    cursor: pointer; font-size: 9px; color: var(--text2); user-select: none;
    display: inline-block; width: 16px; text-align: center;
    transition: transform 0.15s; vertical-align: middle;
}
.loc-tbl-toggle.collapsed { transform: rotate(-90deg); }
.loc-tbl-toggle:hover { color: var(--text); }
.loc-tbl-toggle-spacer { display: inline-block; width: 16px; }
#loc-mgmt-table tr.loc-tbl-hidden { display: none; }
.loc-indent-1 { padding-left: 20px; }
.loc-indent-2 { padding-left: 40px; }
.loc-indent-3 { padding-left: 60px; }
.loc-indent-4 { padding-left: 80px; }

/* Location Tree Picker widget */
.loc-tree-picker { position: relative; flex: 1; min-width: 200px; }
.loc-tree-picker.ltp-compact { min-width: 160px; }
.loc-tree-btn {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 6px 10px; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    font-size: 13px; cursor: pointer; text-align: left; gap: 8px;
}
.loc-tree-btn:hover { border-color: var(--accent); }
.loc-tree-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.loc-tree-label.ltp-placeholder { color: var(--text2); }
.loc-tree-arrow { font-size: 10px; color: var(--text2); flex-shrink: 0; }
.loc-tree-dropdown {
    position: absolute; top: 100%; left: 0; min-width: 320px;
    z-index: 1000; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    margin-top: 4px; max-height: 320px; display: flex; flex-direction: column;
}
.loc-tree-search {
    padding: 8px 10px; border: none; border-bottom: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 13px;
    outline: none; border-radius: var(--radius) var(--radius) 0 0;
}
.loc-tree-search::placeholder { color: var(--text2); }
.loc-tree-search-hint {
    position: absolute; pointer-events: none; padding: 8px 10px;
    color: var(--text2); opacity: 0.5; font-size: 13px;
    white-space: nowrap; overflow: hidden;
}
.loc-tree-list {
    list-style: none; margin: 0; padding: 4px 0;
    overflow-y: auto; max-height: 270px;
}
.ltp-item {
    display: flex; align-items: center; gap: 4px;
    padding: 5px 10px; cursor: pointer; font-size: 13px;
    color: var(--text); white-space: nowrap;
}
.ltp-item:hover { background: var(--border); }
.ltp-item.ltp-selected { background: rgba(88,166,255,0.15); color: var(--accent); }
.ltp-item.ltp-highlight { background: rgba(88,166,255,0.08); }
.ltp-toggle {
    width: 16px; flex-shrink: 0; text-align: center; font-size: 9px;
    color: var(--text2); cursor: pointer; user-select: none;
}
.ltp-toggle:hover { color: var(--text); }
.ltp-toggle-spacer { width: 16px; flex-shrink: 0; }
.ltp-name { overflow: hidden; text-overflow: ellipsis; }
.ltp-path { font-size: 12px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; }
.ltp-path .ltp-match { color: var(--accent); font-weight: 600; }
.ltp-crumb { font-size: 10px; color: var(--text2); margin-right: 4px; opacity: 0.7; }

.stock-controls {
    display: inline-flex; align-items: center; gap: 4px;
}
.stock-controls .btn-sm { padding: 2px 8px; min-width: 28px; text-align: center; }

/* Stock tree display */
.stock-tree-row {
    display: flex; align-items: center; gap: 4px;
    padding: 4px 8px; font-size: 13px; border-bottom: 1px solid var(--border);
}
.stock-tree-row:last-child { border-bottom: none; }

.history-list { list-style: none; }
.history-list li {
    padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
    display: flex; gap: 12px; align-items: flex-start;
}
.history-list li:last-child { border-bottom: none; }
.history-action {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 11px; font-weight: 500; min-width: 50px; text-align: center;
}
.action-add { background: rgba(63,185,80,0.15); color: var(--green); }
.action-remove { background: rgba(248,81,73,0.15); color: var(--red); }
.action-edit { background: rgba(88,166,255,0.15); color: var(--accent); }
.action-create { background: rgba(210,153,34,0.15); color: var(--orange); }
.action-adjust { background: rgba(139,148,158,0.2); color: var(--text2); }
.action-move { background: rgba(210,153,34,0.15); color: var(--orange); }
.project-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.project-card h3 { font-size: 16px; margin-bottom: 4px; }
.project-card .project-meta { font-size: 12px; color: var(--text2); }
.shortage-badge {
    background: rgba(248,81,73,0.15); color: var(--red);
    padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500;
}
.scrape-preview {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.scrape-preview .scrape-img { max-width: 200px; max-height: 200px; border-radius: 4px; }
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab {
    padding: 8px 20px; font-size: 14px; color: var(--text2);
    cursor: pointer; border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: color 0.15s, border-color 0.15s;
    text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.inv-nav-badge {
    display: inline-block; background: var(--red); color: #fff; font-size: 10px;
    padding: 1px 6px; border-radius: 8px; margin-left: 4px; font-weight: 600;
}

@media (max-width: 600px) {
    .inv-form .form-grid { grid-template-columns: 1fr; }
    .inv-table thead { display: none; }
    .inv-table, .inv-table tbody, .inv-table tr, .inv-table td { display: block; width: 100%; }
    .inv-table tr {
        background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px;
    }
    .inv-table td {
        padding: 2px 0; border-bottom: none; font-size: 13px;
        display: flex; justify-content: space-between; align-items: center;
    }
    .inv-table td::before {
        font-size: 11px; color: var(--text2); text-transform: uppercase;
        letter-spacing: 0.4px; font-weight: 500; margin-right: 8px; white-space: nowrap;
    }
    .tabs { overflow-x: auto; }
    .tab { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
    .btn { padding: 6px 12px; font-size: 13px; }
}

/* ---- EDA Picker responsive overrides ---- */
/* The picker uses inline grid styles, so we need !important on mobile */
@media (max-width: 900px) {
    /* Stack 3-column grids to 1 column */
    #panel-fp > div,
    #panel-sym > div,
    #panel-m3d > div {
        grid-template-columns: 1fr !important;
    }
    /* Current assignments row */
    .eda-assignments {
        grid-template-columns: 1fr !important;
    }
    .eda-assignments h3 { font-size: 14px; }
    /* Tab buttons: smaller text */
    .eda-tabs .btn { font-size: 12px; padding: 8px 6px; }
    /* Preview panes: not sticky on mobile */
    #fp-preview-pane,
    #sym-preview-pane,
    #m3d-preview-pane {
        position: static !important;
        align-self: auto !important;
    }
    /* Sidebar: horizontal scroll or collapse */
    #m3d-prefixes {
        max-height: 200px !important;
    }
    /* Preview render: reduce min-height */
    #m3d-preview-render,
    #fp-preview-svg,
    #sym-preview-svg {
        min-height: 240px !important;
    }
    /* Results: cap height */
    #m3d-results,
    #fp-results,
    #sym-results {
        max-height: 400px !important;
        overflow-y: auto !important;
    }
}

/* Tablet: 2-column for picker */
@media (min-width: 601px) and (max-width: 900px) {
    #panel-fp > div,
    #panel-sym > div {
        grid-template-columns: 1fr 1fr !important;
    }
    #panel-m3d > div {
        grid-template-columns: 1fr 1fr !important;
    }
    /* Hide prefix sidebar on tablet, search is enough */
    #m3d-prefixes {
        max-height: 150px !important;
    }
    .eda-assignments {
        grid-template-columns: 1fr 1fr 1fr !important;
    }
}

/* ---------- Cell-based spreadsheet editor ---------- */
.sheet-wrap { overflow-x: auto; margin-bottom: 16px; }
.sheet {
    border-collapse: collapse; width: 100%; min-width: 700px;
    font-size: 13px; table-layout: fixed;
}
.sheet th {
    background: var(--surface); color: var(--text2); font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600;
    padding: 6px 8px; border: 1px solid var(--border);
    position: sticky; top: 0; z-index: 2; user-select: none;
}
.sheet td {
    padding: 0; border: 1px solid var(--border); height: 32px;
    position: relative;
}
.sheet td.row-num {
    width: 36px; min-width: 36px; text-align: center;
    color: var(--text2); font-size: 11px; background: var(--surface);
    padding: 6px 4px; user-select: none;
}
.sheet td input, .sheet td select {
    width: 100%; height: 100%; border: none; outline: none;
    background: transparent; color: var(--text); padding: 4px 8px;
    font-size: 13px; font-family: inherit; box-sizing: border-box;
}
.sheet td:focus-within {
    box-shadow: inset 0 0 0 2px var(--accent);
    z-index: 1;
}
.sheet td input:focus, .sheet td select:focus {
    background: rgba(88,166,255,0.06);
}
.sheet td.cell-error { background: rgba(248,81,73,0.08); }
.sheet td.cell-ok { background: rgba(63,185,80,0.08); }
.sheet .delete-col { width: 32px; min-width: 32px; text-align: center; }
.sheet .delete-col button {
    background: none; border: none; color: var(--text2); cursor: pointer;
    font-size: 14px; padding: 4px;
}
.sheet .delete-col button:hover { color: var(--red); }
.sheet-toolbar {
    display: flex; gap: 8px; margin-bottom: 12px; align-items: center;
    flex-wrap: wrap;
}
.sheet-toolbar .spacer { flex: 1; }
.sheet-status {
    font-size: 12px; color: var(--text2); margin-top: 8px;
}
.sheet-status .count-ok { color: var(--green); font-weight: 600; }
.sheet-status .count-err { color: var(--red); font-weight: 600; }
.paste-area {
    width: 100%; min-height: 80px; background: var(--bg);
    border: 1px dashed var(--border); border-radius: var(--radius);
    color: var(--text); padding: 12px; font-family: monospace; font-size: 13px;
    resize: vertical;
}

/* ---- Stock Cart badge & button ---- */
.cart-badge {
    position: absolute; top: -6px; right: -10px;
    background: var(--accent, #3498db); color: #fff;
    font-size: 10px; min-width: 16px; height: 16px; line-height: 16px;
    text-align: center; border-radius: 50%; font-weight: 700;
    pointer-events: none;
}
.cart-badge-pop { animation: cart-pop 0.3s ease; }
@keyframes cart-pop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.4); }
    100% { transform: scale(1); }
}
.cart-add-btn:hover { color: var(--accent, #3498db) !important; }
