/* EEG Web Streaming Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
}

.container {
    display: flex;
    height: 100vh;
    gap: 20px;
    padding: 20px;
}

.control-panel {
    width: 350px;
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow-y: auto;
}

.control-panel h1 {
    color: #2c3e50;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.5em;
}

.control-panel h3 {
    color: #34495e;
    margin: 20px 0 10px 0;
    font-size: 1.1em;
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 5px;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
}

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

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

.btn-primary:hover:not(:disabled) {
    background-color: #2980b9;
}

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

.btn-secondary:hover:not(:disabled) {
    background-color: #7f8c8d;
}

.btn-success {
    background-color: #27ae60;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: #229954;
}

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

.btn-danger:hover:not(:disabled) {
    background-color: #c0392b;
}

.btn-info {
    background-color: #17a2b8;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background-color: #138496;
}

.btn-warning {
    background-color: #ffc107;
    color: #212529;
}

.btn-warning:hover:not(:disabled) {
    background-color: #e0a800;
}

.impedance-section {
    margin-bottom: 15px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 5px;
    border: 1px solid #e9ecef;
}

.impedance-section h4 {
    color: #495057;
    margin: 0 0 10px 0;
    font-size: 1em;
    font-weight: 500;
}

.status-section, .info-section {
    margin-bottom: 15px;
}

.status {
    padding: 8px 12px;
    border-radius: 5px;
    font-weight: 500;
    text-align: center;
    margin-bottom: 10px;
}

.status.connected {
    background-color: #d5f4e6;
    color: #27ae60;
    border: 1px solid #27ae60;
}

.status.disconnected {
    background-color: #fadbd8;
    color: #e74c3c;
    border: 1px solid #e74c3c;
}

.status.streaming {
    background-color: #d5f4e6;
    color: #27ae60;
    border: 1px solid #27ae60;
}

.status.stopped {
    background-color: #f8f9fa;
    color: #6c757d;
    border: 1px solid #6c757d;
}

.error-message {
    background-color: #f8d7da;
    color: #721c24;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #f5c6cb;
    font-size: 14px;
    display: none;
}

.error-message.show {
    display: block;
}

.data-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 14px;
    color: #666;
}

.data-info span {
    display: flex;
    justify-content: space-between;
}

.scale-info {
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border: 1px solid #e9ecef;
}

.scale-info h3 {
    margin-top: 0;
    color: #495057;
}

#scaleInfo div {
    margin-bottom: 8px;
    font-size: 14px;
    color: #666;
}

#scaleInfo span {
    font-weight: 500;
    color: #333;
}

/* 스케일 바 스타일 */
.scale-bar-container {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.scale-bar-container h4 {
    margin: 0 0 10px 0;
    color: #495057;
    font-size: 14px;
}

.scale-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.scale-bar-line {
    width: 3px;
    height: 100px; /* 기본값, JavaScript에서 동적으로 변경됨 */
    background-color: #007bff;
    border-radius: 2px;
    position: relative;
    transition: height 0.3s ease; /* 부드러운 애니메이션 */
}

.scale-bar-line::before {
    content: '';
    position: absolute;
    top: 0;
    left: -3px;
    width: 9px;
    height: 2px;
    background-color: #007bff;
}

.scale-bar-line::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -3px;
    width: 9px;
    height: 2px;
    background-color: #007bff;
}

.scale-bar-label {
    font-size: 12px;
    color: #666;
    font-weight: 500;
    text-align: center;
}

.scale-bar-label span {
    color: #007bff;
    font-weight: 600;
}

/* 데이터 저장 섹션 */
.save-section {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

/* 채널 선택 섹션 */
.channel-selection-section {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.channel-selection-section h3 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
    text-align: center;
    border-bottom: 2px solid #007bff;
    padding-bottom: 8px;
}

.channel-selection-section .form-group {
    margin-bottom: 0;
}

.channel-selection-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #495057;
    font-size: 14px;
}

.channel-selection-section .form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.channel-selection-section .form-control:focus {
    border-color: #007bff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* 임계값 설정 섹션 */
.threshold-settings-section {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.threshold-settings-section h3 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
    text-align: center;
    border-bottom: 2px solid #007bff;
    padding-bottom: 8px;
}

.threshold-group {
    margin-bottom: 20px;
    padding: 12px;
    background-color: white;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.threshold-group:last-child {
    margin-bottom: 0;
}

.threshold-group h4 {
    margin: 0 0 12px 0;
    color: #495057;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 6px;
}

.threshold-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.threshold-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.threshold-item label {
    flex: 0 0 80px;
    font-size: 12px;
    font-weight: 500;
    color: #495057;
    text-align: right;
}

.threshold-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
    background-color: white;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.threshold-input:focus {
    border-color: #007bff;
    outline: 0;
    box-shadow: 0 0 0 0.1rem rgba(0, 123, 255, 0.25);
}

.threshold-item span {
    flex: 0 0 25px;
    font-size: 11px;
    color: #6c757d;
    font-weight: 500;
}

.save-section h3 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
    border-bottom: 2px solid #007bff;
    padding-bottom: 8px;
}

.save-section .button-group {
    margin-bottom: 10px;
}

.save-section .status {
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 4px;
    text-align: center;
}

.save-section .status.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.save-section .status.warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.save-section .status.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.save-section .status.stopped {
    background-color: #e2e3e5;
    color: #383d41;
    border: 1px solid #d6d8db;
}

/* 오른쪽 패널 (그래프 + 표) */
.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: calc(100vh - 40px); /* 전체 높이에서 패딩 제외 */
    overflow: hidden; /* 오버플로우 방지 */
}

.graph-container {
    flex: 1; /* 그래프가 남은 공간 차지 */
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    min-height: 0; /* flex item이 축소될 수 있도록 */
}

#eegPlot {
    flex: 1;
    min-height: 0; /* flex item이 축소될 수 있도록 */
}

/* 반응형 디자인 */
@media (max-width: 1200px) {
    .container {
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 15px;
    }
    
    .control-panel {
        width: 100%;
        max-width: none;
    }
    
    .right-panel {
        flex: none;
        height: auto;
    }
    
    .graph-container {
        flex: none;
        min-height: 400px;
    }
    
    .test-tables-container {
        flex: none;
        flex-direction: column;
        max-height: none;
    }
    
    .test-table {
        margin-bottom: 10px;
        height: auto;
    }
    
    .test-table table {
        display: table; /* 기본 테이블 레이아웃으로 복원 */
    }
    
    .test-table tbody {
        overflow-y: visible; /* 스크롤 제거 */
    }
}

/* 로딩 애니메이션 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 버퍼 크기 조절 UI */
.buffer-control-section {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.buffer-control-section h4 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
}

.buffer-control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.buffer-control-group label {
    font-weight: 500;
    color: #495057;
    margin-bottom: 5px;
}

.buffer-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.buffer-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.buffer-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.buffer-presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid #007bff;
    color: #007bff;
    transition: all 0.2s ease;
}

.btn-outline:hover {
    background-color: #007bff;
    color: white;
}

.btn-outline.active {
    background-color: #007bff;
    color: white;
}

/* 테스트 결과 표들 */
.test-tables-container {
    display: flex;
    gap: 15px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    flex: 0 0 auto; /* 내용에 맞춰 크기 조정 */
    min-height: 0;
    overflow: visible; /* 스크롤 제거 - 모든 내용 표시 */
    align-items: flex-start; /* 상단 정렬 */
    justify-content: flex-start; /* 왼쪽 정렬 */
}

.test-table {
    flex: 0 0 auto; /* 내용에 맞춰 고정 크기 */
    background-color: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: auto; /* 내용에 맞춰 높이 조정 */
    width: fit-content; /* 내용에 맞춰 너비 조정 */
    max-height: none; /* 최대 높이 제한 제거 */
    overflow: visible; /* 스크롤 제거 */
}

/* 추가 그래프 스타일 */
.test-graph {
    flex: 1 0 auto; /* 넓이는 남은 공간 차지, 높이는 내용에 맞춤 */
    background-color: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    min-width: 300px; /* 최소 너비 보장 */
    align-self: stretch; /* 부모 높이에 맞춤 */
}

.test-graph h3 {
    margin: 0 0 10px 0;
    color: #495057;
    font-size: 14px;
    text-align: center;
    border-bottom: 2px solid #007bff;
    padding-bottom: 5px;
}

#frequencyPlot {
    flex: 1; /* 남은 공간 차지 */
    width: 100%; /* 전체 너비 사용 */
    min-height: 0; /* flex item이 축소될 수 있도록 */
}

.test-table h3 {
    margin: 0 0 10px 0;
    color: #495057;
    font-size: 14px;
    text-align: center;
    border-bottom: 2px solid #007bff;
    padding-bottom: 5px;
}

.test-table h3 small {
    font-size: 10px;
    color: #666;
    font-weight: normal;
    margin-left: 5px;
}

.test-table table {
    width: auto; /* 내용에 맞춰 너비 조정 */
    border-collapse: collapse;
    font-size: 11px;
    display: table; /* 기본 테이블 레이아웃 */
    height: auto; /* 내용에 맞춰 높이 조정 */
    min-width: fit-content; /* 최소 너비는 내용에 맞춤 */
}

.test-table thead {
    display: table-header-group; /* 기본 테이블 헤더 */
}

.test-table tbody {
    display: table-row-group; /* 기본 테이블 본문 */
    overflow-y: visible; /* 스크롤 제거 - 모든 행 표시 */
}

.test-table th,
.test-table td {
    padding: 4px 3px;
    text-align: center;
    border: 1px solid #dee2e6;
    white-space: nowrap;
    width: auto; /* 내용에 맞춰 너비 조정 */
}

.test-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
}

.test-table td {
    background-color: white;
    color: #333;
}

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

.test-table tbody tr:hover {
    background-color: #e3f2fd;
}

/* 상태 표시 스타일 */
.status-good {
    color: #28a745;
    font-weight: 600;
}

.status-warning {
    color: #ffc107;
    font-weight: 600;
}

.status-error {
    color: #dc3545;
    font-weight: 600;
}

.status-unknown {
    color: #6c757d;
    font-weight: 600;
}
