/* ============================================
   IC Pinout & Datasheet Quick-Finder
   Theme-aware, responsive, a11y. Pairs with bench-tools.css.
   ============================================ */

:root {
    --ic-grp-power: #e5484d;
    --ic-grp-ground: #8b8b8b;
    --ic-grp-clock: #f5a524;
    --ic-grp-address: #3e9bff;
    --ic-grp-data: #00c774;
    --ic-grp-control: #a855f7;
    --ic-grp-io: #00c2d1;
    --ic-grp-analog: #ff7ac6;
    --ic-grp-nc: #6b7280;
}

/* --- Visualizer stage --- */
.ic-stage {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.ic-viz-nojs {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin: 0;
    line-height: 1.5;
}

.ic-section-title {
    margin: 2rem 0 1rem;
}

.ic-detail {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
}

.ic-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--border);
}

.ic-detail-row:last-child {
    border-bottom: none;
}

.ic-detail-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
    padding-top: 0.1rem;
}

.ic-detail-value {
    font-family: var(--font-mono);
    font-size: 0.86rem;
    color: var(--text-primary);
    text-align: right;
    line-height: 1.45;
    word-break: break-word;
}

/* --- Legend --- */
.ic-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.ic-legend-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.75rem;
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ic-legend-btn::before {
    content: '';
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--ic-grp-io);
    flex-shrink: 0;
}

.ic-legend-btn--power::before    { background: var(--ic-grp-power); }
.ic-legend-btn--ground::before   { background: var(--ic-grp-ground); }
.ic-legend-btn--clock::before    { background: var(--ic-grp-clock); }
.ic-legend-btn--address::before  { background: var(--ic-grp-address); }
.ic-legend-btn--data::before     { background: var(--ic-grp-data); }
.ic-legend-btn--control::before  { background: var(--ic-grp-control); }
.ic-legend-btn--io::before       { background: var(--ic-grp-io); }
.ic-legend-btn--analog::before   { background: var(--ic-grp-analog); }
.ic-legend-btn--nc::before      { background: var(--ic-grp-nc); }

.ic-legend-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ic-legend-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

.ic-legend-btn.active::before {
    box-shadow: 0 0 0 2px var(--bg-primary);
}

/* --- Zoom controls --- */
.ic-zoom {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.ic-zoom-btn {
    padding: 0.35rem 0.85rem;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    min-width: 38px;
}

.ic-zoom-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* --- SVG stage (scrollable, pinch-zoom friendly) --- */
.ic-svg-stage {
    overflow: auto;
    touch-action: pan-x pan-y pinch-zoom;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    max-height: 70vh;
    display: flex;
    justify-content: center;
}

.ic-svg {
    max-width: 100%;
    height: auto;
    flex-shrink: 0;
}

/* --- SVG pin styles (colour by group via CSS classes, never inline hex) --- */
.ic-pin {
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.ic-pin text {
    pointer-events: none;
}

.ic-pin rect {
    transition: stroke 0.15s ease, stroke-width 0.15s ease;
}

.ic-pin--power rect    { fill: var(--ic-grp-power);    fill-opacity: 0.22; stroke: var(--ic-grp-power); }
.ic-pin--ground rect   { fill: var(--ic-grp-ground);   fill-opacity: 0.22; stroke: var(--ic-grp-ground); }
.ic-pin--clock rect    { fill: var(--ic-grp-clock);    fill-opacity: 0.22; stroke: var(--ic-grp-clock); }
.ic-pin--address rect  { fill: var(--ic-grp-address);  fill-opacity: 0.22; stroke: var(--ic-grp-address); }
.ic-pin--data rect     { fill: var(--ic-grp-data);     fill-opacity: 0.22; stroke: var(--ic-grp-data); }
.ic-pin--control rect  { fill: var(--ic-grp-control);  fill-opacity: 0.22; stroke: var(--ic-grp-control); }
.ic-pin--io rect       { fill: var(--ic-grp-io);       fill-opacity: 0.22; stroke: var(--ic-grp-io); }
.ic-pin--analog rect   { fill: var(--ic-grp-analog);   fill-opacity: 0.22; stroke: var(--ic-grp-analog); }
.ic-pin--nc rect       { fill: var(--ic-grp-nc);       fill-opacity: 0.22; stroke: var(--ic-grp-nc); }

.ic-pin:hover rect,
.ic-pin:focus rect {
    stroke-width: 2.5;
    filter: drop-shadow(0 0 4px var(--accent-glow));
}

.ic-pin.is-selected rect {
    stroke: var(--accent);
    stroke-width: 2.5;
    filter: drop-shadow(0 0 5px var(--accent-glow));
}

.ic-pin.is-selected text {
    fill: var(--accent);
}

.ic-pin.is-dimmed {
    opacity: 0.2;
}

/* --- Hub search + autocomplete --- */
.ic-search-wrap {
    position: relative;
    margin-bottom: 1rem;
}

.ic-search-input {
    width: 100%;
    max-width: 420px;
    padding: 0.6rem 1rem;
    font-family: var(--font-body);
    font-size: 0.88rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.ic-search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.ic-autocomplete {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 20;
    margin-top: 0.25rem;
    width: 100%;
    max-width: 420px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-card-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    display: none;
}

.ic-autocomplete.is-open {
    display: block;
}

.ic-ac-item {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease;
}

.ic-ac-item:last-child {
    border-bottom: none;
}

.ic-ac-item.is-active,
.ic-ac-item:hover {
    background: var(--accent-glow);
}

.ic-ac-item-name {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.ic-ac-item-part {
    font-size: 0.74rem;
    color: var(--text-muted);
}

/* --- Category pills (reuse rf-pill look) --- */
.ic-category-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

/* --- Popular quick links --- */
.ic-popular {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
}

.ic-popular-link {
    padding: 0.3rem 0.7rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.ic-popular-link:hover {
    background: var(--accent);
    color: var(--bg-primary);
    transform: translateY(-1px);
}

/* --- Card grid --- */
.ic-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.85rem;
}

.ic-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ic-card.is-hidden {
    display: none;
}

.ic-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 12px var(--accent-glow);
}

.ic-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.ic-badge {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 0.16rem 0.5rem;
    border-radius: 12px;
    white-space: nowrap;
}

.ic-badge--cat {
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}

.ic-card-name {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.ic-card-name a {
    color: inherit;
    text-decoration: none;
}

.ic-card-name a:hover {
    color: var(--accent);
}

.ic-card-part {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--text-muted);
}

.ic-card-short {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
}

.ic-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.ic-card-preview {
    padding: 0.35rem 0.75rem;
    font-family: var(--font-heading);
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.ic-card-preview:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-glow);
}

.ic-card-cta {
    font-family: var(--font-heading);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
}

.ic-card-cta:hover {
    text-decoration: underline;
}

.ic-card-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.ic-no-results {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* --- Chip page: spec grid + pin table --- */
.ic-spec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.ic-spec-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
}

.ic-spec-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.3rem;
}

.ic-spec-value {
    font-family: var(--font-mono);
    font-size: 0.86rem;
    color: var(--text-primary);
    line-height: 1.45;
}

.ic-pin-table-wrap {
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

.ic-pin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.ic-pin-table th,
.ic-pin-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.ic-pin-table th {
    font-family: var(--font-heading);
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-secondary);
}

.ic-pin-table td {
    color: var(--text-secondary);
    vertical-align: top;
}

.ic-pin-table .ic-pin-num {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.ic-pin-table .ic-pin-name {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
}

.ic-pin-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
    background: var(--ic-grp-io);
}

.ic-pin-dot--power    { background: var(--ic-grp-power); }
.ic-pin-dot--ground   { background: var(--ic-grp-ground); }
.ic-pin-dot--clock    { background: var(--ic-grp-clock); }
.ic-pin-dot--address  { background: var(--ic-grp-address); }
.ic-pin-dot--data      { background: var(--ic-grp-data); }
.ic-pin-dot--control   { background: var(--ic-grp-control); }
.ic-pin-dot--io        { background: var(--ic-grp-io); }
.ic-pin-dot--analog    { background: var(--ic-grp-analog); }
.ic-pin-dot--nc        { background: var(--ic-grp-nc); }

/* --- Chip page: datasheets + related + pager --- */
.ic-datasheet-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem;
    display: grid;
    gap: 0.5rem;
}

.ic-datasheet-list a {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.9rem;
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.ic-datasheet-list a:hover {
    background: var(--accent);
    color: var(--bg-primary);
    transform: translateY(-1px);
}

.ic-related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}

.ic-related-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    text-decoration: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ic-related-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 12px var(--accent-glow);
}

.ic-related-card h3 {
    font-family: var(--font-heading);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.25rem;
}

.ic-related-card span {
    font-size: 0.76rem;
    color: var(--text-muted);
}

.ic-pager {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2rem;
}

.ic-pager-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.ic-pager-link:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.ic-pager-link small {
    display: block;
    font-size: 0.66rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ic-prose {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    max-width: 820px;
    margin-bottom: 1.5rem;
}

.ic-prose p {
    margin: 0 0 1rem;
}

.ic-diagnostics {
    list-style: disc;
    padding-left: 1.25rem;
    margin: 0 0 1.5rem;
    max-width: 820px;
}

.ic-diagnostics li {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .ic-card-grid {
        grid-template-columns: 1fr;
    }
    .ic-related-grid {
        grid-template-columns: 1fr;
    }
    .ic-pager {
        flex-direction: column;
    }
}
