/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #6b7280;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --bg-light: #f9fafb;
    --bg-white: #ffffff;
    --border: #e5e7eb;
    --text-dark: #1f2937;
    --text-light: #6b7280;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --border-color: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-red: #ef4444;
    --accent-green: #10b981;
    --accent-yellow: #fbbf24;
    --accent-cyan: #06b6d4;
    --amber: #f59e0b;
    --blue: #3b82f6;
    --emerald: #10b981;
    --transition: all 0.3s ease;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    color: var(--text-primary);
    overflow: hidden;
}

/* ===== MODAL STYLES ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-white);
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

.modal-header {
    text-align: center;
    margin-bottom: 24px;
}

.beaker-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.modal-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.modal-header p {
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.safety-alert {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.warning-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.safety-alert p {
    margin: 0;
    font-size: 14px;
    color: #78350f;
}

.alert-title {
    font-weight: 700;
    margin-bottom: 4px;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-size: 1em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

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

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

.btn-secondary:hover {
    background: #4b5563;
}

.btn-block {
    width: 100%;
}

/* ===== APP LAYOUT ===== */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
}

.container.hidden {
    display: none;
}

/* ===== HEADER ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: rgba(30, 41, 59, 0.8);
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    backdrop-filter: blur(8px);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-icon {
    font-size: 32px;
}

.app-title {
    font-size: 24px;
    font-weight: 700;
    color: white;
    margin-bottom: 4px;
}

.app-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    gap: 16px;
    align-items: center;
}

.mode-buttons {
    display: flex;
    gap: 8px;
    border-right: 1px solid rgba(148, 163, 184, 0.2);
    padding-right: 16px;
}

.mode-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.mode-btn.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent-blue);
    color: white;
}

/* ===== MAIN LAYOUT ===== */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    gap: 0;
}

/* ===== CONTROL PANEL ===== */
.control-panel {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    overflow-y: auto;
    flex-shrink: 0;
}

.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.control-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.control-buttons {
    display: flex;
    gap: 8px;
}

.parameter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.parameter-label {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-secondary);
}

.param-display {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: var(--accent-blue);
}

.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    transition: var(--transition);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
}

.hint-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: -4px;
}

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

.toggle-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.toggle-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.switch {
    appearance: none;
    width: 44px;
    height: 24px;
    background: var(--bg-tertiary);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: background 0.3s ease;
}

.switch:checked {
    background: var(--accent-green);
}

.switch-slider {
    position: absolute;
    left: 3px;
    top: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 999px;
    transition: all 0.3s ease;
    pointer-events: none;
}

.switch:checked ~ .switch-slider {
    transform: translateX(20px);
}

.legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.legend-box {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ===== WORKSPACE ===== */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
    gap: 24px;
}

.canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    min-height: 400px;
}

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

.diagrams-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
}

.diagrams-title {
    font-size: 16px;
    font-weight: 700;
    color: white;
    margin-bottom: 16px;
}

.diagram-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.diagram-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.diagram-card svg {
    width: 100%;
    height: 160px;
    margin-bottom: 8px;
}

.diagram-card h4 {
    font-size: 13px;
    font-weight: 700;
    color: white;
    text-align: center;
}

.diagram-card p {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.6);
}

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

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

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
    .main-layout {
        flex-direction: column;
    }
    
    .control-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 200px;
        overflow-y: auto;
    }
    
    .diagram-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    
    .header-right {
        flex-direction: column;
        width: 100%;
    }
    
    .mode-buttons {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-right: 0;
        padding-bottom: 8px;
    }
    
    .control-panel {
        max-height: 250px;
    }
    
    .workspace {
        padding: 16px;
    }
}