/* =========================================================
   LearnerBox Dataset Viewer
   Clean, compact SPSS/Jamovi-style stylesheet
   ========================================================= */

/* ---------- Viewer shell ---------- */
.lb-dataset-viewer {
    --lb-accent: #2563eb;
    --lb-accent-soft: #eff6ff;
    --lb-border: #dbe3ee;
    --lb-text: #172033;
    --lb-muted: #667085;
    margin: 1rem 0;
    overflow: hidden;
    color: var(--lb-text);
    background: #fff;
    border: 1px solid var(--lb-border);
    border-radius: 14px;
    box-shadow: 0 5px 18px rgba(15, 23, 42, 0.045);
}

/* ---------- Heading and metadata ---------- */
.lb-dv-heading {
    display: flex;
    justify-content: space-between;
    gap: 0.85rem;
    padding: 0.9rem 1rem 0.65rem;
}
.lb-dv-heading h2 {
    margin: 0.08rem 0 0.25rem;
    font-size: clamp(1.25rem, 2.2vw, 1.75rem);
    line-height: 1.15;
}
.lb-dv-heading p {
    max-width: 760px;
    margin: 0;
    color: var(--lb-muted);
    font-size: 0.9rem;
    line-height: 1.45;
}
.lb-dv-kicker {
    margin-bottom: 0.15rem !important;
    color: var(--lb-accent) !important;
    font-size: 0.7rem !important;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.lb-dv-meta {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.35rem;
}
.lb-dv-meta span,
.lb-dv-meta a {
    padding: 0.32rem 0.58rem;
    color: var(--lb-text);
    font-size: 0.76rem;
    text-decoration: none;
    white-space: nowrap;
    border: 1px solid var(--lb-border);
    border-radius: 999px;
}
.lb-dv-meta a {
    color: #fff;
    background: var(--lb-accent);
    border-color: var(--lb-accent);
}

/* ---------- Tabs ---------- */
.lb-dv-tabs {
    display: flex;
    gap: 0.15rem;
    padding: 0 1rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--lb-border);
}
.lb-dv-tabs button {
    padding: 0.62rem 0.68rem;
    color: var(--lb-muted);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
}
.lb-dv-tabs button.is-active {
    color: var(--lb-accent);
    border-bottom-color: var(--lb-accent);
}

/* ---------- Panels, toolbars, and form controls ---------- */
.lb-dv-panel { padding: 0.6rem 0.75rem 0.75rem; }
.lb-dv-panel[hidden] { display: none !important; }
.lb-dv-toolbar,
.lb-dv-chart-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 0.65rem;
    margin-bottom: 0.7rem;
}
.lb-dv-toolbar { justify-content: space-between; }
.lb-dv-chart-controls { justify-content: flex-start; }
.lb-dv-toolbar label,
.lb-dv-chart-controls label {
    display: grid;
    gap: 0.22rem;
    font-size: 0.78rem;
    font-weight: 700;
}
.lb-dv-toolbar input,
.lb-dv-chart-controls select {
    min-width: 170px;
    padding: 0.5rem 0.62rem;
    color: var(--lb-text);
    font-size: 0.88rem;
    background: #fff;
    border: 1px solid var(--lb-border);
    border-radius: 9px;
}
.lb-dv-chart-controls label[hidden] { display: none !important; }
.lb-dv-row-status,
.lb-dv-page-status,
.lb-dv-dictionary-status {
    color: var(--lb-muted);
    font-size: 0.82rem;
}
.lb-dv-note {
    margin-top: 0;
    color: var(--lb-muted);
}

/* ---------- Tables: compact SPSS/Jamovi style ---------- */
.lb-dv-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--lb-border);
    border-radius: 9px;
}
.lb-dv-table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.lb-dv-table th,
.lb-dv-table td {
    height: 24px;
    padding: 3px 6px;
    line-height: 1.15;
    vertical-align: middle;
    border-bottom: 1px solid var(--lb-border);
}
.lb-dv-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 4px 6px;
    color: var(--lb-text);
    font-size: 13px;
    font-weight: 700;
    text-align: left;
    white-space: nowrap;
    background: #eef2f6;
}
.lb-dv-table tbody tr:nth-child(even) { background: #f8fafc; }
.lb-dv-table tbody tr:hover { background: #eaf2ff; }
.lb-dv-table code { font-size: 0.86em; }
.lb-dv-compact { min-width: 0; }

/* Raw dataset table */
.lb-dv-data-table {
    width: max-content;
    min-width: max-content;
    font-size: 0.76rem;
    line-height: 1.15;
}
.lb-dv-data-table th,
.lb-dv-data-table td {
    padding: 3px 6px;
    white-space: nowrap;
    border-right: 1px solid var(--lb-border);
}
.lb-dv-data-table th:last-child,
.lb-dv-data-table td:last-child { border-right: 0; }
.lb-dv-data-table th {
    font-size: 0.74rem;
    background: #eef2f6;
}

/* ---------- Pagination ---------- */
.lb-dv-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.45rem;
}
.lb-dv-pagination button {
    padding: 0.4rem 0.68rem;
    cursor: pointer;
    background: #fff;
    border: 1px solid var(--lb-border);
    border-radius: 9px;
}
.lb-dv-pagination button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

/* ---------- Category cards ---------- */
.lb-dv-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.45rem;
}
.lb-dv-category-card {
    padding: 0.45rem;
    overflow: hidden;
    border: 1px solid var(--lb-border);
    border-radius: 9px;
}
.lb-dv-category-card h3 {
    margin: 0 0 0.3rem;
    font-size: 0.88rem;
    line-height: 1.15;
}
.lb-dv-category-card .lb-dv-table-wrap { border: 0; }
.lb-dv-category-card table {
    overflow: hidden;
    border: 1px solid var(--lb-border);
    border-radius: 8px;
}

/* ---------- Charts ---------- */
.lb-dv-chart-card {
    padding: 0.65rem;
    background: #fff;
    border: 1px solid var(--lb-border);
    border-radius: 10px;
}
.lb-dv-chart {
    display: block;
    width: 100%;
    height: auto;
    max-height: 440px;
}
.lb-dv-chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.3rem 0.75rem;
    margin: 0.45rem 0 0.05rem;
}
.lb-dv-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--lb-muted);
    font-size: 0.78rem;
}
.lb-dv-legend-item i {
    display: inline-block;
    flex: 0 0 11px;
    width: 11px;
    height: 11px;
    border-radius: 3px;
}
.lb-dv-chart-caption {
    margin: 0.4rem 0 0;
    color: var(--lb-muted);
    font-size: 0.82rem;
    text-align: center;
}

/* ---------- Errors ---------- */
.lb-dv-error {
    padding: 1rem;
    color: #8a1c1c;
    background: #fff1f1;
    border: 1px solid #f0b4b4;
    border-radius: 10px;
}

/* ---------- Searchable data dictionary ---------- */
.lb-dv-dictionary-toolbar {
    justify-content: space-between;
    gap: 0.45rem;
    margin-bottom: 0.45rem;
}
.lb-dv-dictionary-toolbar input { min-width: 260px; }
.lb-dv-dictionary-status { align-self: center; }
.lb-dv-dictionary-table code { white-space: nowrap; }
.lb-dv-dictionary-row { cursor: pointer; }
.lb-dv-dictionary-row td:first-child code {
    color: var(--lb-accent);
    font-weight: 700;
}
.lb-dv-dictionary-row:hover { background: var(--lb-accent-soft) !important; }
.lb-dv-dictionary-row:focus {
    outline: 2px solid var(--lb-accent);
    outline-offset: -2px;
    background: var(--lb-accent-soft);
}

/* ---------- Variable detail drawer ---------- */
.lb-dv-dictionary-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(15, 23, 42, 0.35);
}
.lb-dv-variable-drawer {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 9999;
    width: min(420px, 92vw);
    height: 100vh;
    overflow-y: auto;
    background: #fff;
    box-shadow: -18px 0 45px rgba(15, 23, 42, 0.18);
}
.lb-dv-variable-drawer[hidden],
.lb-dv-dictionary-backdrop[hidden] { display: none !important; }
.lb-dv-variable-drawer-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    background: #fff;
    border-bottom: 1px solid var(--lb-border);
}
.lb-dv-variable-kicker {
    margin: 0 0 0.15rem;
    color: var(--lb-accent);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.lb-dv-variable-title {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 1.35rem;
}
.lb-dv-variable-close {
    width: 34px;
    height: 34px;
    color: var(--lb-text);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    background: #fff;
    border: 1px solid var(--lb-border);
    border-radius: 50%;
}
.lb-dv-variable-close:hover { background: var(--lb-accent-soft); }
.lb-dv-variable-drawer-body { padding: 1rem 1.1rem 1.5rem; }
.lb-dv-variable-meta-list {
    display: grid;
    gap: 0.8rem;
    margin: 0;
}
.lb-dv-variable-meta-list div {
    padding: 0.7rem;
    background: #fbfdff;
    border: 1px solid var(--lb-border);
    border-radius: 9px;
}
.lb-dv-variable-meta-list dt {
    color: var(--lb-muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.lb-dv-variable-meta-list dd {
    margin: 0.22rem 0 0;
    line-height: 1.45;
}
.lb-dv-variable-section { margin-top: 1rem; }
.lb-dv-variable-section h4 {
    margin: 0 0 0.45rem;
    font-size: 0.95rem;
}
.lb-dv-variable-uses {
    margin: 0.25rem 0 0;
    padding-left: 1.15rem;
}
.lb-dv-variable-uses li { margin: 0.22rem 0; }
.lb-dv-variable-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}
.lb-dv-variable-stats div {
    padding: 0.6rem;
    background: #f8fafc;
    border: 1px solid var(--lb-border);
    border-radius: 8px;
}
.lb-dv-variable-stats span {
    display: block;
    color: var(--lb-muted);
    font-size: 0.72rem;
}
.lb-dv-variable-stats strong {
    display: block;
    margin-top: 0.12rem;
    overflow-wrap: anywhere;
    font-size: 0.9rem;
}
body.lb-dv-drawer-open { overflow: hidden; }

/* ---------- Responsive adjustments ---------- */
@media (max-width: 700px) {
    .lb-dv-heading {
        display: block;
        padding: 0.75rem 0.8rem 0.55rem;
    }
    .lb-dv-meta { margin-top: 0.6rem; }
    .lb-dv-tabs { padding: 0 0.7rem; }
    .lb-dv-panel { padding: 0.7rem; }
    .lb-dv-toolbar { align-items: stretch; }
    .lb-dv-toolbar label,
    .lb-dv-toolbar input,
    .lb-dv-chart-controls label,
    .lb-dv-chart-controls select {
        width: 100%;
        min-width: 0;
    }
    .lb-dv-table { min-width: 900px; }
    .lb-dv-table th,
    .lb-dv-table td {
        height: 22px;
        padding: 2px 5px;
        font-size: 12px;
    }
    .lb-dv-data-table {
        width: max-content;
        min-width: max-content;
        font-size: 0.72rem;
    }
    .lb-dv-category-card .lb-dv-table { min-width: 0; }
    .lb-dv-chart-card { padding: 0.45rem; }
    .lb-dv-dictionary-toolbar input {
        width: 100%;
        min-width: 0;
    }
    .lb-dv-dictionary-status { align-self: flex-start; }
}

@media (max-width: 520px) {
    .lb-dv-variable-drawer { width: 100vw; }
    .lb-dv-variable-stats { grid-template-columns: 1fr 1fr; }
}
