/* ── Theme ── */
:root {
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --accent: #3a86ff;
    --accent-light: #e8f0fe;
    --text: #2b2d42;
    --text-muted: #8b8fa3;
    --border: #e2e5ea;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.10);
    --radius: 8px;
    --sidebar-w: 230px;
    --transition: 0.2s ease;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #e8e8f0;
    padding: 0.8rem 1.5rem;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: inherit;
}
.header-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.header-github {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color var(--transition);
}
.header-github:hover { color: #fff; }
.header-github svg { flex-shrink: 0; }

/* ── Layout ── */
.layout {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ── Sidebar ── */
#sidebar {
    width: var(--sidebar-w);
    min-width: 160px;
    max-width: 50vw;
    flex-shrink: 0;
    background: var(--card-bg);
    border-right: none;
    overflow-y: auto;
    padding: 0.6rem 0;
    position: relative;
}
.sidebar-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    background: var(--border);
    transition: background var(--transition);
    z-index: 5;
}
.sidebar-handle:hover,
.sidebar-handle.dragging {
    background: var(--accent);
}
#device-list { list-style: none; }

/* Overview link */
.nav-overview {
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 600;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    margin-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
}
.nav-overview:hover { background: var(--accent-light); }
.nav-overview.active {
    background: var(--accent-light);
    border-left-color: var(--accent);
    color: var(--accent);
}

/* Manufacturer group */
.nav-group { list-style: none; }
.nav-group-header {
    padding: 0.45rem 1rem 0.45rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.02em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    user-select: none;
    transition: color var(--transition);
}
.nav-group-header:hover { color: var(--text); }
.nav-group-header:not(:hover) .nav-group-arrow { color: var(--accent); }
.nav-group-arrow {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform var(--transition);
    flex-shrink: 0;
}
.nav-group.collapsed .nav-group-arrow {
    transform: rotate(-90deg);
}
.nav-group-items {
    list-style: none;
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.25s ease;
}
.nav-group.collapsed .nav-group-items {
    max-height: 0;
}

/* Device items */
.nav-group-items li {
    padding: 0.4rem 1rem 0.4rem 1.5rem;
    cursor: pointer;
    font-size: 0.86rem;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    position: relative;
}
.nav-group-items li:hover {
    background: var(--accent-light);
}
.nav-group-items li.active {
    background: var(--accent-light);
    border-left-color: var(--accent);
    font-weight: 600;
}
.nav-group-items li.active::after {
    content: "";
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: var(--bg);
}

/* ── Detail panel ── */
#detail-panel {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 1.5rem 2rem;
}
#detail-panel > * {
    max-width: 1100px;
}

#welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 0.8rem;
}
#welcome .welcome-icon {
    font-size: 2.5rem;
    opacity: 0.3;
}
#welcome p {
    font-size: 0.95rem;
}

/* ── Summary / overview table ── */
.summary-page h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1rem;
}
.overview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}
.overview-table th {
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.5rem 0.6rem;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.overview-table td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}
.overview-table tbody tr:hover {
    background: var(--accent-light);
}
.overview-img-cell {
    width: 40px;
    padding: 0.25rem 0.4rem !important;
}
.overview-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    cursor: zoom-in;
    display: block;
}
.overview-device-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.overview-device-link:hover {
    text-decoration: underline;
}

/* ── Device detail ── */
.detail-header {
    margin-bottom: 0.3rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}
.detail-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}
.detail-header .manufacturer-line {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}
.detail-header .manufacturer-line strong {
    color: var(--text);
    font-weight: 600;
}

/* Cards row */
.cards-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.2rem;
}
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
    box-shadow: var(--shadow-sm);
}
.card-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.8rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

/* Device summary card */
.summary-content {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}
.summary-image {
    flex-shrink: 0;
    width: 220px;
}
.summary-info {
    flex: 1;
    min-width: 0;
}
.device-image {
    border-radius: var(--radius);
    overflow: hidden;
}
.device-image-zoomable { cursor: zoom-in; }
.device-image img {
    display: block;
    width: 100%;
    height: auto;
}
.image-placeholder {
    width: 100%;
    height: 180px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--border);
    border-radius: var(--radius);
}
.image-placeholder span {
    font-size: 0.78rem;
    color: var(--text-muted);
}
.summary-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0.8rem 0 0.25rem;
}
.summary-table {
    border-collapse: collapse;
    font-size: 0.86rem;
    width: 100%;
}
.summary-table th, .summary-table td {
    padding: 0.2rem 0.6rem 0.2rem 0;
    text-align: left;
    border: none;
}
.summary-table th {
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}
.summary-table td {
    font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
    font-size: 0.84rem;
}
.summary-table td a { color: var(--accent); text-decoration: none; }
.summary-table td a:hover { text-decoration: underline; }

/* Tag badges */
.tag-row {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.7rem;
    flex-wrap: wrap;
}
.tag {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    color: var(--text);
    background: var(--bg);
}

/* Specs card */
.specs-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 1rem 0 0.3rem;
}
.specs-section-title:first-child { margin-top: 0; }
.specs-table {
    border-collapse: collapse;
    font-size: 0.86rem;
}
.specs-table th, .specs-table td {
    padding: 0.25rem 1rem 0.25rem 0;
    text-align: left;
    border: none;
    vertical-align: middle;
}
.specs-table th {
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}
.specs-table td {
    font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
    font-size: 0.84rem;
    white-space: nowrap;
}

/* Channel order color badges */
.ch-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin-right: 2px;
}
.ch-badge-R { background: #d62728; }
.ch-badge-G { background: #2ca02c; }
.ch-badge-B { background: #1f77b4; }

/* Plots grid */
.plots-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.plot-container {
    aspect-ratio: 4 / 3;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

/* ── Footer ── */
footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    background: var(--card-bg);
}
.footer-links {
    display: flex;
    gap: 1.2rem;
}
.footer-links a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.footer-links a:hover {
    text-decoration: underline;
}

/* ── Lightbox ── */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ── Scrollbar ── */
#sidebar::-webkit-scrollbar,
#detail-panel::-webkit-scrollbar {
    width: 6px;
}
#sidebar::-webkit-scrollbar-thumb,
#detail-panel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
#sidebar::-webkit-scrollbar-thumb:hover,
#detail-panel::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .layout { flex-direction: column; }
    #sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-y: visible;
        max-height: 35vh;
    }
    .nav-group-items li.active::after { display: none; }
    #detail-panel { padding: 1rem; }
    .cards-row { grid-template-columns: 1fr; }
    .plots-row { grid-template-columns: 1fr; }
    footer { flex-direction: column; gap: 0.4rem; text-align: center; }
}
@media (max-width: 600px) {
    .summary-content { flex-direction: column; }
    .summary-image { width: 100%; }
    .plots-row { grid-template-columns: 1fr; }
}
