/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link for keyboard navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    z-index: 1000;
}

.skip-link:focus {
    top: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    line-height: 1.4;
    color: #333;
    background: #f5f5f5;
    height: 100vh;
    overflow: hidden;
    padding: 16px;
}

.container {
    height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Header */
header {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 16px 24px;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 28px;
    font-weight: 700;
    color: #333;
    margin: 0;
}

/* AI Toggle Switch */
.ai-toggle-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.toggle-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.toggle-label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.toggle-switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    width: 48px;
    height: 24px;
    background-color: #ccc;
    border-radius: 24px;
    transition: background-color 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider {
    background-color: #0078d4;
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.toggle-switch input[type="checkbox"]:disabled + .toggle-slider {
    background-color: #e0e0e0;
    cursor: not-allowed;
    opacity: 0.6;
}

.toggle-switch input[type="checkbox"]:disabled ~ .toggle-label {
    color: #999;
}

.toggle-switch input[type="checkbox"]:focus + .toggle-slider {
    outline: 2px solid #0078d4;
    outline-offset: 2px;
}

.toggle-switch input[type="checkbox"]:disabled {
    cursor: not-allowed;
}

/* AI Transparency Note */
.ai-transparency-note {
    font-size: 12px;
}

.ai-transparency-note a {
    color: #0078d4;
    text-decoration: none;
}

.ai-transparency-note a:hover {
    text-decoration: underline;
}

.ai-transparency-note a:focus {
    outline: 2px solid #0078d4;
    outline-offset: 2px;
    border-radius: 2px;
}

label.toggle-switch:has(input:disabled) {
    cursor: not-allowed;
}


/* Main layout */
main {
    flex: 1;
    overflow: hidden;
}

.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr 320px;
    height: 100%;
    min-height: 0;
}

/* Left sidebar - Upload area */
.upload-sidebar {
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.upload-zone {
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.upload-area {
    border: 2px dashed #d0d0d0;
    border-radius: 8px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fafafa;
}

.upload-area:hover {
    border-color: #007acc;
    background: #f0f8ff;
}

.upload-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.upload-text {
    font-size: 12px;
    color: #666;
    line-height: 1.3;
}

.browse-link {
    color: #007acc;
    text-decoration: underline;
    cursor: pointer;
}

.browse-link:hover {
    color: #005a9e;
}

.thumbnails-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.thumbnail-item {
    position: relative;
    margin-bottom: 8px;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s ease;
    aspect-ratio: 1;
}

.thumbnail-item:hover {
    border-color: #007acc;
}

.thumbnail-item.selected {
    border-color: #007acc;
    box-shadow: 0 0 0 1px #007acc;
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.thumbnail-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.thumbnail-remove:hover {
    background: rgba(255, 0, 0, 0.8);
}

.sample-overlay {
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    background: rgba(0, 122, 204, 0.9);
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    padding: 2px 4px;
    border-radius: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(2px);
}

/* Center area - Main content */
.main-content {
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.analyze-header {
    padding: 16px 24px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.analyze-btn {
    background: #007acc;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.analyze-btn:hover:not(:disabled) {
    background: #005a9e;
}

.analyze-btn:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

.progress-section {
    padding: 16px 24px;
    border-bottom: 1px solid #e0e0e0;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background-color: #e0e0e0;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: #007acc;
    width: 0%;
    transition: width 0.3s ease;
}

#progressText {
    font-size: 12px;
    color: #666;
    margin: 0;
}

/* Model loading section */
.model-loading-section {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.model-loading-content {
    text-align: center;
    max-width: 400px;
    padding: 40px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top: 4px solid #007acc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.model-loading-content h3 {
    font-size: 18px;
    color: #333;
    margin-bottom: 12px;
    font-weight: 400;
}

.model-loading-content p {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
}

.model-progress-bar {
    width: 100%;
    height: 6px;
    background-color: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 12px;
}

.model-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007acc, #0099ff);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

/* UI disabled state */
.ui-disabled {
    pointer-events: none;
    opacity: 0.6;
}

.ui-disabled .upload-area {
    cursor: not-allowed;
    border-color: #ccc;
    background: #f5f5f5;
}

.ui-disabled .thumbnail-item {
    cursor: not-allowed;
}

/* Analysis in progress disabled states */
.upload-area.disabled {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #ccc;
    background: #f5f5f5;
}

.upload-area.disabled .upload-text {
    color: #999;
}

.upload-area.disabled .upload-icon {
    opacity: 0.5;
}

.thumbnail-item.disabled {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
}

.thumbnail-item.disabled img {
    filter: grayscale(50%);
}

.thumbnail-remove:disabled {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
    background: #f0f0f0;
    color: #ccc;
}

.content-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
    position: relative;
}

.image-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.zoom-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    padding: 12px 16px;
    flex-shrink: 0;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    background: white;
    color: #333;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: #007acc;
    color: white;
    border-color: #007acc;
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-btn:disabled {
    background: #f0f0f0;
    color: #ccc;
    border-color: #e0e0e0;
    cursor: not-allowed;
    transform: none;
}

.zoom-btn:disabled:hover {
    background: #f0f0f0;
    color: #ccc;
    border-color: #e0e0e0;
    transform: none;
}

.zoom-btn.reset {
    font-size: 12px;
}

.zoom-level {
    font-size: 13px;
    font-weight: 500;
    color: #666;
    min-width: 40px;
    text-align: center;
    padding: 0 8px;
}

.image-viewer {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    position: relative;
}

.image-viewer img,
.image-viewer canvas {
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
    cursor: grab;
}

.image-viewer img:active,
.image-viewer canvas:active {
    cursor: grabbing;
}

.content-placeholder {
    color: #999;
    font-size: 14px;
    text-align: center;
}

/* Right sidebar - Results */
.results-panel {
    background: white;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.results-tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    color: #666;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-btn.active {
    color: #007acc;
    border-bottom-color: #007acc;
    background: #f8f8f8;
}

.tab-btn:hover:not(.active) {
    color: #333;
    background: #f5f5f5;
}

.results-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
    padding: 16px;
}

.tab-content.active {
    display: block;
}

.results-placeholder {
    text-align: center;
    color: #999;
    font-size: 13px;
    padding: 40px 20px;
    font-style: italic;
}

.fields-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.field-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 12px;
}

.field-label {
    font-weight: 600;
    color: #495057;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.field-value {
    color: #212529;
    font-size: 13px;
    word-break: break-word;
    line-height: 1.4;
}

.field-value.empty {
    color: #6c757d;
    font-style: italic;
}

.field-message {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 16px;
    color: #856404;
}

.field-message p {
    margin: 0 0 8px 0;
    line-height: 1.5;
}

.field-message p:last-child {
    margin-bottom: 0;
}

.field-message strong {
    color: #533f03;
}

.result-content pre {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 12px;
    font-size: 11px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    /* Performance improvements for large content */
    contain: content;
    will-change: scroll-position;
}

/* Error section */
.error-section {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 1px solid #007acc !important;
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    color: #333 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    min-width: 300px;
}

.error-section h2 {
    margin-bottom: 12px;
    font-size: 16px;
    color: #333 !important;
}

.error-section p {
    margin-bottom: 16px;
    font-size: 14px;
    color: #333 !important;
}

.action-btn {
    background: #007acc;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s ease;
}

.action-btn:hover {
    background: #005a9e;
}

/* Drag and drop styles */
.upload-area.dragover {
    border-color: #007acc;
    background: #f0f8ff;
    transform: scale(1.02);
}

/* Loading state */
.loading {
    pointer-events: none;
    opacity: 0.7;
}

/* Animation for field updates */
.field-item.updated {
    animation: highlightField 0.6s ease;
}

@keyframes highlightField {
    0% {
        background: #d4edda;
        border-color: #c3e6cb;
    }
    100% {
        background: #f8f9fa;
        border-color: #e9ecef;
    }
}

/* Responsive design */
@media (max-width: 1200px) {
    .app-layout {
        grid-template-columns: 200px 1fr 280px;
    }
}

@media (max-width: 1024px) {
    .app-layout {
        grid-template-columns: 180px 1fr 250px;
    }
    
    .upload-area {
        padding: 16px 12px;
    }
    
    .upload-text {
        font-size: 11px;
    }
}

@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    
    .upload-sidebar,
    .results-panel {
        border: none;
        border-top: 1px solid #e0e0e0;
    }
    
    .thumbnails-list {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px;
    }
    
    .thumbnail-item {
        flex-shrink: 0;
        width: 80px;
        margin-right: 8px;
        margin-bottom: 0;
    }
}