/* ============================================
 * AI Model Configuration Modal Styles
 * Admin panel for configuring AI models
 * Uses theme variables for multi-theme support
 * ============================================ */

/* Modal Container - Higher z-index than admin panel */
.ai-model-config-modal.modal {
    z-index: 100100 !important;
    background: rgba(0, 0, 0, 0.7);
}

.ai-model-config-modal .dialog.ai-config-dialog {
    max-width: 850px;
    width: 95%;
    max-height: 85vh;
    margin: 0;
    background: var(--bg-dark);
    border-radius: 16px;
    border: 1px solid var(--border-light);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Title bar */
.ai-model-config-modal .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    background: var(--bg-medium);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.ai-model-config-modal .title h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.ai-model-config-modal .title button.alt {
    background: var(--bg-light);
    border: 1px solid var(--border-medium);
    color: var(--text-primary);
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.ai-model-config-modal .title button.alt:hover {
    background: var(--bg-lighter);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Subtitle */
.ai-model-config-modal .ai-config-subtitle {
    margin: 0;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* Body - Scrollable */
.ai-model-config-modal .body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.25rem 1.5rem;
    background: var(--bg-darkest);
}

/* Scrollbar styling */
.ai-model-config-modal .body::-webkit-scrollbar {
    width: 8px;
}

.ai-model-config-modal .body::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 4px;
}

.ai-model-config-modal .body::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

.ai-model-config-modal .body::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Loading State */
.ai-config-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem;
}

.ai-config-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: ai-config-spin 1s linear infinite;
}

@keyframes ai-config-spin {
    to { transform: rotate(360deg); }
}

/* Error State */
.ai-config-error {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.ai-config-error p {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
}

.ai-config-error button {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: filter 0.2s;
}

.ai-config-error button:hover {
    filter: brightness(1.1);
}

/* Content Container */
.ai-config-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Section */
.ai-config-section {
    background: var(--bg-dark);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1rem;
}

.ai-config-section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 1rem 0;
    padding-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-primary);
    border-bottom: 1px solid var(--border-subtle);
}

.section-icon {
    font-size: 1.25rem;
}

/* Config Items Container */
.ai-config-items {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Individual Config Item */
.ai-config-item {
    background: var(--bg-medium);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-config-item:hover {
    border-color: var(--border-accent);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* Item Header */
.ai-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    background: var(--bg-light);
}

.ai-config-title {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.ai-config-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.ai-config-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Toggle Switch */
.ai-config-toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.ai-config-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.ai-config-toggle .toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-lighter);
    border-radius: 26px;
    transition: background 0.3s ease;
}

.ai-config-toggle .toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: transform 0.3s ease, background 0.3s ease;
}

.ai-config-toggle input:checked + .toggle-slider {
    background: var(--accent-primary);
}

.ai-config-toggle input:checked + .toggle-slider:before {
    transform: translateX(22px);
    background: var(--text-inverse);
}

/* Item Body */
.ai-config-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    border-top: 1px solid var(--border-faint);
    transition: opacity 0.2s ease;
}

.ai-config-body.disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* Config Rows */
.ai-config-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.ai-config-row > label {
    min-width: 120px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Select Dropdowns - IMPORTANT: High contrast styling */
.ai-config-row select {
    flex: 1;
    padding: 0.6rem 0.875rem;
    background: var(--bg-darkest);
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    /* Ensure text is visible */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.ai-config-row select:hover {
    border-color: var(--accent-primary);
}

.ai-config-row select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: var(--focus-ring);
}

/* Select Options - Override browser defaults for better readability */
.ai-config-row select option {
    background: var(--bg-dark);
    color: var(--text-primary);
    padding: 0.5rem;
}

.ai-config-row select option:hover,
.ai-config-row select option:checked {
    background: var(--accent-primary);
    color: var(--text-inverse);
}

/* Parameters Row */
.ai-config-params {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.param-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 180px;
}

.param-group label {
    min-width: auto;
    white-space: nowrap;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Range Input */
.param-group input[type="range"] {
    flex: 1;
    height: 6px;
    background: var(--bg-lighter);
    border-radius: 3px;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.param-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.param-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.param-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

/* Number Input */
.param-group input[type="number"] {
    width: 90px;
    padding: 0.5rem 0.75rem;
    background: var(--bg-darkest);
    border: 1px solid var(--border-medium);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    text-align: center;
    transition: border-color 0.2s;
}

.param-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: var(--focus-ring);
}

.param-group input[type="number"]::placeholder {
    color: var(--text-faint);
}

.param-value {
    min-width: 35px;
    font-size: 0.85rem;
    color: var(--accent-primary);
    font-weight: 600;
    font-family: monospace;
    text-align: center;
}

/* Actions Row */
.ai-config-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 0.25rem;
}

.btn-reset-config {
    padding: 0.4rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-reset-config:hover {
    background: var(--bg-light);
    border-color: var(--border-medium);
    color: var(--text-primary);
}

/* Footer */
.ai-config-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--bg-medium);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    gap: 1rem;
}

.ai-config-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.info-icon {
    font-size: 1.1rem;
}

.ai-config-buttons {
    display: flex;
    gap: 0.75rem;
}

.btn-reset-all {
    padding: 0.6rem 1.25rem;
    background: transparent;
    border: 1px solid var(--accent-secondary);
    border-radius: 8px;
    color: var(--accent-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-reset-all:hover {
    background: var(--accent-secondary);
    color: var(--text-inverse);
}

.btn-save-all {
    padding: 0.6rem 1.25rem;
    background: var(--accent-primary);
    border: none;
    border-radius: 8px;
    color: var(--text-inverse);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-save-all:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* Extra options row (Google Search) */
.ai-config-extra {
    background: var(--bg-light);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-top: 0.5rem;
}

.ai-config-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.ai-config-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.ai-config-extra .ai-config-hint {
    margin-top: 0.25rem;
    margin-left: 26px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* =============================================
   Responsive Design
   ============================================= */
@media (max-width: 768px) {
    .ai-model-config-modal .dialog.ai-config-dialog {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .ai-model-config-modal .title,
    .ai-config-subtitle,
    .ai-model-config-modal .body,
    .ai-config-footer {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .ai-config-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    
    .ai-config-row > label {
        min-width: auto;
    }
    
    .ai-config-params {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .param-group {
        min-width: auto;
    }
    
    .ai-config-footer {
        flex-direction: column;
        gap: 1rem;
    }
    
    .ai-config-buttons {
        width: 100%;
    }
    
    .ai-config-buttons button {
        flex: 1;
    }
}

/* =============================================
   Theme-specific adjustments
   ============================================= */

/* Light themes need darker dropdown backgrounds */
[data-theme="light-sunset"] .ai-config-row select,
[data-theme="light-midday"] .ai-config-row select {
    background-color: var(--bg-medium);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333333' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

[data-theme="light-sunset"] .ai-config-row select option,
[data-theme="light-midday"] .ai-config-row select option {
    background: var(--bg-dark);
    color: var(--text-primary);
}

[data-theme="light-sunset"] .param-group input[type="number"],
[data-theme="light-midday"] .param-group input[type="number"] {
    background: var(--bg-medium);
}

/* Light theme modal background */
[data-theme="light-sunset"] .ai-model-config-modal.modal,
[data-theme="light-midday"] .ai-model-config-modal.modal {
    background: rgba(0, 0, 0, 0.4);
}

/* Light theme toggle unchecked state */
[data-theme="light-sunset"] .ai-config-toggle .toggle-slider,
[data-theme="light-midday"] .ai-config-toggle .toggle-slider {
    background: var(--bg-lighter);
}

[data-theme="light-sunset"] .ai-config-toggle .toggle-slider:before,
[data-theme="light-midday"] .ai-config-toggle .toggle-slider:before {
    background: var(--text-muted);
}

/* =============================================
   Usage Statistics Styles
   ============================================= */

.ai-usage-stats {
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--bg-darkest);
    border-radius: 10px;
    border: 1px solid var(--border-light);
}

.ai-usage-stats.empty {
    padding: 10px 16px;
    text-align: center;
}

.ai-usage-stats .stats-empty {
    color: var(--text-muted);
    font-size: 12px;
}

.ai-usage-stats .stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
}

.ai-usage-stats .stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 70px;
}

.ai-usage-stats .stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-usage-stats .stat-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.ai-usage-stats .stat-item.cost .stat-value {
    color: var(--accent-primary);
    font-weight: 700;
}

.ai-usage-stats .stats-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
    font-size: 11px;
    color: var(--text-secondary);
}

.ai-usage-stats .stats-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Responsive adjustments for stats */
@media (max-width: 500px) {
    .ai-usage-stats .stats-row {
        flex-direction: column;
        gap: 8px;
    }
    
    .ai-usage-stats .stat-item {
        flex-direction: row;
        justify-content: space-between;
        min-width: 100%;
    }
    
    .ai-usage-stats .stats-meta {
        flex-direction: column;
        gap: 4px;
    }
}

/* Light theme adjustments for stats */
[data-theme="light-sunset"] .ai-usage-stats,
[data-theme="light-midday"] .ai-usage-stats {
    background: var(--bg-medium);
}
