/* ==========================================
   ANALYTICS DASHBOARD STYLES
   Beautiful, modern analytics UI for Systems Modeler
   ========================================== */

/* ==========================================
   CHART STYLES
   ========================================== */
.chart-svg {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
}

.chart-svg .axis line,
.chart-svg .axis path {
    stroke: var(--border-color);
}

.chart-svg .axis text {
    fill: var(--text-secondary);
    font-size: 11px;
}

.chart-svg .grid line {
    stroke: var(--border-color);
    stroke-opacity: 0.2;
}

.chart-svg .grid path {
    stroke-width: 0;
}

.no-data {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-style: italic;
}

/* Chart tooltip */
.chart-tooltip {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 100;
    box-shadow: var(--shadow);
    max-width: 200px;
}

.tooltip-time {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.tooltip-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.25rem 0;
}

.tooltip-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tooltip-name {
    color: var(--text-secondary);
}

.tooltip-value {
    color: var(--text-primary);
    font-weight: 500;
    margin-left: auto;
}

/* Chart options panel */
.chart-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-panel);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
}

.chart-option-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-option-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.chart-option-btn {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chart-option-btn:hover {
    background: var(--bg-panel);
    color: var(--text-primary);
}

.chart-option-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.chart-export-btn {
    margin-left: auto;
    padding: 0.4rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.chart-export-btn:hover {
    background: var(--bg-panel);
    color: var(--text-primary);
}

/* ==========================================
   ANALYTICS DASHBOARD
   ========================================== */
.analytics-dashboard {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0.5rem;
}

.analytics-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    text-align: center;
}

/* Analytics sections */
.analytics-section {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    overflow: hidden;
}

.analytics-section-header {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    background: var(--bg-secondary);
    cursor: pointer;
    user-select: none;
    gap: 0.5rem;
    transition: background 0.15s ease;
}

.analytics-section-header:hover {
    background: var(--bg-panel);
}

.section-icon {
    font-size: 1.1rem;
}

.section-title {
    font-weight: 600;
    font-size: 0.9rem;
    flex: 1;
}

.section-toggle {
    color: var(--text-muted);
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.analytics-section.collapsed .section-toggle {
    transform: rotate(-90deg);
}

.analytics-section.collapsed .analytics-section-content {
    display: none;
}

.analytics-section-content {
    padding: 1rem;
}

/* Summary section */
.analytics-summary .summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.summary-item {
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    text-align: center;
}

.summary-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.summary-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-primary);
}

/* Statistics table */
.stats-table-wrapper {
    overflow-x: auto;
    margin: -0.5rem;
    padding: 0.5rem;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.stats-table th {
    text-align: left;
    padding: 0.5rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.7rem;
    border-bottom: 1px solid var(--border-color);
}

.stats-table td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-table .var-name {
    font-weight: 500;
    color: var(--accent-primary);
}

.stats-table .change {
    font-weight: 500;
}

.stats-table .change.positive {
    color: var(--accent-success);
}

.stats-table .change.negative {
    color: var(--accent-secondary);
}

/* Patterns section */
.patterns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.pattern-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 0.875rem;
    transition: transform 0.15s ease;
}

.pattern-card:hover {
    transform: translateY(-2px);
}

.pattern-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.pattern-var {
    font-weight: 600;
    font-size: 0.9rem;
}

.pattern-icon {
    font-size: 1.1rem;
}

.pattern-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.pattern-name {
    font-size: 0.8rem;
    font-weight: 500;
}

.equilibrium-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-top: 0.25rem;
}

.equilibrium-badge.reached {
    background: rgba(46, 204, 113, 0.2);
    color: var(--accent-success);
}

.equilibrium-badge.not-reached {
    background: rgba(233, 69, 96, 0.1);
    color: var(--text-muted);
}

.pattern-sparkline {
    height: 30px;
    margin-top: 0.5rem;
}

.pattern-sparkline svg {
    width: 100%;
    height: 100%;
}

/* Peaks section */
.peaks-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.peak-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.peak-icon {
    font-size: 0.9rem;
}

.peak-item.peak .peak-icon {
    color: var(--accent-success);
}

.peak-item.trough .peak-icon {
    color: var(--accent-secondary);
}

.peak-var {
    font-weight: 500;
    min-width: 80px;
}

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

.peak-info strong {
    color: var(--text-primary);
}

/* Correlations section */
.correlations-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.correlation-item {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.correlation-vars {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.correlation-arrow {
    color: var(--text-muted);
}

.correlation-bar-container {
    width: 60px;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.correlation-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.correlation-bar.positive {
    background: var(--accent-success);
}

.correlation-bar.negative {
    background: var(--accent-secondary);
}

.correlation-value {
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 50px;
    text-align: right;
}

.correlation-value.positive {
    color: var(--accent-success);
}

.correlation-value.negative {
    color: var(--accent-secondary);
}

.correlation-label {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    text-transform: capitalize;
    min-width: 100px;
    text-align: center;
}

.correlation-label.strong {
    background: rgba(46, 204, 113, 0.2);
    color: var(--accent-success);
}

.correlation-label.moderate {
    background: rgba(243, 156, 18, 0.2);
    color: var(--accent-warning);
}

.correlation-label.weak {
    background: rgba(160, 160, 160, 0.2);
    color: var(--text-secondary);
}

/* No data message */
.analytics-section .no-data {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

/* ==========================================
   AI AGENT STYLES
   ========================================== */
.ai-agent-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ai-agent-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.ai-agent-placeholder .ai-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.btn-analyze {
    margin-top: 1rem;
}

.ai-agent-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

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

.ai-agent-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--accent-secondary);
}

.ai-agent-error .error-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* AI Sections */
.ai-section {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 1rem;
}

.ai-section h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.ai-section h3 .ai-icon {
    font-size: 1rem;
}

.ai-summary p {
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Insights list */
.insights-list,
.recommendations-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.insight-item,
.recommendation-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.625rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.insight-bullet {
    color: var(--accent-primary);
    font-size: 0.5rem;
    margin-top: 0.4rem;
}

.insight-text,
.rec-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
}

.rec-bullet {
    color: var(--accent-success);
    font-size: 0.8rem;
}

/* Q&A Section */
.ai-qa {
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

.ai-conversation {
    flex: 1;
    min-height: 120px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 0.75rem;
    padding-right: 0.5rem;
}

.conversation-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 1rem;
}

.example-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
    justify-content: center;
}

.example-question {
    padding: 0.4rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.example-question:hover {
    background: var(--bg-panel);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.conversation-message {
    margin-bottom: 0.75rem;
    max-width: 85%;
}

.conversation-message.user {
    margin-left: auto;
}

.conversation-message.user .message-content {
    background: var(--accent-primary);
    color: white;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius) var(--radius) 4px var(--radius);
}

.conversation-message.assistant .message-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius) var(--radius) var(--radius) 4px;
}

.conversation-message.error .message-content {
    background: rgba(233, 69, 96, 0.1);
    color: var(--accent-secondary);
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
}

.supporting-insights {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.supporting-insights small {
    display: block;
    margin-bottom: 0.25rem;
}

.supporting-insights ul {
    margin: 0;
    padding-left: 1rem;
}

.supporting-insights li {
    margin: 0.25rem 0;
}

/* AI Input */
.ai-input-container {
    display: flex;
    gap: 0.5rem;
}

.ai-question-input {
    flex: 1;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.ai-question-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.ai-question-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-ask {
    padding: 0.75rem 1.25rem;
}

.ai-unavailable-notice {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
}

/* ==========================================
   RESPONSIVE STYLES
   ========================================== */

/* Mobile-first: Results tabs should always be visible */
.results-tabs {
    display: flex !important;
    flex-wrap: nowrap;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.results-tabs::-webkit-scrollbar {
    display: none;
}

.results-tabs-mobile {
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 10;
    padding: 0.5rem 0;
    margin: -1rem -1rem 0.75rem -1rem;
    padding: 0.75rem 1rem 0.5rem 1rem;
}

.results-tab {
    padding: 0.625rem 1rem;
    min-height: 48px; /* Touch target size */
    min-width: 80px;
    font-size: 0.85rem;
    flex-shrink: 0;
    white-space: nowrap;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Chart options for mobile */
.chart-options-mobile {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
}

.chart-options-mobile .chart-option-btn {
    min-height: 40px;
    padding: 0.5rem 1rem;
}

/* Very narrow portrait screens (375px and below) */
@media (max-width: 380px) {
    .results-tabs {
        gap: 0.125rem;
        flex-wrap: nowrap;
        justify-content: stretch;
    }

    .results-tab {
        padding: 0.5rem 0.25rem;
        min-width: 0;
        flex: 1 1 0;
        font-size: 0.65rem;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
    }

    /* Ensure tabs are visible by abbreviating on very small screens */
    .results-tabs-mobile .results-tab[data-tab="analytics-mobile"],
    .results-tabs .results-tab[data-tab="analytics"] {
        /* Keep Analytics visible */
    }
}

/* Portrait mode (narrow screens) - primary mobile breakpoint */
@media (max-width: 480px) {
    .results-tabs {
        gap: 0.25rem;
    }

    .results-tab {
        padding: 0.5rem 0.75rem;
        min-width: 70px;
        font-size: 0.75rem;
    }

    .analytics-section-header {
        padding: 0.75rem;
    }

    .section-title {
        font-size: 0.85rem;
    }

    .analytics-section-content {
        padding: 0.75rem;
    }

    .summary-item {
        padding: 0.5rem;
    }

    .summary-label {
        font-size: 0.65rem;
    }

    .summary-value {
        font-size: 1rem;
    }

    .ai-section {
        padding: 0.75rem;
    }

    .ai-section h3 {
        font-size: 0.85rem;
    }

    .ai-question-input {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 48px;
    }

    .btn-ask {
        min-height: 48px;
        padding: 0.75rem 1rem;
    }
}

@media (max-width: 600px) {
    .stats-table th,
    .stats-table td {
        padding: 0.375rem;
        font-size: 0.75rem;
    }

    .patterns-grid {
        grid-template-columns: 1fr;
    }

    .correlation-item {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .correlation-bar-container {
        width: 100%;
    }

    .example-questions {
        flex-direction: column;
    }

    .example-question {
        width: 100%;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Analytics dashboard adjustments */
    .analytics-dashboard {
        gap: 0.75rem;
        padding: 0.25rem;
    }

    /* Peak items */
    .peak-item {
        flex-wrap: wrap;
    }

    .peak-var {
        min-width: auto;
    }

    /* AI conversation */
    .ai-conversation {
        max-height: 200px;
    }

    .conversation-message {
        max-width: 95%;
    }
}

/* ==========================================
   RESULTS PANEL ENHANCEMENTS
   ========================================== */
/* Base styles moved to responsive section above */

.results-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.results-tab.active {
    background: var(--accent-primary);
    color: white;
}

.results-tab-content {
    display: none;
}

.results-tab-content.active {
    display: block;
}

/* ==========================================
   VARIABLE TOGGLES
   ========================================== */
.chart-variables {
    margin-bottom: 0.75rem;
}

.variable-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.variable-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

.variable-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

.variable-toggle .color-picker {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
}

.variable-toggle .color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.variable-toggle .color-picker::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.variable-toggle label {
    cursor: pointer;
    color: var(--text-secondary);
    user-select: none;
}

.variable-toggle label:hover {
    color: var(--text-primary);
}

/* ==========================================
   SENSITIVITY SECTION
   ========================================== */
.sensitivity-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.sensitivity-item {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.sensitivity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.sensitivity-var {
    font-weight: 500;
    font-size: 0.9rem;
}

.sensitivity-value {
    font-weight: 600;
    color: var(--accent-primary);
}

.sensitivity-bar-container {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.sensitivity-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.sensitivity-bar.high {
    background: linear-gradient(90deg, var(--accent-secondary), #ff6b6b);
}

.sensitivity-bar.medium {
    background: linear-gradient(90deg, var(--accent-warning), #ffc107);
}

.sensitivity-bar.low {
    background: linear-gradient(90deg, var(--accent-success), #6bcf7b);
}

.sensitivity-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    display: inline-block;
}

.sensitivity-label.high {
    background: rgba(233, 69, 96, 0.2);
    color: var(--accent-secondary);
}

.sensitivity-label.medium {
    background: rgba(243, 156, 18, 0.2);
    color: var(--accent-warning);
}

.sensitivity-label.low {
    background: rgba(46, 204, 113, 0.2);
    color: var(--accent-success);
}

/* ==========================================
   MOBILE PORTRAIT CRITICAL FIXES
   ========================================== */

/* Ensure slide panel content is scrollable */
.slide-panel-content {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Force results tabs to always display in row - ALL screen sizes */
.results-tabs,
.results-tabs-mobile {
    display: flex !important;
    flex-direction: row !important;
    visibility: visible !important;
    opacity: 1 !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 0.25rem;
}

.results-tabs::-webkit-scrollbar,
.results-tabs-mobile::-webkit-scrollbar {
    display: none;
}

/* Ensure tab buttons are always visible */
.results-tab {
    display: inline-flex !important;
    flex: 0 0 auto;
}

/* Mobile portrait mode - ensure Analytics tab is always visible */
@media (max-width: 400px) {
    .results-tabs,
    .results-tabs-mobile {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
    }

    .results-tabs::-webkit-scrollbar,
    .results-tabs-mobile::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .results-tab {
        flex: 1 0 auto;
        min-width: 70px;
        padding: 0.625rem 0.5rem;
        font-size: 0.7rem;
    }
}

/* Mobile scrolling - only for slide panels, not main content */
@media (max-width: 900px) {
    /* Slide panel should be scrollable internally */
    .slide-panel {
        overflow: hidden;
        position: fixed;
    }

    .slide-panel-content {
        flex: 1;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* Ensure tab content inside slide panel can scroll */
    .slide-panel-content .results-tab-content {
        max-height: none;
        overflow-y: visible;
    }

    .slide-panel-content .results-tab-content.active {
        display: block;
        overflow-y: visible;
    }

    /* Analytics container scrollable */
    .slide-panel-content #analytics-container-mobile,
    .slide-panel-content #ai-agent-container-mobile {
        overflow-y: visible;
        max-height: none;
    }

    /* Chart container responsive sizing */
    .slide-panel-content .chart-container {
        height: 200px;
        min-height: 150px;
    }
}

/* iPhone SE and similar very narrow screens */
@media (max-width: 375px) {
    .results-tabs,
    .results-tabs-mobile {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: stretch;
        gap: 0.125rem;
    }

    .results-tab {
        padding: 0.5rem 0.25rem;
        font-size: 0.65rem;
        min-width: 0;
        flex: 1;
        text-align: center;
    }

    .analytics-section-header {
        padding: 0.625rem 0.5rem;
    }

    .section-title {
        font-size: 0.8rem;
    }

    .analytics-section-content {
        padding: 0.5rem;
    }

    .ai-section {
        padding: 0.5rem;
    }

    .ai-section h3 {
        font-size: 0.8rem;
    }
}

/* Touch-friendly improvements for analytics */
@media (hover: none) and (pointer: coarse) {
    .results-tab {
        min-height: 48px;
    }

    .analytics-section-header {
        min-height: 48px;
    }

    .example-question {
        min-height: 44px;
        padding: 0.75rem;
    }

    .btn-ask {
        min-height: 48px;
        min-width: 48px;
    }
}

/* ==========================================
   FULLSCREEN ANALYTICS MODE
   ========================================== */
.analytics-fullscreen-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.15s ease;
    z-index: 10;
}

.analytics-fullscreen-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.results-panel {
    position: relative;
}

/* Fullscreen overlay */
.analytics-fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-primary);
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.analytics-fullscreen-overlay.active {
    display: flex;
}

.fullscreen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.fullscreen-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.fullscreen-close-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.fullscreen-close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.fullscreen-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.fullscreen-tab {
    padding: 0.625rem 1.25rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: all 0.15s ease;
}

.fullscreen-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.fullscreen-tab.active {
    background: var(--accent-primary);
    color: white;
}

.fullscreen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1rem;
}

/* Fullscreen layout: Chart at top, analytics at bottom */
.fullscreen-chart-section {
    height: 50%;
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

.fullscreen-chart-section .chart-container {
    flex: 1;
    min-height: 0;
    height: 100%;
}

.fullscreen-analytics-section {
    height: 50%;
    overflow-y: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    -webkit-overflow-scrolling: touch;
}

.fullscreen-tab-content {
    display: none;
    height: 100%;
    overflow: hidden;
}

.fullscreen-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Full chart view in fullscreen */
.fullscreen-tab-content.chart-only .chart-container {
    height: 100%;
}

/* Mobile fullscreen adjustments */
@media (max-width: 600px) {
    .fullscreen-header {
        padding: 0.5rem;
    }

    .fullscreen-header h2 {
        font-size: 0.9rem;
    }

    .fullscreen-tabs {
        padding: 0.25rem 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .fullscreen-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        min-width: 70px;
        flex-shrink: 0;
    }

    .fullscreen-content {
        padding: 0.5rem;
    }

    .fullscreen-chart-section {
        height: 45%;
    }

    .fullscreen-analytics-section {
        height: 55%;
    }
}

/* Portrait mode on mobile */
@media (max-width: 480px) and (orientation: portrait) {
    .fullscreen-chart-section {
        height: 40%;
        min-height: 150px;
    }

    .fullscreen-analytics-section {
        height: 60%;
    }
}

/* ==========================================
   AI MODEL FEEDBACK SYSTEM STYLES
   ========================================== */

.ai-feedback {
    border: 1px solid var(--accent-primary);
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, rgba(74, 144, 217, 0.1) 100%);
}

.ai-feedback h3 {
    color: var(--accent-primary);
}

.feedback-tools {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.feedback-tool {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.feedback-tool h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.feedback-tool p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.feedback-tool .btn {
    margin-top: 0.5rem;
}

/* Refine input */
.refine-input-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.refine-feedback-input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.refine-feedback-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Fit data input */
.fit-data-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.fit-variable-select {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.fit-data-input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: monospace;
    resize: vertical;
    min-height: 80px;
}

.fit-data-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Feedback result container */
.feedback-result-container {
    margin-top: 1rem;
    min-height: 60px;
}

.feedback-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.feedback-loading .loading-spinner {
    margin-bottom: 0.75rem;
}

/* Feedback result styles */
.feedback-result {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 1rem;
    border-left: 4px solid var(--border-color);
}

.feedback-result.success {
    border-left-color: var(--accent-success);
}

.feedback-result.partial {
    border-left-color: var(--accent-warning);
}

.feedback-result.error {
    border-left-color: var(--accent-secondary);
}

.feedback-result h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.feedback-result.success h4 {
    color: var(--accent-success);
}

.feedback-result.partial h4 {
    color: var(--accent-warning);
}

.feedback-result.error h4 {
    color: var(--accent-secondary);
}

.feedback-result .feedback-message {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.feedback-params,
.feedback-equilibrium,
.feedback-suggestions {
    margin: 0.75rem 0;
}

.feedback-params h5,
.feedback-equilibrium h5,
.feedback-suggestions h5 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.feedback-params ul,
.feedback-equilibrium ul {
    list-style: none;
    padding: 0;
    font-size: 0.85rem;
}

.feedback-params li,
.feedback-equilibrium li {
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border-color);
}

.feedback-params li:last-child,
.feedback-equilibrium li:last-child {
    border-bottom: none;
}

.convergence-time {
    font-size: 0.85rem;
    color: var(--accent-success);
    margin: 0.5rem 0;
}

/* Metrics display */
.feedback-metrics {
    display: flex;
    gap: 1rem;
    margin: 0.75rem 0;
}

.feedback-metrics .metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    min-width: 80px;
}

.feedback-metrics .metric-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.feedback-metrics .metric-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.feedback-metrics .metric-value.good {
    color: var(--accent-success);
}

/* Suggestion items */
.suggestion-item {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.suggestion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.suggestion-header strong {
    color: var(--accent-primary);
}

.suggestion-change {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.suggestion-reason {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

.feedback-explanation {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 0.75rem;
}

/* Mobile responsiveness for feedback */
@media (max-width: 600px) {
    .feedback-tool {
        padding: 0.75rem;
    }

    .refine-input-container,
    .fit-data-container {
        gap: 0.5rem;
    }

    .feedback-metrics {
        flex-direction: column;
        gap: 0.5rem;
    }

    .feedback-metrics .metric {
        flex-direction: row;
        justify-content: space-between;
    }

    .suggestion-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
}
