:root {
    --google-blue: #1a73e8;
    --google-green: #34a853;
    /* Sens */
    --google-red: #ea4335;
    /* Res */
    --google-yellow: #fbbc04;
    --bg-color: #f8f9fa;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
}

html,
body {
    height: 100%;
}

body {
    font-family: 'Roboto', 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 0 0 auto;
}

header h1 {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin: 0;
}

.status {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Main Layout - Split Screen */
main {
    flex: 1 1 auto;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 1rem;
    display: grid;
    grid-template-columns: minmax(360px, 38%) minmax(0, 62%);
    gap: 1rem;
    align-items: stretch;
    overflow: hidden;
    box-sizing: border-box;
}

/* Left Panel - Scrolling Results */
.left-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

/* Right Panel - Sticky Analysis */
.right-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Cards */
.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0;
    /* Removing padding from parent card to let header/body handle it */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    /* For smooth corners */
    flex-shrink: 0;
    height: 100%;
    min-height: 0;
}

.card-header {
    background: #f8f9fa;
    padding: 1rem 1.5rem;
    cursor: pointer;
    border-bottom: 1px solid transparent;
    /* Prepare for border */
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.card-header:hover {
    background: #e8f0fe;
}

.card-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.card-body {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: block;
    /* Default open */
    min-height: 0;
}

.arrow {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
    transform: rotate(0deg);
    /* Down arrow */
}

/* Fix table card flex behavior */
.table-card {
    display: flex;
    flex-direction: column;
}

.table-card .card-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    /* Remove padding for flush table */
    display: flex;
    /* Ensure wrapper fills height */
    flex-direction: column;
}

.table-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Inputs */
.input-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

textarea {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: monospace;
    resize: vertical;
    transition: border 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--google-blue);
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

button.primary-btn {
    background-color: var(--google-blue);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 1rem;
    transition: background 0.2s;
    width: 100%;
}

button.primary-btn:hover {
    background-color: #1557b0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

button.primary-btn:disabled,
.secondary-btn:disabled {
    background: #f1f3f4;
    color: #9aa0a6;
    border-color: #dadce0;
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.75;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

th {
    text-align: left;
    padding: 0.8rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-weight: 500;
}

td {
    padding: 0.8rem;
    border-bottom: 1px solid var(--border);
}

tr:hover {
    background-color: #f1f3f4;
    cursor: pointer;
}

tr.selected {
    background-color: #e8f0fe;
    /* Light Blue */
}

/* Badges */
.badge {
    background: #e8f0fe;
    color: var(--google-blue);
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 1rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.2s;
    text-align: center;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: #f8f9fa;
}

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

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    flex-direction: column;
    padding: 1rem;
    box-sizing: border-box;
}

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

#tabLiterature,
#tabHypothesis {
    overflow-y: auto;
}

.primary-analysis-tabs {
    gap: 0.35rem;
    padding: 0.5rem 0.75rem 0;
    margin-bottom: 0;
    background: linear-gradient(180deg, #ffffff 0%, #f7f9fc 100%);
}

.primary-tab-btn {
    border-radius: 10px 10px 0 0;
    border: 1px solid transparent;
    border-bottom: none;
}

.primary-tab-btn.active {
    background: #fff;
    border-color: var(--border);
    border-bottom: 2px solid #fff;
}

.workflow-note {
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: linear-gradient(135deg, #eef4ff 0%, #f8fbff 100%);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.overview-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    padding: 0.85rem;
}

.overview-card span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
}

.overview-card strong {
    display: block;
    font-size: 1rem;
    color: var(--text-primary);
}

.overview-callout {
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 0.9rem 1rem;
    background: #fff;
    margin-bottom: 0.85rem;
}

.explanation-layout {
    display: grid;
    grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
    gap: 1rem;
    min-height: 0;
    flex: 1 1 auto;
}

.explanation-sidecar {
    min-height: 0;
}

.explanation-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.explanation-subtabs {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
}

.explanation-subtab-btn {
    background: #f5f7fa;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.55rem 0.85rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 500;
}

.explanation-subtab-btn.active {
    background: #e8f0fe;
    color: var(--google-blue);
    border-color: #c7dafc;
}

.explanation-panel {
    display: none;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
}

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

.selection-mode-text {
    margin-top: 0.45rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.hypothesis-ops-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Left Panel Tabs */
.left-tab-btn {
    border-bottom: none;
    border-right: 1px solid var(--border);
    flex: 1;
    text-align: center;
    padding: 0.8rem 0.5rem;
    font-size: 0.85rem;
    background: #f8f9fa;
    cursor: pointer;
    border-top: 3px solid transparent;
    /* Highlight top for these tabs if desired */
}

.left-tab-btn:last-child {
    border-right: none;
}

.left-tab-btn.active {
    background: #fff;
    color: var(--google-blue);
    font-weight: 500;
    border-bottom: 2px solid var(--google-blue);
    /* Visual indicator */
}

.left-tab-content {
    display: none;
    animation: fadeIn 0.2s ease;
    height: 100%;
    /* Important for internal scheduling */
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.left-tab-content.active {
    display: flex;
    /* Flex to allow scrolling internal components */
}

.left-panel .note {
    margin-top: 0;
}

/* Visualization Containers */
.plot-container {
    background: #fff;
    padding: 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 0;
    overflow: hidden;
    box-sizing: border-box;
    flex: 1 1 auto;
}

.plot-image {
    max-width: 100%;
    max-height: 100%;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: auto;
    border-radius: 4px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

.plot-container iframe,
.plot-container canvas {
    max-width: 100%;
    max-height: 100%;
}

.plot-container h4 {
    margin: 0 0 0.35rem 0;
    font-size: 0.85rem;
}

.bubble-shell {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    min-height: 0;
    flex: 1 1 auto;
}

.bubble-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8f9fa;
}

.bubble-selection-meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 240px;
    flex: 1 1 240px;
}

.bubble-selection-title {
    font-size: 0.92rem;
    color: var(--text-primary);
}

.bubble-selection-help {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.bubble-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.bubble-selection-chips {
    max-height: 5.5rem;
    overflow: auto;
    margin: 0;
    padding: 0.2rem 0.05rem 0.1rem;
}

.bubble-chart-container {
    min-height: 360px;
    flex: 1 1 auto;
}

.note {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: -0.5rem;
    margin-bottom: 1rem;
}


/* Chat Differentiation */
.chat-message {
    padding: 0.8rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    max-width: 85%;
    font-size: 0.9rem;
    line-height: 1.4;
}

.chat-message.user {
    background-color: #e8f0fe;
    /* Light Blue */
    color: var(--text-primary);
    margin-left: auto;
    /* Right align */
    border-top-right-radius: 0;
}

.chat-message.assistant {
    background-color: #f1f3f4;
    /* Gray */
    color: var(--text-primary);
    margin-right: auto;
    /* Left align */
    border-top-left-radius: 0;
}

/* Chat Controls */
.chat-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.secondary-btn {
    background-color: #fff;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background-color: #f8f9fa;
    color: var(--text-primary);
    border-color: #ccc;
}

.secondary-btn:disabled:hover {
    background: #f1f3f4;
    color: #9aa0a6;
    border-color: #dadce0;
}

.analysis-toolbar {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
    background: #f8f9fa;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex: 0 0 auto;
}

.lit-controls {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem;
    background: #f8f9fa;
    margin-bottom: 1rem;
    max-height: 30vh;
    overflow: auto;
}

.lit-control-group {
    margin-bottom: 0.75rem;
}

.lit-control-group label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.lit-control-group input,
.lit-control-group select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 0.9rem;
    background: #fff;
}

.lit-control-group textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem;
    font-size: 0.9rem;
    background: #fff;
    font-family: inherit;
    box-sizing: border-box;
}

#litGeneSelect {
    min-height: 120px;
}

.lit-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.45rem 0.75rem;
}

.lit-inline-check {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.lit-shell {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 0;
    height: 100%;
}

.lit-header-block h3 {
    margin: 0 0 0.2rem 0;
    font-size: 1.05rem;
}

.lit-header-block .note {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.35;
}

.lit-subtabs {
    display: flex;
    gap: 0.35rem;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    padding-bottom: 0.1rem;
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fff;
}

.lit-subtab-btn {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    padding: 0.65rem 0.9rem;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.lit-subtab-btn:hover {
    color: var(--text-primary);
    background: #f8f9fa;
}

.lit-subtab-btn.active {
    color: var(--google-blue);
    border-bottom-color: var(--google-blue);
}

.lit-subtab-panels {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.lit-subtab-content {
    display: none;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding: 0.85rem;
}

.lit-subtab-content.active {
    display: flex;
}

.lit-scroll-pane {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

.lit-overview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.lit-overview-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8f9fa;
    padding: 0.75rem;
}

.lit-overview-card span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.35rem;
}

.lit-overview-card strong {
    display: block;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.lit-overview-summary {
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: #fff;
    padding: 0.85rem;
    color: var(--text-primary);
    line-height: 1.55;
}

.lit-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.lit-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    background: #e8f0fe;
    color: var(--google-blue);
    font-size: 0.78rem;
    font-weight: 500;
}

.lit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.lit-progress-wrap {
    margin-bottom: 1rem;
}

.lit-progress-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: #e9edf2;
    overflow: hidden;
    border: 1px solid #dfe3e8;
}

.lit-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #1a73e8, #34a853);
    transition: width 0.4s ease;
}

.lit-status-text {
    margin-top: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.lit-export-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.lit-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.8rem;
    background: #fff;
}

.lit-section summary {
    cursor: pointer;
    font-weight: 500;
    padding: 0.7rem 0.9rem;
}

.lit-section-body {
    border-top: 1px solid var(--border);
    padding: 0.75rem;
}

.lit-table-wrap {
    overflow-x: auto;
}

.oa-badge {
    display: inline-block;
    margin-left: 0.4rem;
    font-size: 0.72rem;
    padding: 0.1rem 0.35rem;
    border-radius: 10px;
    background: #d4f8df;
    color: #0d7a34;
}

.confidence-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 12px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.conf-high {
    background: #d4f8df;
    color: #0d7a34;
}

.conf-medium {
    background: #fff4d3;
    color: #8a6700;
}

.conf-low {
    background: #fde1e1;
    color: #a13030;
}

.rank-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.7rem;
    margin-bottom: 0.6rem;
    background: #fcfcfd;
}

.rank-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.45rem;
}

.score-bar {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: #e9edf2;
    overflow: hidden;
    margin-bottom: 0.4rem;
}

.score-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #34a853, #1a73e8);
}

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

@media (max-width: 1100px) {
    main {
        grid-template-columns: 1fr;
    }

    .overview-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .explanation-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .overview-grid {
        grid-template-columns: 1fr;
    }

    .primary-analysis-tabs {
        overflow-x: auto;
    }

    .primary-tab-btn {
        min-width: 170px;
    }
}

/* ── Bubble chart legend & support note ─────────────────────────── */
.bubble-support-note {
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
    margin: 0.4rem 0 0.25rem;
    border-radius: 4px;
    color: var(--text-secondary);
    background: #f8f9fa;
    border-left: 3px solid #dadce0;
    transition: background 0.2s, border-color 0.2s;
}

.bubble-support-note.note-positive {
    background: #e6f4ea;
    border-left-color: #34a853;
    color: #1e7e34;
}

.bubble-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 1rem;
    padding: 0.45rem 0.25rem 0.2rem;
    border-top: 1px solid var(--border);
    margin-top: 0.35rem;
    font-size: 0.77rem;
    color: var(--text-secondary);
}

.bubble-legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}

.bubble-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid transparent;
    flex-shrink: 0;
}

.bubble-legend-size-note {
    margin-left: auto;
    color: #9aa0a6;
    font-style: italic;
}
