/* Searchable Select Component */
.searchable-select {
    position: relative;
    width: 100%;
}

.searchable-select input {
    width: 100%;
    padding: 8px 40px 8px 12px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    box-sizing: border-box;
    /* Ensure consistent text positioning */
    line-height: 1.4;
    vertical-align: top;
}

.searchable-select input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
    cursor: text;
    /* Maintain same positioning when focused */
    padding: 8px 40px 8px 12px;
    line-height: 1.4;
}

.searchable-select input:read-only {
    cursor: pointer;
    background: white;
    /* Ensure readonly state has identical positioning */
    padding: 8px 40px 8px 12px;
    line-height: 1.4;
    /* Prevent text selection highlighting in readonly mode */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Prevent text selection highlighting during transitions */
.searchable-select input:focus:read-only {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.searchable-select .dropdown-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #6c757d;
    font-size: 12px;
    transition: transform 0.2s ease;
}

.searchable-select.open .dropdown-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.searchable-select .dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.searchable-select .dropdown-list.hidden {
    display: none;
}

.dropdown-option {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f8f9fa;
    font-size: 14px;
    color: #212529;
    transition: background-color 0.15s ease;
}

.dropdown-option:last-child {
    border-bottom: none;
}

.dropdown-option:hover,
.dropdown-option.highlighted {
    background-color: #f8f9fa;
}

.dropdown-option.selected {
    background-color: var(--primary-color);
    color: white;
}

.no-results {
    padding: 12px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    font-size: 14px;
}

/* Ensure dropdown appears above other elements */
.searchable-select {
    z-index: 10;
}

.searchable-select.open {
    z-index: 1001;
}


.location-info-section, .table-info-section {
    margin-bottom: 2rem;
}

.location-info, .table-info {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e9ecef;
}

.info-item:last-child {
    border-bottom: none;
}

.info-label {
    font-weight: 600;
    color: #495057;
    min-width: 80px;
}

.info-value {
    color: #212529;
    text-align: right;
    flex: 1;
    margin-left: 1rem;
}

.table-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e9ecef;
}

.table-item:last-child {
    border-bottom: none;
}

.table-name {
    font-weight: 500;
    color: #212529;
    flex: 1;
}

.annotation-count {
    font-size: 0.875rem;
    color: #6c757d;
    background: #f8f9fa;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid #dee2e6;
}

/* Danger Button */
.danger-btn {
    background-color: #dc3545;
    color: white;
    border: 1px solid #dc3545;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.danger-btn:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

.danger-btn:disabled {
    background-color: #6c757d;
    border-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Modal Enhancements */
.warning-text {
    color: #dc3545;
    font-weight: 500;
    margin: 1rem 0;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.modal-actions button {
    min-width: 80px;
}

/* Form enhancements */
.readonly-input {
    background-color: #f8f9fa;
    color: #6c757d;
    border: 1px solid #dee2e6;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.help-text {
    font-size: 0.85em;
    color: #6c757d;
    margin-top: 5px;
    display: block;
}

textarea {
    min-height: 60px;
    resize: vertical;
    font-family: inherit;
}

/* Create Table Accordion */
.create-table-section {
    margin: 15px 0;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

.accordion-btn {
    width: 100%;
    padding: 12px 15px;
    background: #f8f9fa;
    border: none;
    text-align: left;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.accordion-btn:hover:not(:disabled) {
    background: #e9ecef;
}

.accordion-btn:disabled {
    background: #f1f3f4;
    color: #6c757d;
    cursor: not-allowed;
}

.accordion-btn .icon {
    font-size: 0.9em;
    transition: transform 0.2s;
}

.accordion-btn.active .icon {
    transform: rotate(45deg);
}

.accordion-content {
    padding: 20px;
    background: white;
    border-top: 1px solid #dee2e6;
    max-height: 500px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.accordion-content.hidden {
    display: none;
}

/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.api-config {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.api-config input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    width: 200px;
}

.api-config button {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.2s;
}

.api-config button:hover {
    background: #1d4ed8;
}

.status {
    font-size: 0.875rem;
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
}

.status.success {
    color: var(--success-color);
    background: #10b98120;
}

.status.error {
    color: var(--danger-color);
    background: #ef444420;
}

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

/* Panels */
.left-panel, .right-panel {
    flex: 0 1 380px; /* Don't grow, shrink if needed, start at 380px */
    min-width: 320px; /* Prevent them from shrinking too much */
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 1.5rem;
}

.right-panel {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.center-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-tertiary);
    position: relative;
    padding: 1.5rem;
}

/* Control Sections */
.control-section, .annotations-section, .statistics-section {
    margin-bottom: 2rem;
}

.control-section h3, .annotations-section h3, .statistics-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Form Groups */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background: var(--bg-primary);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group input[type="file"] {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.form-group input[type="range"] {
    width: calc(100% - 3rem);
    margin-right: 0.5rem;
}

/* Buttons */
.primary-btn, .secondary-btn {
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

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

.primary-btn:hover:not(:disabled) {
    background: #1d4ed8;
    box-shadow: var(--shadow-md);
}

.primary-btn:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.5;
}

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

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

/* Tab Navigation */
.tab-buttons {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    background: var(--bg-tertiary);
    padding: 0.25rem;
    border-radius: 0.5rem;
}

.tab-btn {
    flex: 1;
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--bg-primary);
    color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    padding: 0.5rem 0;
}

.tab-content.hidden {
    display: none;
}

/* Tool Buttons */
.tool-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tool-btn {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tool-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
}

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

.tool-btn .icon {
    font-size: 1.125rem;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    background: white;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-md);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#annotationCanvas {
    max-width: 100%;
    max-height: 100%;
}

.canvas-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    display: flex;
    justify-content: space-between;
}

/* Instructions */
.instructions {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    z-index: 5;
}

.instructions.hidden {
    display: none;
}

.instructions p {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.instructions ol {
    margin-left: 1.5rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

/* Annotations List */
.filter-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.filter-controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.annotations-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: var(--bg-secondary);
}

.annotation-item {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.annotation-item:hover {
    background: var(--bg-tertiary);
}

.annotation-item.selected {
    background: #2563eb20;
    border-left: 3px solid var(--primary-color);
}

.annotation-item:last-child {
    border-bottom: none;
}

.annotation-item h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.annotation-item .meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.annotation-item .actions {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
}

.annotation-item .actions button {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 0.25rem;
}

/* Statistics */
.statistics {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.375rem;
    border: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.875rem;
}

.stat-item:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Status Bar */
.status-bar {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger-color);
}

.status-dot.connected {
    background: var(--success-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 0.5rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-content h3 {
    margin-bottom: 1rem;
    color: var(--danger-color);
}

.close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

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

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: white;
    margin-top: 1rem;
    font-size: 0.875rem;
}

/* Retry Info */
.retry-info {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 0.375rem;
    font-size: 0.75rem;
}

.retry-attempt {
    padding: 0.25rem 0;
    color: var(--text-secondary);
}

.retry-attempt.success {
    color: var(--success-color);
}

.retry-attempt.failed {
    color: var(--danger-color);
}

/* Utility Classes */
.no-data {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.hidden {
    display: none !important;
}


@media (max-width: 1024px) {
    .right-panel {
        display: none;
    }
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .left-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 40vh;
    }
    
    .center-panel {
        min-height: 60vh;
    }
}