/* 샘플링 도구 CSS */
* { box-sizing: border-box; }

body {
    font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    background-color: #f5f5f5;
}

h1 { text-align: center; color: #333; margin-bottom: 30px; }
h2 { color: #444; border-bottom: 2px solid #007bff; padding-bottom: 10px; margin-top: 30px; }
h3 { margin-top: 0; }

.container { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.full-width { grid-column: 1 / -1; }

label { display: block; margin-bottom: 5px; font-weight: bold; color: #555; }
input[type="text"], input[type="number"], input[type="password"] {
    width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; margin-bottom: 15px;
}
input[type="number"] { width: 120px; }
input[type="file"] { margin-bottom: 15px; }
textarea { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; resize: vertical; }

button {
    background-color: #007bff; color: white; padding: 10px 20px; border: none;
    border-radius: 4px; cursor: pointer; font-size: 14px; margin-right: 10px; margin-bottom: 10px;
}
button:hover { background-color: #0056b3; }
button:disabled { background-color: #ccc; cursor: not-allowed; }
button.secondary { background-color: #6c757d; }
button.secondary:hover { background-color: #545b62; }
button.danger { background-color: #dc3545; }
button.danger:hover { background-color: #c82333; }
button.success { background-color: #28a745; }
button.success:hover { background-color: #218838; }
button.warning { background-color: #ffc107; color: #000; }
button.warning:hover { background-color: #e0a800; }

/* 로그인 섹션 */
.login-section { max-width: 400px; margin: 100px auto; }
.login-section h1 { margin-bottom: 20px; }

/* 헤더 네비게이션 */
.header-nav {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; padding: 10px 0; border-bottom: 1px solid #ddd;
}
.header-nav a { color: #007bff; text-decoration: none; margin-right: 15px; }
.header-nav a:hover { text-decoration: underline; }
.header-nav .right-section { display: flex; align-items: center; gap: 10px; }

/* 모달 */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: white; padding: 30px; border-radius: 8px; max-width: 600px;
    width: 90%; max-height: 80vh; overflow-y: auto;
}

/* 파일 목록 */
.file-list { list-style: none; padding: 0; margin: 0; }
.file-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px; border-bottom: 1px solid #eee;
}
.file-list li:hover { background: #f5f5f5; }
.file-info { flex: 1; cursor: pointer; }
.file-info .filename { font-weight: bold; color: #007bff; }
.file-info .meta { font-size: 12px; color: #666; }
.file-actions { display: flex; gap: 5px; }
.file-actions button { padding: 5px 10px; font-size: 12px; margin: 0; }

/* 파일 관리 */
.file-management { background: #e9ecef; padding: 15px; border-radius: 8px; margin-bottom: 20px; }
.file-management h3 { margin-bottom: 15px; font-size: 16px; }
.current-file-info { background: #d4edda; padding: 10px 15px; border-radius: 4px; margin-bottom: 15px; color: #155724; }
.current-file-info.unsaved { background: #fff3cd; color: #856404; }

/* 레이아웃 */
.inline-group { display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; }
.inline-group > div { flex: 1; min-width: 100px; }
.metadata-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; }

/* 결과 박스 */
.result-box { background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; padding: 15px; margin-top: 10px; min-height: 60px; }
.result-box.highlight { background: #e7f3ff; border-color: #007bff; }
.result-box.success { background: #d4edda; border-color: #28a745; }
.result-box.warning { background: #fff3cd; border-color: #ffc107; }

/* 텍스트 표시 */
.page-list { font-size: 18px; font-weight: bold; color: #007bff; word-break: break-all; }
.char-count { font-size: 16px; color: #28a745; font-weight: bold; margin-top: 10px; }
.char-count.warning { color: #ffc107; }
.char-count.danger { color: #dc3545; }

/* JSON 출력 */
#jsonOutput {
    font-family: 'Consolas', 'Monaco', monospace; font-size: 12px;
    white-space: pre-wrap; word-break: break-all; max-height: 500px;
    overflow-y: auto; background: #2d2d2d; color: #f8f8f2; padding: 15px; border-radius: 4px;
}

/* 세그먼트 정보 */
.segment-info { background: #e9ecef; padding: 10px; border-radius: 4px; margin-bottom: 15px; }
.segment-info span { margin-right: 20px; font-weight: bold; }

/* 체크박스 */
.checkbox-group { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.checkbox-group input[type="checkbox"] { width: 20px; height: 20px; }

/* 기타 */
.note { font-size: 12px; color: #6c757d; margin-top: 5px; }
hr { border: none; border-top: 1px solid #dee2e6; margin: 20px 0; }

/* 스텝 인디케이터 */
.steps { display: flex; margin-bottom: 20px; }
.step {
    flex: 1; text-align: center; padding: 15px; background: #e9ecef;
    border-right: 1px solid #dee2e6; position: relative;
}
.step:last-child { border-right: none; }
.step.active { background: #007bff; color: white; }
.step.completed { background: #28a745; color: white; }
.step-number { font-size: 24px; font-weight: bold; }
.step-title { font-size: 12px; margin-top: 5px; }

/* 이미지 업로드 영역 */
.upload-area {
    border: 2px dashed #ccc; border-radius: 8px; padding: 40px; text-align: center;
    cursor: pointer; transition: all 0.3s; margin-bottom: 15px;
}
.upload-area:hover { border-color: #007bff; background: #f8f9fa; }
.upload-area.dragover { border-color: #28a745; background: #d4edda; }

/* 이미지 미리보기 그리드 */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 15px; margin-top: 15px; }
.image-item {
    border: 1px solid #ddd; border-radius: 8px; padding: 10px; text-align: center; position: relative;
}
.image-item img { max-width: 100%; height: 100px; object-fit: cover; border-radius: 4px; }
.image-item .page-label { font-weight: bold; margin-top: 5px; }
.image-item .ocr-status { font-size: 11px; color: #666; }
.image-item .ocr-status.success { color: #28a745; }
.image-item .ocr-status.error { color: #dc3545; }
.image-item .ocr-status.pending { color: #ffc107; }
.image-item .remove-btn {
    position: absolute; top: 5px; right: 5px; background: #dc3545; color: white;
    border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-size: 14px;
}

/* 샘플링 결과 테이블 */
.sampling-table { width: 100%; border-collapse: collapse; margin-top: 15px; }
.sampling-table th, .sampling-table td { border: 1px solid #dee2e6; padding: 10px; text-align: center; }
.sampling-table th { background: #007bff; color: white; }
.sampling-table tr:nth-child(even) { background: #f8f9fa; }
.sampling-table tr.frame { background: #fff3cd; }
.sampling-table tr.sampled { background: #d4edda; }

/* 로딩 스피너 */
.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* 상태 표시 */
.status-indicator { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; }
.status-indicator.connected { background: #28a745; }
.status-indicator.disconnected { background: #dc3545; }
.status-indicator.loading { background: #ffc107; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* 진행률 바 */
.progress-bar { width: 100%; height: 20px; background: #e9ecef; border-radius: 10px; overflow: hidden; margin: 10px 0; }
.progress-bar .progress { height: 100%; background: #007bff; transition: width 0.3s; }
.progress-bar .progress.success { background: #28a745; }

/* 샘플링 정보 (층화 무작위 추출) */
.sampling-info { background: #e7f3ff; border-radius: 4px; padding: 10px; margin-top: 10px; }
.sampling-details { margin: 5px 0 0 20px; font-size: 13px; color: #555; }
.sampling-details li { margin-bottom: 3px; }

/* 통계 테이블 */
.stats-table { width: 100%; border-collapse: collapse; margin: 15px 0; font-size: 13px; }
.stats-table th, .stats-table td { border: 1px solid #dee2e6; padding: 8px 12px; text-align: center; }
.stats-table th { background: #495057; color: white; font-weight: normal; }
.stats-table td { background: white; }
.stats-table td.good { color: #28a745; font-weight: bold; }
.stats-table td.warn { color: #dc3545; font-weight: bold; }

/* 통계 유효성 표시 */
.validity-indicator { 
    margin-top: 15px; padding: 12px 15px; border-radius: 6px; 
    font-weight: bold; text-align: center; 
}
.validity-indicator.valid { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.validity-indicator.warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

/* 다중 업로드 섹션 */
.multi-upload-section { margin-bottom: 20px; }

.drop-zone {
    border: 3px dashed #ccc;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #fafafa;
}

.drop-zone:hover {
    border-color: #007bff;
    background: #f0f7ff;
}

.drop-zone.dragover {
    border-color: #28a745;
    background: #d4edda;
    transform: scale(1.02);
}

.drop-zone-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.drop-zone-text {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.drop-zone-hint {
    font-size: 12px;
    color: #888;
}

/* 다중 업로드 상태 */
.multi-upload-status {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.multi-upload-status .progress-bar {
    margin-bottom: 10px;
}

.multi-upload-status .upload-status-text {
    text-align: center;
    color: #666;
    font-size: 14px;
}

.upload-complete {
    text-align: center;
    padding: 10px;
    border-radius: 6px;
    font-weight: bold;
}

.upload-complete.success {
    background: #d4edda;
    color: #155724;
}

.upload-complete.warning {
    background: #fff3cd;
    color: #856404;
}

.upload-error {
    text-align: center;
    padding: 10px;
    background: #f8d7da;
    color: #721c24;
    border-radius: 6px;
}

/* 이미지 업로드 플레이스홀더 */
.upload-placeholder {
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-placeholder:hover {
    background: #f0f7ff;
    border-color: #007bff;
}

/* OCR 분석 중 이미지 표시 */
.analyzing-image-container {
    background: #f0f7ff;
    border: 2px solid #007bff;
    border-radius: 12px;
    padding: 20px;
    margin-top: 15px;
    text-align: center;
}

.analyzing-image-container h4 {
    margin: 0 0 15px 0;
    color: #007bff;
}

.analyzing-image-wrapper {
    position: relative;
    display: inline-block;
    max-width: 400px;
    margin: 0 auto;
}

.analyzing-image-wrapper img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.analyzing-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 123, 255, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.analyzing-label {
    margin-top: 10px;
    font-weight: bold;
    color: #333;
}

/* 테이블 행 상태 스타일 */
.pending-row { background: #f8f9fa; }
.analyzing-row { background: #e7f3ff !important; }
.success-row { background: #d4edda !important; }
.error-row { background: #f8d7da !important; }

/* 상태 뱃지 */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

.status-badge.pending { background: #e9ecef; color: #6c757d; }
.status-badge.analyzing { background: #007bff; color: white; }
.status-badge.success { background: #28a745; color: white; }
.status-badge.error { background: #dc3545; color: white; }

/* 미니 스피너 */
.mini-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* 진행 텍스트 */
.progress-text {
    text-align: center;
    font-weight: bold;
    color: #333;
    margin-top: 5px;
}

/* 에러 메시지 */
.error-message {
    color: #721c24;
    font-size: 12px;
    text-align: left;
}

/* 재분석 섹션 */
.reanalyze-section {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.reanalyze-section h4 {
    margin: 0 0 15px 0;
    color: #495057;
}

.reanalyze-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.reanalyze-controls label {
    margin: 0;
    font-weight: normal;
}

.reanalyze-controls input {
    margin: 0;
}

.reanalyze-controls button {
    margin: 0;
}

/* 작은 버튼 */
.small-btn {
    padding: 4px 8px;
    font-size: 12px;
    margin: 0;
    background: #6c757d;
}

.small-btn:hover {
    background: #545b62;
}

/* 이미지 아이템 분석 중 상태 */
.image-item.analyzing {
    border-color: #007bff;
    box-shadow: 0 0 10px rgba(0,123,255,0.3);
}

.image-item .ocr-status.analyzing {
    color: #007bff;
    font-weight: bold;
}

/* 현재 분석 섹션 */
.current-analysis {
    margin-top: 15px;
}
/* 기존 이미지 알림 스타일 */
.existing-images-alert {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    border: 2px solid #f39c12;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    animation: alertPulse 2s ease-in-out infinite;
}

@keyframes alertPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.4); }
    50% { box-shadow: 0 0 15px 5px rgba(243, 156, 18, 0.2); }
}

.existing-images-alert .alert-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.existing-images-alert .alert-icon {
    font-size: 24px;
}

.existing-images-alert .alert-text {
    flex: 1;
    font-size: 14px;
    color: #856404;
}

.existing-images-alert button.small {
    padding: 6px 12px;
    font-size: 12px;
    margin: 0;
}

/* 기존 이미지 모달 */
.existing-images-modal-content {
    max-height: 60vh;
    overflow-y: auto;
}

.existing-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.existing-images-grid .img-thumb {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
}

/* ========== 세션 타이머 ========== */
.session-timer {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: #007bff;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    font-family: 'Consolas', 'Monaco', monospace;
    color: white;
    transition: all 0.3s ease;
}

.session-timer.warning {
    background: #ffc107;
    color: #000;
    animation: timer-pulse 1s ease-in-out infinite;
}

.session-timer.danger {
    background: #dc3545;
    color: white;
    animation: timer-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* 자동 저장 알림 */
.auto-save-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #28a745;
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10000;
    font-weight: bold;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}