/* ============================================
   FGB Studio Utility Components CSS
   Toast notifications, confirm modal, loading overlay
   ============================================ */

/* ============================================
   Toast Notifications
   ============================================ */
.fgb-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    background: var(--fgb-bg-primary);
    border: 1px solid var(--fgb-border-color);
    border-radius: 8px;
    box-shadow: var(--fgb-shadow-lg);
    z-index: 10001;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

    .fgb-toast.show {
        opacity: 1;
        transform: translateY(0);
    }

    .fgb-toast i {
        font-size: 1.25rem;
    }

    .fgb-toast span {
        font-size: 0.9rem;
        color: var(--fgb-text-primary);
    }

.fgb-toast-success {
    border-left: 4px solid var(--fgb-accent-green);
}

    .fgb-toast-success i {
        color: var(--fgb-accent-green);
    }

.fgb-toast-error {
    border-left: 4px solid var(--fgb-accent-red);
}

    .fgb-toast-error i {
        color: var(--fgb-accent-red);
    }

.fgb-toast-warning {
    border-left: 4px solid var(--fgb-accent-yellow);
}

    .fgb-toast-warning i {
        color: var(--fgb-accent-yellow);
    }

.fgb-toast-info {
    border-left: 4px solid var(--fgb-accent-blue);
}

    .fgb-toast-info i {
        color: var(--fgb-accent-blue);
    }

/* ============================================
   Confirm Modal
   ============================================ */
.fgb-confirm-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--fgb-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    opacity: 0;
    transition: opacity 0.2s ease;
}

    .fgb-confirm-modal.show {
        opacity: 1;
    }

.fgb-confirm-content {
    background: var(--fgb-bg-primary);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: var(--fgb-shadow-lg);
    transform: scale(0.9);
    transition: transform 0.2s ease;
}

.fgb-confirm-modal.show .fgb-confirm-content {
    transform: scale(1);
}

.fgb-confirm-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.fgb-confirm-title {
    color: var(--fgb-text-primary);
    margin: 0 0 0.75rem;
    font-size: 1.25rem;
}

.fgb-confirm-message {
    color: var(--fgb-text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.fgb-confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

    .fgb-confirm-actions .btn {
        min-width: 100px;
    }

/* ============================================
   Loading Overlay
   ============================================ */
.fgb-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--fgb-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: inherit;
}

.fgb-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    background: var(--fgb-bg-primary);
    border-radius: 12px;
    box-shadow: var(--fgb-shadow-lg);
}

.fgb-loading-text {
    color: var(--fgb-text-secondary);
    font-size: 0.95rem;
}

/* ============================================
   Event Tab Close Button Styling
   ============================================ */
.event-tab .event-tab-close {
    margin-left: 0.5rem;
    opacity: 0.6;
    font-size: 0.7rem;
    padding: 0.125rem;
    border-radius: 3px;
    transition: background 0.15s ease, opacity 0.15s ease;
}

    .event-tab .event-tab-close:hover {
        opacity: 1;
        background: var(--fgb-bg-tertiary);
    }

.event-tab:hover .event-tab-close {
    opacity: 0.8;
}

/* ============================================
   Spin Animation (for refresh buttons)
   ============================================ */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.spin-animation {
    animation: spin 1s linear infinite;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
    .fgb-toast {
        left: 20px;
        right: 20px;
        bottom: 10px;
    }

    .fgb-confirm-content {
        padding: 1.25rem;
    }

    .fgb-confirm-actions {
        flex-direction: column;
    }

        .fgb-confirm-actions .btn {
            width: 100%;
        }
}

/* Settings dropdown toggle item */
.dropdown-item-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    gap: 1rem;
}

    .dropdown-item-toggle .form-check-label {
        display: flex;
        align-items: center;
        margin-bottom: 0;
        font-size: 0.875rem;
        color: var(--fgb-text-primary);
        cursor: pointer;
    }

    .dropdown-item-toggle .form-switch {
        padding-left: 2.5em;
        min-height: auto;
        margin-bottom: 0;
    }

    .dropdown-item-toggle .form-check-input {
        cursor: pointer;
    }

    .dropdown-item-toggle:hover {
        background: var(--fgb-bg-hover);
    }

/* ============================================
   Display Options Dropdown
   ============================================ */
.display-options-dropdown {
    position: relative;
    display: inline-flex;
}

.btn-toolbar-settings {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--fgb-border-color, #dee2e6);
    border-radius: 6px;
    background: var(--fgb-bg-secondary, #fff);
    color: var(--fgb-text-secondary, #6c757d);
    cursor: pointer;
    transition: all 0.15s ease;
}

    .btn-toolbar-settings:hover {
        background: var(--fgb-bg-tertiary, #f8f9fa);
        color: var(--fgb-text-primary, #212529);
        border-color: var(--fgb-border-color-hover, #adb5bd);
    }

    .btn-toolbar-settings.active {
        background: var(--fgb-primary, #10b981);
        color: #fff;
        border-color: var(--fgb-primary, #10b981);
    }

.display-options-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    padding: 12px;
    background: var(--fgb-bg-primary, #fff);
    border: 1px solid var(--fgb-border-color, #dee2e6);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: none;
}

    .display-options-menu.show {
        display: block;
    }

.display-options-section {
    margin-bottom: 12px;
}

    .display-options-section:last-child {
        margin-bottom: 0;
    }

.display-options-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--fgb-text-secondary, #6c757d);
    margin-bottom: 8px;
}

.format-style-options,
.color-scheme-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.format-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 0.875rem;
    color: var(--fgb-text-primary, #212529);
}

    .format-option:hover {
        background: var(--fgb-bg-tertiary, #f8f9fa);
    }

    .format-option input[type="radio"] {
        margin: 0;
        accent-color: var(--fgb-primary, #10b981);
    }

    .format-option span {
        flex: 1;
    }

/* ============================================
   Player Filter Button
   ============================================ */
.btn-toolbar-filter {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--fgb-border-color, #dee2e6);
    border-radius: 6px;
    background: var(--fgb-bg-secondary, #fff);
    color: var(--fgb-text-secondary, #6c757d);
    cursor: pointer;
    transition: all 0.15s ease;
}

    .btn-toolbar-filter:hover {
        background: var(--fgb-bg-tertiary, #f8f9fa);
        color: var(--fgb-text-primary, #212529);
        border-color: var(--fgb-border-color-hover, #adb5bd);
    }

    .btn-toolbar-filter.has-filters {
        background: var(--fgb-primary-light, rgba(16, 185, 129, 0.1));
        color: var(--fgb-primary, #10b981);
        border-color: var(--fgb-primary, #10b981);
    }

.filter-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    color: #fff;
    background: var(--fgb-primary, #10b981);
    border-radius: 9px;
}

/* ============================================
   Export Button (if not already styled)
   ============================================ */
.btn-toolbar-export {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--fgb-border-color, #dee2e6);
    border-radius: 6px;
    background: var(--fgb-bg-secondary, #fff);
    color: var(--fgb-text-secondary, #6c757d);
    cursor: pointer;
    transition: all 0.15s ease;
}

    .btn-toolbar-export:hover {
        background: var(--fgb-bg-tertiary, #f8f9fa);
        color: var(--fgb-text-primary, #212529);
        border-color: var(--fgb-border-color-hover, #adb5bd);
    }

/* ============================================
   Toolbar Settings Group
   ============================================ */
.toolbar-settings {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ============================================
   Dark Mode Overrides
   ============================================ */
[data-bs-theme="dark"] .display-options-menu {
    background: var(--fgb-bg-primary-dark, #1a1a2e);
    border-color: var(--fgb-border-color-dark, #2d2d44);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-bs-theme="dark"] .format-option:hover {
    background: var(--fgb-bg-tertiary-dark, #2d2d44);
}

[data-bs-theme="dark"] .btn-toolbar-settings,
[data-bs-theme="dark"] .btn-toolbar-filter,
[data-bs-theme="dark"] .btn-toolbar-export {
    background: var(--fgb-bg-secondary-dark, #252538);
    border-color: var(--fgb-border-color-dark, #2d2d44);
    color: var(--fgb-text-secondary-dark, #9ca3af);
}

    [data-bs-theme="dark"] .btn-toolbar-settings:hover,
    [data-bs-theme="dark"] .btn-toolbar-filter:hover,
    [data-bs-theme="dark"] .btn-toolbar-export:hover {
        background: var(--fgb-bg-tertiary-dark, #2d2d44);
        color: var(--fgb-text-primary-dark, #e5e7eb);
    }

/* ============================================
   Custom Stats Modal - Selected Stats Summary
   ============================================ */
.selected-stats-summary {
    background: var(--fgb-bg-tertiary, #f8f9fa);
    border: 1px solid var(--fgb-border-color, #dee2e6);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.selected-stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.selected-stats-label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--fgb-text-primary, #212529);
}

.selected-stats-actions {
    display: flex;
    gap: 8px;
}

    .selected-stats-actions .btn {
        font-size: 0.75rem;
        padding: 4px 10px;
    }

.selected-stats-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 120px;
    overflow-y: auto;
}

.no-stats-message {
    color: var(--fgb-text-secondary, #6c757d);
    font-size: 0.8125rem;
    font-style: italic;
}

.stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--fgb-primary-light, rgba(16, 185, 129, 0.1));
    border: 1px solid var(--fgb-primary, #10b981);
    border-radius: 16px;
    font-size: 0.75rem;
    color: var(--fgb-primary-dark, #059669);
}

.stat-chip-label {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--fgb-primary, #10b981);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s ease;
}

    .stat-chip-remove:hover {
        background: var(--fgb-primary, #10b981);
        color: #fff;
    }

/* ============================================
   Dark Mode - Selected Stats Summary
   ============================================ */
[data-bs-theme="dark"] .selected-stats-summary {
    background: var(--fgb-bg-secondary-dark, #252538);
    border-color: var(--fgb-border-color-dark, #2d2d44);
}

[data-bs-theme="dark"] .stat-chip {
    background: rgba(16, 185, 129, 0.15);
    border-color: var(--fgb-primary, #10b981);
    color: var(--fgb-primary-light, #34d399);
}

[data-bs-theme="dark"] .stat-chip-remove {
    color: var(--fgb-primary-light, #34d399);
}

    [data-bs-theme="dark"] .stat-chip-remove:hover {
        background: var(--fgb-primary, #10b981);
        color: #fff;
    }

/* ============================================
   Player Filters - Exclude from Rankings
   ============================================ */
.exclude-rankings-item {
    flex-direction: column;
    align-items: flex-start !important;
}

.filter-help-text {
    display: block;
    margin-top: 4px;
    margin-left: 24px;
    font-size: 0.75rem;
    color: var(--fgb-text-secondary, #6c757d);
    line-height: 1.3;
}

[data-bs-theme="dark"] .filter-help-text {
    color: var(--fgb-text-secondary-dark, #9ca3af);
}

/* ============================================
   Player Filters - Min Rounds with Toggle
   ============================================ */
.min-rounds-filter {
    display: flex;
    align-items: center;
    gap: 10px;
}

    .min-rounds-filter .filter-toggle {
        flex: 1;
    }

.min-rounds-input {
    width: 70px !important;
    flex-shrink: 0;
}

    .min-rounds-input:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

/* ============================================
   Player Filters - Sub-options (indented)
   ============================================ */
.player-filter-suboptions {
    margin-left: 24px;
    padding-left: 12px;
    border-left: 2px solid var(--fgb-border-color, #dee2e6);
    margin-top: 8px;
}

    .player-filter-suboptions .player-filter-item {
        margin-bottom: 6px;
    }

        .player-filter-suboptions .player-filter-item:last-child {
            margin-bottom: 0;
        }

[data-bs-theme="dark"] .player-filter-suboptions {
    border-left-color: var(--fgb-border-color-dark, #3d3d5c);
}

/* ============================================
   Per-Bucket Eligibility Styles
   For ApproachIQ and DrivingIQ models
   ============================================ */

/* ----------------------------------------
   ApproachIQ Eligibility Styles
   ---------------------------------------- */

/* Ineligible bucket cell - greyed out background */
.aiq-bucket-ineligible {
    background-color: rgba(128, 128, 128, 0.08) !important;
}

/* Dark mode adjustment */
[data-bs-theme="dark"] .aiq-bucket-ineligible {
    background-color: rgba(128, 128, 128, 0.15) !important;
}

/* Ineligible value text styling */
.aiq-ineligible-value {
    color: #999 !important;
    font-style: italic;
}

/* Dark mode text */
[data-bs-theme="dark"] .aiq-ineligible-value {
    color: #666 !important;
}

/* Optional: Add a subtle left border to indicate ineligible groups */
.aiq-bucket-ineligible.aiq-group-first {
    border-left: 2px solid rgba(128, 128, 128, 0.3) !important;
}

/* ----------------------------------------
   DrivingIQ Eligibility Styles
   ---------------------------------------- */

/* Ineligible bucket cell - greyed out background */
.diq-bucket-ineligible {
    background-color: rgba(128, 128, 128, 0.08) !important;
}

/* Dark mode adjustment */
[data-bs-theme="dark"] .diq-bucket-ineligible {
    background-color: rgba(128, 128, 128, 0.15) !important;
}

/* Ineligible value text styling */
.diq-ineligible-value {
    color: #999 !important;
    font-style: italic;
}

/* Dark mode text */
[data-bs-theme="dark"] .diq-ineligible-value {
    color: #666 !important;
}

/* Optional: Add a subtle left border to indicate ineligible groups */
.diq-bucket-ineligible.diq-group-first {
    border-left: 2px solid rgba(128, 128, 128, 0.3) !important;
}

/* ----------------------------------------
   Shared Player Filter Styles
   ---------------------------------------- */

/* Player filter hint text styling */
.player-filter-hint {
    padding: 4px 0 8px 24px;
    font-size: 0.75rem;
    line-height: 1.3;
}

    .player-filter-hint small {
        color: var(--fgb-text-muted, #6b7280);
    }

/* ============================================
   Summary Config - Column Display Section
   ============================================ */

.config-subsection {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--fgb-border-color, #e5e7eb);
}

    .config-subsection:last-child {
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: none;
    }

.config-subsection-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--fgb-text-secondary, #6b7280);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

    .config-subsection-header i {
        font-size: 0.875rem;
    }

.display-option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
}

    .display-option-row.display-option-readonly {
        opacity: 0.8;
    }

.display-option-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin: 0;
}

    .display-option-toggle input[type="checkbox"] {
        width: 1rem;
        height: 1rem;
        cursor: pointer;
        accent-color: var(--fgb-primary, #10b981);
    }

.display-option-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--fgb-text-primary, #374151);
}

    .display-option-label i {
        color: var(--fgb-text-secondary, #6b7280);
        font-size: 0.875rem;
    }

.display-option-auto {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--fgb-text-tertiary, #9ca3af);
    background: var(--fgb-bg-tertiary, #f3f4f6);
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 500;
}

.display-option-rounds {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem 0 0.5rem 1.625rem;
    transition: opacity 0.2s ease;
}

    .display-option-rounds.disabled {
        opacity: 0.4;
        pointer-events: none;
    }

.round-checkbox {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--fgb-text-secondary, #6b7280);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background 0.15s ease;
}

    .round-checkbox:hover {
        background: var(--fgb-bg-tertiary, #f3f4f6);
    }

    .round-checkbox input[type="checkbox"] {
        width: 0.875rem;
        height: 0.875rem;
        cursor: pointer;
        accent-color: var(--fgb-primary, #10b981);
    }

    .round-checkbox.no-data {
        opacity: 0.4;
        cursor: not-allowed;
    }

        .round-checkbox.no-data input {
            cursor: not-allowed;
        }

        .round-checkbox.no-data:hover {
            background: transparent;
        }

/* ============================================
   Dark Mode - Column Display Section
   ============================================ */

[data-bs-theme="dark"] .config-subsection {
    border-bottom-color: var(--fgb-border-color-dark, #2d2d44);
}

[data-bs-theme="dark"] .display-option-auto {
    background: var(--fgb-bg-secondary-dark, #252538);
    color: var(--fgb-text-tertiary-dark, #6b7280);
}

[data-bs-theme="dark"] .round-checkbox:hover {
    background: var(--fgb-bg-tertiary-dark, #2d2d44);
}

[data-bs-theme="dark"] .round-checkbox.no-data:hover {
    background: transparent;
}

/* ============================================
   No Models Prompt (Weights Tab)
   ============================================ */

.no-models-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.5rem 1rem;
}

.no-models-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--fgb-bg-tertiary, #f3f4f6);
    border-radius: 50%;
    margin-bottom: 0.75rem;
}

    .no-models-icon i {
        font-size: 1.25rem;
        color: var(--fgb-text-secondary, #6b7280);
    }

.no-models-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--fgb-text-primary, #374151);
    margin: 0 0 0.5rem;
}

.no-models-description {
    font-size: 0.8rem;
    color: var(--fgb-text-secondary, #6b7280);
    margin: 0 0 1rem;
    line-height: 1.4;
}

/* Dark mode */
[data-bs-theme="dark"] .no-models-icon {
    background: var(--fgb-bg-secondary-dark, #252538);
}

    [data-bs-theme="dark"] .no-models-icon i {
        color: var(--fgb-text-secondary-dark, #9ca3af);
    }

/* ============================================
   Unavailable/Disabled States
   ============================================ */

.display-option-row.unavailable {
    opacity: 0.6;
}

    .display-option-row.unavailable .display-option-label {
        color: var(--fgb-text-muted, #9ca3af);
    }

        .display-option-row.unavailable .display-option-label i {
            color: var(--fgb-text-muted, #9ca3af);
        }

.display-option-unavailable {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--fgb-text-muted, #9ca3af);
    background: var(--fgb-bg-tertiary, #f3f4f6);
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 500;
    white-space: nowrap;
}

.config-subsection.unavailable {
    opacity: 0.6;
}

.config-subsection-unavailable {
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    color: var(--fgb-text-muted, #9ca3af);
    margin-left: 0.5rem;
}

/* Dark mode */
[data-bs-theme="dark"] .display-option-unavailable {
    background: var(--fgb-bg-secondary-dark, #252538);
    color: var(--fgb-text-muted-dark, #6b7280);
}

[data-bs-theme="dark"] .display-option-row.unavailable .display-option-label,
[data-bs-theme="dark"] .display-option-row.unavailable .display-option-label i {
    color: var(--fgb-text-muted-dark, #6b7280);
}

/* Save Status Indicator */
.config-save-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    color: var(--bs-secondary-color, #6c757d);
    margin-right: 0.75rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

    .config-save-status:not(:empty) {
        opacity: 1;
    }

    .config-save-status.saved {
        color: var(--bs-success, #198754);
    }

    .config-save-status i {
        font-size: 0.7rem;
        transition: transform 0.2s ease;
    }

    .config-save-status.saved i {
        animation: checkPop 0.3s ease;
    }

@keyframes checkPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

/* Dark mode support */
[data-bs-theme="dark"] .config-save-status.saved {
    color: #75b798;
}

/* ============================================
   Restoration Overlay
   ============================================ */
.restoration-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--fgb-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.restoration-content {
    text-align: center;
    padding: 2rem;
}

.restoration-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--fgb-border-color);
    border-top-color: var(--fgb-accent-green);
    border-radius: 50%;
    animation: restorationSpin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

.restoration-status {
    color: var(--fgb-text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

@keyframes restorationSpin {
    to {
        transform: rotate(360deg);
    }
}

.event-tab.restoring,
.add-event-btn.restoring {
    pointer-events: none;
    opacity: 0.5;
}

/* ============================================
   Template Menu (three-dot overflow)
   ============================================ */
#modelTabsContainer .template-menu-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    vertical-align: middle;
}

#modelTabsContainer .template-menu-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--fgb-text-muted, #6b7280);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}

    #modelTabsContainer .template-menu-btn:hover {
        color: var(--fgb-accent, #10b981);
        background: rgba(255, 255, 255, 0.06);
    }

#modelTabsContainer .template-menu-dropdown {
    display: none;
    position: fixed;
    z-index: 1050;
    min-width: 210px;
    background: var(--fgb-surface, #1e2332);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    padding: 4px;
    flex-direction: column;
}

    #modelTabsContainer .template-menu-dropdown.show {
        display: flex;
    }

#modelTabsContainer .template-menu-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: #e5e7eb;
    font-size: 0.85rem;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    transition: background 0.15s;
}

    #modelTabsContainer .template-menu-item:hover {
        background: rgba(255, 255, 255, 0.07);
    }

    #modelTabsContainer .template-menu-item i {
        color: var(--fgb-accent, #10b981);
        font-size: 0.9rem;
        flex-shrink: 0;
    }

/* ============================================
   Dataset Modal - Template Button
   ============================================ */
.dataset-template-divider {
    display: flex;
    align-items: center;
    margin: 1.25rem 0;
    gap: 12px;
}

    .dataset-template-divider::before,
    .dataset-template-divider::after {
        content: '';
        flex: 1;
        height: 1px;
        background: rgba(255, 255, 255, 0.08);
    }

    .dataset-template-divider span {
        font-size: 0.8rem;
        color: var(--fgb-text-muted, #6b7280);
        text-transform: lowercase;
    }

.dataset-template-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: #e5e7eb;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-align: left;
}

    .dataset-template-btn:hover {
        background: rgba(255, 255, 255, 0.06);
        border-color: var(--fgb-accent, #10b981);
    }

    .dataset-template-btn i {
        font-size: 1.4rem;
        color: var(--fgb-accent, #10b981);
        flex-shrink: 0;
    }

.dataset-template-btn-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

    .dataset-template-btn-text span {
        font-size: 0.9rem;
        font-weight: 500;
    }

    .dataset-template-btn-text small {
        font-size: 0.78rem;
        color: var(--fgb-text-muted, #6b7280);
    }

/* ============================================
   Apply Template Modal
   ============================================ */
.template-search-wrapper {
    position: relative;
    padding: 16px 0 8px;
}

    .template-search-wrapper .template-search-icon {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-30%);
        color: var(--fgb-text-muted, #6b7280);
        font-size: 0.85rem;
        pointer-events: none;
    }

    .template-search-wrapper input {
        padding-left: 36px;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(255, 255, 255, 0.08);
        color: #e5e7eb;
        border-radius: 8px;
        font-size: 0.875rem;
    }

        .template-search-wrapper input:focus {
            background: rgba(255, 255, 255, 0.06);
            border-color: var(--fgb-accent, #10b981);
            box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
        }

        .template-search-wrapper input::placeholder {
            color: var(--fgb-text-muted, #6b7280);
        }

.template-list-container {
    max-height: 420px;
    overflow-y: auto;
    padding: 4px 0;
}

.template-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Empty state */
.template-empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

    .template-empty-state i {
        font-size: 2rem;
        color: var(--fgb-text-muted, #6b7280);
        display: block;
        margin-bottom: 0.75rem;
    }

    .template-empty-state p {
        color: #e5e7eb;
        font-size: 0.95rem;
        font-weight: 500;
        margin: 0 0 4px;
    }

    .template-empty-state span {
        color: var(--fgb-text-muted, #6b7280);
        font-size: 0.82rem;
        line-height: 1.5;
    }

/* Card */
.template-card {
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 6px;
}

    .template-card:hover {
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(255, 255, 255, 0.12);
    }

.template-card-main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 16px;
    gap: 16px;
}

.template-card-info {
    flex: 1;
    min-width: 0;
}

.template-card-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: #f3f4f6;
    margin: 0 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.template-card-desc {
    font-size: 0.8rem;
    color: var(--fgb-text-muted, #9ca3af);
    margin: 0 0 8px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Model badges */
.template-model-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.template-model-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--fgb-accent, #10b981);
    white-space: nowrap;
}

    .template-model-badge i {
        font-size: 0.65rem;
    }

/* Meta row */
.template-card-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.template-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--fgb-text-muted, #6b7280);
}

    .template-meta-item i {
        font-size: 0.7rem;
    }

/* Actions column */
.template-card-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.template-apply-btn {
    font-size: 0.8rem;
    font-weight: 500;
    padding: 5px 16px;
    border-radius: 6px;
    white-space: nowrap;
}

.template-overflow-btn {
    background: transparent;
    border: none;
    color: var(--fgb-text-muted, #6b7280);
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: color 0.15s;
}

    .template-overflow-btn:hover {
        color: #e5e7eb;
    }

/* Overflow menu */
.template-overflow-menu {
    min-width: 140px;
    background: var(--fgb-surface, #1e2332);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    padding: 4px;
    z-index: 1100;
}

.template-overflow-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: #e5e7eb;
    font-size: 0.83rem;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

    .template-overflow-item:hover {
        background: rgba(255, 255, 255, 0.07);
    }

    .template-overflow-item.danger {
        color: #ef4444;
    }

        .template-overflow-item.danger:hover {
            background: rgba(239, 68, 68, 0.1);
        }

    .template-overflow-item i {
        font-size: 0.8rem;
    }

/* Light mode overrides */
[data-bs-theme="light"] .template-search-wrapper input {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #111827;
}

[data-bs-theme="light"] .template-card {
    background: #f9fafb;
    border-color: #e5e7eb;
}

    [data-bs-theme="light"] .template-card:hover {
        background: #f3f4f6;
        border-color: #d1d5db;
    }

[data-bs-theme="light"] .template-card-name {
    color: #111827;
}

[data-bs-theme="light"] .template-empty-state p {
    color: #374151;
}

[data-bs-theme="light"] .template-overflow-menu {
    background: #fff;
    border-color: #e5e7eb;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-bs-theme="light"] .template-overflow-item {
    color: #374151;
}

    [data-bs-theme="light"] .template-overflow-item:hover {
        background: #f3f4f6;
    }

/* Template sections */
.template-section {
    margin-bottom: 4px;
}

.template-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 4px 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--fgb-text-muted, #9ca3af);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.template-section-icon {
    font-size: 0.72rem;
}

.template-section-header .bi-star-fill {
    color: #f59e0b;
}

.template-section-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 8px 0;
}

/* Public template card accent */
.template-card-public {
    border-color: rgba(245, 158, 11, 0.15);
}

    .template-card-public:hover {
        border-color: rgba(245, 158, 11, 0.3);
    }

/* Name row with badge */
.template-card-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

    .template-card-name-row .template-card-name {
        margin-bottom: 0;
    }

/* Public badge */
.template-public-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 7px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #f59e0b;
    white-space: nowrap;
    flex-shrink: 0;
}

    .template-public-badge i {
        font-size: 0.55rem;
    }

/* Public indicator in meta */
.template-meta-public {
    color: var(--fgb-accent, #10b981) !important;
}

/* Light mode */
[data-bs-theme="light"] .template-section-header {
    color: #6b7280;
}

[data-bs-theme="light"] .template-section-divider {
    background: #e5e7eb;
}

[data-bs-theme="light"] .template-card-public {
    border-color: rgba(245, 158, 11, 0.2);
}

    [data-bs-theme="light"] .template-card-public:hover {
        border-color: rgba(245, 158, 11, 0.4);
    }

/* Correlation Badge */
.correlation-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: default;
    white-space: nowrap;
}

    .correlation-badge i {
        font-size: 0.7rem;
    }

.correlation-value {
    font-weight: 600;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.73rem;
}

.correlation-label {
    font-weight: 500;
    font-size: 0.7rem;
    opacity: 0.85;
}

/* Light mode */
[data-bs-theme="light"] .correlation-badge {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.08);
}

/* ============================================
   Template Toolbar (Search + Sort)
   ============================================ */
.template-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 0 12px;
}

    .template-toolbar .template-search-wrapper {
        flex: 1;
        margin: 0;
        padding: 0;
    }

.template-sort-toggle {
    display: flex;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.template-sort-btn {
    background: transparent;
    border: none;
    padding: 6px 10px;
    color: var(--fgb-text-muted, #6b7280);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
    line-height: 1;
}

    .template-sort-btn:first-child {
        border-right: 1px solid rgba(255, 255, 255, 0.08);
    }

    .template-sort-btn.active {
        background: var(--fgb-accent, #10b981);
        color: #fff;
    }

    .template-sort-btn:not(.active):hover {
        background: rgba(255, 255, 255, 0.05);
    }

[data-bs-theme="light"] .template-sort-toggle {
    border-color: #e5e7eb;
}

[data-bs-theme="light"] .template-sort-btn:first-child {
    border-color: #e5e7eb;
}

[data-bs-theme="light"] .template-sort-btn:not(.active):hover {
    background: rgba(0, 0, 0, 0.04);
}

/* ============================================
   Template Section Count Badge
   ============================================ */
.template-section-count {
    font-size: 0.65rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.06);
    color: var(--fgb-text-muted, #9ca3af);
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 2px;
}

[data-bs-theme="light"] .template-section-count {
    background: rgba(0, 0, 0, 0.06);
    color: #6b7280;
}

/* ============================================
   Compact Template Card (v2)
   ============================================ */
.tmpl-row-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.tmpl-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.tmpl-badge-public {
    color: #f59e0b;
    font-size: 0.65rem;
    flex-shrink: 0;
}

.tmpl-meta-public {
    color: var(--fgb-accent, #10b981);
    font-size: 0.7rem;
    flex-shrink: 0;
}

.tmpl-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

    .tmpl-actions .template-apply-btn {
        font-size: 0.75rem;
        padding: 3px 14px;
        border-radius: 6px;
        font-weight: 600;
    }

    .tmpl-actions .template-overflow-btn {
        padding: 3px 6px;
        font-size: 0.85rem;
    }

.tmpl-row-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.tmpl-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--fgb-text-muted, #9ca3af);
    white-space: nowrap;
}

    .tmpl-meta-item i {
        font-size: 0.65rem;
        opacity: 0.7;
    }

/* Expandable model details */
.tmpl-model-details {
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

    .tmpl-model-details.expanded {
        display: flex;
    }

.tmpl-model-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--fgb-accent, #10b981);
    white-space: nowrap;
}

    .tmpl-model-tag i {
        font-size: 0.6rem;
        opacity: 0.6;
    }

[data-bs-theme="light"] .tmpl-model-details {
    border-top-color: #e5e7eb;
}

[data-bs-theme="light"] .tmpl-model-tag {
    background: rgba(16, 185, 129, 0.06);
}

/* Flash highlight animation */
.template-card-flash {
    animation: tmpl-flash 1.2s ease;
}

@keyframes tmpl-flash {
    0% {
        background: rgba(16, 185, 129, 0.15);
    }

    100% {
        background: rgba(255, 255, 255, 0.03);
    }
}

[data-bs-theme="light"] .template-card-flash {
    animation: tmpl-flash-light 1.2s ease;
}

@keyframes tmpl-flash-light {
    0% {
        background: rgba(16, 185, 129, 0.12);
    }

    100% {
        background: #f9fafb;
    }
}

/* Template Apply Mode Dialog */
.template-apply-mode-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.template-apply-mode-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
    color: inherit;
}

    .template-apply-mode-btn:hover {
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(16, 185, 129, 0.4);
    }

.template-apply-mode-icon {
    font-size: 1.4rem;
    color: var(--fgb-accent, #10b981);
    flex-shrink: 0;
}

    .template-apply-mode-icon.text-warning {
        color: #f59e0b;
    }

.template-apply-mode-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

    .template-apply-mode-info strong {
        font-size: 0.88rem;
    }

    .template-apply-mode-info span {
        font-size: 0.78rem;
        color: var(--fgb-text-muted, #9ca3af);
        line-height: 1.3;
    }

/* Light mode */
[data-bs-theme="light"] .template-apply-mode-btn {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.1);
}

    [data-bs-theme="light"] .template-apply-mode-btn:hover {
        background: rgba(0, 0, 0, 0.04);
        border-color: rgba(16, 185, 129, 0.4);
    }

/* Share Code Dialog */
.share-code-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 16px 0 12px;
    padding: 14px 20px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.share-code-value {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--fgb-text-primary, #e5e7eb);
}

.share-code-copy-btn {
    background: none;
    border: none;
    color: var(--fgb-text-muted, #9ca3af);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

    .share-code-copy-btn:hover {
        color: var(--fgb-accent, #10b981);
        background: rgba(16, 185, 129, 0.1);
    }

.share-code-hint {
    font-size: 0.75rem;
    color: var(--fgb-text-muted, #9ca3af);
    margin: 0;
    text-align: center;
}

/* Shared Code Input Section */
.shared-code-section {
    padding: 12px 0;
}

.shared-code-input-row {
    display: flex;
    gap: 8px;
}

    .shared-code-input-row .form-control {
        font-family: 'SF Mono', 'Consolas', monospace;
        font-size: 0.88rem;
        letter-spacing: 0.03em;
        text-align: center;
    }

.shared-code-error {
    margin-top: 8px;
    font-size: 0.8rem;
    color: #ef4444;
}

/* Shared Preview Card */
.shared-code-preview {
    margin-top: 10px;
}

.shared-preview-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: rgba(16, 185, 129, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 10px;
}

.shared-preview-info {
    flex: 1;
    min-width: 0;
}

    .shared-preview-info strong {
        display: block;
        font-size: 0.88rem;
        margin-bottom: 2px;
    }

.shared-preview-desc {
    font-size: 0.78rem;
    color: var(--fgb-text-muted, #9ca3af);
    margin: 2px 0 4px;
}

.shared-preview-card .template-model-badges {
    margin-top: 4px;
}

/* Light mode */
[data-bs-theme="light"] .share-code-container {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}

[data-bs-theme="light"] .share-code-value {
    color: #1f2937;
}

[data-bs-theme="light"] .shared-preview-card {
    background: rgba(16, 185, 129, 0.05);
    border-color: rgba(16, 185, 129, 0.15);
}

/* ============================================
   Template Modal v3 — ADD to fgbstudio-utils.css
   ============================================ */

/* Modal wider layout */
.tmpl-modal-v3 {
    max-width: 920px !important;
}

/* Header */
.tmpl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tmpl-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

    .tmpl-header-left h2 {
        margin: 0;
        font-size: 1.1rem;
        font-weight: 700;
    }

/* Quick Re-Apply Bar */
.tmpl-quick-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 22px;
    background: rgba(16, 185, 129, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.tmpl-quick-label {
    font-size: 0.78rem;
    color: var(--fgb-text-muted, #9ca3af);
}

.tmpl-quick-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: #e5e7eb;
}

.tmpl-quick-ago {
    font-size: 0.7rem;
    color: var(--fgb-text-muted, #6b7280);
}

.tmpl-quick-apply-btn {
    padding: 4px 14px;
    border-radius: 6px;
    border: 1px solid rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.08);
    color: var(--fgb-accent, #10b981);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

    .tmpl-quick-apply-btn:hover {
        background: rgba(16, 185, 129, 0.15);
        border-color: rgba(16, 185, 129, 0.5);
    }

/* Toolbar Row (search + sort + share code) */
.tmpl-toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.tmpl-search-wrap {
    position: relative;
    flex: 1;
}

.tmpl-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--fgb-text-muted, #6b7280);
    font-size: 0.8rem;
    pointer-events: none;
}

.tmpl-search-wrap input {
    padding-left: 34px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
    border-radius: 8px;
    font-size: 0.85rem;
    height: 34px;
}

    .tmpl-search-wrap input:focus {
        background: rgba(255, 255, 255, 0.06);
        border-color: var(--fgb-accent, #10b981);
        box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
    }

    .tmpl-search-wrap input::placeholder {
        color: var(--fgb-text-muted, #6b7280);
    }

.tmpl-sort-toggle {
    display: flex;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.tmpl-sort-btn {
    background: transparent;
    border: none;
    padding: 6px 10px;
    color: var(--fgb-text-muted, #6b7280);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
    line-height: 1;
}

    .tmpl-sort-btn:first-child {
        border-right: 1px solid rgba(255, 255, 255, 0.08);
    }

    .tmpl-sort-btn.active {
        background: var(--fgb-accent, #10b981);
        color: #fff;
    }

    .tmpl-sort-btn:not(.active):hover {
        background: rgba(255, 255, 255, 0.05);
    }

.tmpl-toolbar-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.06);
    margin: 0 4px;
    flex-shrink: 0;
}

.tmpl-share-input {
    width: 130px !important;
    flex-shrink: 0;
    text-align: center;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.82rem;
    letter-spacing: 0.03em;
    height: 34px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
    border-radius: 8px;
}

    .tmpl-share-input:focus {
        border-color: var(--fgb-accent, #10b981);
        box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
    }

.tmpl-share-load-btn {
    flex-shrink: 0;
    height: 34px;
    padding: 0 12px;
}

.tmpl-share-error {
    padding: 4px 22px 8px;
    font-size: 0.8rem;
    color: #ef4444;
}

.tmpl-share-preview {
    padding: 0 22px 8px;
}

/* Tabs */
.tmpl-tabs {
    display: flex;
    gap: 0;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tmpl-tab {
    padding: 10px 18px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--fgb-text-muted, #6b7280);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    white-space: nowrap;
}

    .tmpl-tab:hover {
        color: #d1d5db;
    }

    .tmpl-tab.active {
        color: var(--fgb-accent, #10b981);
        border-bottom-color: var(--fgb-accent, #10b981);
    }

.tmpl-tab-count {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--fgb-text-muted, #6b7280);
}

.tmpl-tab.active .tmpl-tab-count {
    background: rgba(16, 185, 129, 0.15);
    color: var(--fgb-accent, #10b981);
}

/* Body: split list + preview */
.tmpl-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 350px;
    max-height: 460px;
}

.tmpl-list-panel {
    flex: 0 0 55%;
    overflow-y: auto;
    padding: 12px 16px 12px 22px;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.tmpl-preview-panel {
    flex: 0 0 45%;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.12);
}

/* Cards */
.tmpl-card {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 5px;
}

    .tmpl-card:hover {
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.04);
    }

    .tmpl-card.selected {
        border-color: var(--fgb-accent, #10b981);
        background: rgba(16, 185, 129, 0.06);
    }

.tmpl-card-public {
    border-left: 3px solid rgba(245, 158, 11, 0.3);
}

.tmpl-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tmpl-card-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.tmpl-star {
    color: #f59e0b;
    font-size: 0.6rem;
    flex-shrink: 0;
}

.tmpl-globe {
    color: var(--fgb-accent, #10b981);
    font-size: 0.65rem;
    flex-shrink: 0;
}

.tmpl-card-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: #e5e7eb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tmpl-card-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

    .tmpl-card-actions .tmpl-apply-btn {
        font-size: 0.73rem;
        padding: 3px 14px;
        border-radius: 6px;
        font-weight: 600;
    }

    .tmpl-card-actions .tmpl-overflow-btn {
        padding: 3px 6px;
        font-size: 0.85rem;
        color: var(--fgb-text-muted, #6b7280);
        border: none;
        background: none;
        cursor: pointer;
        border-radius: 4px;
    }

        .tmpl-card-actions .tmpl-overflow-btn:hover {
            background: rgba(255, 255, 255, 0.06);
        }

.tmpl-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 5px;
    flex-wrap: wrap;
}

.tmpl-meta {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 0.7rem;
    color: var(--fgb-text-muted, #6b7280);
    white-space: nowrap;
}

    .tmpl-meta i {
        font-size: 0.6rem;
        opacity: 0.6;
    }

/* Card flash animation */
.tmpl-card-flash {
    animation: tmplFlash 1.2s ease;
}

@keyframes tmplFlash {
    0% {
        background: rgba(16, 185, 129, 0.15);
    }

    100% {
        background: rgba(255, 255, 255, 0.02);
    }
}

/* Empty state */
.tmpl-empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--fgb-text-muted, #6b7280);
}

    .tmpl-empty-state i {
        font-size: 1.8rem;
        display: block;
        margin-bottom: 0.5rem;
        opacity: 0.3;
    }

    .tmpl-empty-state p {
        margin: 0;
        font-size: 0.85rem;
        color: #9ca3af;
    }

/* Preview panel */
.tmpl-preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #4b5563;
    text-align: center;
    padding: 2rem 1.5rem;
}

    .tmpl-preview-empty i {
        font-size: 1.8rem;
        opacity: 0.3;
        margin-bottom: 8px;
    }

    .tmpl-preview-empty p {
        margin: 0;
        font-size: 0.85rem;
        opacity: 0.5;
    }

.tmpl-preview-content {
    padding: 18px 20px;
}

.tmpl-preview-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.tmpl-preview-name {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: #f3f4f6;
}

.tmpl-preview-desc {
    font-size: 0.8rem;
    color: #9ca3af;
    margin: 4px 0 12px;
    line-height: 1.4;
}

.tmpl-preview-meta {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-wrap: wrap;
}

.tmpl-preview-section {
    margin-bottom: 16px;
}

.tmpl-preview-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
    margin-bottom: 8px;
}

.tmpl-preview-models {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tmpl-preview-model-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.tmpl-preview-model-icon {
    color: var(--fgb-accent, #10b981);
    font-size: 0.85rem;
}

.tmpl-preview-model-info {
    display: flex;
    flex-direction: column;
}

.tmpl-preview-model-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: #e5e7eb;
}

.tmpl-preview-model-type {
    font-size: 0.68rem;
    color: #6b7280;
}

.tmpl-preview-apply-row {
    margin-top: 20px;
}

.tmpl-preview-apply-btn {
    width: 100%;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.85rem;
}

/* Light mode overrides */
[data-bs-theme="light"] .tmpl-quick-bar {
    background: rgba(16, 185, 129, 0.03);
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

[data-bs-theme="light"] .tmpl-quick-name {
    color: #111827;
}

[data-bs-theme="light"] .tmpl-search-wrap input,
[data-bs-theme="light"] .tmpl-share-input {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #111827;
}

[data-bs-theme="light"] .tmpl-sort-toggle {
    border-color: #e5e7eb;
}

[data-bs-theme="light"] .tmpl-sort-btn:first-child {
    border-color: #e5e7eb;
}

[data-bs-theme="light"] .tmpl-sort-btn:not(.active):hover {
    background: rgba(0, 0, 0, 0.04);
}

[data-bs-theme="light"] .tmpl-toolbar-divider {
    background: #e5e7eb;
}

[data-bs-theme="light"] .tmpl-tabs {
    border-bottom-color: #e5e7eb;
}

[data-bs-theme="light"] .tmpl-tab:hover {
    color: #374151;
}

[data-bs-theme="light"] .tmpl-tab-count {
    background: rgba(0, 0, 0, 0.06);
}

[data-bs-theme="light"] .tmpl-list-panel {
    border-right-color: #e5e7eb;
}

[data-bs-theme="light"] .tmpl-preview-panel {
    background: #f9fafb;
}

[data-bs-theme="light"] .tmpl-card {
    background: #fff;
    border-color: #e5e7eb;
}

    [data-bs-theme="light"] .tmpl-card:hover {
        background: #f3f4f6;
        border-color: #d1d5db;
    }

    [data-bs-theme="light"] .tmpl-card.selected {
        background: rgba(16, 185, 129, 0.04);
        border-color: var(--fgb-accent, #10b981);
    }

[data-bs-theme="light"] .tmpl-card-name {
    color: #111827;
}

[data-bs-theme="light"] .tmpl-preview-name {
    color: #111827;
}

[data-bs-theme="light"] .tmpl-preview-model-item {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.06);
}

[data-bs-theme="light"] .tmpl-preview-model-name {
    color: #111827;
}

[data-bs-theme="light"] .tmpl-preview-meta {
    border-bottom-color: #e5e7eb;
}

@keyframes tmplFlashLight {
    0% {
        background: rgba(16, 185, 129, 0.12);
    }

    100% {
        background: #fff;
    }
}

[data-bs-theme="light"] .tmpl-card-flash {
    animation: tmplFlashLight 1.2s ease;
}

/* Responsive */
@media (max-width: 768px) {
    .tmpl-modal-v3 {
        max-width: 100% !important;
    }

    .tmpl-body {
        flex-direction: column;
        max-height: none;
    }

    .tmpl-list-panel {
        flex: none;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        max-height: 300px;
    }

    .tmpl-preview-panel {
        flex: none;
        min-height: 200px;
    }

    .tmpl-toolbar-row {
        flex-wrap: wrap;
    }

    .tmpl-share-input {
        width: 100% !important;
    }

    .tmpl-tabs {
        overflow-x: auto;
        padding: 0 16px;
    }
}