/* Theme Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --background: #ffffff;
    --surface: #f8fafc;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow: rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --spacing: 1rem;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Bootstrap Icons Styling */
.bi {
    vertical-align: -0.125em;
    margin-right: 0.25rem;
}

.kb-card h4 .bi,
.modal-header h2 .bi {
    margin-right: 0.5rem;
}

.kb-tip .bi,
.kb-warning .bi,
.kb-example .bi {
    margin-right: 0.35rem;
}

.kb-tip li .bi {
    color: var(--success);
    margin-right: 0.5rem;
}

.kb-warning .bi-exclamation-triangle-fill {
    color: var(--warning);
}

.kb-warning .bi-x-lg {
    color: var(--error);
}

/* Header */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: calc(var(--spacing) * 2);
    text-align: center;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Main Container */
.container {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: calc(var(--spacing) * 2);
    padding: calc(var(--spacing) * 2);
    max-width: 1600px;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
}

/* Controls Panel */
.controls-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: calc(var(--spacing) * 1.5);
    height: fit-content;
    position: sticky;
    top: calc(var(--spacing) * 2);
}

.control-group {
    margin-bottom: calc(var(--spacing) * 1.5);
    padding-bottom: calc(var(--spacing) * 1.5);
    border-bottom: 1px solid var(--border);
}

.control-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.control-group h2 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: var(--spacing);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

/* Radio & Checkbox Groups */
.radio-group,
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.radio-group label,
.checkbox-group label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9375rem;
}

.radio-group input[type="radio"],
.checkbox-group input[type="checkbox"] {
    margin-right: 0.5rem;
    cursor: pointer;
}

/* Disability Categories */
.category-items input[type="checkbox"],
.category-items input[type="radio"] {
    margin-right: 0.5rem;
    cursor: pointer;
}
.disability-category {
    background: white;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) / 2);
    padding: calc(var(--spacing) * 0.75);
    margin-bottom: calc(var(--spacing) * 0.75);
}

.disability-category:last-child {
    margin-bottom: 0;
}

.category-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0.625rem 0;
    text-transform: none;
    letter-spacing: 0.02em;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    border-top: 1px solid var(--border);
}
.top-category {
    margin-top: 0 !important;
    border-top: none !important;
}

.category-items {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.category-items label {
    padding-left: 0.25rem;
    transition: background 0.15s;
    padding: 0.25rem;
    border-radius: calc(var(--radius) / 3);
}

.category-items label:hover {
    background: var(--surface);
}

/* Toggle Switch */
.toggle-wrapper {
    display: flex;
    align-items: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9375rem;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    margin-right: 0.75rem;
    transition: background 0.2s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-label input:checked + .toggle-switch {
    background: var(--primary-color);
}

.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(20px);
}

/* Buttons */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: white;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface);
}

.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Display Panel */
.display-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: calc(var(--spacing) * 1.5);
    min-height: 600px;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: calc(var(--spacing) * 4);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.drop-zone.compact {
    min-height: auto;
    padding: calc(var(--spacing) * 1);
    margin-bottom: calc(var(--spacing) * 1.5);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: var(--surface);
}

.upload-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.drop-zone.compact .upload-prompt {
    display: none;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: var(--text-secondary);
    margin-bottom: var(--spacing);
    stroke-width: 1.5;
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

/* Image Preview */
.image-preview {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--spacing);
}

.image-preview canvas {
    max-width: 120px;
    max-height: 80px;
    border-radius: calc(var(--radius) / 2);
    border: 1px solid var(--border);
    object-fit: contain;
}

.preview-filename {
    flex: 1;
    text-align: left;
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Results Container */
.results-container {
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Single Result View */
.single-result-view .comparison-wrapper {
    display: flex;
    gap: var(--spacing);
    margin-bottom: calc(var(--spacing) * 2);
    align-items: flex-start;
}

.processed-image {
    flex: 1;
    position: relative;
}

.original-image-small {
    width: 200px;
    position: relative;
}

.processed-image canvas,
.original-image-small canvas {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: white;
}

.image-label {
    display: block;
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Slider Comparison */
.slider-container {
    margin-bottom: calc(var(--spacing) * 2);
}

.slider-wrapper {
    position: relative;
    width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    user-select: none;
}

.slider-wrapper canvas {
    display: block;
    width: 100%;
    height: auto;
}

#sliderCanvasBottom {
    position: relative;
    display: block;
}

.slider-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    overflow: hidden;
}

.slider-overlay canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
}

.slider-handle {
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    transform: translateX(-2px);
    pointer-events: none;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.slider-line {
    width: 4px;
    flex: 1;
    background: white;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
}

.slider-button {
    width: 48px;
    height: 48px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
    margin: 4px 0;
}

.slider-button svg {
    width: 24px;
    height: 24px;
    color: var(--primary-color);
    stroke-width: 2.5;
}

.image-slider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: ew-resize;
    opacity: 0;
    z-index: 30;
}

.image-slider::-webkit-slider-thumb {
    cursor: ew-resize;
}

.image-slider::-moz-range-thumb {
    cursor: ew-resize;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.75rem;
    padding: 0 0.5rem;
}

.slider-label-left,
.slider-label-right {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.slider-label-left {
    text-align: left;
    color: var(--primary-color);
}

.slider-label-right {
    text-align: right;
    color: var(--secondary-color);
}

/* Complete Result View */
.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: calc(var(--spacing) * 1.5);
    margin-bottom: calc(var(--spacing) * 2);
}

.analysis-item {
    position: relative;
}

.analysis-item canvas {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: white;
}

/* Analysis Report */
.analysis-report {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: calc(var(--spacing) * 1.5);
    margin-top: calc(var(--spacing) * 2);
}

.analysis-report h3 {
    font-size: 1.125rem;
    margin-bottom: var(--spacing);
    color: var(--text-primary);
}

#reportContent {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.report-item {
    padding: var(--spacing);
    margin-bottom: var(--spacing);
    background: var(--surface);
    border-radius: calc(var(--radius) / 2);
    border-left: 3px solid var(--primary-color);
}

.report-item.warning {
    border-left-color: var(--warning);
}

.report-item.error {
    border-left-color: var(--error);
}

.report-item.success {
    border-left-color: var(--success);
}

.report-item h4 {
    font-size: 0.9375rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.report-item p {
    font-size: 0.875rem;
    line-height: 1.6;
}

/* Info Button */
.btn-info {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: #8b5cf6;
    color: white;
    margin-bottom: 0;
}

.btn-info:hover {
    background: #7c3aed;
}

/* Knowledge Base Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(var(--spacing) * 1.5);
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--text-primary);
}

.close-button {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    line-height: 1;
}

.close-button:hover {
    background: var(--surface);
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.kb-navigation {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: calc(var(--spacing) * 1.5);
    background: var(--surface);
    border-right: 1px solid var(--border);
    min-width: 180px;
}

.kb-nav-btn {
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    text-align: left;
    cursor: pointer;
    border-radius: calc(var(--radius) / 2);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.kb-nav-btn:hover {
    background: white;
    color: var(--text-primary);
}

.kb-nav-btn.active {
    background: var(--primary-color);
    color: white;
}

.kb-content {
    flex: 1;
    padding: calc(var(--spacing) * 2);
    overflow-y: auto;
}

.kb-section {
    animation: fadeIn 0.3s;
}

.kb-section h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.kb-section h4 {
    font-size: 1.1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--primary-color);
}

.kb-section p {
    margin-bottom: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.kb-section ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.kb-section li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.kb-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.kb-card h4 {
    margin-top: 0;
    font-size: 1.125rem;
}

.kb-card strong {
    color: var(--primary-color);
}

.kb-stat {
    display: inline-block;
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    margin-right: 0.5rem;
}

.kb-example {
    background: #f0f9ff;
    border-left: 3px solid var(--primary-color);
    padding: 1rem;
    margin: 1rem 0;
    border-radius: calc(var(--radius) / 2);
}

.kb-example strong {
    color: var(--primary-color);
}

.kb-tip {
    background: #ecfdf5;
    border-left: 3px solid var(--success);
    padding: 1rem;
    margin: 1rem 0;
    border-radius: calc(var(--radius) / 2);
}

.kb-warning {
    background: #fff7ed;
    border-left: 3px solid var(--warning);
    padding: 1rem;
    margin: 1rem 0;
    border-radius: calc(var(--radius) / 2);
}

.kb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.kb-grid-item {
    background: white;
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: calc(var(--radius) / 2);
}

.kb-grid-item strong {
    display: block;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        position: static;
    }

    .single-result-view .comparison-wrapper {
        flex-direction: column;
    }

    .original-image-small {
        width: 100%;
    }
    
    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .modal-body {
        flex-direction: column;
    }
    
    .kb-navigation {
        flex-direction: row;
        flex-wrap: wrap;
        min-width: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .kb-nav-btn {
        flex: 1;
        min-width: 100px;
        text-align: center;
    }
}
