/**
 * OCR Interface Styles
 * File: css/service_ocr.css
 * Dedicated styles for the OCR application interface
 */

/* ==========================================================================
   OCR LAYOUT & STRUCTURE
   ========================================================================== */

   .ocr-results-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 24px;
    min-height: 500px;
}

.ocr-image-panel {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.ocr-text-panel {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ==========================================================================
   IMAGE PANEL COMPONENTS
   ========================================================================== */

.ocr-image-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.ocr-image-header h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.region-badge {
    background: var(--gradient-primary);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.ocr-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ==========================================================================
   IMAGE CONTAINER & OVERLAY
   ========================================================================== */

.ocr-image-container {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
}

.ocr-image {
    width: 100%;
    height: auto;
    display: block;
    max-height: 400px;
    object-fit: contain;
}

.ocr-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ocr-overlay.hidden {
    opacity: 0;
}

/* ==========================================================================
   CONFIDENCE LEGEND
   ========================================================================== */

.ocr-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.high-confidence { background: #10b981; }
.medium-confidence { background: #f59e0b; }
.low-confidence { background: #ef4444; }

/* ==========================================================================
   TEXT PANEL SECTIONS
   ========================================================================== */

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.section-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.section-actions {
    display: flex;
    gap: 8px;
}

.sort-controls select {
    font-size: 0.75rem;
    padding: 4px 8px;
    min-width: 120px;
}

/* ==========================================================================
   FULL TEXT DISPLAY
   ========================================================================== */

.ocr-text-section {
    flex: 0 0 auto;
}

.ocr-full-text {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    min-height: 120px;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
}

.ocr-full-text:empty::before {
    content: attr(placeholder);
    color: var(--text-tertiary);
    font-style: italic;
}

/* ==========================================================================
   TEXT REGIONS LIST
   ========================================================================== */

.ocr-regions-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ocr-regions-list {
    flex: 1;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
}

/* ==========================================================================
   INDIVIDUAL TEXT REGION ITEMS
   ========================================================================== */

.text-region-item {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: var(--bg-primary);
}

.text-region-item:last-child {
    border-bottom: none;
}

.text-region-item:hover {
    background: var(--bg-tertiary);
    transform: translateX(2px);
}

.text-region-item.highlighted {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--accent-primary);
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.2);
}

/* ==========================================================================
   REGION CONTENT ELEMENTS
   ========================================================================== */

.region-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.region-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.region-confidence {
    display: flex;
    align-items: center;
    gap: 8px;
}

.confidence-indicator {
    width: 40px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.confidence-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 1px;
}

.confidence-fill.high { background: #10b981; }
.confidence-fill.medium { background: #f59e0b; }
.confidence-fill.low { background: #ef4444; }

.confidence-text {
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 35px;
    color: var(--text-secondary);
}

.region-text {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    margin-bottom: 8px;
    word-break: break-word;
    color: var(--text-primary);
    line-height: 1.4;
}

/* ==========================================================================
   REGION METADATA & ACTIONS
   ========================================================================== */

.region-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.region-location {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.region-actions {
    display: flex;
    gap: 4px;
}

.region-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
}

.region-action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: scale(1.1);
}

/* ==========================================================================
   OCR SPECIFIC ANIMATIONS
   ========================================================================== */

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes pulseHighlight {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(99, 102, 241, 0);
    }
}

/* ==========================================================================
   OCR UPLOAD AREA ENHANCEMENTS
   ========================================================================== */

.upload-area {
    position: relative;
    overflow: hidden;
}

.upload-area:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-tertiary);
    transform: translateY(-1px);
}

.upload-area.dragover {
    border-color: var(--accent-primary);
    background-color: rgba(99, 102, 241, 0.05);
    transform: scale(1.02);
}

/* ==========================================================================
   OCR PROCESSING STATES
   ========================================================================== */

.processing-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(var(--bg-primary-rgb), 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    z-index: 10;
}

/* ==========================================================================
   CUSTOM SCROLLBARS
   ========================================================================== */

.ocr-regions-list::-webkit-scrollbar {
    width: 6px;
}

.ocr-regions-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.ocr-regions-list::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 3px;
}

.ocr-regions-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.ocr-full-text::-webkit-scrollbar {
    width: 6px;
}

.ocr-full-text::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.ocr-full-text::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 3px;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 1200px) {
    .ocr-results-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .ocr-image-panel {
        order: 1;
    }
    
    .ocr-text-panel {
        order: 2;
    }
}

@media (max-width: 768px) {
    .ocr-image-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .ocr-controls {
        justify-content: center;
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .section-actions {
        justify-content: center;
    }
    
    .ocr-legend {
        justify-content: space-around;
        gap: 8px;
    }
    
    .legend-item {
        font-size: 0.7rem;
    }
    
    .region-meta {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    
    .region-location {
        flex-direction: column;
        gap: 4px;
    }
}

@media (max-width: 480px) {
    .ocr-results-layout {
        gap: 16px;
    }
    
    .ocr-image-panel,
    .ocr-text-panel {
        padding: 16px;
    }
    
    .ocr-image {
        max-height: 300px;
    }
    
    .ocr-full-text {
        max-height: 150px;
        font-size: 0.8rem;
    }
    
    .text-region-item {
        padding: 10px;
    }
    
    .region-text {
        font-size: 0.8rem;
        padding: 6px;
    }
}

/* ==========================================================================
   ACCESSIBILITY & FOCUS STATES
   ========================================================================== */

.text-region-item:focus,
.region-action-btn:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.text-region-item:focus-visible,
.region-action-btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   HIGH CONTRAST MODE SUPPORT
   ========================================================================== */

@media (prefers-contrast: high) {
    .ocr-overlay {
        filter: contrast(1.2);
    }
    
    .confidence-fill.high { background: #008000; }
    .confidence-fill.medium { background: #ff8000; }
    .confidence-fill.low { background: #ff0000; }
    
    .legend-color {
        border: 2px solid var(--text-primary);
    }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    .ocr-controls,
    .section-actions,
    .region-actions {
        display: none;
    }
    
    .ocr-results-layout {
        grid-template-columns: 1fr;
    }
    
    .ocr-image-panel {
        break-inside: avoid;
    }
    
    .text-region-item {
        break-inside: avoid;
        border: 1px solid #ccc;
        margin-bottom: 8px;
    }
    
    .ocr-overlay {
        display: none;
    }
}