/* CSS Variables - Dark Theme */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-panel: #1f2940;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --text-muted: #6a6a6a;
    --accent-primary: #4a90d9;
    --accent-secondary: #e94560;
    --accent-success: #2ecc71;
    --accent-warning: #f39c12;
    --border-color: #2a3a50;
    --stock-color: #4a90d9;
    --flow-color: #9b59b6;
    --variable-color: #e67e22;
    --connector-color: #7f8c8d;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-sm: 4px;

    /* Touch target sizes - minimum 48px for accessibility */
    --touch-target: 48px;
    --touch-target-sm: 44px;

    /* Safe area insets for notched phones */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;
    height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
    overflow: hidden; /* No scrolling - fit to screen */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* App Layout - Mobile First */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}

/* ==========================================
   HEADER - Mobile First
   ========================================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    padding-left: calc(0.5rem + var(--safe-area-left));
    padding-right: calc(0.5rem + var(--safe-area-right));
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 0.5rem;
    min-height: 56px;
    flex-shrink: 0;
    z-index: 50;
}

.header-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.logo {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-primary);
    white-space: nowrap;
}

/* Hide "Systems Modeler" text on small screens */
.logo-text {
    display: none;
}

.model-name-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-align: center;
    width: 100%;
    max-width: 150px;
    min-height: var(--touch-target);
}

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

.model-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    color: var(--text-primary);
    cursor: pointer;
    min-width: 80px;
    min-height: var(--touch-target);
    font-size: 0.875rem;
}

/* ==========================================
   BUTTONS - 48px Touch Targets
   ========================================== */
.btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    min-height: var(--touch-target);
    min-width: var(--touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background-color: #3a80c9;
}

.btn-primary:active {
    background-color: #2a70b9;
    transform: scale(0.98);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-panel);
}

.btn-secondary:active {
    background-color: var(--bg-secondary);
    transform: scale(0.98);
}

.btn-tool {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    flex-direction: column;
    font-size: 0.7rem;
    gap: 0.25rem;
    min-width: 52px;
}

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

.btn-tool:active {
    background-color: var(--bg-panel);
}

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

.btn-danger {
    color: var(--accent-secondary);
}

.btn-danger:hover {
    background-color: var(--accent-secondary);
    color: white;
}

.btn-danger:active {
    background-color: #d03050;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-icon-only {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

/* ==========================================
   MAIN CONTENT - Mobile First
   ========================================== */
.main-content {
    height: 0; /* Allow flex to control height */
    display: flex;
    flex-direction: column;
    flex: 1;
    
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* ==========================================
   CANVAS AREA - Mobile First
   ========================================== */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex child overflow */
    position: relative;
}

.canvas-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background-color: var(--bg-primary);
    background-image:
        linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    touch-action: none; /* Enable custom touch handling */
}

.canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ==========================================
   BOTTOM TOOLBAR - Mobile First
   ========================================== */
.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0.5rem;
    padding-left: calc(0.5rem + var(--safe-area-left));
    padding-right: calc(0.5rem + var(--safe-area-right));
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    gap: 0.25rem;
    flex-shrink: 0;
    min-height: 64px;
}

.toolbar-separator {
    display: none;
}

/* ==========================================
   TAB BAR - Mobile Only
   ========================================== */
.tab-bar {
    display: flex;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    padding-bottom: var(--safe-area-bottom);
}

.tab-btn {
    flex: 1;
    padding: 0.5rem;
    padding-top: 0.75rem;
    background: transparent;
    border: none;
    border-top: 3px solid transparent;
    color: var(--text-secondary);
    font-size: 0.7rem;
    cursor: pointer;
    min-height: var(--touch-target);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.tab-btn:active {
    background-color: var(--bg-tertiary);
}

.tab-btn.active {
    border-top-color: var(--accent-primary);
    color: var(--accent-primary);
    background-color: var(--bg-panel);
}

.tab-btn svg {
    width: 22px;
    height: 22px;
}

/* ==========================================
   SLIDE-UP PANEL - Mobile
   ========================================== */
.slide-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.slide-panel.open {
    transform: translateY(0);
}

.slide-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    min-height: 56px;
}

.slide-panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.slide-panel-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.75rem;
    cursor: pointer;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    -webkit-tap-highlight-color: transparent;
}

.slide-panel-close:active {
    background-color: var(--bg-tertiary);
}

.slide-panel-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    max-height: calc(70vh - 56px); /* Account for header */
}

/* Ensure content inside slide panel can scroll */
.slide-panel-content .results-tab-content {
    min-height: 0;
    overflow-y: auto;
}

/* ==========================================
   PANELS - Hidden on Mobile
   ========================================== */
.panel {
    display: none;
}

/* ==========================================
   LLM STATUS
   ========================================== */
.llm-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    background-color: var(--bg-tertiary);
}

.llm-status.available {
    background-color: rgba(46, 204, 113, 0.2);
    color: var(--accent-success);
}

.llm-status.unavailable {
    background-color: rgba(233, 69, 96, 0.2);
    color: var(--accent-secondary);
}

/* ==========================================
   CHAT CONTAINER
   ========================================== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 250px;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.chat-message {
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    max-width: 90%;
    word-wrap: break-word;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-message.user {
    background-color: var(--accent-primary);
    color: white;
    align-self: flex-end;
}

.chat-message.assistant {
    background-color: var(--bg-tertiary);
    align-self: flex-start;
}

.chat-message.error {
    background-color: rgba(233, 69, 96, 0.2);
    color: var(--accent-secondary);
}

.chat-message p {
    margin-bottom: 0.5rem;
}

.chat-message p:last-child {
    margin-bottom: 0;
}

.examples {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.examples-list {
    font-size: 0.8rem;
    margin-left: 1rem;
    color: var(--text-muted);
}

.examples-list li {
    margin-top: 0.25rem;
}

.chat-input-container {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.875rem;
    color: var(--text-primary);
    resize: none;
    font-family: inherit;
    font-size: 16px; /* Prevent zoom on iOS */
    min-height: var(--touch-target);
    line-height: 1.4;
}

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

.btn-send {
    align-self: flex-end;
    min-width: 70px;
}

/* ==========================================
   PROPERTIES PANEL
   ========================================== */
.properties-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.no-selection, .no-results {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    text-align: center;
    padding: 2rem 1rem;
}

.property-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.property-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.property-group input,
.property-group select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.875rem;
    color: var(--text-primary);
    font-size: 16px; /* Prevent zoom on iOS */
    min-height: var(--touch-target);
    width: 100%;
}

.property-group input:focus,
.property-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ==========================================
   RESULTS PANEL
   ========================================== */
.results-content {
    margin-bottom: 1rem;
}

.results-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    padding: 0.25rem 0;
}

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

.chart-container {
    width: 100%;
    height: 300px;
    min-height: 200px;
    max-height: 50vh;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.chart-container:empty {
    display: none;
}

/* Ensure chart SVG fills container */
.chart-container svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Ensure chart container in mobile slide panel has proper height */
.slide-panel-content .chart-container {
    height: 220px;
    min-height: 180px;
    max-height: 35vh;
}

/* ==========================================
   CHART STYLES
   ========================================== */
.chart-container svg {
    width: 100%;
    height: 100%;
}

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

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

.chart-line {
    fill: none;
    stroke-width: 2.5;
}

.chart-legend {
    font-size: 11px;
    fill: var(--text-primary);
}

/* ==========================================
   CANVAS ELEMENTS
   ========================================== */
.stock-rect {
    fill: var(--stock-color);
    stroke: white;
    stroke-width: 2;
    cursor: move;
}

.stock-rect.selected {
    stroke: var(--accent-warning);
    stroke-width: 3;
}

.flow-valve {
    fill: var(--flow-color);
    stroke: white;
    stroke-width: 2;
    cursor: move;
}

.flow-valve.selected {
    stroke: var(--accent-warning);
    stroke-width: 3;
}

.variable-circle {
    fill: var(--variable-color);
    stroke: white;
    stroke-width: 2;
    cursor: move;
}

.variable-circle.selected {
    stroke: var(--accent-warning);
    stroke-width: 3;
}

.element-label {
    fill: white;
    font-size: 12px;
    text-anchor: middle;
    pointer-events: none;
    font-weight: 500;
}

.connector-line {
    stroke: var(--connector-color);
    stroke-width: 2;
    stroke-dasharray: 5, 5;
    fill: none;
}

.flow-line {
    stroke: var(--flow-color);
    stroke-width: 3;
    fill: none;
    marker-end: url(#arrowhead);
}

/* ==========================================
   LOADING SPINNER
   ========================================== */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--bg-tertiary);
    border-radius: 50%;
    border-top-color: var(--accent-primary);
    animation: spin 0.8s ease-in-out infinite;
}

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

/* ==========================================
   ICON SHAPES - Touch Friendly
   ========================================== */
.icon-stock {
    width: 22px;
    height: 16px;
    background: var(--stock-color);
    border: 2px solid white;
    border-radius: 3px;
}

.icon-flow {
    width: 0;
    height: 0;
    border-left: 11px solid transparent;
    border-right: 11px solid transparent;
    border-bottom: 16px solid var(--flow-color);
}

.icon-variable {
    width: 18px;
    height: 18px;
    background: var(--variable-color);
    border-radius: 50%;
    border: 2px solid white;
}

.icon-connect {
    font-size: 1.25rem;
    color: var(--connector-color);
}

.icon-connect::before {
    content: '\2192';
}

.icon-delete {
    font-size: 1.25rem;
}

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

/* ==========================================
   SCROLLBAR STYLING
   ========================================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==========================================
   OVERLAY FOR MODALS
   ========================================== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ==========================================
   ZOOM INDICATOR
   ========================================== */
.zoom-indicator {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: var(--bg-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    z-index: 10;
    pointer-events: none;
    opacity: 0.85;
    border: 1px solid var(--border-color);
}

/* ==========================================
   MODE INDICATOR
   ========================================== */
.mode-indicator {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-primary);
    color: white;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    box-shadow: var(--shadow);
}

.mode-indicator.visible {
    opacity: 1;
}

/* ==========================================
   TOAST NOTIFICATION
   ========================================== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.toast.visible {
    opacity: 1;
}

.toast.success {
    border-color: var(--accent-success);
}

.toast.error {
    border-color: var(--accent-secondary);
}

/* ==========================================
   TABLET BREAKPOINT (600px+)
   ========================================== */
@media (min-width: 600px) {
    .header {
        padding: 0.75rem 1rem;
    }

    .logo {
        font-size: 1rem;
    }

    .logo-text {
        display: inline;
    }

    .model-name-input {
        max-width: 220px;
    }

    .btn-tool {
        flex-direction: row;
        font-size: 0.8rem;
        padding: 0.5rem 0.875rem;
        min-width: auto;
    }

    .toolbar-separator {
        display: block;
        width: 1px;
        height: 28px;
        background-color: var(--border-color);
        margin: 0 0.5rem;
    }

    .chat-message {
        max-width: 80%;
    }

    .chart-container {
        height: 320px;
    }

    .slide-panel {
        max-height: 65vh;
    }
}

/* ==========================================
   DESKTOP BREAKPOINT (900px+)
   ========================================== */
@media (min-width: 900px) {
    /* Switch to 3-column layout */
    .main-content {
    height: 0; /* Allow flex to control height */
        flex-direction: row;
    }

    /* Show panels on desktop */
    .panel {
        display: flex;
        flex-direction: column;
        background-color: var(--bg-panel);
    }

    .panel-left {
        width: 280px;
        flex-shrink: 0;
        border-right: 1px solid var(--border-color);
        overflow: hidden;
    }

    .panel-right {
        width: 280px;
        flex-shrink: 0;
        border-left: 1px solid var(--border-color);
        overflow-y: auto;
        overflow-x: hidden;
        display: flex;
        flex-direction: column;
    }

    /* Hide mobile tab bar on desktop */
    .tab-bar {
        display: none;
    }

    /* Hide slide panel on desktop */
    .slide-panel {
        display: none !important;
    }

    .overlay {
        display: none !important;
    }

    /* Canvas area is center column */
    .canvas-area {
        flex: 1;
        min-width: 0;
        border: none;
        overflow: hidden;
    }

    /* Toolbar at top on desktop */
    .canvas-toolbar {
        justify-content: flex-start;
        border-top: none;
        border-bottom: 1px solid var(--border-color);
        order: -1;
        padding: 0.4rem 0.5rem;
        flex-wrap: wrap;
        gap: 0.25rem;
        min-height: auto;
    }

    .canvas-toolbar .btn-tool {
        padding: 0.35rem 0.6rem;
        font-size: 0.7rem;
        min-width: auto;
        min-height: 36px;
    }

    .canvas-toolbar .btn-primary {
        padding: 0.35rem 0.8rem;
        min-height: 36px;
    }

    .toolbar-separator {
        display: block;
        width: 1px;
        height: 24px;
        background: var(--border-color);
        margin: 0 0.25rem;
    }

    /* Desktop header styling */
    .header {
        padding: 0.75rem 1.5rem;
        gap: 1rem;
    }

    .logo {
        font-size: 1.25rem;
    }

    .model-name-input {
        max-width: 280px;
    }

    /* Panel header styling */
    .panel-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
        min-height: 56px;
    }

    .panel-header h2 {
        font-size: 0.875rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-secondary);
    }

    /* Chat fills left panel */
    .chat-container {
        flex: 1;
        padding: 1rem;
        min-height: auto;
    }

    .chat-header {
        display: none;
    }

    /* Properties panel - compact when empty */
    .properties-panel {
        padding: 0.5rem 0.75rem;
        border-bottom: 1px solid var(--border-color);
    }

    .properties-panel .no-selection {
        display: none;
    }

    .properties-panel h2 {
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-secondary);
        margin-bottom: 0;
    }

    .properties-panel:has(.property-group) h2 {
        margin-bottom: 0.5rem;
    }

    /* Results panel */
    .results-panel {
        padding: 0.5rem 0.75rem;
        position: relative;
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .results-panel h2 {
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-secondary);
        margin-bottom: 0.25rem;
    }

    .chart-container {
        min-height: 160px;
        max-height: 300px;
        height: 220px;
        flex-shrink: 0;
    }

    .chart-container:empty {
        display: none;
    }

    /* Chart options - compact row below chart */
    .chart-options {
        display: flex;
        flex-wrap: wrap;
        gap: 0.2rem;
        margin-top: 0.25rem;
        margin-bottom: 0.25rem;
    }

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

    .chart-option-label {
        font-size: 0.7rem;
        color: var(--text-muted);
    }

    .chart-option-btn {
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
        cursor: pointer;
        white-space: nowrap;
    }

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

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

    .chart-export-btn {
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
        cursor: pointer;
    }

    /* Variable toggles */
    .chart-variables {
        max-height: 80px;
        overflow-y: auto;
        margin-bottom: 0.5rem;
    }

    .variable-toggles {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .variable-toggle {
        display: flex;
        align-items: center;
        gap: 0.25rem;
        font-size: 0.75rem;
    }

    .variable-toggle label {
        font-size: 0.75rem;
        color: var(--text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 80px;
    }

    .variable-toggle .color-picker {
        width: 18px;
        height: 18px;
        border: none;
        padding: 0;
        cursor: pointer;
    }

    /* Results tabs */
    .results-tabs {
        display: flex;
        gap: 0.25rem;
        margin-bottom: 0.25rem;
        flex-shrink: 0;
    }

    .results-tab {
        flex: 1;
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
        cursor: pointer;
        text-align: center;
    }

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

    .results-tab-content {
        display: none;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }

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

    /* Results content with final values */
    .results-content {
        font-size: 0.8rem;
        margin-top: 0.5rem;
        max-height: 120px;
        overflow-y: auto;
    }

    /* Fullscreen button */
    .analytics-fullscreen-btn {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        padding: 0.25rem 0.5rem;
        border-radius: var(--radius-sm);
        cursor: pointer;
        font-size: 0.8rem;
        z-index: 5;
    }
}

/* ==========================================
   LARGE DESKTOP (1200px+)
   ========================================== */
@media (min-width: 1200px) {
    .panel-left, .panel-right {
        width: 320px;
    }

    .btn-tool {
        padding: 0.5rem 1.25rem;
    }
}

/* ==========================================
   EXTRA LARGE DESKTOP (1600px+)
   ========================================== */
@media (min-width: 1600px) {
    .panel-left, .panel-right {
        width: 380px;
    }
}

/* ==========================================
   TOUCH-SPECIFIC STYLES
   ========================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets on touch devices */
    .btn {
        min-height: var(--touch-target);
    }

    .property-group input,
    .property-group select {
        min-height: var(--touch-target);
        padding: 0.875rem;
    }

    /* Disable hover effects on touch devices */
    .btn:hover {
        background-color: inherit;
    }

    .btn-primary:hover {
        background-color: var(--accent-primary);
    }

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

    .btn-tool:hover {
        background-color: transparent;
        color: var(--text-secondary);
    }

    .btn-tool.active:hover {
        background-color: var(--accent-primary);
        color: white;
    }

    .btn-danger:hover {
        background-color: transparent;
        color: var(--accent-secondary);
    }

    /* Improve tap feedback */
    .btn:active {
        transform: scale(0.96);
    }

    .tab-btn:active {
        transform: scale(0.96);
    }
}

/* ==========================================
   LANDSCAPE PHONE ADJUSTMENTS
   ========================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        min-height: 48px;
        padding: 0.25rem 0.5rem;
    }

    .canvas-toolbar {
        min-height: 52px;
        padding: 0.25rem;
    }

    .tab-bar {
        padding-bottom: 0;
    }

    .slide-panel {
        max-height: 85vh;
    }

    .btn-tool {
        min-height: 44px;
        min-width: 44px;
    }
}

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

    .slide-panel {
        transition: none;
    }

    .overlay {
        transition: none;
    }
}

/* ==========================================
   DARK MODE SPECIFIC (for future light mode)
   ========================================== */
@media (prefers-color-scheme: dark) {
    /* Already dark by default, but could add tweaks here */
}

/* ==========================================
   HIGH CONTRAST MODE
   ========================================== */
@media (prefers-contrast: high) {
    :root {
        --border-color: #4a5a70;
        --text-secondary: #c0c0c0;
    }

    .btn {
        border-width: 2px;
    }

    .stock-rect,
    .flow-valve,
    .variable-circle {
        stroke-width: 3;
    }
}

/* ==========================================
   FLOATING ACTION BUTTON (FAB) - Mobile Only
   ========================================== */
.fab-container { 
    display: none;
    position: fixed;
    bottom: 140px;
    left: 120px;
    z-index: 90;
}

.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(74, 144, 217, 0.8);
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.fab:active {
    transform: scale(0.92);
    background: rgba(74, 144, 217, 1);
}

.fab.open {
    transform: rotate(45deg);
    background: rgba(233, 69, 96, 0.9);
}

.fab-icon {
    font-weight: 300;
    line-height: 1;
    transition: transform 0.3s ease;
}

.fab-menu {
    position: absolute;
    bottom: 70px;
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fab-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.fab-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.fab-item:active {
    transform: scale(0.95);
    background: var(--bg-tertiary);
}

.fab-item .icon-stock,
.fab-item .icon-flow,
.fab-item .icon-variable {
    transform: scale(0.9);
}

.fab-item .icon-connect::before {
    font-size: 1.1rem;
}

.fab-danger {
    color: var(--accent-secondary);
    border-color: rgba(233, 69, 96, 0.3);
}

.fab-danger:active {
    background: rgba(233, 69, 96, 0.2);
}

.fab-delete-icon {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--accent-secondary);
}

/* Mobile Simulate Button */
.mobile-settings-btn {
    display: none;
    position: fixed;
    bottom: 140px;
    left: 90px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 90;
    touch-action: manipulation;
}

.mobile-settings-btn:active {
    transform: scale(0.95);
    background: var(--bg-tertiary);
}

.mobile-simulate-btn, .mobile-settings-btn {
    display: none;
    position: fixed;
    bottom: 140px;
    left: 20px;
    padding: 14px 24px;
    background: var(--accent-primary);
    border: none;
    border-radius: 28px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: all 0.15s ease;
    z-index: 90;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mobile-simulate-btn:active {
    transform: scale(0.95);
    background: #3a80c9;
}

/* Show FAB and hide desktop toolbar on mobile */
@media (max-width: 899px) {
    .desktop-toolbar {
        display: none !important;
    }

    .fab-container { 
        display: block;
    }

    .mobile-simulate-btn, .mobile-settings-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Adjust FAB position when tab bar is visible */
@media (max-width: 899px) {
    .fab-container { 
        bottom: calc(64px + var(--safe-area-bottom) + 16px);
    }

    .mobile-simulate-btn, .mobile-settings-btn {
        bottom: calc(64px + var(--safe-area-bottom) + 16px);
    }
}

/* Landscape mobile - move FAB up less */
@media (max-height: 500px) and (orientation: landscape) {
    .fab-container { 
        bottom: calc(52px + 15px);
    }

    .mobile-simulate-btn, .mobile-settings-btn {
        bottom: calc(52px + 15px);
    }

    .fab {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }

    .fab-menu {
        bottom: 60px;
        gap: 8px;
    }

    .fab-item {
        padding: 10px 14px;
        font-size: 0.8rem;
    }
}

/* ==========================================
   SETTINGS ICON
   ========================================== */
.icon-settings {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* ==========================================
   MODAL STYLES
   ========================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

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

.modal {
    background: var(--bg-panel);
    border-radius: var(--radius);
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

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

.modal-body {
    padding: 1rem;
}

.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Settings form styles */
.settings-group {
    margin-bottom: 1rem;
}

.settings-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.settings-group 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: 1rem;
}

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

.settings-info {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--accent-primary);
    text-align: center;
    margin-bottom: 1rem;
}

.settings-presets {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.presets-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

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

.preset-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.preset-btn:active {
    transform: scale(0.98);
}

/* ===========================================
/* ===========================================
   CRITICAL MOBILE VERTICAL FIX - NO SCROLL
   =========================================== */
@media (max-width: 768px) and (orientation: portrait) {
    html, body {
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }
    
    .app {
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .header {
        flex-shrink: 0 !important;
    }
    
    .main-content {
        flex: 1 1 0 !important;
        height: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .canvas-area {
        flex: 1 1 0 !important;
        height: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .canvas-container {
        flex: 1 1 0 !important;
        height: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }
    
    .tab-bar {
        flex-shrink: 0 !important;
        flex-grow: 0 !important;
        position: relative !important;
    }
    
    /* Ensure SVG fits */
    .canvas, #canvas {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
    }
}

/* ===========================================
   MOBILE SLIDE PANEL EXPAND/COLLAPSE
   =========================================== */
.slide-panel-expand {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    margin-right: 0.5rem;
    -webkit-tap-highlight-color: transparent;
}

.slide-panel-expand:active {
    background-color: var(--bg-tertiary);
    color: var(--accent-primary);
}

/* Fullscreen mode for slide panel */
.slide-panel.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    max-height: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    transform: translateY(0) !important;
    z-index: 200 !important;
}

.slide-panel.fullscreen .slide-panel-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding-top: calc(0.5rem + var(--safe-area-top));
}

.slide-panel.fullscreen .slide-panel-content {
    max-height: none !important;
    height: calc(100% - 60px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* Chart container in fullscreen gets more space */
.slide-panel.fullscreen .chart-container {
    height: 45vh !important;
    min-height: 250px !important;
    max-height: none !important;
}

/* Analytics content in fullscreen */
.slide-panel.fullscreen #analytics-container,
.slide-panel.fullscreen #ai-agent-container {
    max-height: none;
}

/* ===========================================
   FLOATING MODEL TITLE ON CANVAS
   =========================================== */
.floating-title {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
}

.floating-title-input {
    background: rgba(26, 26, 46, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(74, 144, 217, 0.3);
    border-radius: 12px;
    padding: 10px 20px;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    min-width: 200px;
    max-width: 80vw;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
}

.floating-title-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 4px 24px rgba(74, 144, 217, 0.3);
}

.floating-title-input::placeholder {
    color: var(--text-muted);
}

/* Hide original header title on mobile */
@media (max-width: 899px) {
    .header-center {
        display: none !important;
    }
    
    .floating-title {
        top: 12px;
    }
    
    .floating-title-input {
        font-size: 0.95rem;
        padding: 8px 16px;
        min-width: 150px;
    }
}

/* Desktop - keep both but make floating more prominent */
@media (min-width: 900px) {
    .header-center {
        visibility: hidden;
    }
    
    .floating-title-input {
        font-size: 1.2rem;
        padding: 12px 24px;
    }
}
/* ===========================================
   REDESIGNED COMPACT HEADER
   =========================================== */

/* Override header styles */
.header {
    min-height: 44px !important;
    padding: 6px 12px !important;
    background: rgba(22, 33, 62, 0.95) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2) !important;
}

.logo {
    font-size: 0.85rem !important;
    opacity: 0.9;
}

.logo-text {
    display: inline !important;
    background: linear-gradient(135deg, var(--accent-primary), #6bb3f0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Hide center on all sizes since title is floating */
.header-center {
    display: none !important;
}

/* Compact icon buttons */
.header .btn {
    min-height: 36px !important;
    min-width: 36px !important;
    padding: 6px 12px !important;
    font-size: 0.75rem !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    transition: all 0.2s ease !important;
}

.header .btn:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(74, 144, 217, 0.4) !important;
}

.header .btn-primary {
    background: rgba(74, 144, 217, 0.8) !important;
    border-color: rgba(74, 144, 217, 0.6) !important;
}

.header .btn-primary:hover {
    background: rgba(74, 144, 217, 1) !important;
}

/* Compact select dropdown */
.model-select {
    min-height: 36px !important;
    padding: 6px 10px !important;
    font-size: 0.75rem !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    min-width: 70px !important;
}

.header-right {
    gap: 6px !important;
}

/* Mobile: even more compact */
@media (max-width: 600px) {
    .header {
        padding: 4px 8px !important;
        min-height: 40px !important;
    }
    
    .logo {
        font-size: 0.75rem !important;
    }
    
    .header .btn {
        min-height: 32px !important;
        min-width: 32px !important;
        padding: 4px 8px !important;
        font-size: 0.7rem !important;
    }
    
    .model-select {
        min-height: 32px !important;
        min-width: 60px !important;
        font-size: 0.7rem !important;
    }
    
    .header-right {
        gap: 4px !important;
    }
}
/* ===========================================
   SPACIOUS BEAUTIFUL HEADER
   =========================================== */

/* Override header styles - larger and more spacious */
.header {
    min-height: 64px !important;
    padding: 12px 20px !important;
    background: linear-gradient(180deg, rgba(22, 33, 62, 0.98) 0%, rgba(26, 26, 46, 0.95) 100%) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border-bottom: 1px solid rgba(74, 144, 217, 0.25) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) !important;
}

.logo {
    font-size: 1.1rem !important;
}

.logo-text {
    display: inline !important;
    background: linear-gradient(135deg, #4a90d9 0%, #6bb3f0 50%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-size: 1rem;
}

/* Hide center since title is floating */
.header-center {
    display: none !important;
}

/* Larger, elegant buttons */
.header .btn {
    min-height: 42px !important;
    min-width: 42px !important;
    padding: 10px 18px !important;
    font-size: 0.85rem !important;
    border-radius: 10px !important;
    background: rgba(255, 255, 255, 0.06) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    transition: all 0.25s ease !important;
    font-weight: 500 !important;
    letter-spacing: 0.3px !important;
}

.header .btn:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(74, 144, 217, 0.5) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
}

.header .btn-primary {
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.9), rgba(100, 160, 230, 0.9)) !important;
    border-color: rgba(74, 144, 217, 0.6) !important;
    box-shadow: 0 2px 8px rgba(74, 144, 217, 0.3) !important;
}

.header .btn-primary:hover {
    background: linear-gradient(135deg, rgba(74, 144, 217, 1), rgba(100, 160, 230, 1)) !important;
    box-shadow: 0 4px 16px rgba(74, 144, 217, 0.4) !important;
}

/* Elegant select dropdown */
.model-select {
    min-height: 42px !important;
    padding: 10px 14px !important;
    font-size: 0.85rem !important;
    border-radius: 10px !important;
    background: rgba(255, 255, 255, 0.06) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    min-width: 90px !important;
    cursor: pointer !important;
}

.model-select:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(74, 144, 217, 0.4) !important;
}

.header-right {
    gap: 10px !important;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .header {
        padding: 10px 12px !important;
        min-height: 56px !important;
    }
    
    .logo-text {
        font-size: 0.85rem !important;
    }
    
    .header .btn {
        min-height: 38px !important;
        min-width: 38px !important;
        padding: 8px 12px !important;
        font-size: 0.75rem !important;
    }
    
    .model-select {
        min-height: 38px !important;
        min-width: 75px !important;
        font-size: 0.75rem !important;
    }
    
    .header-right {
        gap: 6px !important;
    }
}
/* ===========================================
   TWO-LINE BEAUTIFUL HEADER
   =========================================== */

/* Stack header vertically */
.header {
    flex-direction: column !important;
    align-items: stretch !important;
    min-height: auto !important;
    padding: 0 !important;
    background: linear-gradient(180deg, rgba(15, 25, 45, 0.98) 0%, rgba(22, 33, 62, 0.95) 100%) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2) !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4) !important;
    gap: 0 !important;
}

/* Logo row - centered, beautiful */
.header-left {
    width: 100% !important;
    justify-content: center !important;
    padding: 14px 16px 10px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
}

.logo {
    font-size: 1.3rem !important;
    text-align: center !important;
}

.logo-text {
    display: inline !important;
    background: linear-gradient(135deg, #5a9fe0 0%, #8ec5f7 40%, #5a9fe0 80%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800 !important;
    letter-spacing: 3px !important;
    text-transform: uppercase !important;
    font-size: 1.1rem !important;
    text-shadow: 0 0 30px rgba(74, 144, 217, 0.3);
}

/* Hide center */
.header-center {
    display: none !important;
}

/* Buttons row - spread nicely */
.header-right {
    width: 100% !important;
    justify-content: center !important;
    padding: 10px 16px 12px !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
}

/* Elegant pill buttons */
.header .btn {
    min-height: 36px !important;
    min-width: auto !important;
    padding: 8px 16px !important;
    font-size: 0.8rem !important;
    border-radius: 20px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    transition: all 0.2s ease !important;
    font-weight: 500 !important;
    letter-spacing: 0.5px !important;
}

.header .btn:hover {
    background: rgba(255, 255, 255, 0.15) !important;
    border-color: rgba(74, 144, 217, 0.5) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.header .btn-primary {
    background: linear-gradient(135deg, #4a90d9, #6aabeb) !important;
    border: none !important;
    box-shadow: 0 2px 10px rgba(74, 144, 217, 0.4) !important;
}

.header .btn-primary:hover {
    box-shadow: 0 4px 16px rgba(74, 144, 217, 0.5) !important;
}

/* Elegant dropdown */
.model-select {
    min-height: 36px !important;
    padding: 8px 14px !important;
    font-size: 0.8rem !important;
    border-radius: 20px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    min-width: 85px !important;
}

.model-select:hover {
    background: rgba(255, 255, 255, 0.12) !important;
}

/* Mobile */
@media (max-width: 480px) {
    .header-left {
        padding: 10px 12px 8px !important;
    }
    
    .logo-text {
        font-size: 0.95rem !important;
        letter-spacing: 2px !important;
    }
    
    .header-right {
        padding: 8px 10px 10px !important;
        gap: 6px !important;
    }
    
    .header .btn {
        padding: 6px 12px !important;
        font-size: 0.75rem !important;
        min-height: 32px !important;
    }
    
    .model-select {
        min-height: 32px !important;
        font-size: 0.75rem !important;
        min-width: 70px !important;
    }
}

/* ============================================
   Glass Header - Two-Line Layout
   ============================================ */

.glass-header {
    flex-direction: column !important;
    padding: 0.5rem 1rem !important;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.95) 0%, rgba(22, 33, 62, 0.9) 100%) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2) !important;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3) !important;
    gap: 0.4rem !important;
    min-height: auto !important;
}

.header-title-row {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.header-brand {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    background: linear-gradient(135deg, #4a90d9 0%, #67b8e3 50%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(74, 144, 217, 0.3);
}

.header-controls-row {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
}

.controls-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* Glass buttons */
.btn-glass {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.9) !important;
    padding: 0.35rem 0.7rem !important;
    font-size: 0.8rem !important;
    border-radius: 8px !important;
    transition: all 0.2s ease !important;
    font-weight: 500;
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(74, 144, 217, 0.4) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(74, 144, 217, 0.2);
}

.btn-glass.btn-primary {
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.3) 0%, rgba(74, 144, 217, 0.2) 100%) !important;
    border-color: rgba(74, 144, 217, 0.4) !important;
}

.btn-glass.btn-primary:hover {
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.5) 0%, rgba(74, 144, 217, 0.35) 100%) !important;
    box-shadow: 0 4px 20px rgba(74, 144, 217, 0.3);
}

/* Glass select dropdown */
.glass-select {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.9) !important;
    padding: 0.35rem 0.7rem !important;
    font-size: 0.8rem !important;
    border-radius: 8px !important;
    cursor: pointer;
}

.glass-select:hover {
    border-color: rgba(74, 144, 217, 0.4) !important;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .glass-header {
        padding: 0.4rem 0.5rem !important;
    }
    
    .header-brand {
        font-size: 0.95rem;
        letter-spacing: 0.2em;
    }
    
    .btn-glass {
        padding: 0.3rem 0.5rem !important;
        font-size: 0.75rem !important;
    }
    
    .glass-select {
        padding: 0.3rem 0.5rem !important;
        font-size: 0.75rem !important;
        max-width: 70px;
    }
}

/* ============================================
   Header v2 - Horizontal Icon Layout
   ============================================ */

.glass-header {
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0.6rem 1rem !important;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.95) 0%, rgba(22, 33, 62, 0.9) 100%) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2) !important;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3) !important;
    gap: 0.75rem !important;
    min-height: 50px !important;
}

.glass-header .header-brand {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    background: linear-gradient(135deg, #4a90d9 0%, #67b8e3 50%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    justify-content: flex-end;
}

/* Icon buttons */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(74, 144, 217, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.25);
}

.btn-icon.btn-primary {
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.35) 0%, rgba(74, 144, 217, 0.2) 100%);
    border-color: rgba(74, 144, 217, 0.5);
}

.btn-icon.btn-primary:hover {
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.55) 0%, rgba(74, 144, 217, 0.35) 100%);
    box-shadow: 0 4px 16px rgba(74, 144, 217, 0.35);
}

.btn-icon svg {
    flex-shrink: 0;
}

/* Model dropdown */
.model-dropdown {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.9);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    min-width: 140px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.model-dropdown:hover {
    border-color: rgba(74, 144, 217, 0.5);
}

.model-dropdown option {
    background: #1a1a2e;
    color: #fff;
}

/* Mobile adjustments for icon header */
@media (max-width: 480px) {
    .glass-header {
        padding: 0.5rem !important;
        gap: 0.4rem !important;
    }
    
    .glass-header .header-brand {
        font-size: 0.7rem;
        letter-spacing: 0.15em;
    }
    
    .btn-icon {
        width: 34px;
        height: 34px;
    }
    
    .btn-icon svg {
        width: 16px;
        height: 16px;
    }
    
    .model-dropdown {
        min-width: 100px;
        padding: 0.4rem 0.5rem;
        font-size: 0.75rem;
    }
}

/* ============================================
   Header v3 - Two-line with larger icons
   ============================================ */

.glass-header {
    flex-direction: column !important;
    padding: 0.5rem 1rem !important;
    gap: 0.5rem !important;
    min-height: auto !important;
}

.header-title-row {
    display: flex;
    justify-content: center;
    width: 100%;
}

.glass-header .header-brand {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    background: linear-gradient(135deg, #4a90d9 0%, #67b8e3 50%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    flex-wrap: wrap;
}

/* Larger icon buttons */
.btn-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
}

.btn-icon svg {
    width: 22px;
    height: 22px;
}

/* Larger dropdown */
.model-dropdown {
    min-width: 150px;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    border-radius: 12px;
}

/* Mobile adjustments v3 */
@media (max-width: 480px) {
    .glass-header {
        padding: 0.4rem 0.6rem !important;
        gap: 0.4rem !important;
    }
    
    .glass-header .header-brand {
        font-size: 0.85rem;
        letter-spacing: 0.2em;
    }
    
    .btn-icon {
        width: 40px;
        height: 40px;
    }
    
    .btn-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .model-dropdown {
        min-width: 120px;
        padding: 0.5rem 0.6rem;
        font-size: 0.8rem;
    }
}

/* ============================================
   FAQ Modal
   ============================================ */

.faq-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

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

.faq-content {
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.98) 0%, rgba(22, 33, 62, 0.98) 100%);
    border: 1px solid rgba(74, 144, 217, 0.3);
    border-radius: 16px;
    max-width: 500px;
    max-height: 80vh;
    width: 100%;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.faq-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2);
}

.faq-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: #67b8e3;
    font-weight: 600;
}

.faq-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.faq-close:hover {
    color: #fff;
}

.faq-body {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(80vh - 60px);
}

.faq-section {
    margin-bottom: 1.25rem;
}

.faq-section:last-child {
    margin-bottom: 0;
}

.faq-section h3 {
    color: #4a90d9;
    font-size: 0.9rem;
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2);
}

.faq-section p {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 0 0 0.6rem 0;
}

.faq-section p strong {
    color: #67b8e3;
}

.faq-section p svg {
    vertical-align: middle;
    margin-right: 0.25rem;
    color: #4a90d9;
}

/* ============================================
   Header v4 - Compact Single Line
   ============================================ */

.glass-header-v4 {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0.4rem 0.6rem !important;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.95) 0%, rgba(22, 33, 62, 0.9) 100%) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2) !important;
    gap: 0.4rem !important;
    min-height: 48px !important;
    flex-wrap: nowrap !important;
}

.glass-header-v4 .header-brand {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    background: linear-gradient(135deg, #4a90d9 0%, #67b8e3 50%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-icons {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
}

/* Compact icon buttons */
.glass-header-v4 .btn-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.glass-header-v4 .btn-icon svg {
    width: 18px;
    height: 18px;
}

.glass-header-v4 .btn-icon:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(74, 144, 217, 0.5);
}

.glass-header-v4 .btn-icon.btn-accent {
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.3) 0%, rgba(74, 144, 217, 0.15) 100%);
    border-color: rgba(74, 144, 217, 0.4);
}

/* Compact dropdown */
.glass-header-v4 .model-dropdown {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.9);
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
    min-width: 70px;
    max-width: 90px;
    cursor: pointer;
}

.glass-header-v4 .model-dropdown option {
    background: #1a1a2e;
}

/* Mobile - even more compact */
@media (max-width: 400px) {
    .glass-header-v4 {
        padding: 0.3rem 0.4rem !important;
        gap: 0.25rem !important;
    }
    
    .glass-header-v4 .header-brand {
        font-size: 0.55rem;
        letter-spacing: 0.1em;
    }
    
    .header-icons {
        gap: 0.2rem;
    }
    
    .glass-header-v4 .btn-icon {
        width: 32px;
        height: 32px;
        min-width: 32px;
        border-radius: 6px;
    }
    
    .glass-header-v4 .btn-icon svg {
        width: 16px;
        height: 16px;
    }
    
    .glass-header-v4 .model-dropdown {
        padding: 0.3rem 0.4rem;
        font-size: 0.7rem;
        min-width: 55px;
        max-width: 70px;
    }
}

/* ============================================
   Header v5 - Two lines, 42px icons
   ============================================ */

.glass-header-v5 {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    padding: 0.5rem 0.5rem !important;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.95) 0%, rgba(22, 33, 62, 0.9) 100%) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-bottom: 1px solid rgba(74, 144, 217, 0.2) !important;
    gap: 0.4rem !important;
}

.glass-header-v5 .header-title {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    background: linear-gradient(135deg, #4a90d9 0%, #67b8e3 50%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.glass-header-v5 .header-icons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    flex-wrap: nowrap;
}

/* 42px icon buttons */
.glass-header-v5 .btn-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.glass-header-v5 .btn-icon svg {
    width: 22px;
    height: 22px;
}

.glass-header-v5 .btn-icon:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(74, 144, 217, 0.5);
    transform: translateY(-1px);
}

.glass-header-v5 .btn-icon.btn-accent {
    background: linear-gradient(135deg, rgba(74, 144, 217, 0.3) 0%, rgba(74, 144, 217, 0.15) 100%);
    border-color: rgba(74, 144, 217, 0.4);
}

.glass-header-v5 .help-icon {
    font-size: 20px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.85);
}

/* Dropdown */
.glass-header-v5 .model-dropdown {
    height: 42px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.9);
    padding: 0 0.6rem;
    font-size: 0.85rem;
    min-width: 80px;
    cursor: pointer;
}

.glass-header-v5 .model-dropdown option {
    background: #1a1a2e;
}

/* Mobile - keep same size, tighter spacing */
@media (max-width: 400px) {
    .glass-header-v5 {
        padding: 0.4rem !important;
        gap: 0.3rem !important;
    }
    
    .glass-header-v5 .header-title {
        font-size: 0.8rem;
    }
    
    .glass-header-v5 .header-icons {
        gap: 0.25rem;
    }
    
    .glass-header-v5 .model-dropdown {
        min-width: 65px;
        padding: 0 0.4rem;
        font-size: 0.75rem;
    }
}

/* Steps Control */
.steps-control {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-right: 0.5rem;
}

.steps-control label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.steps-control input {
    width: 55px;
    padding: 0.3rem 0.4rem;
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

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

@media (max-width: 400px) {
    .steps-control {
        display: none;
    }
}

/* ============================================
   Model Library Browser
   ============================================ */
/* ==========================================
   LOADING SCREEN
   ========================================== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-logo {
    font-size: 2rem;
    font-weight: 700;
    color: #4a90d9;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px rgba(74, 144, 217, 0.5);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    position: relative;
    margin-bottom: 1.5rem;
}

.loading-spinner::before,
.loading-spinner::after {
    content: "";
    position: absolute;
    border-radius: 50%;
}

.loading-spinner::before {
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-top-color: #4a90d9;
    border-right-color: #4a90d9;
    animation: spin 1s linear infinite;
}

.loading-spinner::after {
    width: 70%;
    height: 70%;
    top: 15%;
    left: 15%;
    border: 3px solid transparent;
    border-bottom-color: #e94560;
    border-left-color: #e94560;
    animation: spin 0.8s linear infinite reverse;
}

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

.loading-text {
    color: #a0a0a0;
    font-size: 0.9rem;
    animation: pulse 1.5s ease-in-out infinite;
}

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

.loading-progress {
    width: 200px;
    height: 3px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    margin-top: 1rem;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4a90d9, #e94560, #4a90d9);
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
    width: 100%;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ==========================================
   LIBRARY MODAL - DARK THEME FIXED
   ========================================== */
.library-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 0;
}

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

.library-content {
    background: var(--bg-primary);
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0;
}

@media (min-width: 769px) {
    .library-content {
        max-width: 700px;
        max-height: 80vh;
        height: auto;
        border-radius: 12px;
        border: 1px solid var(--border-color);
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    }
    
    .library-modal {
        padding: 1rem;
    }
}

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

.library-header h2 {
    margin: 0;
    font-size: 1.1rem;
    flex: 1;
    color: var(--text-primary);
}

.library-count {
    color: var(--text-muted);
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
}

.library-close {
    background: var(--bg-tertiary);
    border: none;
    font-size: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.library-close:hover {
    background: var(--accent-secondary);
    color: white;
}

.library-controls {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.library-search {
    flex: 1;
    min-width: 0;
    padding: 0.6rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.library-search::placeholder {
    color: var(--text-muted);
}

.library-search:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.library-category,
.library-sort {
    padding: 0.6rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    min-width: 0;
    flex-shrink: 1;
}

.library-category {
    flex: 1;
    max-width: 50%;
}

.library-sort {
    flex: 0 0 auto;
}

.library-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg-primary);
    -webkit-overflow-scrolling: touch;
}

/* Library Items - Dark Theme */
.library-item {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 0.5rem;
    background: var(--bg-secondary);
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.library-item:hover {
    border-color: var(--accent-primary);
}

.library-item.expanded {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

.library-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    gap: 0.5rem;
}

.library-item-info {
    flex: 1;
    cursor: pointer;
    min-width: 0;
}

.library-item-name {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.expand-icon {
    color: var(--text-muted);
    font-size: 0.65rem;
    flex-shrink: 0;
    width: 12px;
}

.library-item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.35rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    align-items: center;
}

.library-item-category {
    background: rgba(74, 144, 217, 0.2);
    color: var(--accent-primary);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.65rem;
    text-transform: capitalize;
    font-weight: 500;
}

.library-item-stats {
    color: var(--text-muted);
    font-size: 0.65rem;
}

.library-item-import {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 32px;
}

.library-item-import:hover {
    background: #3a80c9;
}

.library-item-import:active {
    transform: scale(0.95);
}

/* Expanded Details - Dark Theme */
.library-item-details {
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem;
}

.detail-section {
    margin-bottom: 0.75rem;
}

.detail-section:last-child {
    margin-bottom: 0;
}

.detail-label {
    font-weight: 600;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-value {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.detail-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 120px;
    overflow-y: auto;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.5rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.75rem;
    gap: 0.5rem;
}

.detail-item .item-name {
    font-weight: 500;
    color: var(--text-primary);
    flex-shrink: 0;
}

.detail-item .item-value,
.detail-item .item-equation {
    color: var(--text-muted);
    font-family: "SF Mono", Monaco, monospace;
    font-size: 0.65rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
    flex: 1;
    min-width: 0;
}

.detail-actions {
    margin-top: 0.75rem;
    text-align: center;
}

.btn-import-full {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    width: 100%;
    max-width: 250px;
}

.btn-import-full:hover {
    background: linear-gradient(135deg, #27ae60, #219a52);
}

.btn-import-full:active {
    transform: scale(0.98);
}

.library-empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.library-notification {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 25px;
    opacity: 0;
    transition: all 0.3s;
    z-index: 1001;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.4);
}

.library-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Mobile Portrait Optimization */
@media (max-width: 480px) {
    .library-header {
        padding: 0.75rem;
    }
    
    .library-header h2 {
        font-size: 1rem;
    }
    
    .library-controls {
        padding: 0.5rem;
        gap: 0.4rem;
    }
    
    .library-search {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 0.5rem;
    }
    
    .library-category,
    .library-sort {
        font-size: 0.75rem;
        padding: 0.5rem;
    }
    
    .library-item-header {
        padding: 0.6rem;
    }
    
    .library-item-name {
        font-size: 0.85rem;
    }
    
    .library-item-import {
        padding: 0.4rem 0.6rem;
        font-size: 0.7rem;
    }
    
    .library-item-details {
        padding: 0.5rem;
    }
    
    .detail-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.15rem;
    }
    
    .detail-item .item-equation {
        text-align: left;
        max-width: 100%;
    }
}

/* Library Loading Spinner */
.library-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
}

.library-spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    position: relative;
}

.library-spinner::before,
.library-spinner::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.library-spinner::before {
    border: 3px solid transparent;
    border-top-color: var(--accent-primary);
    border-right-color: var(--accent-primary);
    animation: lib-spin 1s linear infinite;
}

.library-spinner::after {
    border: 3px solid transparent;
    border-bottom-color: var(--accent-secondary);
    border-left-color: var(--accent-secondary);
    animation: lib-spin 0.8s linear infinite reverse;
    width: 70%;
    height: 70%;
    top: 15%;
    left: 15%;
}

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

.library-loading-text {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
}

.library-loading-sub {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.detail-more {
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    font-style: italic;
}

.library-notification.error {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

/* Fix mobile settings button - position above run button */
.mobile-settings-btn {
    display: none;
    position: fixed;
    bottom: calc(64px + var(--safe-area-bottom) + 70px) !important;
    left: 20px !important;
    padding: 12px 16px !important;
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    font-size: 1.2rem;
    border-radius: 25px;
    z-index: 91;
}

.mobile-simulate-btn {
    bottom: calc(64px + var(--safe-area-bottom) + 16px) !important;
    left: 20px !important;
}

@media (max-width: 899px) {
    .mobile-settings-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .mobile-settings-btn {
        bottom: calc(52px + 60px) !important;
    }
}

/* ============================================
   MOBILE CHART UI - REDESIGN
   ============================================ */

.mobile-results-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 0.5rem;
}

/* Mobile Results Tabs */
.mobile-results-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}

.mobile-results-tab {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all 0.2s;
}

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

.mobile-tab-content {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    overflow-y: auto;
}

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

/* Variable Chips */
.var-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}

.var-chip {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    border: 2px solid var(--chip-color, var(--border));
    background: transparent;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.5;
}

.var-chip.active {
    background: color-mix(in srgb, var(--chip-color) 15%, transparent);
    color: var(--text-primary);
    opacity: 1;
}

.var-chip-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.var-chip-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chart Controls */
.chart-controls-mobile {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}

.chart-type-btns {
    display: flex;
    gap: 0.25rem;
}

.chart-type-btn {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

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

.chart-toggle-btns {
    display: flex;
    gap: 0.25rem;
}

.chart-toggle-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Chart Wrapper */
.chart-wrapper-mobile {
    flex: 1;
    min-height: 200px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

.chart-wrapper-mobile .chart-container {
    width: 100%;
    height: 100%;
    min-height: 200px;
}

/* Results Summary */
.results-summary-mobile {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}

.summary-header {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
}

.summary-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-primary);
    border-radius: calc(var(--radius) - 2px);
}

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

.summary-name {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* No Results State */
.no-results-mobile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.no-results-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.no-results-mobile p {
    margin: 0.25rem 0;
}

/* Portrait-specific adjustments */
@media (max-width: 480px) {
    .var-chip {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .chart-type-btn {
        padding: 0.35rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .chart-toggle-btn {
        width: 32px;
        height: 32px;
    }
    
    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }
}


/* Section labels for mobile chart */
.mobile-chart-section {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.section-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-left: 0.25rem;
}

/* Fix var chip active state visibility */
.var-chip {
    opacity: 0.4;
    border-color: transparent;
    background: var(--bg-tertiary);
}

.var-chip.active {
    opacity: 1;
    border-color: var(--chip-color, var(--accent-primary));
    background: color-mix(in srgb, var(--chip-color, var(--accent-primary)) 20%, transparent);
}

.var-chip:active {
    transform: scale(0.95);
}

/* Better button feedback */
.chart-type-btn:active,
.chart-toggle-btn:active {
    transform: scale(0.95);
}

