/* 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, #f5f7fa 0%, #c3cfe2 100%);
    color: #333;
    line-height: 1.4;
    overflow-x: hidden;
}

/* Container with responsive height */
.container {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 10px;
}

/* Check if in iframe and adjust height */
@media (max-height: 500px) {
    .container {
        height: 450px;
        max-height: 450px;
    }
}

/* Control Panel - compact design at top */
.control-panel {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
    justify-content: space-between;
    min-height: 60px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 200px;
}

.control-label {
    font-weight: 600;
    color: #2c3e50;
    white-space: nowrap;
    cursor: help;
}

.slider {
    flex: 1;
    height: 8px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    min-width: 120px;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    box-shadow: 0 2px 4px 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 4px rgba(0,0,0,0.2);
}

.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px; /* Touch-friendly size */
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2980b9;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #7f8c8d;
    transform: translateY(-1px);
}

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

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

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 32px;
}

/* Main content area */
.main-content {
    flex: 1;
    display: flex;
    gap: 15px;
    min-height: 0;
    overflow: hidden;
}

/* Diagram container */
.diagram-container {
    flex: 1;
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 300px;
}

.diagram {
    width: 100%;
    height: auto;
    max-width: 400px;
    max-height: 300px;
}

.mirror {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.normal {
    opacity: 0.7;
}

.ray {
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.arrow {
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.label {
    font-size: 12px;
    font-weight: 600;
    fill: #2c3e50;
}

.ray-label {
    font-size: 11px;
    font-weight: 600;
    fill: #2c3e50;
}

.angle-label {
    font-size: 10px;
    font-weight: 700;
    fill: #2c3e50;
}

.angle-arc {
    opacity: 0.8;
}

/* Data container */
.data-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 250px;
    max-width: 350px;
}

.table-container, .graph-container {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    flex: 1;
    min-height: 0;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 10px;
    cursor: help;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: #ecf0f1;
    padding: 8px;
    text-align: center;
    font-weight: 600;
    color: #2c3e50;
    border: 1px solid #bdc3c7;
    font-size: 12px;
}

.data-table td {
    padding: 6px 8px;
    text-align: center;
    border: 1px solid #bdc3c7;
    background: #fff;
}

.data-table tbody tr:nth-child(even) {
    background: #f8f9fa;
}

.data-table tbody tr:hover {
    background: #e8f4f8;
}

.no-data {
    text-align: center;
    color: #7f8c8d;
    font-style: italic;
    padding: 20px;
    font-size: 13px;
}

.graph {
    width: 100%;
    height: auto;
    border: 1px solid #bdc3c7;
    border-radius: 8px;
    background: #fafafa;
}

/* Analytics Panel */
.analytics-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: hidden;
    max-height: 200px;
    display: flex;
    flex-direction: column;
}

.analytics-header {
    background: #34495e;
    color: white;
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
    user-select: none;
    min-height: 44px;
}

.analytics-header:hover {
    background: #2c3e50;
}

.toggle-icon {
    transition: transform 0.3s ease;
}

.toggle-icon.rotated {
    transform: rotate(180deg);
}

.analytics-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 150px;
    transition: max-height 0.3s ease;
    overflow: hidden;
}

.analytics-content.collapsed {
    max-height: 0;
}

.analytics-controls {
    padding: 8px 15px;
    border-bottom: 1px solid #ecf0f1;
    display: flex;
    justify-content: flex-end;
}

.log-container {
    flex: 1;
    padding: 10px 15px;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.4;
    background: #f8f9fa;
}

.log-entry {
    margin-bottom: 4px;
    padding: 2px 0;
    color: #2c3e50;
}

.log-entry:last-child {
    margin-bottom: 0;
}

/* Responsive design for mobile */
@media (max-width: 768px) {
    .container {
        padding: 5px;
        gap: 8px;
    }
    
    .control-panel {
        padding: 10px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .control-group {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        min-width: auto;
    }
    
    .control-label {
        text-align: center;
        white-space: normal;
    }
    
    .main-content {
        flex-direction: column;
        gap: 10px;
    }
    
    .data-container {
        max-width: none;
        min-width: auto;
    }
    
    .diagram-container {
        min-width: auto;
        min-height: 200px;
    }
    
    .btn {
        flex: 1;
        min-width: 80px;
    }
    
    .section-title {
        font-size: 14px;
    }
    
    .data-table {
        font-size: 11px;
    }
    
    .data-table th, .data-table td {
        padding: 4px;
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .control-panel {
        padding: 8px;
    }
    
    .diagram-container, .table-container, .graph-container {
        padding: 10px;
    }
    
    .btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .analytics-panel {
        max-height: 150px;
    }
    
    .analytics-content {
        max-height: 100px;
    }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 48px;
        min-width: 48px;
    }
    
    .slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    .analytics-header {
        min-height: 48px;
    }
}