/**
 * StoryCraft - Components
 * Composants réutilisables : boutons, cartes, modals, formulaires
 * @version 2.0
 */

/* === BOUTONS === */

/* Bouton de base */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--animation-duration) cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    user-select: none;
    box-shadow: var(--shadow-light);
    background: var(--background-card);
    color: var(--text-primary);
    min-height: 48px;
}

.btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s ease;
    z-index: 1;
}

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

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Visible focus outline for accessibility */
.btn:focus-visible {
    outline: 3px solid rgba(102, 126, 234, 0.6);
    outline-offset: 2px;
}

/* Generic focus ring for common interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* Floating Stellie toggle (if present) */
#stellie-chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1200;
    border: none;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    font-size: 1.6rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Variantes de boutons - WCAG AA compliant */
.btn-primary {
    background: var(--primary-color);
    color: var(--text-on-color, white);
    border-color: var(--primary-color);
    text-shadow: var(--text-on-color-shadow, 0 1px 2px rgba(0, 0, 0, 0.3));
    font-weight: 600;
}

.btn-primary:hover {
    background: color-mix(in srgb, var(--primary-color) 85%, black);
    box-shadow: var(--shadow-medium);
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--text-on-color, white);
    border-color: var(--secondary-color);
    text-shadow: var(--text-on-color-shadow, 0 1px 2px rgba(0, 0, 0, 0.3));
    font-weight: 600;
}

.btn-secondary:hover {
    background: color-mix(in srgb, var(--secondary-color) 85%, black);
    box-shadow: var(--shadow-medium);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-color) 0%, #1e8449 100%);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn-success:hover {
    background: linear-gradient(135deg, #1e8449 0%, var(--success-color) 100%);
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning-color) 0%, #b7791f 100%);
    color: #1a1a2e; /* dark text for better contrast on yellow */
    text-shadow: none;
}

.btn-error {
    background: linear-gradient(135deg, var(--error-color) 0%, #922b21 100%);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.btn-error:hover {
    background: linear-gradient(135deg, #e74c3c 0%, var(--error-color) 100%);
}

/* Bouton spécial de génération */
.btn-primary.generate-button {
    background: linear-gradient(135deg, #ff6b9d 0%, #c3affe 25%, #4ecdc4 50%, #f093fb 75%, #45b7d1 100%);
    background-size: 300% 300%;
    animation: rainbow 3s ease infinite;
    font-size: var(--font-size-lg);
    padding: var(--spacing-lg) var(--spacing-2xl);
    border-radius: var(--border-radius-large);
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    box-shadow: var(--shadow-fun);
}

.btn-primary.generate-button::after {
    content: "✨";
    position: absolute;
    right: 1rem;
    animation: sparkle 2s ease-in-out infinite;
    font-size: 1.2em;
}

.btn-primary.generate-button:hover::after {
    animation: bounce 0.6s ease-in-out infinite;
}

/* Tailles de boutons */
.btn-sm {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    min-height: 36px;
}

.btn-lg {
    padding: var(--spacing-lg) var(--spacing-2xl);
    font-size: var(--font-size-lg);
    min-height: 56px;
}

/* Boutons ronds */
.btn-circle {
    border-radius: 50%;
    width: 48px;
    height: 48px;
    padding: 0;
}

.btn-circle.btn-sm {
    width: 36px;
    height: 36px;
}

.btn-circle.btn-lg {
    width: 56px;
    height: 56px;
}

/* === CARTES === */

/* Carte de base */
.card {
    background: var(--background-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-light);
    padding: var(--spacing-lg);
    transition: all var(--animation-duration) ease;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-medium);
}

.card-header {
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: var(--spacing-xs) 0 0 0;
    font-weight: 500; /* slightly bolder for better readability */
}

.card-body {
    flex: 1;
}

.card-footer {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Cartes de livre - fond solide pour meilleur contraste texte */
.book-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
    transition: all var(--animation-duration) ease;
    background: var(--background-card);
}

.book-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(var(--primary-color-rgb, 214, 77, 122), 0.05) 100%);
    opacity: 0;
    transition: opacity var(--animation-duration) ease;
}

.book-card:hover::before {
    opacity: 1;
}

.book-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-fun);
}

.book-cover {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--border-radius-small);
    margin-bottom: var(--spacing-md);
}

.book-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.book-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    margin: 0 0 var(--spacing-sm) 0;
    color: var(--text-primary);
    line-height: 1.3;
}

.book-meta {
    display: flex;
    gap: var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
}

.book-description {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: var(--spacing-md);
    flex: 1;
    font-weight: 500; /* slightly bolder for readability */
}

/* Cartes de template - fond solide */
.template-card {
    background: var(--background-card);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-lg);
    cursor: pointer;
    transition: all var(--animation-duration) cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.template-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 107, 157, 0.1), transparent);
    transition: left 0.6s ease;
}

.template-card:hover::before {
    left: 100%;
}

.template-card:hover {
    transform: translateY(-6px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-fun);
}

.template-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
}

.template-icon {
    font-size: var(--font-size-2xl);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--fun-orange) 100%);
    border-radius: 50%;
    color: white;
    animation: float 3s ease-in-out infinite;
}

.template-badge {
    font-size: var(--font-size-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-radius: var(--border-radius-small);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.template-content {
    flex: 1;
}

.template-name {
    font-size: var(--font-size-lg);
    font-weight: 700;
    margin: 0 0 var(--spacing-xs) 0;
    color: var(--text-primary);
}

.template-desc {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin: 0 0 var(--spacing-md) 0;
}

.template-preview {
    font-size: var(--font-size-sm);
    font-style: italic;
    color: var(--text-secondary);
    background: rgba(255, 107, 157, 0.05);
    padding: var(--spacing-md);
    border-radius: var(--border-radius-small);
    border-left: 4px solid var(--primary-color);
    margin-bottom: var(--spacing-md);
}

.template-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.template-style,
.template-duration {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--background-secondary);
    border-radius: var(--border-radius-small);
    font-weight: 500;
}

/* Form controls base */
.form-input,
.form-textarea,
.form-select,
.setting-input,
.setting-textarea,
.setting-select {
    width: 100%;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-small);
    padding: var(--spacing-md);
    background: var(--background-card);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    min-height: 48px;
    transition:
        border-color var(--animation-duration) ease,
        box-shadow var(--animation-duration) ease,
        background-color var(--animation-duration) ease;
}

.form-input:hover,
.form-textarea:hover,
.form-select:hover,
.setting-input:hover,
.setting-textarea:hover,
.setting-select:hover {
    border-color: var(--primary-color);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus,
.setting-input:focus,
.setting-textarea:focus,
.setting-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(var(--primary-color-rgb, 214, 77, 122), 0.15);
    background: var(--background-secondary);
}

.form-input::placeholder,
.form-textarea::placeholder,
.setting-input::placeholder,
.setting-textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* === FORMULAIRES === */

/* Groupe de formulaire */
.form-group,
.setting-group {
    margin-bottom: var(--spacing-lg);
}

.form-label,
.setting-group label {
    display: block;
    font-weight: 600;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.form-help,
.setting-help {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-top: var(--spacing-xs);
    line-height: 1.4;
}

.setting-help a {
    color: var(--primary-color);
    text-decoration: none;
}

.setting-help a:hover {
    text-decoration: underline;
}

/* Inputs - Additional styles */
.form-textarea,
.setting-textarea {
    min-height: 120px;
    resize: vertical;
}

/* Input with icon */
.input-with-icon {
    position: relative;
}

.input-with-icon .form-input {
    padding-left: 44px;
}

.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--font-size-lg);
    color: var(--text-secondary);
    pointer-events: none;
}

/* Checkbox et radio */
.form-checkbox,
.form-radio {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    cursor: pointer;
}

.form-checkbox input,
.form-radio input {
    width: 20px;
    height: 20px;
    accent-color: var(--primary-color);
}

/* === SWITCHERS MODERNES === */

.setting-checkbox {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--background-card);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-md);
    transition: all var(--animation-duration) ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.setting-checkbox:hover {
    border-color: var(--primary-color);
    background: var(--background-secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-light);
}

.setting-checkbox.checked {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, rgba(255, 107, 157, 0.1) 0%, rgba(69, 183, 209, 0.1) 100%);
}

.setting-checkbox::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 107, 157, 0.1), transparent);
    transition: left 0.6s ease;
}

.setting-checkbox:hover::before {
    left: 100%;
}

.setting-checkbox input[type="checkbox"] {
    display: none;
}

.setting-checkbox label {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    cursor: pointer;
    font-weight: 600;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    margin: 0;
    flex: 1;
}

.setting-checkbox label::before {
    content: "";
    font-size: var(--font-size-xl);
    margin-right: var(--spacing-sm);
}

/* Icônes spécifiques pour chaque setting */
.setting-checkbox label[for="auto-save"]::before {
    content: "💾";
}

.setting-checkbox label[for="sound-effects"]::before {
    content: "🔊";
}

.setting-checkbox label[for="night-mode"]::before {
    content: "🌙";
}

/* Switch Toggle */
.switch {
    position: relative;
    width: 60px;
    height: 30px;
    background: var(--background-secondary);
    border-radius: 25px;
    border: 2px solid var(--border-color);
    transition: all var(--animation-duration) ease;
    cursor: pointer;
    flex-shrink: 0;
}

.switch::before {
    content: "";
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: all var(--animation-duration) cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.setting-checkbox input:checked + label + .switch {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--fun-orange) 100%);
    border-color: var(--primary-color);
}

.setting-checkbox input:checked + label + .switch::before {
    transform: translateX(30px);
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.switch:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(255, 107, 157, 0.3);
}

/* Animation pour l'état activé */
.setting-checkbox input:checked + label + .switch {
    animation: switchGlow 2s ease-in-out infinite alternate;
}

@keyframes switchGlow {
    0% {
        box-shadow: 0 0 5px rgba(255, 107, 157, 0.3);
    }
    100% {
        box-shadow: 0 0 15px rgba(255, 107, 157, 0.6);
    }
}

/* États des labels selon l'activation */
.setting-checkbox input:checked + label {
    color: var(--primary-color);
    font-weight: 700;
}

.setting-checkbox input:not(:checked) + label {
    color: var(--text-secondary);
}

/* Animation d'activation */
.setting-checkbox.checked {
    animation: settingActivated 0.5s ease-out;
}

@keyframes settingActivated {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

/* Amélioration responsive pour les switchers */
@media (max-width: 768px) {
    .setting-checkbox {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .setting-checkbox label {
        font-size: var(--font-size-sm);
    }

    .switch {
        width: 50px;
        height: 25px;
    }

    .switch::before {
        width: 19px;
        height: 19px;
    }

    .setting-checkbox input:checked + label + .switch::before {
        transform: translateX(25px);
    }
}

/* API Key Container */
.api-key-container {
    position: relative;
    display: flex;
    align-items: center;
}

.api-key-container .setting-input {
    padding-right: 50px;
}

.btn-icon {
    position: absolute;
    right: 10px;
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--animation-duration) ease;
}

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

/* Setting row layout */
.setting-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

/* Slider container */
.slider-container {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.setting-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--background-secondary);
    outline: none;
    cursor: pointer;
    appearance: none;
}

.setting-slider::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--fun-orange) 100%);
    cursor: pointer;
    box-shadow: var(--shadow-light);
    transition: all var(--animation-duration) ease;
}

.setting-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: var(--shadow-fun);
}

.slider-value {
    min-width: 40px;
    text-align: center;
    font-weight: 600;
    color: var(--primary-color);
    background: var(--background-secondary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--border-radius-small);
}

/* === MODALS === */

/* Overlay de modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transition: all var(--animation-duration) ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Modal */
.modal {
    background: var(--background-card);
    border-radius: var(--border-radius-large);
    box-shadow: var(--shadow-heavy);
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.8);
    transition: all var(--animation-duration) cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.show .modal {
    transform: scale(1);
}

.modal-header {
    padding: var(--spacing-lg) var(--spacing-xl);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, var(--background-secondary) 0%, var(--background-card) 100%);
}

.modal-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--error-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-lg);
    transition: all var(--animation-duration) ease;
}

.modal-close:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 4px;
}

.modal-close:hover {
    background: #e74c3c;
    transform: scale(1.1);
}

.modal-body {
    padding: var(--spacing-xl);
    overflow-y: auto;
    max-height: 70vh;
}

.modal-footer {
    padding: var(--spacing-lg) var(--spacing-xl);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--spacing-md);
    background: var(--background-secondary);
}

/* === BADGES ET ÉTIQUETTES === */

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: var(--border-radius-small);
}

.badge-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--fun-orange) 100%);
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.badge-success {
    background: linear-gradient(135deg, var(--success-color) 0%, #1e8449 100%);
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.badge-warning {
    background: linear-gradient(135deg, var(--warning-color) 0%, #b7791f 100%);
    color: #1a1a2e; /* dark text for yellow badges */
}

.badge-error {
    background: linear-gradient(135deg, var(--error-color) 0%, #922b21 100%);
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

/* === TOOLTIPS === */

.tooltip {
    position: relative;
    cursor: help;
}

.tooltip::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-small);
    font-size: var(--font-size-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--animation-duration) ease;
    z-index: var(--z-tooltip);
}

.tooltip::after {
    content: "";
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    visibility: hidden;
    transition: all var(--animation-duration) ease;
}

.tooltip:hover::before,
.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* === PROGRESS BARS === */

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--background-secondary);
    border-radius: var(--border-radius-small);
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    border-radius: var(--border-radius-small);
    transition: width var(--animation-duration) ease;
    position: relative;
}

.progress-fill::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shine 2s ease-in-out infinite;
}

/* === RESPONSIVE === */

@media (max-width: 768px) {
    .btn {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: var(--font-size-sm);
    }

    .btn-lg {
        padding: var(--spacing-md) var(--spacing-lg);
        font-size: var(--font-size-base);
    }

    .card {
        padding: var(--spacing-md);
    }

    .modal {
        margin: var(--spacing-md);
        max-width: calc(100vw - 2rem);
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--spacing-md);
    }

    .template-card {
        padding: var(--spacing-md);
    }
}

/* === CUSTOM MODEL SELECTOR === */

.custom-model-selector {
    position: relative;
    width: 100%;
    margin-bottom: var(--spacing-md);
}

.model-selector-header {
    background: linear-gradient(135deg, var(--background-card) 0%, var(--background-secondary) 100%);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    cursor: pointer;
    transition: all var(--animation-duration) cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-light);
    position: relative;
    overflow: hidden;
}

.model-selector-header.active {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--fun-orange) 100%);
    color: white;
    box-shadow: var(--shadow-fun);
}

.selected-model {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.selected-model-icon {
    font-size: var(--font-size-lg);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.selected-model-info {
    flex: 1;
}

.selected-model-name {
    font-weight: 600;
    font-size: var(--font-size-base);
    margin-bottom: var(--spacing-xs);
}

.selected-model-details {
    font-size: var(--font-size-sm);
    opacity: 0.8;
}

.model-selector-arrow {
    font-size: var(--font-size-lg);
    transition: transform var(--animation-duration) ease;
}

.model-selector-header.active .model-selector-arrow {
    transform: rotate(180deg);
}

.model-selector-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--background-card);
    border: 2px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    box-shadow: var(--shadow-heavy);
    z-index: var(--z-dropdown);
    max-height: 0;
    overflow: hidden;
    transition: all var(--animation-duration) cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateY(-10px);
}

.model-selector-dropdown.show {
    max-height: 500px;
    opacity: 1;
    transform: translateY(0);
}

.model-search-container {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.model-search {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-small);
    font-size: var(--font-size-sm);
    transition: all var(--animation-duration) ease;
}

.model-search:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 107, 157, 0.1);
}

.model-filter-tabs {
    display: flex;
    background: var(--background-secondary);
}

.model-filter-tab {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    background: transparent;
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-size: var(--font-size-sm);
    transition: all var(--animation-duration) ease;
    color: var(--text-secondary);
}

.model-filter-tab.active {
    color: var(--primary-color);
    background: var(--background-card);
}

.model-list {
    max-height: 300px;
    overflow-y: auto;
    padding: var(--spacing-sm);
}

.model-category {
    margin-bottom: var(--spacing-md);
}

.model-category-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--background-secondary);
    border-radius: var(--border-radius-small);
    margin-bottom: var(--spacing-sm);
}

.model-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border-radius: var(--border-radius-small);
    cursor: pointer;
    transition: all var(--animation-duration) ease;
    border: 1px solid transparent;
    position: relative;
}

.model-item:hover {
    background: var(--background-secondary);
    border-color: var(--primary-color);
    transform: translateX(4px);
}

.model-item.selected {
    background: linear-gradient(135deg, rgba(255, 107, 157, 0.1) 0%, rgba(69, 183, 209, 0.1) 100%);
    border-color: var(--primary-color);
}

.model-item.highlighted {
    background: linear-gradient(135deg, rgba(69, 183, 209, 0.1) 0%, rgba(78, 205, 196, 0.1) 100%);
    border-left: 3px solid var(--accent-color);
}

.model-icon {
    font-size: var(--font-size-lg);
    width: 30px;
    text-align: center;
}

.model-info {
    flex: 1;
}

.model-name {
    font-weight: 600;
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-xs);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.model-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: var(--border-radius-small);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.model-badge.free {
    background: linear-gradient(135deg, var(--success-color) 0%, #1e8449 100%);
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.model-badge.premium {
    background: linear-gradient(135deg, var(--warning-color) 0%, #b7791f 100%);
    color: #1a1a2e; /* dark text for yellow/gold badge */
}

/* Offline / fallback badge */
.badge-offline,
.model-badge.offline {
    background: linear-gradient(135deg, #555 0%, #777 100%);
    color: #fff;
    display: inline-block;
    padding: 2px 6px;
    border-radius: var(--border-radius-small);
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Category container when data source is fallback */
.model-category.offline-source .model-category-header {
    background: repeating-linear-gradient(
        45deg,
        var(--background-secondary),
        var(--background-secondary) 8px,
        rgba(120, 120, 120, 0.15) 8px,
        rgba(120, 120, 120, 0.15) 16px
    );
    position: relative;
}

.model-category.offline-source .model-category-header::after {
    content: "OFFLINE";
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    background: #555;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: auto;
}

.model-description {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

.model-meta {
    display: flex;
    gap: var(--spacing-md);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.model-size,
.model-context {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.model-loading {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-secondary);
}

.model-empty-state {
    text-align: center;
    padding: var(--spacing-lg);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    opacity: 0.85;
}

/* Generic hidden helper (needed for dynamic model filtering) */
.hidden {
    display: none !important;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--spacing-md) auto;
}

.primary-button-large {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 25px;
    padding: 1.2rem 2.5rem;
    font-size: 1.4rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 30px rgba(102, 51, 153, 0.3);
    font-family: "Comic Sans MS", cursive, sans-serif;
}

.primary-button-large:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(102, 51, 153, 0.4);
}

.primary-button-large:active {
    transform: translateY(0);
}
