/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow-x: hidden;
}

/* Container layout - responsive for iframe and full screen */
.container {
    width: 100%;
    height: 100vh;
    max-height: 450px;
    display: grid;
    grid-template-columns: 250px 1fr 200px;
    grid-template-rows: 1fr auto auto;
    grid-template-areas: 
        "controls main data"
        "inquiry inquiry inquiry"
        "analytics analytics analytics";
    gap: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

/* Detect if running in new tab (full height) */
@media (min-height: 500px) {
    .container {
        max-height: 90vh;
    }
}

/* Control Panel */
.control-panel {
    grid-area: controls;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
}

.control-group {
    margin-bottom: 16px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #2c3e50;
    cursor: help;
}

/* Sliders */
.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
    background: #2980b9;
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Preset buttons */
.preset-buttons {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.preset-btn {
    flex: 1;
    padding: 6px 8px;
    background: #ecf0f1;
    border: 1px solid #bdc3c7;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    min-height: 32px;
}

.preset-btn:hover {
    background: #d5dbdb;
    transform: translateY(-1px);
}

.preset-btn.active {
    background: #3498db;
    color: white;
    border-color: #2980b9;
}

/* Checkboxes */
.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 8px;
}

.checkbox-container input {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    background: #ecf0f1;
    border: 2px solid #bdc3c7;
    border-radius: 4px;
    margin-right: 8px;
    position: relative;
    transition: all 0.2s ease;
}

.checkbox-container input:checked + .checkmark {
    background: #3498db;
    border-color: #2980b9;
}

.checkbox-container input:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    left: 2px;
    top: -2px;
    color: white;
    font-size: 14px;
    font-weight: bold;
}

/* Buttons */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.action-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    min-height: 44px;
    background: #ecf0f1;
    color: #2c3e50;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.action-btn.primary {
    background: #e74c3c;
    color: white;
}

.action-btn.primary:hover {
    background: #c0392b;
}

.small-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    background: #ecf0f1;
    color: #2c3e50;
    transition: all 0.2s ease;
    min-height: 32px;
}

.small-btn:hover {
    background: #d5dbdb;
    transform: translateY(-1px);
}

/* Main Content */
.main-content {
    grid-area: main;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.canvas-container {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: relative;
}

#simulation-canvas {
    width: 100%;
    height: 200px;
    border: 2px solid #ecf0f1;
    border-radius: 8px;
    background: linear-gradient(to bottom, #87ceeb 0%, #98fb98 100%);
}

.canvas-info {
    display: flex;
    justify-content: space-around;
    margin-top: 12px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 8px;
}

.info-item {
    text-align: center;
    font-size: 12px;
}

.info-item .label {
    display: block;
    font-weight: 600;
    color: #7f8c8d;
    margin-bottom: 2px;
}

/* Graphs */
.graphs-container {
    display: flex;
    gap: 8px;
}

.graph-panel {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.graph-panel h4 {
    font-size: 12px;
    margin-bottom: 8px;
    text-align: center;
    color: #2c3e50;
}

.graph-panel canvas {
    width: 100%;
    height: 80px;
    border: 1px solid #ecf0f1;
    border-radius: 4px;
}

/* Data Panel */
.data-panel {
    grid-area: data;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.panel-header h4 {
    font-size: 14px;
    color: #2c3e50;
}

.panel-controls {
    display: flex;
    gap: 4px;
}

.data-table-container {
    flex: 1;
    overflow-y: auto;
    max-height: 200px;
}

#data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

#data-table th,
#data-table td {
    padding: 4px 6px;
    text-align: center;
    border-bottom: 1px solid #ecf0f1;
}

#data-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
    position: sticky;
    top: 0;
}

/* Analytics Panel */
.analytics-panel {
    grid-area: analytics;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.analytics-content {
    max-height: 100px;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.4;
}

#action-log {
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
}

.log-entry {
    margin-bottom: 4px;
    padding: 4px 8px;
    background: white;
    border-radius: 4px;
    border-left: 3px solid #3498db;
}

/* Inquiry Panel */
.inquiry-panel {
    grid-area: inquiry;
    display: flex;
    gap: 8px;
}

.inquiry-step {
    flex: 1;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    opacity: 0.6;
    transition: all 0.3s ease;
}

.inquiry-step.active {
    opacity: 1;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.inquiry-step h4 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #2c3e50;
}

.inquiry-step p {
    font-size: 12px;
    color: #7f8c8d;
    line-height: 1.4;
}

/* Tooltips */
.tooltip {
    position: relative;
}

.tooltip-popup {
    position: absolute;
    background: #2c3e50;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    max-width: 200px;
    word-wrap: break-word;
}

.tooltip-popup.show {
    opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto;
        grid-template-areas: 
            "controls"
            "main"
            "data"
            "inquiry"
            "analytics";
        max-height: none;
        height: auto;
    }
    
    .control-panel {
        padding: 12px;
    }
    
    .button-group {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .action-btn {
        flex: 1;
        min-width: 100px;
    }
    
    .graphs-container {
        flex-direction: column;
    }
    
    .inquiry-panel {
        flex-direction: column;
    }
    
    /* Ensure touch targets are at least 44px */
    .slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    .preset-btn,
    .action-btn,
    .small-btn {
        min-height: 44px;
    }
    
    .checkmark {
        width: 22px;
        height: 22px;
    }
}

/* Animation classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.pulse {
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Hide analytics by default on mobile */
@media (max-width: 768px) {
    .analytics-panel {
        display: none;
    }
    
    .analytics-panel.show {
        display: block;
    }
}