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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f0f2f5;
    height: 100vh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header Styles */
.app-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.header-left h1 {
    font-size: 1.25rem;
    margin-bottom: 0.125rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.subtitle {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-left: 2rem;
}

.header-right {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.header-right .form-select {
    min-width: 180px;
}

/* Main Content Layout */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    background-color: #f0f2f5;
}

/* Panel Styles */
.pdf-panel, .form-panel {
    display: flex;
    flex-direction: column;
    background-color: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.pdf-panel {
    flex: 1;
    min-width: 400px;
}

.form-panel {
    flex: 1.2;
    min-width: 500px;
}

.panel-header {
    background-color: #fff;
    padding: 0.75rem 1rem;
    border-bottom: 2px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h5 {
    font-size: 1rem;
    color: #495057;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* PDF Container */
.pdf-container {
    flex: 1;
    position: relative;
    overflow: auto;
    background-color: #e9ecef;
}

#pdfViewer {
    width: 100%;
    height: 100%;
    border: none;
    background-color: white;
    display: block;
}

.pdf-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6c757d;
}

.pdf-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Form Container */
.form-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.form-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Tab Styles */
.nav-tabs {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    padding: 0 1rem;
}

.nav-tabs .nav-link {
    color: #6c757d;
    border: none;
    border-radius: 0;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
}

.nav-tabs .nav-link:hover {
    color: #495057;
    background-color: rgba(0,0,0,0.05);
}

.nav-tabs .nav-link.active {
    color: #667eea;
    background-color: white;
    border-bottom: 2px solid #667eea;
    margin-bottom: -2px;
    font-weight: 500;
}

/* Tab Content */
.tab-content {
    flex: 1;
    overflow-y: auto;
    background-color: #fff;
    max-height: calc(100vh - 200px);
}

.tab-pane {
    height: 100%;
    overflow-y: auto;
    padding: 1rem;
}

/* Form Styling */
.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #495057;
    margin-bottom: 0.25rem;
}

.form-control, .form-select {
    font-size: 0.875rem;
    border: 1px solid #dee2e6;
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

.form-control-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
}

/* Accordion Styles for Medical Codes */
.accordion-item {
    border: 1px solid #dee2e6;
    margin-bottom: 0.5rem;
    border-radius: 0.375rem;
    overflow: hidden;
}

.accordion-button {
    background-color: #f8f9fa;
    font-size: 0.875rem;
    padding: 0.75rem 1rem;
}

.accordion-button:not(.collapsed) {
    background-color: #e7f1ff;
    color: #0c63e4;
}

.accordion-button:focus {
    box-shadow: none;
    border-color: #dee2e6;
}

.code-title {
    display: flex;
    align-items: center;
    font-weight: 500;
}

.code-value {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #0c63e4;
}

.main-diagnosis-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

/* Query Item Styles */
.query-item {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
}

.query-item:hover {
    background-color: #e9ecef;
}

/* Todo Item Styles */
.todo-item {
    background-color: #fff;
    border: 1px solid #dee2e6;
    transition: all 0.2s ease;
}

.todo-item:hover {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Confidence Slider */
.confidence-slider {
    cursor: pointer;
}

.confidence-value {
    min-width: 50px;
    text-align: center;
}

/* Status Bar */
.status-bar {
    background-color: #f8f9fa;
    padding: 0.5rem 1rem;
    border-top: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #6c757d;
}

#statusMessage {
    font-weight: 500;
}

#statusMessage.success {
    color: #28a745;
}

#statusMessage.error {
    color: #dc3545;
}

/* Resizer */
.resizer {
    width: 4px;
    background-color: #dee2e6;
    cursor: col-resize;
    position: relative;
    transition: background-color 0.2s ease;
}

.resizer:hover {
    background-color: #667eea;
    width: 6px;
    margin: 0 -1px;
}

/* JSON View */
#jsonView {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    font-family: 'Courier New', monospace;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3rem;
}

/* Custom Scrollbar */
.tab-content::-webkit-scrollbar,
.form-control::-webkit-scrollbar,
textarea::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.tab-content::-webkit-scrollbar-track,
.form-control::-webkit-scrollbar-track,
textarea::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.tab-content::-webkit-scrollbar-thumb,
.form-control::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.tab-content::-webkit-scrollbar-thumb:hover,
.form-control::-webkit-scrollbar-thumb:hover,
textarea::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Buttons */
.btn-sm {
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
}

.btn-outline-light {
    border-color: rgba(255, 255, 255, 0.5);
    color: white;
}

.btn-outline-light:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: white;
    color: white;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .form-panel {
        min-width: 450px;
    }
    
    .pdf-panel {
        min-width: 350px;
    }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .header-right {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .resizer {
        display: none;
    }
    
    .pdf-panel, .form-panel {
        min-width: unset;
        width: 100%;
    }
}

/* Three Column Codes Management */
.codes-management-container {
    height: calc(100vh - 250px);
    overflow-y: auto;
    padding: 1rem;
}

.code-category-column {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow: hidden;
}

.category-header {
    padding: 1rem;
    border-bottom: 2px solid #dee2e6;
}

.code-drop-zone {
    min-height: 400px;
    max-height: 60vh;
    padding: 1rem;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
}

.drop-zone-placeholder {
    display: none;
    text-align: center;
    color: #adb5bd;
    padding: 3rem 1rem;
}

.code-drop-zone:empty .drop-zone-placeholder {
    display: block;
}

.code-drop-zone.drag-over {
    background-color: rgba(102, 126, 234, 0.1);
    border: 2px dashed #667eea;
}

#importJsonBtn.drag-over {
    border: 2px dashed rgba(255, 255, 255, 0.8);
    background-color: rgba(255, 255, 255, 0.1);
}

/* Code Cards */
.code-card {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    cursor: move;
    transition: all 0.2s ease;
}

.code-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.code-card.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
}

.code-card-header {
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f9fa;
}

.code-card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0; /* Allow flex item to shrink below content size */
    overflow: hidden; /* Contain overflowing content */
}

.code-badge {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    background: #e9ecef;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    flex-shrink: 0; /* Prevent badge from shrinking */
}

.code-description {
    font-size: 0.875rem;
    color: #495057;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1; /* Take remaining space */
    min-width: 0; /* Allow text to shrink */
}

.code-card-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0; /* Prevent actions from shrinking */
    margin-left: 0.5rem; /* Add some spacing from the title */
}

.code-card-body {
    padding: 0.75rem;
    border-top: 1px solid #dee2e6;
}

.code-card-body .reasoning-input {
    min-height: 100px;
}

/* Codes to Add Container */
.codes-to-add-container {
    max-height: 500px;
    overflow-y: auto;
}

.code-to-add-item {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s;
}

.code-to-add-item:hover {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.code-to-add-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.code-to-add-code {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    background: #007bff;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.9rem;
}

.code-to-add-actions {
    display: flex;
    gap: 0.25rem;
}

.code-to-add-field {
    margin-bottom: 0.5rem;
}

.code-to-add-field label {
    font-size: 0.75rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.code-to-add-field input,
.code-to-add-field textarea {
    width: 100%;
    font-size: 0.875rem;
}

.code-to-add-field textarea {
    resize: vertical;
    min-height: 60px;
}

/* Category-specific styling */
#codesToAdd .code-card {
    border-left: 3px solid #28a745;
}

#codesToAdd .code-badge {
    background-color: rgba(40, 167, 69, 0.1);
    color: #28a745;
}

#codesToKeep .code-card {
    border-left: 3px solid #0c63e4;
}

#codesToKeep .code-badge {
    background-color: rgba(12, 99, 228, 0.1);
    color: #0c63e4;
}

#codesToRemove .code-card {
    border-left: 3px solid #dc3545;
}

#codesToRemove .code-badge {
    background-color: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

/* Main diagnosis indicator */
.code-card.main-diagnosis .code-card-header {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
}

.code-card.main-diagnosis .main-diagnosis-btn i {
    color: #ffc107;
}

.main-diagnosis-btn i {
    color: #dee2e6;
    transition: color 0.2s ease;
}

.main-diagnosis-btn:hover i {
    color: #ffc107;
}

/* Animation for adding/removing items */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.code-card,
.query-item,
.todo-item {
    animation: slideIn 0.3s ease;
}

/* Form label adjustments */
.form-label-sm {
    font-size: 0.75rem;
    font-weight: 500;
    color: #6c757d;
    margin-bottom: 0.25rem;
}

/* Bootstrap Overrides */
.form-check-input:checked {
    background-color: #667eea;
    border-color: #667eea;
}

.form-range::-webkit-slider-thumb {
    background-color: #667eea;
}

.form-range::-moz-range-thumb {
    background-color: #667eea;
}

.btn-primary {
    background-color: #667eea;
    border-color: #667eea;
}

.btn-primary:hover {
    background-color: #5a6fd8;
    border-color: #5a6fd8;
}

/* Select2 Overrides */
.select2-container--bootstrap-5 .select2-selection {
    font-size: 0.875rem;
    border-color: #dee2e6;
}

.select2-container--bootstrap-5 .select2-selection--single {
    height: calc(1.5em + 0.5rem + 2px);
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection {
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}
