/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
a { color: inherit; text-decoration: none; }

html { scrollbar-width: thin; scrollbar-color: #bbb transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #bbb; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #888; }

:root {
    --bg: #ffffff;
    --bg-subtle: #f7f7f7;
    --surface: #ffffff;
    --border: #e5e5e5;
    --border-light: #f0f0f0;
    --text: #0d0d0d;
    --text-secondary: #737373;
    --text-tertiary: #a3a3a3;
    --primary: #171717;
    --primary-hover: #404040;
    --accent: #171717;
    --accent-light: #f5f5f5;
    --accent-border: #e5e5e5;
    --highlight: #f5f5f5;
    --highlight-border: #d4d4d4;
    --focus-ring: #7c3aed;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
    --transition: 150ms ease;
}

.staging-badge {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    background: #dc2626;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 6px 24px;
    border-radius: 0 0 6px 6px;
    pointer-events: none;
}

html { font-size: 16px; }

body {
    font-family: 'Geist Sans', -apple-system, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    font-family: inherit;
}

.btn-primary { background: var(--primary); color: white; border-radius: 6px; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 32px; }

.visibility-toggle { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); cursor: pointer; }
.visibility-toggle .vis-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.visibility-toggle.is-public { background: transparent; color: var(--text); }
.visibility-toggle.is-public .vis-dot { background: #34d399; }
.visibility-toggle.is-public:hover { background: var(--bg-subtle); }
.visibility-toggle.is-private { background: transparent; color: var(--text); border-color: var(--border); }
.visibility-toggle.is-private .vis-dot { background: #ef4444; }
.visibility-toggle.is-private:hover { background: var(--bg-subtle); }

/* Nav hamburger menu */
/* Hidden by default; shown at the marketing-spec mobile breakpoint (768px). */
.nav-hamburger { display: none; }
.nav-menu { display: none; }

@media (max-width: 767px) {
    .nav-hamburger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 0;
        background: transparent;
        color: var(--text);
        border: none;
        border-radius: 9999px;
        cursor: pointer;
        transition: background 150ms ease-out;
    }
    .nav-hamburger:hover { background: var(--accent-light); }
    .nav-hamburger svg { width: 16px; height: 16px; }
    .nav-action-item { display: none !important; }
    .visibility-toggle .vis-label { display: none; }
    .nav-menu {
        display: none;
        position: absolute;
        top: 100%;
        right: 16px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        box-shadow: 0 4px 16px rgba(0,0,0,0.12);
        z-index: 100;
        min-width: 160px;
        padding: 4px 0;
    }
    .nav-menu.open { display: block; }
    .nav-menu-item {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        padding: 10px 16px;
        font-size: 0.85rem;
        color: var(--text);
        background: none;
        border: none;
        cursor: pointer;
        text-decoration: none;
        font-family: inherit;
    }
    .nav-menu-item:hover { background: var(--bg-subtle); }
    .top-nav-inner { position: relative; }
}

/* === Index Page === */
.index-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px 80px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 32px;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

/* === Global Drag-and-Drop Upload Overlay === */
.drop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.55);
    align-items: center;
    justify-content: center;
}
.drop-overlay.visible {
    display: flex;
}
.drop-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #fff;
    pointer-events: none;
}
.drop-overlay-content svg {
    opacity: 0.9;
}
.drop-overlay-title {
    font-size: 1.25rem;
    font-weight: 600;
}
.drop-overlay-sub {
    font-size: 0.88rem;
    opacity: 0.7;
}

/* === Upload Progress Toast === */
.drop-progress {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    width: 300px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}
.drop-progress.active {
    display: block;
}
.drop-progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.drop-progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 2px;
}
.drop-progress-status {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 8px;
    overflow-wrap: anywhere;
}

@media (max-width: 900px) {
    .drop-progress {
        bottom: 16px;
        right: 16px;
        left: 16px;
        width: auto;
    }
}

.datasets-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.dataset-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    text-decoration: none;
    color: var(--text);
    transition: background var(--transition);
}

.dataset-row:hover { background: var(--bg-subtle); }

.dataset-name { font-weight: 500; font-size: 0.9rem; }

.dataset-meta { font-size: 0.78rem; color: var(--text-tertiary); }

/* === Top Nav === */
/* Spec parity with tablepage.ai marketing nav. See DESIGN.md → Top Navigation. */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    /* Spec: hsl(0 0% 92%) — slightly lighter than --border (90%). Inlined to match marketing exactly. */
    border-bottom: 1px solid hsl(0 0% 92%);
    transition: transform 0.3s ease;
}
.top-nav.nav-hidden {
    transform: translateY(-100%);
}
body:not(.nav-ready) .top-nav {
    transform: translateY(-100%);
}

.top-nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
    padding: 0 32px 0 var(--content-left-pad, 32px);
    transition: padding-left 180ms ease;
}

@media (min-width: 1024px) {
    .top-nav-inner {
        padding: 0 48px 0 var(--content-left-pad, 48px);
    }
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.75rem;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-signin {
    display: inline-flex;
    align-items: center;
    padding: 0 20px;
    height: 36px;
    background: var(--primary);
    color: white;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 150ms ease-out;
}

.nav-signin:hover { background: rgba(23, 23, 23, 0.9); }

.nav-signout {
    display: inline-flex;
    align-items: center;
    padding: 0 16px;
    height: 36px;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 150ms ease-out, color 150ms ease-out;
}

.nav-signout:hover {
    background: var(--accent-light);
    color: var(--text);
}

/* === Directory Page === */
.directory-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px 80px;
}

.directory-header {
    margin-bottom: 24px;
}

.directory-header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 4px;
}

.directory-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.directory-layout {
    display: flex;
    gap: 32px;
}

.directory-sidebar {
    flex-shrink: 0;
    width: 180px;
    position: sticky;
    top: 24px;
    align-self: flex-start;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

.sidebar-heading {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.tag-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.tag-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: color var(--transition), background var(--transition);
}

.tag-link:hover {
    color: var(--text);
    background: var(--surface);
}

.tag-link-active {
    color: var(--text);
    font-weight: 600;
    background: var(--surface);
}

.tag-count {
    font-size: 0.7rem;
    opacity: 0.5;
}

/* Search */
.directory-search {
    margin-bottom: 20px;
}

.gallery-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    max-width: 480px;
    margin: 0 auto 28px;
    padding: 14px 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9999px;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.gallery-cta:hover { border-color: var(--text); box-shadow: var(--shadow); transform: translateY(-1px); }
.gallery-cta svg { width: 18px; height: 18px; color: var(--text-secondary); flex-shrink: 0; }
.gallery-cta:hover svg { color: var(--text); }

@media (max-width: 600px) {
    .gallery-cta {
        gap: 8px;
        padding: 10px 16px;
        margin-bottom: 16px;
        font-size: 0.85rem;
    }
    .gallery-cta svg { width: 14px; height: 14px; }
    .gallery-cta .gallery-cta-icon { display: none; }
}

.search-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}

.search-input:focus {
    border-color: var(--text-secondary);
}

/* Tag overflow */
.tag-overflow { display: none; }
.tag-list-expanded .tag-overflow { display: flex; }

.tag-show-more {
    display: block;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 6px 10px;
    margin-top: 4px;
}

.tag-show-more:hover { color: var(--text-secondary); }

.directory-main {
    flex: 1;
    min-width: 0;
}

.directory-grid {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.directory-card {
    display: block;
    padding: 16px 20px;
    background: var(--surface);
    text-decoration: none;
    color: var(--text);
    transition: background var(--transition);
}

.directory-card:hover { background: var(--accent-light); }

.directory-card-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.badge-private {
    display: inline-flex;
    align-items: center;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #7c3aed;
    background: #f3f0ff;
    border: 1px solid #e0d4fc;
    border-radius: 100px;
    padding: 1px 8px;
    vertical-align: middle;
    margin-left: 6px;
    position: relative;
    top: -1px;
}

.dataset-card-story {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-left: 8px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}
.dataset-card-story svg { width: 12px; height: 12px; }

.directory-card-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 6px;
}

.directory-card-meta {
    display: flex;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.directory-empty {
    color: var(--text-tertiary);
    font-size: 0.9rem;
    text-align: center;
    padding: 40px 0;
}

/* Mobile: sidebar collapses to horizontal scroll */
@media (max-width: 640px) {
    .directory-layout { flex-direction: column; gap: 16px; }
    .directory-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        overflow-x: auto;
    }
    .tag-list { flex-direction: row; flex-wrap: nowrap; gap: 4px; }
    .tag-link {
        white-space: nowrap;
        padding: 4px 10px;
        border: 1px solid var(--border);
        border-radius: 100px;
        font-size: 0.78rem;
    }
    .tag-link-active { border-color: var(--text); }
    .tag-count { display: none; }
}

/* Dataset tags on detail page */
.dataset-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    text-decoration: none;
    transition: color var(--transition), border-color var(--transition);
}

.tag-pill:hover {
    color: var(--text);
    border-color: var(--text-tertiary);
}

/* Related datasets */
.related-datasets {
    padding: 24px 20px;
    margin-top: 24px;
    text-align: center;
}

.related-heading {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.related-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    max-width: 960px;
    margin: 0 auto;
    text-align: left;
}

.related-card {
    display: block;
    flex: 0 1 calc((960px - 24px) / 3);
    min-width: 200px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: border-color var(--transition);
}

.related-card:hover {
    border-color: var(--text-tertiary);
}

.related-card-title {
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.related-card-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 6px;
}

.related-card-meta {
    font-size: 0.72rem;
    color: var(--text-tertiary);
}

.related-see-all {
    display: block;
    text-align: center;
    margin-top: 12px;
    font-size: 0.84rem;
    color: var(--text-secondary);
    text-decoration: none;
}

.related-see-all:hover {
    color: var(--text);
}

.related-stories {
    padding: 24px 20px 8px;
    margin-top: 24px;
    text-align: center;
}

.related-stories-list {
    list-style: none;
    margin: 0 auto;
    padding: 0;
    max-width: 720px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
}

.related-story-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition);
}

.related-story-item:hover {
    border-color: var(--text-tertiary);
}

.related-story-link {
    display: block;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text);
}

.related-story-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 4px;
    line-height: 1.35;
}

.related-story-dek {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin: 0 0 6px;
}

.related-story-meta {
    font-size: 0.72rem;
    color: var(--text-tertiary);
}

.viz-story-link {
    color: #b45309;
}

.viz-story-link:hover {
    color: #92400e;
    background: #fef3c7;
}

/* Signup CTA for analysis rate limit */
.ask-signup-cta {
    text-align: center;
    padding: 20px 16px;
}

.ask-signup-cta p {
    margin: 0 0 10px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

/* Rate limit modal (shown inside ask modal) */
.ask-modal:has(.ask-rate-limit-modal) {
    max-width: 360px;
    padding: 0;
}

.ask-modal:has(.ask-rate-limit-modal) > .ask-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1;
}

.ask-rate-limit-modal {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 32px 32px;
    text-align: center;
}

.ask-rate-limit-icon {
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.ask-rate-limit-msg {
    font-size: 0.92rem;
    color: var(--text-secondary);
    margin: 0 0 16px;
    line-height: 1.5;
}

.ask-rate-limit-modal .btn {
    margin-top: 0;
}

/* Breadcrumb */
.dataset-breadcrumb {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 20px;
    font-size: 0.78rem;
    color: var(--text-tertiary);
    border-top: 1px solid var(--border);
}

.dataset-breadcrumb a {
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
}

.dataset-breadcrumb a:hover {
    color: var(--text);
}

.breadcrumb-sep {
    color: var(--text-tertiary);
    opacity: 0.5;
}

/* === Dataset Page === */
.dataset-page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 24px;
    overflow-x: hidden;
    position: relative;
}

.dataset-title-section {
    margin-bottom: 16px;
    text-align: center;
}

.dataset-name {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.3;
    margin-bottom: 4px;
}

.dataset-subtitle {
    font-size: 0.82rem;
    color: var(--text-tertiary);
}

.badge {
    padding: 2px 10px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* === Toolbar === */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.ask-toolbar-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 10px;
    flex: 1;
    min-width: 180px;
    transition: border-color var(--transition);
}

.search-box:focus-within { border-color: var(--accent); }
.search-box svg { color: var(--text-tertiary); flex-shrink: 0; }

.search-box input {
    border: none;
    background: none;
    padding: 8px 0;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    width: 100%;
    outline: none;
}


/* === Layout === */
.dataset-layout {
    display: block;
    height: auto;
}

/* === Table === */
.table-wrapper {
    min-width: 0;
    height: 70vh;
    min-height: 70vh;
    display: flex;
    flex-direction: column;
}

.table-container {
    order: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table-scroll {
    overflow-x: auto;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    overscroll-behavior-x: none;
    scrollbar-width: thin;
    scrollbar-color: #c1c5cd transparent;
}
.table-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb { background: #c1c5cd; border-radius: 4px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: #a0a4ac; }
.table-scroll::-webkit-scrollbar-corner { background: transparent; }

.data-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.84rem;
}

.data-table thead { position: sticky; top: 0; z-index: 10; background: var(--accent-light); }

.data-table th {
    background: var(--accent-light);
    padding: 10px 12px;
    text-align: left;
    font-weight: 500;
    font-size: 0.82rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid #d5d8e0;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-table th:last-child {
    border-right: none;
}

.data-table th.sortable {
    cursor: default;
    user-select: none;
    transition: color var(--transition);
}

.data-table th.sortable:hover {
    color: var(--text);
}

.sort-icon {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
}

.sort-icon:hover {
    background: rgba(0,0,0,0.06);
}

.sort-icon::after {
    content: '⇅';
    margin-left: 4px;
    opacity: 0.3;
    font-size: 0.7rem;
}

.data-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: cell;
    position: relative;
}

.data-table td.cell-selected {
    outline: 1px solid #9ca3af;
    outline-offset: -1px;
    z-index: 2;
}

.data-table td.cell-anchor {
    outline: 2px solid #6b7280;
    outline-offset: -2px;
    z-index: 3;
}

.data-table td.cell-selected.cell-copied,
.data-table td.cell-anchor.cell-copied {
    outline-color: #22c55e;
    background: #dcfce7;
}

/* Color groups for repeating pattern chunks */
.data-table td.cell-group-0 { outline-color: #6366f1; background: rgba(99,102,241,0.10); }
.data-table td.cell-group-1 { outline-color: #f59e0b; background: rgba(245,158,11,0.10); }
.data-table td.cell-group-2 { outline-color: #10b981; background: rgba(16,185,129,0.10); }
.data-table td.cell-group-3 { outline-color: #ef4444; background: rgba(239,68,68,0.10); }
.data-table td.cell-group-4 { outline-color: #8b5cf6; background: rgba(139,92,246,0.10); }
.data-table td.cell-group-5 { outline-color: #ec4899; background: rgba(236,72,153,0.10); }

.reset-table-fab {
    position: fixed;
    top: 48px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 28px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary, #1f2937);
    background: #fff;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.14);
    z-index: 1000;
    transition: background 0.15s, box-shadow 0.15s;
    animation: fab-slide-down 0.2s ease-out;
}
.reset-table-fab:hover {
    background: var(--bg-secondary, #f9fafb);
    box-shadow: 0 4px 16px rgba(0,0,0,0.14);
}
.reset-table-fab:active {
    transform: translateX(-50%) scale(0.97);
}
@keyframes fab-slide-down {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.reset-table-fab .reset-key-hint {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--bg-tertiary, #e5e7eb);
    color: var(--text-tertiary, #9ca3af);
    font-family: monospace;
    font-weight: 500;
}

.cell-copy-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}
.cell-copy-toast.show { opacity: 1; }

.data-table tbody {
    content-visibility: auto;
    contain-intrinsic-size: auto 2000px;
}
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:nth-child(even) { background: var(--bg); }
.data-table tbody tr:hover { background: var(--bg-subtle); }


.data-table th.row-num,
.data-table td.row-num {
    position: sticky;
    left: 0;
    z-index: 5;
    background: inherit;
    color: var(--text-tertiary);
    font-size: 0.74rem;
    width: 40px;
    min-width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}

.data-table th.row-num {
    z-index: 20;
    background: #f5f5f5;
}

.data-table td.row-num {
    background: var(--surface);
    cursor: grab;
}

.table-footer {
    padding: 8px 12px;
    font-size: 0.78rem;
    color: var(--text-tertiary);
    border-top: 1px solid var(--border);
}

/* === Insights Sidebar === */
/* Insights hint in toolbar */
.insights-hint {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}
.insights-hint-ready {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}
.insights-hint-ready:hover { text-decoration: underline; }
.pulse-dot-sm {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse-dot 1.5s ease-in-out infinite;
}

.insights-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    display: flex;
    flex-direction: column;
    position: static;
    max-height: none;
    height: auto;
    margin-top: 20px;
}

/* Sidebar tabs */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-tab {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color var(--transition), border-color var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.sidebar-tab:hover {
    color: var(--text-secondary);
    background: var(--bg);
}

.sidebar-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.sidebar-tab .tab-badge {
    background: #ef4444;
    color: white;
    border-radius: 10px;
    padding: 0 6px;
    font-size: 0.65rem;
    font-weight: 600;
    min-width: 16px;
    text-align: center;
    line-height: 16px;
}

.sidebar-tab-panel {
    display: none;
    padding: 14px;
    flex: 1;
}

.sidebar-tab-panel.active {
    display: block;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 12px;
}

.sidebar-header svg { color: var(--accent); }
.sidebar-header h3 { font-size: 0.85rem; font-weight: 600; }

.insights-count {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--accent);
    background: var(--accent-light);
    padding: 2px 8px;
    border-radius: 100px;
}

.insights-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.insight-card {
    position: relative;
    display: block;
    width: 100%;
    padding: 5px 8px;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    text-align: left;
    font-family: inherit;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.insight-dismiss-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}

.insight-card:hover .insight-dismiss-btn {
    opacity: 1;
}

.insight-dismiss-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

.insight-card:hover { background: var(--bg-subtle); color: var(--text); }
.insight-card.active { background: var(--accent-light); color: var(--text); }

.insight-type-badge {
    display: inline-flex;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    width: fit-content;
}

.insight-type-badge.info { background: #f0f0f0; color: #525252; }
.insight-type-badge.stat { background: #f0f0f0; color: #525252; }
.insight-type-badge.anomaly { background: #171717; color: #ffffff; }
.insight-type-badge.correlation { background: #f0f0f0; color: #525252; }
.insight-type-badge.distribution { background: #f0f0f0; color: #525252; }
.insight-type-badge.quality { background: #171717; color: #ffffff; }

.insight-text { line-height: 1.4; }
.insight-row-count { font-size: 0.72rem; color: var(--text-tertiary); }

/* === Data Quality primary section === */
.insight-section-primary {
    margin-bottom: 12px;
    padding-bottom: 12px;
}
.insight-section-primary .sidebar-header {
    margin-bottom: 8px;
}
details.insight-section-primary > summary.sidebar-header {
    margin-bottom: 0;
}
details.insight-section-primary[open] > summary.sidebar-header {
    margin-bottom: 8px;
}

/* === Collapsible sections (Patterns + Data Quality) === */
details.insight-section-primary > summary {
    cursor: pointer;
    list-style: none;
    padding: 5px 6px;
    margin: 0 -6px;
    border-radius: 4px;
    transition: background 0.12s ease;
}
details.insight-section-primary > summary:hover {
    background: var(--bg-subtle);
}
details.insight-section-primary > summary::-webkit-details-marker { display: none; }
details.insight-section-primary > summary::marker { display: none; content: ""; }
details.insight-section-primary > summary.sidebar-header::after {
    content: "";
    margin-left: 8px;
    width: 16px;
    height: 16px;
    background: var(--text-tertiary);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") center / contain no-repeat;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    transform: rotate(-90deg);
}
details.insight-section-primary[open] > summary.sidebar-header::after {
    transform: rotate(0deg);
}
.quality-count {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--bg-subtle);
    color: var(--text-secondary);
}
.quality-section[open] .quality-count {
    background: var(--accent-light);
    color: var(--accent);
}

/* === Data Quality overflow (show first 10, toggle the rest) === */
.quality-overflow { display: none; }
.quality-expanded .quality-overflow { display: flex; }
.quality-show-more {
    display: flex;
    width: 100%;
    padding: 6px 10px;
    background: none;
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    justify-content: center;
    margin-top: 2px;
}
.quality-show-more:hover { background: var(--bg-subtle); color: var(--text); }

/* === Insight Groups (collapsible) === */
.insight-group {
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 6px;
}

.insight-group:last-child { border-bottom: none; }

.insight-group-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 0;
    list-style: none;
}

.insight-group-header::-webkit-details-marker { display: none; }

.insight-group-header::before {
    content: '▸';
    font-size: 0.7rem;
    color: var(--text-tertiary);
    transition: transform var(--transition);
}

details.insight-group[open] > .insight-group-header::before {
    transform: rotate(90deg);
}

.insight-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.insight-group-count {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    background: var(--bg-subtle);
    padding: 1px 6px;
    border-radius: 100px;
}

.insight-group-def {
    width: 100%;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    font-style: italic;
    padding-left: 14px;
}

/* === Pattern Gallery === */
.pattern-gallery-wrap {
    position: relative;
}

.pattern-gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card-bg, var(--bg));
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 0;
    transition: color var(--transition), background var(--transition), box-shadow var(--transition);
}
.pattern-gallery-arrow:hover {
    color: var(--text);
    background: var(--bg-subtle);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}
.pattern-gallery-arrow[hidden] { display: none; }
.pattern-gallery-arrow-left { left: -6px; }
.pattern-gallery-arrow-right { right: -6px; }

.pattern-gallery {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 4px 0 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    /* Fade-out scroll hint on right edge */
    mask-image: linear-gradient(to right, black calc(100% - 40px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 40px), transparent 100%);
}

.pattern-gallery::-webkit-scrollbar { height: 4px; }
.pattern-gallery::-webkit-scrollbar-track { background: transparent; }
.pattern-gallery::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.pattern-gallery-card {
    flex: 0 0 400px;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    padding: 0;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.pattern-gallery-card:hover {
    border-color: var(--text-tertiary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    background: none;
}

.pattern-gallery-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
    background: none;
}

.pattern-gallery-thumb {
    width: 100%;
    height: 220px;
    overflow: hidden;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.pattern-gallery-thumb svg {
    width: 100%;
    height: 100%;
    display: block;
}

.pattern-gallery-thumb .plotly-chart,
.pattern-gallery-thumb .js-plotly-plot,
.pattern-gallery-thumb .plot-container {
    width: 100% !important;
    height: 100% !important;
    overflow: hidden;
}

.pattern-gallery-label {
    padding: 8px 10px;
    font-size: 0.72rem;
    line-height: 1.4;
    height: calc(2 * 1.4em + 16px); /* 2 lines + padding */
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pattern-text-list {
    margin-top: 4px;
}

.insight-row-count {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    margin-left: 4px;
}

/* === Pagination === */
.pagination {
    order: 2;
    border: 1px solid var(--border);
    border-top: none;
    background: var(--surface);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.pagination-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    gap: 12px;
    flex-wrap: wrap;
}

.pagination-left {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.78rem;
    color: var(--text-tertiary);
}

.pagination-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pagination-rpp { display: flex; align-items: center; gap: 4px; }

.rpp-btn {
    background: none;
    border: none;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.78rem;
    font-family: inherit;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    min-height: 28px;
}

.rpp-btn:hover { background: var(--bg-subtle); color: var(--text); }
.rpp-btn.active { background: var(--accent); color: white; }

.page-indicator {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    min-width: 50px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

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


/* === Categorical Chips === */
.cat-chip {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.5;
}
.cat-chip-0 { background: #1a1a1a; color: #ffffff; }
.cat-chip-1 { background: #c4d4c8; color: #1e3322; }
.cat-chip-2 { background: #4a4a4a; color: #ffffff; }
.cat-chip-3 { background: #f0ddd0; color: #5c3318; }
.cat-chip-4 { background: #8b8b8b; color: #ffffff; }
.cat-chip-5 { background: #c8d5e6; color: #1a2e4a; }
.cat-chip-6 { background: #d4c4b0; color: #3a2a18; }
.cat-chip-7 { background: #e8d0d8; color: #4a1a2e; }

/* === Column Type Badges === */
.col-type-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 500;
    padding: 0 4px;
    border-radius: 3px;
    margin-left: 4px;
    vertical-align: middle;
    line-height: 16px;
    letter-spacing: 0.01em;
    text-transform: lowercase;
    opacity: 0.7;
}
.col-type-geographic { background: #dbeafe; color: #1e40af; }
.col-type-temporal { background: #ede9fe; color: #5b21b6; }
.col-type-numeric { background: #d1fae5; color: #065f46; }
.col-type-categorical { background: #fef3c7; color: #92400e; }
.col-type-structural { background: #f3f4f6; color: #6b7280; }

/* === Index Column === */
th.col-index {
    background: #e2e5ee !important;
}
.cell-index {
    font-weight: 600;
    color: #1f2937;
}

/* === Column Type Cell Formatting === */
.cell-numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.cell-structural a {
    color: #6366f1;
    text-decoration: none;
}
.cell-structural a:hover { text-decoration: underline; }
.bool-chip {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}
.bool-true { background: #d1fae5; color: #065f46; }
.bool-false { background: #f3f4f6; color: #6b7280; }

/* === HTMX Loading States === */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: block; }
.htmx-request.htmx-indicator { display: block; }

.table-scroll { position: relative; }

.table-loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--surface);
    opacity: 0.5;
    z-index: 5;
}

/* No layout shift during HTMX requests */

/* === First Visit Banner === */
.first-visit-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.84rem;
    color: var(--text);
}

.first-visit-banner code {
    background: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
}

.banner-dismiss {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

/* === Claim Banner === */
.claim-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 32px;
    margin-bottom: 16px;
    font-size: 0.84rem;
    color: var(--text);
}

.claim-banner .btn {
    margin-left: auto;
    white-space: nowrap;
}

/* === Info Banner (skipped rows, notices) === */
.info-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.84rem;
    color: var(--text);
}

/* === Client-Side Preview === */
.preview-area {
    margin-bottom: 24px;
}

.preview-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.preview-filename {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}

.preview-progress {
    flex: 1;
    height: 3px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
}

.preview-progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0;
}

/* === Insights States === */
.insights-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.insights-empty {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 0;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.insights-footer {
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
    margin-top: 10px;
    font-size: 0.72rem;
    color: var(--text-tertiary);
    font-style: italic;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 40px 20px !important;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* === Dataset Description === */
.dataset-description-editable:hover { color: var(--text); }

.desc-form { margin-bottom: 8px; }

.desc-input {
    width: 100%;
    font-size: 0.86rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    outline: none;
    resize: vertical;
    line-height: 1.5;
}

.desc-input:focus { border-color: var(--primary); }

.desc-actions { display: flex; gap: 6px; margin-top: 6px; }

.dataset-about-prose {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    line-height: 1.5;
    max-width: 720px;
    margin-top: 8px;
    padding-bottom: 40px;
}

/* === Datasets Heading === */
.datasets-heading {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* === Dataset Row Description === */
.dataset-row-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dataset-desc {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* === Title Editing === */
.editable-title {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.editable-title .edit-icon {
    opacity: 0;
    transition: opacity var(--transition);
    color: var(--text-tertiary);
}

.editable-title:hover .edit-icon { opacity: 0.6; }

.title-form { display: flex; }

/* === Description Editing === */
.dataset-description-editable {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
    cursor: pointer;
    margin-top: 4px;
    display: block;
}

.dataset-description-editable .edit-icon {
    opacity: 0;
    transition: opacity var(--transition);
    color: var(--text-tertiary);
    margin-left: 4px;
    vertical-align: middle;
}

.dataset-description-editable:hover .edit-icon { opacity: 0.6; }

.title-input {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: inherit;
    letter-spacing: -0.025em;
    line-height: 1.3;
    color: var(--text);
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--primary);
    outline: none;
    padding: 0;
    margin-bottom: 2px;
    width: 100%;
    max-width: 100%;
}

.sidebar-element {
    padding: 8px 0;
}

.sidebar-element + .sidebar-element {
    border-top: 1px solid var(--border-light);
    padding-top: 12px;
}

.sidebar-element-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
}

.sidebar-element-desc {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    margin-top: 4px;
    line-height: 1.4;
}

/* === Enrichment Banner === */
.enrichment-banner .enrichment-pulse {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* === Chart Modal === */
.chart-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.chart-modal.open {
    display: flex;
}

.chart-modal-close {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 110;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .chart-modal-close {
        display: flex;
    }
}

.chart-modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 1000px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    overscroll-behavior: none;
}

.chart-modal-content .plotly-chart,
.chart-modal-content .js-plotly-plot,
.chart-modal-content .plot-container {
    overflow: hidden !important;
}

.chart-modal-content svg {
    width: 100%;
    height: auto;
}

.chart-modal-content .plotly-chart {
    width: 100%;
    min-height: 50px;
}

.chart-modal-content .js-plotly-plot,
.chart-modal-content .plot-container {
    width: 100% !important;
}

.chart-modal-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.chart-modal-desc {
    font-size: 0.84rem;
    color: var(--text-secondary);
    margin-top: 4px;
    margin-bottom: 16px;
    line-height: 1.5;
    text-align: center;
}

/* Combined chart grid (4-panel column viz) */
.combined-chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.combined-chart-cell {
    min-width: 0;
    cursor: pointer;
    border-radius: 8px;
    padding: 4px;
    transition: background 0.15s;
}

.combined-chart-cell:hover {
    background: var(--surface-hover, #f9fafb);
}

.combined-chart-wide {
    grid-column: 1 / -1;
}

.combined-chart-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}

/* Zoom modal — sits above chart modal */
.chart-zoom-modal {
    z-index: 1100;
}

.zoom-close-pill {
    z-index: 1200;
}

@media (max-width: 600px) {
    .combined-chart-grid { grid-template-columns: 1fr; }
    .combined-chart-wide { grid-column: auto; }
}

/* Plotly "Double-click to zoom back out" notification */
.js-plotly-plot .notifier-note {
    font-family: 'Geist Sans', -apple-system, system-ui, sans-serif !important;
    font-size: 0.78rem !important;
    background: var(--surface) !important;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    padding: 6px 12px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
    opacity: 0.9 !important;
}

/* === Dataset Footer === */
.dataset-footer {
    margin-top: 32px;
    padding: 16px 0;
    border-top: 1px solid var(--border-light);
    font-size: 0.8rem;
    color: var(--text-tertiary);
    line-height: 1.5;
}

.dataset-footer p {
    margin: 0 0 4px 0;
}

.dataset-footer-meta {
    font-size: 0.75rem;
}

/* === Site Footer === */
.site-footer {
    text-align: center;
    padding: 24px 16px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    display: flex;
    justify-content: center;
    gap: 8px;
}

.site-footer a {
    color: var(--text-tertiary);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--text-primary);
}

.dataset-meta-grid {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 8px 20px;
    font-size: 0.82rem;
}

.dataset-meta-grid > div {
    display: flex;
    gap: 8px;
}

.dataset-meta-grid dt {
    color: var(--text-tertiary);
    font-weight: 500;
    white-space: nowrap;
}

.dataset-meta-grid dt::after { content: ':'; }

.dataset-meta-grid dd {
    color: var(--text-secondary);
}

@media (max-width: 600px) {
    .dataset-meta-grid {
        grid-template-columns: 1fr;
    }
}

/* === Text Utilities === */
.text-tertiary { color: var(--text-tertiary); font-size: 0.78rem; }

/* === Focus Styles === */
.btn:focus-visible,
.data-table th.sortable:focus-visible,
.rpp-btn:focus-visible,
.insight-card:focus-visible,
.search-input:focus-visible,
.col-filter-input:focus-visible,
.desc-input:focus-visible,
.ask-question-input:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* Numeric column indicator */
th.numeric-col {
    background: #f0f0f0 !important;
}

/* Column chart buttons — always visible on numeric columns */
.col-chart-btn {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    padding: 2px;
    margin-left: 1px;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: color var(--transition);
    vertical-align: middle;
}

.col-chart-btn:hover { color: var(--accent); }

.col-filter-btn {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    padding: 2px;
    margin-left: 1px;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: color var(--transition);
    vertical-align: middle;
}
.col-filter-btn:hover { color: var(--accent); }
th.col-filtered .col-filter-btn { color: var(--accent); }

.col-rename-input {
    font: inherit;
    color: inherit;
    background: var(--bg, #fff);
    border: 1px solid var(--accent);
    border-radius: 3px;
    padding: 1px 4px;
    width: 10em;
    max-width: 100%;
    box-sizing: border-box;
    outline: none;
}

.story-table-section {
    position: relative;
}

/* Column filter popover */
.col-filter-popover {
    position: absolute;
    z-index: 90;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    width: 260px;
}

.col-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 6px;
}

.col-filter-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}

.col-filter-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 0 2px;
    line-height: 1;
}
.col-filter-close:hover { color: var(--text); }

.col-filter-body {
    padding: 8px 14px;
}

.col-filter-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
}

.col-filter-label + .col-filter-input + .col-filter-label {
    margin-top: 8px;
}

.col-filter-input {
    width: 100%;
    padding: 6px 10px;
    font-size: 0.84rem;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
}

.col-filter-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Categorical filter checkboxes */
.col-filter-cat-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.col-filter-cat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 3px 0;
}
.col-filter-cat-item input[type="checkbox"] {
    margin: 0;
    accent-color: var(--accent);
}

/* Numeric range row */
.col-filter-range-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.col-filter-num {
    flex: 1;
    min-width: 0;
}

.col-filter-range-sep {
    color: var(--text-tertiary);
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* Dual range slider */
.col-filter-slider {
    position: relative;
    height: 24px;
    margin: 4px 0;
}

.col-filter-track {
    position: absolute;
    top: 10px;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    pointer-events: none;
}

.col-filter-track-fill {
    position: absolute;
    top: 0;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

.col-filter-range {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    outline: none;
}

.col-filter-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 50%;
    cursor: grab;
    pointer-events: auto;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.col-filter-range::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.15);
}

.col-filter-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 50%;
    cursor: grab;
    pointer-events: auto;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.col-filter-range::-moz-range-thumb:active {
    cursor: grabbing;
    transform: scale(1.15);
}

.col-filter-range::-moz-range-track {
    background: transparent;
    border: none;
}

.col-filter-range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.col-filter-loading {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    padding: 8px 0;
}

.col-filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 6px 14px 10px;
}

/* Active column filter chips */
.active-col-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.active-col-filters:empty {
    display: none;
}

.col-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--accent-light);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 100px;
    white-space: nowrap;
}

.col-filter-chip button {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 0 0 2px;
}

.col-filter-chip button:hover {
    color: var(--text);
}

/* Column resize handle */
th.sortable {
    position: relative;
}

th.sortable .col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    user-select: none;
}

th.sortable .col-resize-handle:hover,
th.sortable .col-resize-handle.resizing {
    background: var(--text-link);
}

/* === Error Page === */
.error-page {
    max-width: 400px;
    margin: 120px auto;
    text-align: center;
    padding: 0 24px;
}

.error-page h1 { font-size: 1.3rem; margin-bottom: 8px; }
.error-page p { color: var(--text-secondary); margin-bottom: 24px; font-size: 0.9rem; }

/* === Split Handle (hidden — sidebar always below table) === */
.split-handle {
    display: none;
}

.split-handle-line {
    width: 3px;
    background: var(--border);
    border-radius: 2px;
    transition: background var(--transition), width var(--transition);
}

.split-handle:hover .split-handle-line,
.split-handle:active .split-handle-line {
    background: var(--text-tertiary);
    width: 4px;
}

/* === Height Handle (below table) === */
.height-handle {
    height: 12px;
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 5;
    position: relative;
}

.height-handle-line {
    height: 3px;
    width: 72px;
    background: var(--border);
    border-radius: 2px;
    transition: background var(--transition), height var(--transition);
}

.height-handle:hover .height-handle-line,
.height-handle:active .height-handle-line {
    background: var(--text-tertiary);
    height: 4px;
}

.height-handle-hint {
    display: none;
    position: absolute;
    top: 100%;
    margin-top: 4px;
    font-size: 0.72rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.height-handle:hover .height-handle-hint {
    display: block;
}

/* === Story Header === */
.story-header {
    margin-bottom: 12px;
    width: 100%;
}


/* === Data Report === */
.data-report {
    margin-top: 32px;
    border-top: 1px solid var(--border);
    padding-top: 24px;
}

/* === Analysis Skeleton (loading placeholder) === */
.analysis-skeleton {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 0;
}
.skeleton-hint {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 20px 0;
}
.skeleton-banner {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 28px;
}
.skeleton-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--text-tertiary);
    flex-shrink: 0;
    animation: skeleton-pulse 1.8s ease-in-out infinite;
}
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.skeleton-line {
    height: 14px;
    border-radius: 7px;
    background: var(--text-tertiary);
    animation: skeleton-pulse 1.8s ease-in-out infinite;
}
.skeleton-narrative {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}
.skeleton-charts {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}
.skeleton-chart {
    flex: 1;
    height: 160px;
    border-radius: var(--radius);
    background: var(--text-tertiary);
    animation: skeleton-pulse 1.8s ease-in-out infinite;
}
@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 0.12; }
}

.report-heading {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text);
    margin: 0 0 20px 0;
    text-align: center;
}


.report-section {
    margin-bottom: 24px;
}

.report-section-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 10px 0;
}

.report-body {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.report-body ul {
    margin: 6px 0;
    padding-left: 20px;
}

.report-body li {
    margin-bottom: 6px;
}

.report-body p {
    margin-bottom: 8px;
}

.report-table-wrap {
    overflow-x: auto;
    margin: 12px 0;
}

.report-body .report-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85rem;
}

.report-body .report-table th,
.report-body .report-table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}

.report-body .report-table th {
    background: var(--bg-subtle, #f7f7f7);
    font-weight: 600;
    color: var(--text-primary);
}

.report-body .report-table tbody tr:nth-child(even) td {
    background: var(--bg-subtle, #fafafa);
}

/* === Sidebar Analysis Section === */
.sidebar-analysis-section {
    margin-bottom: 12px;
}
.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}
.analysis-teaser {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.45;
    margin: 0 0 10px;
}
.sidebar-insights-btn {
    width: 100%;
    justify-content: center;
    gap: 6px;
    margin-bottom: 16px;
    font-size: 0.82rem;
    font-weight: 600;
}

.charts-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.charts-grid > * {
    flex: 1 1 calc(50% - 6px);
    max-width: calc(50% - 6px);
    min-width: 0;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.chart-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.chart-card-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 8px;
}

.chart-card-svg {
    overflow: hidden;
}

.chart-card-svg svg {
    width: 100%;
    height: auto;
}

.chart-card-desc {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    margin-top: 6px;
    line-height: 1.4;
}

/* === Premium Visualization === */
.premium-viz-section {
    margin-top: 32px;
    border-top: 1px solid var(--border);
    padding-top: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 24px;
    margin-bottom: 32px;
}
.premium-viz-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.premium-viz-header .report-section-title {
    margin-bottom: 0;
}
.premium-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #7c3aed;
    background: #f3f0ff;
    border: 1px solid #e0d4fc;
    border-radius: 100px;
    padding: 3px 10px;
}
.premium-chip svg {
    color: #7c3aed;
}
.premium-viz-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
}
.premium-viz-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    flex: 0 1 calc(50% - 8px);
    max-width: calc(50% - 8px);
    min-width: 0;
}
.premium-viz-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    padding: 16px 20px 0;
    text-align: center;
}
.premium-viz-content {
    padding: 12px 20px 20px;
    text-align: center;
}
.premium-viz-content img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}
.premium-viz-content iframe {
    width: 100%;
    border: none;
    border-radius: var(--radius-sm);
}
.premium-viz-content video {
    width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}
.premium-viz-card:only-child {
    flex: 0 1 auto;
    max-width: 50%;
}
.premium-viz-card.full-width {
    flex: 1 1 100%;
    max-width: 100%;
}

/* === Embed Modal === */
.embed-modal-content {
    max-width: 480px;
    text-align: center;
}

.embed-code-block {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    font-family: monospace;
    font-size: 0.78rem;
    word-break: break-all;
    margin-bottom: 12px;
    text-align: left;
    line-height: 1.5;
}

/* === Embed Mode === */
.embed-layout .table-wrapper {
    max-width: 100%;
    height: calc(100vh - 110px);
    min-height: 320px;
}
.embed-layout .split-handle { display: none; }

.embed-footer {
    text-align: center;
    padding: 8px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-subtle);
}
.embed-backlink {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-decoration: none;
}
.embed-backlink:hover { color: var(--text-secondary); }

.dataset-description {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 4px;
}

/* === Inline Editing === */
.cell-edit-input {
    width: 100%;
    border: none;
    outline: none;
    background: #fefce8;
    font: inherit;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.data-table td.cell-modified {
    background: #fefce8 !important;
    border-left: 2px solid #eab308;
}

.data-table tr.row-deleted {
    opacity: 0.35;
    text-decoration: line-through;
    pointer-events: none;
}

.data-table tr.row-added {
    background: #f0fdf4 !important;
}

.data-table tr.row-added td {
    border-left: 2px solid #22c55e;
}

/* === Changelog Sidebar === */
.changelog-section {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.changelog-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}

.changelog-count {
    background: #ef4444;
    color: white;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 0.68rem;
    font-weight: 600;
    margin-left: auto;
}

.changelog-list {
    max-height: 250px;
    overflow-y: auto;
    font-size: 0.78rem;
    margin-bottom: 8px;
}

.changelog-entry {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.changelog-entry:last-child { border-bottom: none; }

.changelog-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.changelog-dot.edit { background: #eab308; }
.changelog-dot.delete { background: #ef4444; }
.changelog-dot.add { background: #22c55e; }

.changelog-entry .undo-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 0.72rem;
    padding: 2px 4px;
    border-radius: 3px;
}

.changelog-entry .undo-btn:hover {
    background: var(--bg);
    color: var(--text);
}

.changelog-actions {
    display: flex;
    gap: 6px;
}

/* Add row — ghost row at bottom of table */
.data-table tr.add-row-tr {
    cursor: pointer;
    opacity: 0.4;
    transition: opacity var(--transition);
}

.data-table tr.add-row-tr:hover {
    opacity: 0.7;
}

.data-table tr.add-row-tr td {
    border-top: 1px dashed var(--border);
    color: var(--text-tertiary);
    font-size: 0.78rem;
    padding: 4px 8px;
}

/* Commit history */
.commit-history {
    margin-top: 8px;
    font-size: 0.78rem;
}

.commit-entry {
    padding: 6px 0;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.commit-entry:last-child { border-bottom: none; }

.commit-info {
    color: var(--text-secondary);
}

.commit-time {
    font-size: 0.72rem;
    color: var(--text-tertiary);
}

.commit-summary {
    font-size: 0.72rem;
}

.rollback-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
}

.rollback-btn:hover {
    background: #fef2f2;
    border-color: #ef4444;
    color: #ef4444;
}

/* Column / row selection + context menu */
.col-selected,
.row-selected {
    background: rgba(107,114,128,0.06) !important;
    outline: 2px solid #9ca3af;
    outline-offset: -2px;
    cursor: grab;
}

.row-delete-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fee2e2;
    border: 1px solid #fca5a5;
    border-radius: 4px;
    padding: 2px 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #dc2626;
    z-index: 10;
}

.row-delete-btn:hover {
    background: #fecaca;
}

/* Suppress all table cell z-indexes when context menu is open */
body.ctx-menu-open .data-table td,
body.ctx-menu-open .data-table th,
body.ctx-menu-open .col-selected,
body.ctx-menu-open .row-selected {
    z-index: auto !important;
}

.col-context-menu {
    position: fixed;
    z-index: 2147483647;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 4px 0;
    min-width: 170px;
    font-size: 0.8rem;
    inset: unset;
}

.col-context-menu::backdrop {
    background: transparent;
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    cursor: pointer;
    color: var(--text-primary);
    white-space: nowrap;
}

.ctx-item:hover {
    background: var(--bg-secondary);
}

.ctx-item svg {
    flex-shrink: 0;
}

.ctx-danger {
    color: #ef4444;
}

.ctx-danger:hover {
    background: #fef2f2;
}

.ctx-shortcut {
    margin-left: auto;
    color: var(--text-tertiary);
    font-size: 0.7rem;
}

.ctx-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.add-col-th {
    cursor: pointer;
    color: var(--text-tertiary);
    font-weight: 400;
    font-size: 1rem;
    min-width: 32px;
    text-align: center;
    user-select: none;
}

.add-col-th:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

/* Row drag-and-drop */
.row-dragging {
    opacity: 0.4;
}

.row-drop-indicator {
    position: absolute;
    height: 3px;
    background: var(--accent, #6366f1);
    z-index: 1000;
    pointer-events: none;
    display: none;
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
}

.row-drop-indicator::before {
    content: '';
    position: absolute;
    left: 0;
    top: -4px;
    width: 11px;
    height: 11px;
    background: var(--accent, #6366f1);
    border-radius: 50%;
}

/* Column drag-and-drop */
.col-dragging {
    opacity: 0.35;
}

.col-drag-ghost {
    position: absolute;
    left: -9999px;
    top: -9999px;
    background: var(--surface);
    border: 2px solid var(--accent, #6366f1);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    overflow: hidden;
    max-width: 200px;
    font-size: 0.82rem;
}

.col-drag-ghost-header {
    background: #f5f5f5;
    padding: 6px 10px;
    font-weight: 600;
    font-size: 0.78rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.col-drag-ghost-cell {
    padding: 4px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.78rem;
}

.col-drop-indicator {
    position: absolute;
    width: 3px;
    background: var(--accent, #6366f1);
    z-index: 100;
    pointer-events: none;
    display: none;
    border-radius: 2px;
    box-shadow: 0 0 6px rgba(99, 102, 241, 0.5);
}

/* Commit diff preview */
.commit-diff {
    padding: 4px 8px 8px;
    border-bottom: 1px solid var(--border);
}

.commit-diff-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.diff-item {
    font-size: 0.72rem;
    padding: 4px 6px;
    border-radius: 4px;
    background: var(--bg-secondary);
}

.diff-label {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.03em;
}

.diff-edit .diff-label { color: #d97706; }
.diff-delete .diff-label { color: #ef4444; }
.diff-add .diff-label { color: #059669; }

.diff-col {
    color: var(--text-primary);
    font-weight: 500;
}

.diff-row {
    color: var(--text-tertiary);
}

.diff-values {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    font-size: 0.72rem;
}

.diff-old {
    color: #ef4444;
    text-decoration: line-through;
}

.diff-arrow {
    color: var(--text-tertiary);
}

.diff-new {
    color: #059669;
    font-weight: 500;
}

/* Commit change highlights in table */
.cell-commit-highlight {
    background: #fef3c7 !important;
    box-shadow: inset 2px 0 0 #d97706;
}

.row-commit-highlight td {
    background: #eff6ff !important;
    box-shadow: inset 2px 0 0 #3b82f6;
}

.commit-info:hover .commit-summary {
    text-decoration: underline;
}

/* === Responsive === */
@media (max-width: 900px) {
    .dataset-layout { grid-template-columns: 1fr; }
    .height-handle { display: none; }
    .table-scroll { max-height: 70vh; }
    .dataset-description { font-size: 0.82rem; }
    /* Nav buttons: keep text on tablet, hamburger takes over on mobile */
    /* Toolbar full width */
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-box { min-width: unset; width: 100%; }
    .ask-toolbar-btn { align-self: center; }
}

/* === Insight Banner === */
.insight-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--accent-light, #f5f3ff);
    border: 1px solid var(--accent-border, #ddd6fe);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.insight-banner-icon {
    flex-shrink: 0;
    color: var(--accent, #7c3aed);
}

.insight-banner-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.insight-banner-content p {
    margin: 0;
    font-size: 0.86rem;
    line-height: 1.5;
    color: var(--text);
    font-weight: 500;
}

@media (max-width: 600px) {
    .charts-grid > * { flex: 1 1 100%; max-width: 100%; }
    .chart-card { padding: 10px; }
    .chart-card-title { font-size: 0.7rem; margin-bottom: 4px; }
    .index-page { padding: 48px 20px 80px; }
    .pagination-rpp { display: none; }
    .pagination-inner { justify-content: center; }
    .first-visit-banner { flex-wrap: wrap; font-size: 0.78rem; }
    .first-visit-banner code { font-size: 0.72rem; }
    .dataset-page { padding: 12px; }
    .dataset-name { font-size: 1.05rem; }
    .title-input { font-size: 1.05rem; }
    .ask-toolbar-btn { width: 50%; display: flex; align-items: center; justify-content: center; gap: 6px; }
    .data-table th.row-num,
    .data-table td.row-num { width: 32px; min-width: 32px; }
    /* Chart modal: reduce padding so charts fill mobile screen */
    .chart-modal { padding: 8px; }
    .chart-modal-content { padding: 16px; }
    .insight-banner { padding: 12px 14px; }
    .related-grid { flex-direction: column; }
    .related-card { flex: 1 1 100%; }
}

/* --- Analysis cards --- */

.data-report {
    text-align: center;
}

.data-report .analysis-card,
.data-report .report-section,
.data-report .report-element {
    text-align: left;
}

.add-analysis-btn {
    margin: 0 auto 20px;
}

.analysis-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 0 auto 20px;
    flex-wrap: wrap;
}
.analysis-actions .add-analysis-btn,
.analysis-actions .premium-viz-toolbar-btn {
    margin: 0;
}

.analysis-card {
    margin-bottom: 16px;
    position: relative;
}

.report-element {
    position: relative;
}

.element-delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-tertiary);
    cursor: pointer;
    width: 24px;
    height: 24px;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, border-color 0.15s, background 0.15s;
    z-index: 2;
    line-height: 0;
}

.report-element:hover .element-delete-btn {
    opacity: 1;
}

.element-delete-btn:hover {
    color: var(--red, #e53e3e);
    border-color: var(--red, #e53e3e);
    background: color-mix(in srgb, var(--red, #e53e3e) 8%, var(--bg));
}


.chart-card-wrapper {
    position: relative;
}

.analysis-card.ask-card {
    padding: 0;
}

/* --- Ask a question modal --- */

.ask-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.ask-modal-overlay.active {
    display: flex;
}

.ask-modal {
    position: relative;
    background: var(--card-bg, var(--bg));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: askModalIn 200ms ease;
}

@keyframes askModalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.ask-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.ask-modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.ask-modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color var(--transition), background var(--transition);
}

.ask-modal-close:hover {
    color: var(--text);
    background: var(--bg-subtle);
}

.ask-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.ask-suggestion-chip {
    display: inline-block;
    padding: 6px 14px;
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--text-secondary);
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: 100px;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
    text-align: left;
}

.ask-suggestion-chip:hover {
    color: var(--text);
    border-color: var(--border);
    background: var(--bg);
}

.ask-question-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ask-question-input {
    width: 100%;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 400;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: calc(0.5rem - 2px);
    background: var(--bg);
    color: var(--text);
    outline: none;
    resize: vertical;
    transition: border-color 150ms ease;
}

.ask-question-input::placeholder {
    color: var(--text-tertiary);
}

.ask-question-input:focus {
    border-color: var(--primary);
}

.ask-question-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.ask-char-count {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.ask-submit-btn {
    min-height: 36px;
}

/* Progress tracker */
.ask-progress-card {
    max-width: 560px;
    margin: 0 auto 28px;
    padding: 20px 24px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ask-progress-question {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 14px;
    line-height: 1.4;
}

.ask-progress-step {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.84rem;
    color: var(--text-secondary);
    padding: 10px 14px;
    background: var(--bg-subtle);
    border-radius: 6px;
}

.ask-progress-eta {
    margin: 10px 0 0;
    font-size: 0.76rem;
    color: var(--text-tertiary);
    text-align: right;
}

/* Results */
.ask-result-block {
    animation: fade-up 0.6s ease-out;
}


.ask-error {
    font-size: 0.78rem;
    color: #991b1b;
    padding: 8px 0;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* === Upload CTA Notification === */
.upload-cta {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 900;
    width: 320px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
}
.upload-cta.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.upload-cta-dismiss {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    transition: color var(--transition);
}
.upload-cta-dismiss:hover { color: #fff; }
.upload-cta h3 {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 4px;
}
.upload-cta p {
    font-size: 0.82rem;
    color: rgba(255,255,255,0.7);
    margin-bottom: 14px;
    line-height: 1.4;
}
.upload-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: #fff;
    color: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.upload-cta-btn:hover { background: #e5e5e5; }

@media (max-width: 900px) {
    .upload-cta {
        bottom: 16px;
        right: 16px;
        left: 16px;
        width: auto;
    }
}

/* === Premium Visualization === */

.premium-viz-toolbar-btn {
    background: #f3f0ff;
    border: 1px solid #e0d4fc;
    color: #6d28d9;
    font-weight: 600;
}
.premium-viz-toolbar-btn:hover {
    background: #ebe5ff;
    border-color: #c4b1f7;
    color: #5b21b6;
}
.premium-viz-toolbar-btn svg {
    color: #7c3aed;
}

.premium-viz-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.55);
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}
.premium-viz-modal-overlay.active {
    display: flex;
}
.premium-viz-modal {
    position: relative;
    background: var(--card-bg, var(--bg));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: min(96vw, 1480px);
    padding: 24px 28px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: askModalIn 200ms ease;
    margin: auto;
}
.premium-viz-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.premium-viz-modal-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}
.premium-viz-modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color var(--transition), background var(--transition);
}
.premium-viz-modal-close:hover {
    color: var(--text);
    background: var(--bg-subtle);
}
.premium-viz-modal-sub {
    margin: 0 0 16px;
    font-size: 0.86rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.premium-viz-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.premium-viz-prompt {
    width: 100%;
    font-family: inherit;
    font-size: 0.92rem;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: calc(0.5rem - 2px);
    background: var(--bg);
    color: var(--text);
    outline: none;
    resize: vertical;
    transition: border-color 150ms ease;
}
.premium-viz-prompt:focus { border-color: var(--primary); }
.premium-viz-form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.premium-viz-cost-hint {
    font-size: 0.76rem;
    color: var(--text-tertiary);
}
.premium-viz-balance {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    color: var(--text);
    font-weight: 500;
}
.premium-viz-balance svg {
    color: var(--primary);
}
.premium-viz-balance #pv-drawer-balance-amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.premium-viz-balance-hint {
    color: var(--text-tertiary);
    font-weight: 400;
}
.premium-viz-submit-btn {
    min-height: 36px;
}
.premium-viz-result-container {
    margin-top: 18px;
}

.premium-viz-progress-card {
    padding: 18px 20px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.premium-viz-progress-prompt {
    font-size: 0.86rem;
    color: var(--text);
    margin-bottom: 12px;
    font-style: italic;
}
.premium-viz-progress-step {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.84rem;
    color: var(--text-secondary);
    padding: 10px 14px;
    background: var(--bg);
    border-radius: 6px;
}
.premium-viz-progress-eta {
    margin: 10px 0 0;
    font-size: 0.76rem;
    color: var(--text-tertiary);
    text-align: right;
}
.premium-viz-balance {
    color: var(--text-secondary);
}

.premium-viz-results-title {
    margin: 0 0 4px;
    font-size: 1rem;
    color: var(--text);
}
.premium-viz-results-sub {
    margin: 0 0 16px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.premium-viz-results .premium-viz-grid {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 14px;
    padding: 4px 2px 6px;
}
.premium-viz-results .premium-viz-card {
    flex: 1 1 0;
    min-width: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0.72;
    transition: border-color var(--transition), box-shadow var(--transition), opacity var(--transition), transform var(--transition);
}
.premium-viz-results .premium-viz-card:hover {
    border-color: var(--primary);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
    opacity: 1;
}
.premium-viz-card-num {
    padding: 12px 14px 0;
    display: flex;
    align-items: center;
}
.premium-viz-card-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1;
}
.premium-viz-card-badge-featured {
    background: #f3f0ff;
    color: #6d28d9;
}
.premium-viz-card-badge-bonus {
    background: var(--bg-subtle);
    color: var(--text-tertiary);
}
.premium-viz-results .premium-viz-card-featured {
    border: 2px solid var(--primary);
    box-shadow: 0 4px 14px rgba(109, 40, 217, 0.12);
    flex: 1.4 1 0;
    opacity: 1;
    transform: scale(1.02);
    z-index: 1;
}
.premium-viz-card-featured:hover {
    box-shadow: 0 8px 22px rgba(109, 40, 217, 0.18);
}
.premium-viz-card-bonus {
    border-color: var(--border-light, #e7e7e7);
}
.premium-viz-card-svg {
    width: 100%;
    background: white;
    border-top: 1px solid var(--border-light, #e7e7e7);
    border-bottom: 1px solid var(--border-light, #e7e7e7);
    margin-top: 10px;
    padding: 14px 16px;
    min-height: 220px;
    max-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-in;
    position: relative;
    overflow: hidden;
}
.premium-viz-card-svg::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.85) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23404040' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/><line x1='11' y1='8' x2='11' y2='14'/><line x1='8' y1='11' x2='14' y2='11'/></svg>") center/14px no-repeat;
    border: 1px solid var(--border);
    opacity: 0;
    transition: opacity var(--transition);
}
.premium-viz-card-svg:hover::after {
    opacity: 1;
}
.premium-viz-card-svg svg {
    width: 100%;
    height: auto;
    max-height: 252px;
    display: block;
}
.premium-viz-card-meta {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}
.premium-viz-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.premium-viz-card-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.premium-viz-pick-btn {
    align-self: stretch;
    margin-top: 10px;
}
.premium-viz-pick-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.premium-viz-card-skeleton {
    border-style: dashed;
    background: #fafafa;
}
.premium-viz-card-skeleton:hover {
    border-color: var(--border);
    box-shadow: none;
}
.premium-viz-card-skeleton .premium-viz-card-svg {
    cursor: default;
    background: #fafafa;
}
.premium-viz-card-skeleton .premium-viz-card-svg::after {
    display: none;
}
.premium-viz-skeleton-svg {
    flex-direction: column;
    gap: 8px;
    color: var(--text-tertiary);
    text-align: center;
    padding: 0 12px;
}
.premium-viz-card-skeleton-empty .premium-viz-skeleton-line {
    animation: none;
    background: #ececec;
    opacity: 0.5;
}
.premium-viz-skeleton-label-empty {
    color: var(--text-tertiary);
    font-style: italic;
}

/* Click-to-zoom lightbox */
.premium-viz-zoom-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2100;
    background: rgba(0, 0, 0, 0.85);
    align-items: center;
    justify-content: center;
    padding: 32px;
    cursor: zoom-out;
}
.premium-viz-zoom-overlay.active {
    display: flex;
}
.premium-viz-zoom-content {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    max-width: 92vw;
    max-height: 92vh;
    overflow: auto;
    cursor: default;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
    position: relative;
}
.premium-viz-zoom-content svg {
    width: 100%;
    height: auto;
    max-width: 100%;
    display: block;
}
.premium-viz-zoom-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition), background var(--transition);
}
.premium-viz-zoom-close:hover {
    color: var(--text);
    background: var(--bg-subtle);
}
.premium-viz-skeleton-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}
.premium-viz-skeleton-line {
    background: linear-gradient(90deg, #f0f0f0, #e4e4e4, #f0f0f0);
    background-size: 200% 100%;
    animation: pv-shimmer 1.4s ease-in-out infinite;
    border-radius: 4px;
    height: 12px;
    width: 100%;
}
.premium-viz-skeleton-line-short {
    width: 75%;
    height: 10px;
}
@keyframes pv-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.premium-viz-error {
    padding: 14px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    color: #991b1b;
    font-size: 0.86rem;
    line-height: 1.5;
}

@media (max-width: 720px) {
    .premium-viz-results .premium-viz-grid {
        flex-direction: column;
    }
    .premium-viz-results .premium-viz-card,
    .premium-viz-results .premium-viz-card-featured {
        flex: 0 0 auto;
        opacity: 1;
        transform: none;
    }
    .premium-viz-results .premium-viz-card-svg {
        min-height: 220px;
        max-height: 280px;
    }
    .premium-viz-results .premium-viz-card-svg svg {
        max-height: 248px;
    }
}

@media (max-width: 900px) {
    .premium-viz-modal {
        padding: 18px;
    }
}

/* === TOC horizontal nav (staging experiment) === */
.toc-nav {
    display: none;
}

@media (min-width: 900px) {
    .toc-nav {
        display: block;
        position: sticky;
        top: 65px;
        z-index: 40;
        height: 41px;
        background: var(--bg);
        border-bottom: 1px solid var(--border-light);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }
    .toc-nav:has(.toc-list:not(:empty)) {
        opacity: 1;
        pointer-events: auto;
    }
}

.toc-list {
    list-style: none;
    margin: 0 auto;
    padding: 0 24px;
    max-width: 1400px;
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.toc-list::-webkit-scrollbar { display: none; }

.toc-list li {
    flex: 0 0 auto;
    margin: 0;
}

.toc-list a {
    display: block;
    padding: 10px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 150ms ease, border-color 150ms ease;
}

.toc-list a:hover {
    color: var(--text);
}

.toc-list a.toc-active {
    color: var(--text);
    border-bottom-color: var(--text);
}

.toc-list .toc-sub a {
    color: var(--text-tertiary);
    font-weight: 400;
}
.toc-list .toc-sub a:hover { color: var(--text); }

/* Smooth-scroll lands below the topnav + toc-nav (65 + ~38 = ~104) */
#story-header,
#story-table-section,
#data-report,
#related-datasets-container,
.analysis-card {
    scroll-margin-top: 110px;
}

/* Right-side slide-out drawer (replaces the centered modal + standalone page) */
.pv-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(760px, 96vw);
    background: var(--card-bg, var(--bg));
    border-left: 1px solid var(--border);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.18);
    transform: translateX(100%);
    transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 1900;
    display: flex;
    flex-direction: column;
}
.pv-drawer.active {
    transform: translateX(0);
}
.pv-drawer-handle {
    position: absolute;
    top: 50%;
    left: -28px;
    transform: translateY(-50%);
    width: 28px;
    height: 56px;
    border-radius: 8px 0 0 8px;
    background: var(--card-bg, var(--bg));
    border: 1px solid var(--border);
    border-right: none;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    padding: 0;
}
.pv-drawer-handle:hover {
    color: var(--text);
    background: var(--bg-subtle);
}
.pv-drawer-handle svg {
    width: 14px;
    height: 14px;
    transition: transform 200ms ease;
}
.pv-drawer.active .pv-drawer-handle svg {
    transform: scaleX(-1);
}
.pv-drawer-inner {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 20px;
    overscroll-behavior: contain;
}
.pv-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.pv-drawer-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.pv-drawer-title svg {
    width: 16px;
    height: 16px;
    color: var(--primary);
}
.pv-drawer-close {
    background: none;
    border: none;
    line-height: 1;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 4px;
    transition: color var(--transition), background var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.pv-drawer-close svg {
    width: 16px;
    height: 16px;
}
.pv-drawer-close:hover {
    color: var(--text);
    background: var(--bg-subtle);
}
.pv-drawer-grabber { display: none; }

.pv-drawer-fab {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 16px;
    width: 52px;
    height: 52px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff;
    box-shadow: 0 6px 20px rgba(109, 40, 217, 0.35);
    cursor: pointer;
    z-index: 1850;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 200ms ease, box-shadow 200ms ease, opacity 200ms ease, bottom 300ms ease;
}
.pv-drawer-fab:hover { transform: scale(1.05); }
.pv-drawer-fab svg { display: block; }
/* Lift the FAB above the upload CTA card when it's visible (mobile especially,
   where both compete for the bottom edge). */
body:has(.upload-cta.visible) .pv-drawer-fab { bottom: 200px; }

@media (max-width: 720px) {
    /* Bottom-sheet layout: slides up from bottom, swipe-down to dismiss */
    .pv-drawer {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100vw;
        height: 88vh;
        max-height: 88vh;
        transform: translateY(100%);
        border-left: none;
        border-top: 1px solid var(--border);
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
    }
    .pv-drawer.active { transform: translateY(0); }
    .pv-drawer.pv-drawer-dragging { transition: none; }

    .pv-drawer-handle { display: none; }

    .pv-drawer-grabber {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 16px;
        margin: 0 auto;
        position: sticky;
        top: 0;
        background: var(--card-bg, var(--bg));
        z-index: 3;
        cursor: grab;
        touch-action: none;
    }
    .pv-drawer-grabber::before {
        content: "";
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--border);
    }
    .pv-drawer-grabber:active { cursor: grabbing; }

    .pv-drawer-header {
        position: sticky;
        top: 16px;
        background: var(--card-bg, var(--bg));
        z-index: 2;
        padding: 6px 0 8px;
        margin-bottom: 0;
        cursor: grab;
        touch-action: pan-y;
    }
    .pv-drawer-header::after {
        content: "";
        position: absolute;
        left: -14px;
        right: -14px;
        bottom: 0;
        height: 1px;
        background: var(--border-light, var(--border));
    }
    .pv-drawer-header:active { cursor: grabbing; }

    .pv-drawer-inner {
        padding: 0 14px 28px;
    }

    .pv-drawer-fab { display: inline-flex; }
    .pv-drawer.active ~ .pv-drawer-fab {
        opacity: 0;
        pointer-events: none;
        transform: scale(0.6);
    }
}

/* === Premium viz history (drawer log) === */
.pv-history {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}
.pv-history-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 10px;
}
.pv-history-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    letter-spacing: 0.01em;
}
.pv-history-count {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    background: var(--bg-subtle);
    padding: 1px 8px;
    border-radius: 999px;
}
.pv-history-empty {
    font-size: 0.82rem;
    color: var(--text-tertiary);
    margin: 6px 0 0;
    line-height: 1.4;
}
.pv-history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.pv-history-item {
    display: flex;
    gap: 10px;
    padding: 10px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.pv-history-item:hover {
    background: var(--bg-subtle);
    border-color: var(--text-tertiary);
}
.pv-history-item:active {
    transform: scale(0.997);
}
.pv-history-item-running {
    cursor: default;
}
.pv-history-item-running:hover {
    background: var(--surface);
    border-color: var(--border);
}
.pv-history-thumb {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    border-radius: 6px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    overflow: hidden;
}
.pv-history-thumb svg {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}
.pv-history-item-picked .pv-history-thumb {
    background: #fff;
    color: var(--text);
}
.pv-history-item-failed .pv-history-thumb {
    color: #c62828;
    background: #fdecea;
}
.pv-history-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}
.pv-history-prompt {
    font-size: 0.82rem;
    color: var(--text);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.pv-history-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.7rem;
    color: var(--text-tertiary);
}
.pv-history-pill {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
}
.pv-history-pill-picked {
    background: #e6f5ec;
    color: #1f7a3a;
    border-color: #c4e6cf;
}
.pv-history-pill-running {
    background: #eef3fb;
    color: #2c4f8a;
    border-color: #cfdcef;
}
.pv-history-pill-failed {
    background: #fdecea;
    color: #c62828;
    border-color: #f5c8c4;
}
.pv-history-pill-drafts {
    background: #fff4e0;
    color: #8a5a14;
    border-color: #f0d8aa;
}
.pv-history-pill-dismissed {
    background: var(--bg-subtle);
    color: var(--text-tertiary);
    border-color: var(--border);
}
.pv-history-saved-title {
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}
.pv-history-time {
    margin-left: auto;
    color: var(--text-tertiary);
    white-space: nowrap;
}
.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}
.pv-history-flash {
    animation: pv-history-flash 1.6s ease-out;
}
@keyframes pv-history-flash {
    0% { box-shadow: 0 0 0 0 rgba(31, 122, 58, 0.55); }
    50% { box-shadow: 0 0 0 6px rgba(31, 122, 58, 0.18); }
    100% { box-shadow: 0 0 0 0 rgba(31, 122, 58, 0); }
}

/* Handle badge (pending changes count) */
.pv-drawer-handle-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 14px;
    height: 14px;
    padding: 0 4px;
    border-radius: 7px;
    background: #ef4444;
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--card-bg, var(--bg));
}

/* Form section + "New analysis" reset button */
/* Unified composer: mode pill + textarea + submit row */
.pv-composer {
    margin-top: 14px;
    padding: 12px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.pv-composer-modes {
    display: inline-flex;
    padding: 3px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    gap: 2px;
}
.pv-composer-mode {
    border: none;
    background: transparent;
    padding: 6px 12px;
    border-radius: 999px;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--transition), color var(--transition);
}
.pv-composer-mode:hover { color: var(--text); }
.pv-composer-mode.active {
    background: var(--text);
    color: #fff;
}
.pv-composer-mode.pv-composer-mode-viz.active {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff;
}
.pv-composer-form { margin-top: 10px; }
.pv-composer-form .ask-suggestions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.pv-composer-form .ask-question-input,
.pv-composer-form .premium-viz-prompt {
    width: 100%;
    box-sizing: border-box;
}
.pv-composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
}
.pv-composer-meta {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    line-height: 1.3;
}
.pv-composer-meta b {
    color: var(--text-secondary);
    font-weight: 500;
}
.pv-composer-meta svg { color: #7c3aed; flex: none; }

/* Data Quality block inside drawer (matches Changes divider) */
.pv-drawer .quality-section {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

/* Patterns block inside drawer (matches Changes divider) */
.pv-drawer > .pv-drawer-inner > details.insight-section-primary,
.pv-drawer details.insight-section-primary {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

/* Changes panel inside drawer (merged from sidebar tab) */
.pv-drawer-changes {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}
.pv-drawer-changes .changelog-section {
    padding: 0;
    border-bottom: none;
    margin-bottom: 12px;
}
.pv-drawer-changes .changelog-list {
    max-height: 200px;
}
.pv-drawer-changes #commit-history-container {
    margin-top: 8px;
}

/* === Blog === */
.blog-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 64px 24px 96px;
}
.blog-index { max-width: 760px; }

.blog-index-header {
    margin-bottom: 56px;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--border);
}
.blog-index-header h1 {
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 10px;
}
.blog-index-tagline {
    color: var(--text-secondary);
    font-size: 1.05rem;
    line-height: 1.55;
    max-width: 520px;
}

.blog-post-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.blog-post-card { padding: 0; }
.blog-post-card-link {
    display: block;
    padding: 22px 16px;
    border-radius: var(--radius);
    transition: background var(--transition);
    color: inherit;
}
.blog-post-card-link:hover { background: var(--bg-subtle); }
.blog-post-card-title {
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}
.blog-post-card-dek {
    color: var(--text-secondary);
    font-size: 0.98rem;
    line-height: 1.55;
    margin-bottom: 10px;
}
.blog-post-card-meta {
    color: var(--text-tertiary);
    font-size: 0.82rem;
}
.blog-post-card-meta a { text-decoration: underline; text-underline-offset: 2px; }
.blog-post-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 8px;
}
.blog-post-badge-running { background: #fef3c7; color: #92400e; }
.blog-post-badge-draft { background: #e5e7eb; color: #374151; }
.blog-post-badge-failed { background: #fee2e2; color: #991b1b; }

.blog-empty {
    padding: 48px 0;
    text-align: center;
    color: var(--text-tertiary);
}

/* Single post */
.blog-post-header {
    margin-bottom: 40px;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--border);
}
.blog-breadcrumb {
    margin-bottom: 22px;
    font-size: 0.85rem;
}
.blog-breadcrumb a { color: var(--text-tertiary); }
.blog-breadcrumb a:hover { color: var(--text); }
.blog-post-title {
    font-size: 2.6rem;
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 14px;
}
.blog-post-dek {
    font-size: 1.15rem;
    line-height: 1.55;
    color: var(--text-secondary);
    margin-bottom: 18px;
    font-weight: 400;
}
.blog-post-byline {
    color: var(--text-tertiary);
    font-size: 0.85rem;
}
.blog-post-byline a {
    color: var(--text-tertiary);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.blog-post-byline a:hover { color: var(--text); }

.blog-post-body {
    font-size: 1.08rem;
    line-height: 1.75;
    color: var(--text);
}
.blog-post-body p {
    margin-bottom: 1.4em;
}
.blog-post-body p.lede {
    font-size: 1.25rem;
    line-height: 1.55;
    color: var(--text);
    font-weight: 500;
    margin-bottom: 1.6em;
}
.blog-post-body h2 {
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 2.2em 0 0.7em;
    line-height: 1.25;
}
.blog-post-body h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 1.6em 0 0.5em;
}
.blog-post-body strong { font-weight: 600; }
.blog-post-body a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--border);
    transition: text-decoration-color var(--transition);
}
.blog-post-body a:hover { text-decoration-color: var(--text); }
.blog-post-body ul, .blog-post-body ol {
    margin: 0 0 1.4em 1.4em;
}
.blog-post-body li { margin-bottom: 0.4em; }

.blog-post-body .blog-chart {
    margin: 2.2em 0;
    padding: 0;
}
.blog-post-body .blog-chart svg,
.blog-post-body .blog-chart .plotly-chart {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
}
.blog-post-body .blog-chart figcaption {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    text-align: center;
    margin-top: 10px;
    line-height: 1.5;
}

.blog-post-body .blog-card {
    margin: 2em 0;
    padding: 18px 22px;
    border-radius: var(--radius);
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
}
.blog-post-body .blog-card-banner {
    background: var(--accent-light);
    border-color: var(--accent-border);
    border-left: 3px solid var(--text);
}
.blog-post-body .blog-card-annotation {
    background: #fffbeb;
    border-color: #fde68a;
}
.blog-post-body .blog-card h3 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    margin: 0 0 8px;
    font-weight: 600;
}
.blog-post-body .blog-card ul {
    margin: 0;
    padding-left: 1.2em;
}
.blog-post-body .blog-card li { margin-bottom: 0.3em; }

.blog-element-missing {
    padding: 16px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: var(--radius-sm);
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
    margin: 1.5em 0;
}

.blog-post-footer {
    margin-top: 48px;
    padding-top: 28px;
    border-top: 1px solid var(--border);
}
.blog-post-source {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}
.blog-post-source a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--border);
}
.blog-post-source a:hover { text-decoration-color: var(--text); }
.blog-post-tags {
    list-style: none;
    padding: 0;
    margin: 18px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.blog-post-tags li {
    font-size: 0.75rem;
    padding: 3px 10px;
    background: var(--bg-subtle);
    border-radius: 999px;
    color: var(--text-secondary);
}

/* Convert-to-blog button shown on dataset pages (staging only) */
.blog-cta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    margin: 24px 0;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.blog-cta-text {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.45;
}
.blog-cta-text strong { color: var(--text); font-weight: 600; }
.blog-cta-status {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* Dataset sources: matches .dataset-story-link styling — thin one-line
   row with an icon, an uppercase label, and one or more linked hosts. */
.dataset-sources {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 4px 0 16px;
    padding: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.dataset-sources-editable { cursor: pointer; }
.dataset-sources-editable .edit-icon {
    opacity: 0;
    color: var(--text-tertiary);
    transition: opacity 0.15s;
}
.dataset-sources-editable:hover .edit-icon { opacity: 1; }
.dataset-sources-icon { width: 14px; height: 14px; color: var(--text-tertiary); flex-shrink: 0; }
.dataset-sources-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
.dataset-source-link {
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
}
.dataset-source-link:hover { text-decoration: underline; }
.dataset-source-sep {
    color: var(--text-tertiary);
    user-select: none;
}
.dataset-sources-empty {
    color: var(--text-tertiary);
    font-style: italic;
}
.sources-form { margin: 6px 0 4px; }
.sources-input {
    width: 100%;
    box-sizing: border-box;
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 0.82rem;
    padding: 8px 10px;
    border: 1px solid var(--border, rgba(0,0,0,0.18));
    border-radius: 6px;
    background: var(--bg, #fff);
    color: var(--text);
    resize: vertical;
    min-height: 70px;
}
.sources-input:focus {
    outline: none;
    border-color: var(--accent, #5b6fff);
}
.sources-form-hint {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* Story link on dataset page: thin one-line affordance above the table when a published blog exists. */
.dataset-story-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 16px;
    padding: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
}
.dataset-story-link:hover { color: var(--text); }
.dataset-story-link:hover .dataset-story-title { text-decoration: underline; }
.dataset-story-icon { width: 14px; height: 14px; color: var(--text-tertiary); flex-shrink: 0; }
.dataset-story-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
.dataset-story-title { font-weight: 500; color: var(--text); }
.dataset-story-arrow { width: 12px; height: 12px; color: var(--text-tertiary); flex-shrink: 0; }

@media (max-width: 600px) {
    .blog-page { padding: 32px 16px 64px; }
    .blog-post-title { font-size: 1.9rem; }
    .blog-post-dek { font-size: 1rem; }
    .blog-post-body { font-size: 1.02rem; line-height: 1.7; }
    .blog-post-body p.lede { font-size: 1.1rem; }
    .blog-index-header h1 { font-size: 1.8rem; }
    .blog-cta { flex-direction: column; align-items: stretch; }
}

/* === Workbook sheet bar (section-divider, staging only) === */
.workbook-bar {
    /* No bottom border. The bar is just a row of tab labels; the active
       tab gets its own short underline (Chrome/Material pattern) rather
       than the whole strip being underlined and disconnected from the
       toolbar below. */
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0;
    margin: 16px 0 8px;
    background: transparent;
    overflow-x: auto;
    overflow-y: hidden;
    /* Scroll horizontally for overflow tabs without painting a scrollbar.
       The bar already telegraphs "more tabs" via the truncated last tab
       cutting off at the edge. */
    scrollbar-width: none;            /* Firefox */
    -ms-overflow-style: none;         /* legacy Edge / IE */
    user-select: none;
}
.workbook-bar::-webkit-scrollbar {    /* Chromium / Safari */
    display: none;
}
.workbook-tab {
    /* Underline-on-active. No border anywhere; only the bottom
       border-color animates so dimensions never shift on hover. */
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    cursor: pointer;
    white-space: nowrap;
    max-width: 240px;
    transition: color var(--transition), border-color var(--transition);
}
.workbook-tab:hover {
    color: var(--text-secondary);
}
.workbook-tab.is-active {
    color: var(--text);
    border-bottom-color: var(--text);
    cursor: default;
}
.workbook-tab.is-active:hover {
    color: var(--text);
}
.workbook-tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    outline: none;
}
.workbook-tab-label[contenteditable="true"] {
    /* Soft pill-shaped editor instead of a harsh 1px outline floating
       around the bare text. box-shadow extends the fill outward so there's
       breathing room without nudging the surrounding layout. */
    background: var(--accent-light);
    border-radius: 4px;
    box-shadow: 0 0 0 3px var(--accent-light);
    cursor: text;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
}
/* "+ Add sheet" always renders as a pill chip — both inside the workbook
   tab bar (multi-sheet) and inline in the toolbar (single-sheet, see
   .toolbar-add-sheet below). The chip shape distinguishes it as an action,
   not another tab. */
.workbook-tab-add {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 4px 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: color var(--transition), border-color var(--transition);
}
.workbook-tab-add:hover {
    color: var(--text);
    border-color: var(--text-tertiary);
}
.workbook-status {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    padding: 0 8px;
    white-space: nowrap;
}
.workbook-tab:focus-visible,
.workbook-tab-add:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

/* Single-sheet "+ Add sheet" pill — lives inline in the dataset toolbar
   (next to Analyze) so the entry point sits with other dataset actions
   instead of adding tab-bar chrome above the table. */
.toolbar-add-sheet {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-tertiary);
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition);
}
.toolbar-add-sheet:hover {
    color: var(--text);
    border-color: var(--text-tertiary);
}
.toolbar-add-sheet:disabled { cursor: default; opacity: 0.6; }

@media (max-width: 600px) {
    .workbook-bar { padding: 8px 16px; }
    .workbook-tab { padding: 10px 12px; }
}
