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

:root {
    /* Color Palette */
    --primary-color: #2563eb;
    --secondary-color: #7c3aed;
    --success-color: #059669;
    --error-color: #dc2626;
    --warning-color: #d97706;
    --info-color: #0891b2;
    
    /* Neutral Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
    
    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    
    /* Radii */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--text-primary);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== MAIN LAYOUT ===== */
.app-container {
    display: flex;
    min-height: 100vh;
    gap: var(--space-6);
    padding: var(--space-6);
}

/* ===== LEFT CONTROL PANEL ===== */
.control-panel {
    flex: 0 0 400px;
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    box-shadow: var(--shadow-xl);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    height: fit-content;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.control-panel::-webkit-scrollbar {
    width: 6px;
}

.control-panel::-webkit-scrollbar-track {
    background: transparent;
}

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

.control-panel::-webkit-scrollbar-thumb:hover {
    background-color: var(--border-hover);
}

/* ===== PANEL HEADER ===== */
.panel-header {
    text-align: center;
    margin-bottom: var(--space-8);
    padding-bottom: var(--space-6);
    border-bottom: 2px solid var(--border-color);
}

.panel-header h1 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
}

.panel-header .icon {
    font-size: var(--font-size-3xl);
}

.system-status {
    display: flex;
    justify-content: center;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    transition: var(--transition-normal);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success-color);
    animation: statusPulse 2s infinite;
    box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4);
}

.status-dot.failed {
    background: var(--error-color);
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4);
}

@keyframes statusPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(5, 150, 105, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(5, 150, 105, 0);
    }
}

.status-text {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

/* ===== SECTIONS ===== */
.probability-section,
.components-section,
.controls-section,
.instructions-section {
    margin-bottom: var(--space-8);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-5);
}

.section-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.section-header .icon {
    font-size: var(--font-size-xl);
}

/* ===== PROBABILITY DISPLAY ===== */
.probability-display {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.main-probability {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.main-probability .value {
    font-size: 3rem;
    font-weight: 800;
    color: var(--success-color);
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    transition: var(--transition-normal);
}

.main-probability .value.failed {
    color: var(--error-color);
    animation: errorPulse 0.5s ease-out;
}

@keyframes errorPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.main-probability .percentage {
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--text-secondary);
}

.equation-display {
    background: var(--bg-primary);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
}

.equation-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
    font-weight: 500;
}

.equation {
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    font-weight: 600;
    word-break: break-all;
    line-height: 1.4;
}

/* ===== COMPONENT CARDS ===== */
.component-legend {
    display: flex;
    gap: var(--space-4);
    font-size: var(--font-size-xs);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--text-muted);
}

.legend-item .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-item.working .dot {
    background: var(--success-color);
}

.legend-item.failed .dot {
    background: var(--error-color);
}

.components-grid {
    display: grid;
    gap: var(--space-4);
}

.component-card {
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    transition: var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.component-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--success-color);
    transition: var(--transition-normal);
}

.component-card.failed::before {
    background: var(--error-color);
}

.component-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.component-card.failed {
    background: rgba(220, 38, 38, 0.02);
    border-color: rgba(220, 38, 38, 0.2);
}

.component-header {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.component-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #8B4513, #A0522D);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.popsicle-stick-icon {
    width: 6px;
    height: 36px;
    background: linear-gradient(to right, #D2B48C, #DDB76F, #D2B48C);
    border-radius: 1px;
    position: relative;
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2);
}

.popsicle-stick-icon::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        rgba(139, 69, 19, 0.2) 1px,
        transparent 2px,
        transparent 6px
    );
}

.component-info h4 {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.component-position {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: 500;
}

.component-metrics {
    margin-bottom: var(--space-4);
}

.probability-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}

.metric-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

.metric-value {
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--success-color);
    transition: var(--transition-normal);
}

.metric-value.failed {
    color: var(--error-color);
}

.reliability-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.bar-track {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), #10b981);
    transition: all var(--transition-slow);
    border-radius: 3px;
    position: relative;
}

.bar-fill::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.bar-fill.failed {
    background: linear-gradient(90deg, var(--error-color), #ef4444);
    width: 0% !important;
}

.bar-percentage {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: 600;
    min-width: 32px;
    text-align: right;
}

.component-actions {
    display: flex;
    gap: var(--space-2);
}

.action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.action-btn:hover::before {
    left: 100%;
}

.fail-btn {
    background: linear-gradient(135deg, var(--error-color), #ef4444);
    color: white;
    border: 1px solid rgba(220, 38, 38, 0.3);
}

.fail-btn:hover {
    background: linear-gradient(135deg, #b91c1c, var(--error-color));
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.restore-btn {
    background: linear-gradient(135deg, var(--success-color), #10b981);
    color: white;
    border: 1px solid rgba(5, 150, 105, 0.3);
}

.restore-btn:hover {
    background: linear-gradient(135deg, #047857, var(--success-color));
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn.hidden {
    display: none;
}

.btn-icon {
    font-size: var(--font-size-base);
}

/* ===== SYSTEM CONTROLS ===== */
.controls-grid {
    display: grid;
    gap: var(--space-3);
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border: none;
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.control-btn:hover::before {
    left: 100%;
}

.control-btn.primary {
    background: linear-gradient(135deg, var(--primary-color), #3b82f6);
    color: white;
    border: 1px solid rgba(37, 99, 235, 0.3);
}

.control-btn.primary:hover {
    background: linear-gradient(135deg, #1d4ed8, var(--primary-color));
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.control-btn.secondary {
    background: linear-gradient(135deg, var(--warning-color), #f59e0b);
    color: white;
    border: 1px solid rgba(217, 119, 6, 0.3);
}

.control-btn.secondary:hover {
    background: linear-gradient(135deg, #b45309, var(--warning-color));
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.control-btn.tertiary {
    background: linear-gradient(135deg, var(--secondary-color), #8b5cf6);
    color: white;
    border: 1px solid rgba(124, 58, 237, 0.3);
}

.control-btn.tertiary:hover {
    background: linear-gradient(135deg, #6d28d9, var(--secondary-color));
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.control-btn:active {
    transform: translateY(0);
}

/* ===== INSTRUCTIONS ===== */
.instructions-list {
    display: grid;
    gap: var(--space-3);
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: var(--transition-normal);
}

.instruction-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-hover);
}

.instruction-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--info-color), #0ea5e9);
    color: white;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    flex-shrink: 0;
}

.instruction-text {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1200px) {
    .app-container {
        flex-direction: column;
        gap: var(--space-4);
        padding: var(--space-4);
    }
    
    .control-panel {
        flex: none;
        max-height: none;
        order: 2;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: var(--space-3);
        gap: var(--space-3);
    }
    
    .control-panel {
        padding: var(--space-4);
    }
    
    .panel-header h1 {
        font-size: var(--font-size-xl);
    }
    
    .main-probability .value {
        font-size: 2rem;
    }
    
    .component-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-2);
    }
    
    .component-actions {
        flex-direction: column;
    }
    
    .controls-grid {
        grid-template-columns: 1fr;
    }
}

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

@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --border-hover: #333333;
        --text-muted: #333333;
    }
    
    .component-card {
        border-width: 3px;
    }
    
    .action-btn, .control-btn {
        border-width: 2px;
    }
}

/* ===== FOCUS STYLES ===== */
.action-btn:focus,
.control-btn:focus,
button:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===== ANIMATION STATES ===== */
.component-card.updating {
    animation: updatePulse 0.6s ease-out;
}

@keyframes updatePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

.probability-display.changing {
    animation: probabilityChange 0.8s ease-out;
}

@keyframes probabilityChange {
    0% { background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%); }
    25% { background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%); }
    50% { background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%); }
    100% { background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%); }
}
