/* Probability Calculator Styles
 * Created: 2025-11-12
 * Purpose: Styling for probability calculator with KaTeX support
 * Dependencies: Bootstrap 5.3.2, Font Awesome 6.4.2, KaTeX
 */


/* ========================================
   CALCULATION MODE SELECTOR
   ======================================== */
.mode-selector-wrapper {
    margin-bottom: 1.5rem;
}

#calculationMode {
    font-size: 1rem;
    font-weight: 600;
    padding: 0.75rem 1rem;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: white;
    color: #333;
    transition: all 0.3s ease;
}

#calculationMode:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* ========================================
   INPUT SECTIONS (DYNAMIC)
   ======================================== */
.input-section {
    display: none;
}

.input-section.active {
    display: block;
}

.input-row {
    margin-bottom: 1rem;
}

.input-row label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.input-row label i.info-icon {
    margin-left: 0.5rem;
    color: #667eea;
    cursor: help;
    font-size: 0.9rem;
}

/* Form Inputs */
.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: white;
}

.form-input:focus {
    outline: none;
    border-color: #48bb78;
    box-shadow: 0 0 0 0.2rem rgba(72, 187, 120, 0.25);
}

.form-input.error {
    border-color: #f56565;
    background: #fff5f5;
}

.form-input.valid {
    border-color: #48bb78;
}

/* Input Help Text */
.input-help {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.25rem;
    font-style: italic;
}

/* Error Messages */
.error-message {
    display: none;
    color: #f56565;
    font-size: 0.85rem;
    margin-top: 0.25rem;
    font-weight: 500;
}

.error-message.show {
    display: block;
}

/* ========================================
   RESULTS DISPLAY
   ======================================== */
.result-display {
    text-align: center;
    padding: 1.5rem;
}

.result-label {
    font-size: 0.95rem;
    color: #666;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.result-value {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 1rem 0;
    line-height: 1;
}

.result-percentage {
    font-size: 1.5rem;
    color: #666;
    margin-top: 0.5rem;
}

.result-details {
    margin-top: 1.5rem;
    text-align: left;
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e0e0e0;
}

.result-item:last-child {
    border-bottom: none;
}

.result-item-label {
    font-weight: 600;
    color: #333;
}

.result-item-value {
    font-weight: 700;
    color: #667eea;
}

/* ========================================
   DETAILED STEPS SECTION (Important Rule 1)
   ======================================== */
.steps-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.toggle-steps {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.toggle-steps:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.steps-container {
    display: none;
}

.steps-container.show {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calculation-step {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    padding: 1.25rem;
    margin-bottom: 1rem;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.calculation-step:hover {
    background: #f0f4ff;
    border-left-color: #764ba2;
}

.step-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
}

.step-number {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    margin-right: 0.75rem;
}

.step-description {
    font-weight: 600;
    color: #333;
    flex: 1;
}

/* KaTeX Formula Display (Important Rule 2) */
.step-formula {
    margin: 1rem 0;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    overflow-x: auto;
}

.step-formula .katex-display {
    margin: 0;
}

.step-formula .katex {
    font-size: 1.1em;
    color: #333;
}

.step-result {
    font-size: 1rem;
    color: #48bb78;
    font-weight: 600;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed #e0e0e0;
}

.step-result strong {
    color: #2f855a;
}

/* ========================================
   PROBABILITY TREE DIAGRAM
   ======================================== */
.tree-display {
    padding: 1.5rem;
    background: white;
    border-radius: 8px;
    overflow-x: auto;
}

.tree-canvas {
    width: 100%;
    height: 400px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
}

.tree-legend {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.tree-legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.tree-legend-item:last-child {
    margin-bottom: 0;
}

.tree-legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    margin-right: 0.75rem;
}

/* ========================================
   DISTRIBUTION CHART
   ======================================== */
.chart-container {
    position: relative;
    height: 400px;
    padding: 1rem;
    background: white;
    border-radius: 8px;
}

#distributionChart {
    width: 100% !important;
    height: 100% !important;
}

.chart-controls {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.chart-control-btn {
    padding: 0.5rem 1rem;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chart-control-btn:hover {
    background: #667eea;
    color: white;
}

.chart-control-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #764ba2;
}

/* ========================================
   ACTION BUTTONS (MANDATORY)
   ======================================== */
.action-buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.btn-custom,
.btn-custom-outline {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
}

.btn-custom {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-custom:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-custom-outline {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-custom-outline:hover {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8edff 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.btn-custom:active,
.btn-custom-outline:active {
    transform: translateY(0);
}

.btn-sponsor {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: white;
}

.btn-sponsor:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-sponsor:active {
    transform: translateY(0);
}

/* ========================================
   TOOLTIPS
   ======================================== */
.tooltip-wrapper {
    position: relative;
    display: inline-block;
}

.tooltip-content {
    visibility: hidden;
    position: absolute;
    z-index: 1000;
    background: #333;
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.4;
    width: 250px;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tooltip-content::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.tooltip-wrapper:hover .tooltip-content {
    visibility: visible;
    opacity: 1;
}

/* ========================================
   LOADING INDICATOR
   ======================================== */
.loading-indicator {
    display: none;
    text-align: center;
    padding: 2rem;
}

.loading-indicator.show {
    display: block;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Mobile (≤576px) */
@media (max-width: 576px) {
    .page-header h1 {
        font-size: 1.8rem;
    }

    .page-header .subtitle {
        font-size: 0.95rem;
    }

    .result-value {
        font-size: 2.5rem;
    }

    .result-percentage {
        font-size: 1.2rem;
    }

    .action-buttons-grid {
        grid-template-columns: 1fr;
    }

    .calculation-step {
        padding: 1rem;
    }

    .step-formula .katex {
        font-size: 0.95em;
    }

    .chart-container {
        height: 300px;
    }

    .tree-canvas {
        height: 300px;
    }

    .seo-section {
        padding: 1.5rem;
    }

    .seo-section h2 {
        font-size: 1.5rem;
    }

    .seo-section h3 {
        font-size: 1.2rem;
    }
}

/* Tablet (577-992px) */
@media (min-width: 577px) and (max-width: 992px) {
    .page-header h1 {
        font-size: 2.2rem;
    }

    .result-value {
        font-size: 2.75rem;
    }

    .chart-container {
        height: 350px;
    }
}

/* Desktop (≥993px) */
@media (min-width: 993px) {
    .main-container {
        max-width: 1400px;
        margin: 0 auto;
    }

    .result-display {
        position: sticky;
        top: 20px;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .action-buttons-grid,
    .toggle-steps,
    .chart-controls {
        display: none;
    }

    .steps-container {
        display: block !important;
    }

    .calculation-step {
        page-break-inside: avoid;
    }

    .glass-card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible for keyboard navigation */
.btn-custom:focus-visible,
.btn-custom-outline:focus-visible,
.btn-sponsor:focus-visible,
.form-input:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .form-input {
        border-width: 3px;
    }

    .calculation-step {
        border-left-width: 6px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
