/* Vue-specific resizable layout styles */
.vue-demo-layout {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Reset any potential inherited styles */
.vue-demo-layout * {
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* Allow specific elements to have their styling */
.btn-back-icon,
.model-dropdown-compact,
.btn-compact,
.btn-icon,
.add-chart-btn,
.editable-title,
.variable-dropdown,
.delete-chart-btn,
.legend-remove,
.equation-box {
    border-radius: revert !important;
    box-shadow: revert !important;
}

.vue-demo-header {
    background-color: var(--light-gray);
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.vue-demo-content {
    flex: 1;
    overflow: hidden;
}

/* Clean banner layout - title left, controls right, fills full width */
.header-horizontal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 60px;
    padding: 0 1rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    flex: 1;
    padding-left: 0.5rem; /* Space for back button */
}

.header-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
    white-space: nowrap;
}

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

/* Back button - absolute positioned at very left */
.demo-nav {
    position: absolute;
    left: 1rem;
    z-index: 10;
}

.btn-back-icon {
    background: var(--light-gray);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.btn-back-icon:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-back-icon svg {
    transition: transform 0.2s ease;
}

.btn-back-icon:hover svg {
    transform: translateX(-1px);
}

/* Compact simulation controls for header */
.controls-panel-compact {
    display: flex !important;
    align-items: center !important;
    gap: 1rem !important;
    margin: 0 !important;
    padding: 0 !important;
}

.controls-body-compact {
    display: flex !important;
    align-items: center !important;
    gap: 1rem !important;
    margin: 0 !important;
    padding: 0 !important;
}

.model-selection {
    margin: 0 !important;
    padding: 0 !important;
}

.model-dropdown-compact {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    background: white;
    color: var(--text-color);
    cursor: pointer;
    min-width: 200px;
    appearance: menulist;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    margin: 0;
}

.model-dropdown-compact:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

.btn-compact {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0;
}

.control-buttons {
    margin: 0 !important;
    padding: 0 !important;
}

/* Resizable panels container - now 3 panels */
.resizable-container {
    height: 100%;
    display: flex;
}

/* Panel layouts - clean flat design */
.panel-structure {
    width: 100%;
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.panel-header-simple {
    background: var(--light-gray);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px; /* Fixed height for consistency */
    box-sizing: border-box;
    min-height: 60px;
}

.panel-content {
    flex: 1;
    overflow: hidden;
}

.panel-content-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.data-table-section {
    margin-top: 2rem;
}

/* Make data table responsive to container width changes */
.responsive-table {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    position: relative !important;
}

/* Ensure table container is responsive */
#tableContainer {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    position: relative !important;
}

/* Force table wrapper to be responsive */
.table-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.section-title {
    margin: 0 0 1rem 0;
    color: var(--primary-color);
    font-size: 1.1rem;
    font-weight: 600;
}

/* Canvas controls in panel header */
.canvas-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-icon {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-color);
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--light-gray);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Simulation info area - fixed width with vertical scroll */
.simulation-info {
    font-size: 0.7rem;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 240px;
    max-width: 240px;
    max-height: 40px;
    overflow-x: hidden;
    overflow-y: auto;
    font-weight: 500;
    padding: 0.25rem;
}

.info-item {
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1.2;
}

.info-placeholder {
    color: var(--text-muted, #6c757d);
    font-style: italic;
    font-size: 0.7rem;
}

/* Panel title styling */
.panel-title {
    margin: 0;
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 600;
}

/* Fix panel header styling */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--light-gray);
}

.panel-title {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.simulation-info {
    font-size: 0.9rem;
    color: var(--accent-color);
    font-weight: 500;
}

.info-placeholder {
    color: var(--text-color);
    opacity: 0.6;
    font-style: italic;
}

.info-item {
    margin-right: 1rem;
}

/* Variable popup equation box styling */
.equation-box {
    background: var(--light-gray);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.75rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    overflow-x: auto;
    user-select: text;
    cursor: text;
    max-height: 100px;
    margin-top: 0.5rem;
    overflow-y: auto;
}

/* Variable popup documentation box styling */
.doc-box {
    background: var(--light-gray);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.75rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-x: auto;
    user-select: text;
    cursor: text;
    max-height: 150px; /* Approximately 8 lines at 1.5 line-height */
    margin-top: 0.5rem;
    overflow-y: auto;
    color: var(--text-color);
}

/* Variable Search Dialog Styles */
.search-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 998;
}

.variable-search-dialog {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 320px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 999;
    display: flex;
    flex-direction: column;
    max-height: 500px;
}

.search-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--primary-color);
    color: white;
    border-radius: 6px 6px 0 0;
}

.search-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: background-color 0.2s;
}

.search-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.search-dialog-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
    overflow: hidden;
}

.search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.search-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

.search-results {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    max-height: 350px;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.15s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: var(--light-gray);
}

.variable-type-badge {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
}

.variable-type-badge.type-stock {
    background-color: #3498db;
}

.variable-type-badge.type-flow {
    background-color: #e74c3c;
}

.variable-type-badge.type-auxiliary {
    background-color: #2ecc71;
}

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

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

/* Responsive banner layout - maintain left title, right controls */
@media (max-width: 1200px) {
    .header-horizontal {
        padding: 0 0.8rem;
    }
    
    .header-title {
        font-size: 1.3rem;
    }
    
    .header-controls {
        gap: 0.8rem;
    }
    
    .simulation-info {
        width: 180px;
        max-width: 180px;
        font-size: 0.65rem;
    }
}

@media (max-width: 1000px) {
    .header-horizontal {
        padding: 0 0.6rem;
    }
    
    .header-title {
        font-size: 1.2rem;
    }
    
    .header-controls {
        gap: 0.6rem;
    }
    
    .simulation-info {
        width: 160px;
        max-width: 160px;
        font-size: 0.6rem;
    }
    
    .model-dropdown-compact {
        min-width: 120px;
        font-size: 0.85rem;
    }
    
    .btn-compact {
        font-size: 0.85rem;
        padding: 0.4rem 0.7rem;
    }
}

@media (max-width: 800px) {
    .header-horizontal {
        padding: 0 0.5rem;
    }
    
    .header-left {
        padding-left: 0.5rem; /* Less space for back button */
    }
    
    .header-title {
        font-size: 1.1rem;
    }
    
    .header-controls {
        gap: 0.5rem;
    }
    
    .simulation-info {
        width: 140px;
        max-width: 140px;
        font-size: 0.55rem;
    }
    
    .model-dropdown-compact {
        min-width: 100px;
        font-size: 0.8rem;
    }
    
    .btn-compact {
        font-size: 0.8rem;
        padding: 0.35rem 0.6rem;
    }
}

@media (max-width: 600px) {
    .header-horizontal {
        padding: 0 0.3rem;
    }
    
    .header-left {
        padding-left: 0.5rem; /* Minimal space for back button */
    }
    
    .header-title {
        font-size: 1rem;
    }
    
    .header-controls {
        gap: 0.3rem;
    }
    
    .simulation-info {
        width: 120px;
        max-width: 120px;
        font-size: 0.5rem;
    }
    
    .model-dropdown-compact {
        min-width: 90px;
        font-size: 0.75rem;
    }
    
    .btn-compact {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
    }
    
    /* MOBILE TOUCH ENHANCEMENTS */
    .variable-search-dialog {
        width: calc(100vw - 20px);
        max-width: 400px;
        top: 60px;
        right: 10px;
        max-height: calc(100vh - 80px);
    }
    
    .search-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.625rem 0.75rem;
    }
    
    .search-result-item {
        padding: 0.875rem 0.75rem; /* Larger touch targets */
        min-height: 48px; /* iOS recommended touch target size */
    }
    
    .btn-icon {
        width: 44px; /* Larger touch targets for mobile */
        height: 44px;
        font-size: 16px;
    }
    
    .variable-type-badge {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }
    
    .variable-name {
        font-size: 0.9rem;
    }
}

/* MOBILE TOUCH: Prevent text selection during pan/zoom */
.model-structure-canvas {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none; /* Disable default touch behaviors */
}

/* Allow text selection in popups and search */
#variablePopup,
.variable-search-dialog {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    touch-action: auto;
}

/* Make variable popup more mobile-friendly */
@media (max-width: 768px) {
    #variablePopup {
        min-width: 280px;
        max-width: calc(100vw - 40px);
        font-size: 0.875rem;
    }
    
    .equation-box,
    .doc-box {
        font-size: 0.8rem;
        max-height: 120px;
    }
    
    .close-btn {
        width: 32px;
        height: 32px;
        font-size: 1.5rem;
    }
}

/* Touch feedback for interactive elements */
@media (hover: none) and (pointer: coarse) {
    /* Only apply on touch devices */
    .btn-icon:active,
    .search-result-item:active,
    .btn-compact:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
    
    .search-close-btn:active {
        transform: scale(0.95);
    }
}

/* 'Loading model…' text shown while a model is fetched/rendered */
.mn-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #4a6fa5;
    font-style: italic;
    z-index: 5;
}
