/* 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: 250px;
    max-height: 50vh;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

/* 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: 320px;
        border-right: 1px solid var(--border-color);
    }

    .panel-right {
        width: 320px;
        border-left: 1px solid var(--border-color);
    }

    /* 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;
        border: none;
    }

    /* 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.5rem 1rem;
    }

    /* 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 */
    .properties-panel {
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
    }

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

    /* Results panel */
    .results-panel {
        flex: 1;
        padding: 1rem;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

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

    .chart-container {
        flex: 1;
        min-height: 200px;
    }
}

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

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

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

/* ==========================================
   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;
    right: 20px;
    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;
    right: 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-simulate-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 {
        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) + 20px);
    }

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

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

    .mobile-simulate-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;
}

