/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #0d0d14;
    --surface:      #16161f;
    --surface-2:    #1e1e2b;
    --surface-3:    #252535;
    --border:       #2a2a3d;
    --border-light: #363650;
    --accent:       #4f7eff;
    --accent-dim:   rgba(79,126,255,.15);
    --accent-hover: #6b94ff;
    --success:      #34d399;
    --warn:         #fbbf24;
    --danger:       #f87171;
    --text:         #e2e2f0;
    --text-muted:   #8888aa;
    --text-dim:     #5555770;
    --radius:       8px;
    --radius-lg:    12px;
    --radius-sm:    5px;
    --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono:         'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    --shadow:       0 4px 24px rgba(0,0,0,.5);
    --shadow-sm:    0 2px 8px rgba(0,0,0,.4);
    --panel-w:      360px;
    --header-h:     64px;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout shell ─────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────── */
.app-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    color: var(--accent);
    flex-shrink: 0;
}

.brand-logo {
    height: 40px;
    width: auto;
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.3px;
}

.header-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* ── Body split ───────────────────────────────────────────── */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--header-h));
}

/* ── Search panel (left sidebar) ──────────────────────────── */
.search-panel {
    width: var(--panel-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-bottom: 16px;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 8px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: color .15s, border-color .15s;
    margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ── Tab panels ───────────────────────────────────────────── */
.tab-panel {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}

.tab-panel.active { display: flex; }

/* ── Form controls ────────────────────────────────────────── */
.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.field--grow { flex: 1; }

.field--end { justify-content: flex-end; }

.field-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
}

.ctrl {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    padding: 7px 10px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    appearance: auto;
}

.ctrl:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.ctrl::placeholder { color: var(--text-muted); }

.ctrl--sm { font-size: 12px; padding: 6px 10px; }

select.ctrl { cursor: pointer; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s, opacity .15s, transform .08s;
    white-space: nowrap;
}

.btn:active:not(:disabled) { transform: scale(.97); }

.btn--primary {
    background: var(--accent);
    color: #fff;
    min-width: 100px;
}

.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn--primary:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.btn--secondary {
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn--secondary:hover { background: var(--border-light); }

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: var(--font);
}

.link-btn:hover { text-decoration: underline; }

/* ── Part chip (found part indicator) ────────────────────── */
.part-chip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
    background: var(--accent-dim);
    border: 1px solid rgba(79,126,255,.3);
    border-radius: var(--radius-sm);
    animation: fadeIn .2s ease;
}

.part-type-badge {
    background: var(--accent);
    color: #fff;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
}

.part-value {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.part-attrs {
    font-size: 12px;
    color: var(--text-muted);
}

.part-usage {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-3);
    padding: 2px 6px;
    border-radius: 3px;
}

.no-match {
    padding: 10px 12px;
    background: rgba(248,113,113,.1);
    border: 1px solid rgba(248,113,113,.3);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 13px;
}

/* ── My PCBs ──────────────────────────────────────────────── */
.my-pcbs {
    border-top: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

.my-pcbs-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.my-pcbs-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.selection-badge {
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
}

.selection-badge.has-selection {
    background: var(--accent-dim);
    border-color: rgba(79,126,255,.4);
    color: var(--accent);
}

.my-pcbs-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 2px;
}

.sep {
    color: var(--text-muted);
    font-size: 11px;
}

.board-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 280px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    background: var(--bg);
}

.board-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background .1s;
    user-select: none;
}

.board-item:hover { background: var(--surface-2); }

.board-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    cursor: pointer;
}

.board-num {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    flex-shrink: 0;
}

.board-name {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Search action ────────────────────────────────────────── */
.search-action {
    padding: 12px 16px 0;
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid var(--border);
    margin-top: auto;
    flex-shrink: 0;
}

.search-hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ── Results panel ────────────────────────────────────────── */
.results-panel {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg);
    min-width: 0;
}

.results-placeholder {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    opacity: .5;
}

.results-placeholder svg {
    width: 64px;
    height: 64px;
}

.results-placeholder p {
    font-size: 15px;
}

/* ── Results ──────────────────────────────────────────────── */
.results-summary {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.results-summary strong { color: var(--text); }

.search-context {
    padding: 12px 16px;
    background: var(--accent-dim);
    border: 1px solid rgba(79,126,255,.25);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.search-context strong { color: var(--text); }

.search-context .ctx-label {
    color: var(--text-muted);
    font-size: 12px;
}

.search-context code {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--surface-3);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--text);
}

.board-card {
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    animation: slideIn .2s ease;
}

.board-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.board-card-number {
    font-family: var(--mono);
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
}

.board-card-name {
    font-size: 13px;
    color: var(--text-muted);
}

.board-card-count {
    margin-left: auto;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 9px;
}

.parts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.parts-table thead th {
    text-align: left;
    padding: 9px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.parts-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}

.parts-table tbody tr:last-child { border-bottom: none; }
.parts-table tbody tr:hover { background: var(--surface-2); }

.parts-table td {
    padding: 9px 12px;
    vertical-align: middle;
}

.td-designator {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.td-value {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--success);
}

.td-muted {
    color: var(--text-muted);
    font-size: 12px;
}

.td-empty {
    color: var(--border-light);
    font-size: 12px;
}

/* ── Empty / error states ─────────────────────────────────── */
.no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 60px 24px;
    color: var(--text-muted);
    text-align: center;
}

.no-results-icon {
    font-size: 48px;
    line-height: 1;
    opacity: .6;
}

.error-msg {
    padding: 14px 18px;
    background: rgba(248,113,113,.08);
    border: 1px solid rgba(248,113,113,.3);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 13px;
}

/* ── Spinner overlay ──────────────────────────────────────── */
.spinner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    backdrop-filter: blur(2px);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Animations ───────────────────────────────────────────── */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar              { width: 6px; height: 6px; }
::-webkit-scrollbar-track        { background: var(--bg); }
::-webkit-scrollbar-thumb        { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover  { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 860px) {
    :root { --panel-w: 100%; }

    .app-body {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    .search-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow: visible;
    }

    .results-panel {
        padding: 16px;
    }
}
