:root {
    --primary-color: #2563eb;
    --secondary-color: #1e40af;
    --success-color: #059669;
    --danger-color: #dc2626;
    --warning-color: #d97706;
    --info-color: #0891b2;
    --light-color: #f8fafc;
    --dark-color: #1e293b;
    --sidebar-width: 250px;
    --navbar-height: 60px;
    --border-radius: 8px;
    --box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

/* Base Styles */
.admin-portal {
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
}

.admin-body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navigation */
.admin-navbar {
    height: var(--navbar-height);
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    box-shadow: var(--box-shadow);
    z-index: 1030 !important;
    position: relative;
}

.admin-navbar .navbar-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: #fff !important;
}

.admin-navbar .nav-link {
    color: rgba(255, 255, 255, 0.8) !important;
    transition: var(--transition);
    border-radius: var(--border-radius);
    margin: 0 2px;
    padding: 8px 12px !important;
}

.admin-navbar .nav-link:hover,
.admin-navbar .nav-link.active {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

/* Select/Dropdown readability */
.form-select {
    color: #1e293b !important; /* readable dark text */
    background-color: #ffffff !important;
    border: 1px solid #ced4da !important;
    appearance: auto !important;
}

.form-select option {
    color: #1e293b !important;
    background-color: #ffffff !important;
}

/* Fix for some browsers rendering white-on-white options */
select.form-select,
select.form-select option,
select.form-select:focus option {
    -webkit-text-fill-color: #1e293b !important;
}

.form-select:focus {
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.25) !important;
}

/* Main Content */
.admin-content {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    margin: 20px;
    border-radius: 20px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    min-height: calc(100vh - var(--navbar-height) - 120px);
}

/* Cards */
.admin-card {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    transition: var(--transition);
    overflow: hidden;
    width: 100%;
}

.admin-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
}

.admin-card .card-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    padding: 1.25rem;
    font-weight: 600;
}

.admin-card .card-body {
    padding: 1.5rem;
}

/* Stats Cards */
.stats-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.8) 100%);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 1.5rem;
    text-align: center;
    transition: var(--transition);
    backdrop-filter: blur(15px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    height: 100%;
}

.stats-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
}

.stats-card .stats-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 1.5rem;
    color: white;
}

.stats-card.primary .stats-icon {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.stats-card.success .stats-icon {
    background: linear-gradient(135deg, var(--success-color) 0%, #10b981 100%);
}

.stats-card.warning .stats-icon {
    background: linear-gradient(135deg, var(--warning-color) 0%, #f59e0b 100%);
}

.stats-card.danger .stats-icon {
    background: linear-gradient(135deg, var(--danger-color) 0%, #ef4444 100%);
}

.stats-card .stats-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--dark-color);
    margin-bottom: 0.5rem;
}

.stats-card .stats-label {
    color: #64748b;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.stats-card .stats-change {
    font-size: 0.875rem;
    font-weight: 600;
}

.stats-change.positive {
    color: var(--success-color);
}

.stats-change.negative {
    color: var(--danger-color);
}

/* Tables */
.admin-table {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.admin-table .table {
    margin: 0;
    border: none;
}

.admin-table .table thead th {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border: none;
    color: var(--dark-color);
    font-weight: 600;
    padding: 1rem;
}

.admin-table .table tbody td {
    border-color: rgba(0, 0, 0, 0.05);
    padding: 1rem;
    vertical-align: middle;
}

.admin-table .table tbody tr:hover {
    background: rgba(37, 99, 235, 0.05);
}

/* Buttons */
.btn-admin {
    border-radius: 10px;
    font-weight: 500;
    padding: 0.5rem 1.5rem;
    transition: var(--transition);
    border: none;
    position: relative;
    overflow: hidden;
}

.btn-admin:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: var(--transition);
}

.btn-admin:hover:before {
    left: 100%;
}

.btn-admin-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.btn-admin-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.3);
}

.btn-admin-success {
    background: linear-gradient(135deg, var(--success-color) 0%, #10b981 100%);
    color: white;
}

.btn-admin-danger {
    background: linear-gradient(135deg, var(--danger-color) 0%, #ef4444 100%);
    color: white;
}

/* Form Controls */
.form-control-admin {
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    transition: var(--transition);
    background: rgba(255, 255, 255, 0.9);
}

.form-control-admin:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.25);
    background: white;
}

/* Charts */
.chart-container {
    position: relative;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    height: auto;
    overflow: hidden;
}

/* Chart wrapper with fixed heights */
.chart-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.chart-wrapper canvas {
    max-width: 100% !important;
    height: auto !important;
    display: block;
}

/* Prevent chart overflow */
canvas {
    max-width: 100% !important;
    height: auto !important;
}

/* Dashboard specific chart heights */
#userGrowthChart {
    max-height: 300px !important;
    height: 300px !important;
}

#chatActivityChart {
    max-height: 300px !important;
    height: 300px !important;
}

#modelUsageChart {
    max-height: 300px !important;
    height: 300px !important;
}

/* Analytics specific chart heights */
#activityChart {
    max-height: 350px !important;
    height: 350px !important;
}

#trafficChart {
    max-height: 350px !important;
    height: 350px !important;
}

#modelUsageChart {
    max-height: 300px !important;
    height: 300px !important;
}

#dailyUsersChart {
    max-height: 300px !important;
    height: 300px !important;
}

/* Footer */
.admin-footer {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.1) !important;
    margin: 20px;
    margin-top: auto;
    border-radius: 15px;
}

/* Badges */
.badge-admin {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
}

.badge-online {
    background: linear-gradient(135deg, var(--success-color) 0%, #10b981 100%);
}

.badge-offline {
    background: linear-gradient(135deg, #6b7280 0%, #9ca3af 100%);
}

.badge-professional {
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
}

.badge-plus {
    background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
}

.badge-free {
    background: linear-gradient(135deg, #6b7280 0%, #9ca3af 100%);
}

/* Loading States */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

/* Responsive */
@media (max-width: 768px) {
    .admin-content {
        margin: 10px;
        border-radius: 15px;
    }
    
    .stats-card {
        margin-bottom: 1rem;
    }
    
    .admin-navbar .navbar-nav {
        background: rgba(0, 0, 0, 0.1);
        border-radius: 10px;
        margin-top: 1rem;
        padding: 0.5rem;
    }
}

/* Modal fixes - robust layering and viewport positioning */
.modal-backdrop {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1040 !important;
    background-color: rgba(0,0,0,0.5) !important;
}

.modal-backdrop.show {
    opacity: 0.5 !important;
}

.modal {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1060 !important; /* above backdrop */
    display: none;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}

.modal.show { z-index: 1060 !important; }

.modal-dialog {
    position: relative !important;
    z-index: 1061 !important;
    margin: 1.75rem auto !important;
}

.modal-content {
    position: relative !important;
    z-index: 1062 !important;
}

/* Prevent scroll jump when modal opens */
body.modal-open {
    overflow: hidden !important;
    padding-right: 0 !important;
    position: relative !important;
}

/* Hide any duplicate or lingering backdrops */
.modal-backdrop ~ .modal-backdrop { display: none !important; }
.modal-backdrop:not(.show) { display: none !important; opacity: 0 !important; }


/* Default model indicators */
.provider-default-indicator {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.global-default-indicator {
    background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 5px;
}

.quick-default-controls {
    display: flex;
    gap: 5px;
    align-items: center;
}

/* Model ordering drag handles */
.sort-handle {
    cursor: move;
    color: #6c757d;
    padding: 5px;
    border-radius: 3px;
}

.sort-handle:hover {
    background: rgba(0,0,0,0.1);
    color: #495057;
}

.provider-section {
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 8px;
    margin-bottom: 20px;
    overflow: hidden;
}

.provider-section-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 15px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.provider-models-list {
    padding: 0;
}

/* Advanced Provider Tabs Styling */
.provider-tabs {
    border-bottom: 2px solid #dee2e6;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.provider-tabs .nav-item {
    margin-right: 2px;
}

.provider-tabs .nav-link {
    border: none;
    border-radius: 8px 8px 0 0;
    padding: 12px 16px;
    background: transparent;
    color: #6c757d;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    min-width: 140px;
}

.provider-tabs .nav-link:hover {
    background: rgba(255, 255, 255, 0.8);
    color: #495057;
    transform: translateY(-2px);
}

.provider-tabs .nav-link.active {
    background: white;
    color: #212529;
    border: 1px solid #dee2e6;
    border-bottom: 2px solid white;
    margin-bottom: -2px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.provider-tab-content {
    display: flex;
    align-items: center;
    min-width: 120px;
}

.provider-icon-sm {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
}

.provider-tab-info {
    flex: 1;
}

.provider-name {
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
}

.provider-stats {
    font-size: 0.75rem;
    line-height: 1.2;
    opacity: 0.8;
}

.model-count {
    color: #6c757d;
}

/* Tab Content Styling - Full Width */
.tab-content.provider-tab-content {
    border-left: 1px solid #dee2e6;
    border-right: 1px solid #dee2e6;
    border-bottom: 1px solid #dee2e6;
    background: white;
    width: 100%;
    min-height: 400px;
    display: block;
}

.tab-pane {
    width: 100%;
    padding: 0;
    margin: 0;
}

.models-container {
    width: 100%;
    padding: 0;
    margin: 0;
}

.provider-panel-header,
.provider-default-section {
    width: 100%;
    margin: 0;
}

.model-card {
    width: 100%;
    margin: 0;
}

/* Ensure full width for all provider content */
.admin-card .card-body {
    width: 100%;
    padding: 0;
}

.admin-card .card-body.p-0 {
    padding: 0 !important;
}

.provider-panel-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.provider-default-section {
    background: linear-gradient(135deg, #e8f5e8 0%, #f0f8f0 100%);
    border-left: 4px solid #28a745;
}

/* Model Cards */
.model-item {
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.model-item:hover {
    background: rgba(37, 99, 235, 0.02);
    border-left-color: #2563eb;
}

.model-item[data-enabled="false"] {
    opacity: 0.6;
}

/* Bulk selection visual feedback */
.model-select-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.model-select-checkbox:checked {
    background-color: #2563eb;
    border-color: #2563eb;
}

.model-select-checkbox.analyzing,
.model-select-checkbox:checked + .analyzing {
    animation: pulse 1s infinite;
}

.col-auto.analyzing {
    background: rgba(255, 193, 7, 0.2);
    border-radius: 4px;
}

.col-auto.success {
    background: rgba(40, 167, 69, 0.2);
    border-radius: 4px;
}

.col-auto.error {
    background: rgba(220, 53, 69, 0.2);
    border-radius: 4px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.model-card {
    position: relative;
}

.drag-handle {
    cursor: move;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.drag-handle:hover {
    background: rgba(0, 0, 0, 0.1);
}

.model-order {
    font-size: 0.75rem;
    min-width: 32px;
}

.model-info h6 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0;
}

.model-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.model-details {
    margin-top: 4px;
}

.model-status {
    min-width: 120px;
}

.model-status .test-info {
    font-size: 0.75rem;
    line-height: 1.2;
}

.model-status .error-info {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-status .badge {
    font-size: 0.7rem;
    padding: 0.25em 0.5em;
}

/* Batch Test Results */
.batch-result-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-radius: 6px;
    margin-bottom: 8px;
    background: #f8f9fa;
    border-left: 4px solid #dee2e6;
    transition: all 0.2s ease;
}

.batch-result-item.success {
    border-left-color: #28a745;
    background: #d4edda;
}

.batch-result-item.error {
    border-left-color: #dc3545;
    background: #f8d7da;
}

.batch-result-item.processing {
    border-left-color: #007bff;
    background: #d1ecf1;
}

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

.batch-result-item .result-message {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.batch-result-item .batch-result-header {
    transition: background-color 0.2s ease;
}

.batch-result-item .batch-result-header:hover {
    background-color: rgba(0,0,0,0.03);
    border-radius: 4px;
    margin: -5px;
    padding: 5px;
}

.batch-result-item .batch-result-details {
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.batch-expand-icon {
    transition: transform 0.2s ease;
}

.model-actions {
    min-width: 200px;
}

.default-controls {
    display: flex;
    gap: 4px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
}

.empty-icon {
    opacity: 0.3;
}

/* Provider Summary Cards */
.provider-summary-card {
    border: 1px solid rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.provider-summary-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Sortable styling */
.sortable-container {
    min-height: 100px;
}

.sortable-item.sortable-ghost {
    opacity: 0.3;
}

.sortable-item.sortable-drag {
    transform: rotate(5deg);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

/* Advanced Controls */
.sync-progress {
    position: relative;
    overflow: hidden;
}

.sync-progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Test Results */
.test-result {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.875rem;
}

.test-result.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.test-result.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f1aeb5;
}

.test-result.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

/* Responsive design for tabs */
@media (max-width: 768px) {
    .provider-tabs {
        flex-wrap: wrap;
        gap: 4px;
        padding: 8px;
    }
    
    .provider-tabs .nav-link {
        padding: 8px 12px;
        font-size: 0.875rem;
    }
    
    .provider-tab-content {
        min-width: auto;
        flex-direction: column;
        text-align: center;
    }
    
    .provider-icon-sm {
        margin: 0 auto 4px;
    }
    
    .model-actions {
        flex-wrap: wrap;
        gap: 4px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .admin-content {
        background: rgba(30, 41, 59, 0.95);
        color: #f1f5f9;
    }
    
    .admin-card {
        background: rgba(51, 65, 85, 0.9);
        color: #f1f5f9;
    }
    
    .stats-card {
        background: linear-gradient(135deg, rgba(51, 65, 85, 0.95) 0%, rgba(30, 41, 59, 0.8) 100%);
        color: #f1f5f9;
    }
    
    .provider-section-header {
        background: linear-gradient(135deg, rgba(51, 65, 85, 0.9) 0%, rgba(30, 41, 59, 0.8) 100%);
        color: #f1f5f9;
    }
    
    .provider-tabs {
        background: linear-gradient(135deg, rgba(51, 65, 85, 0.9) 0%, rgba(30, 41, 59, 0.8) 100%);
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }
    
    .provider-tabs .nav-link {
        color: rgba(255, 255, 255, 0.7);
    }
    
    .provider-tabs .nav-link:hover {
        background: rgba(255, 255, 255, 0.1);
        color: rgba(255, 255, 255, 0.9);
    }
    
    .provider-tabs .nav-link.active {
        background: rgba(51, 65, 85, 0.9);
        color: #f1f5f9;
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .provider-panel-header {
        background: linear-gradient(135deg, rgba(51, 65, 85, 0.9) 0%, rgba(30, 41, 59, 0.8) 100%);
    }
}
