/**
 * StoryCraft - Layout
 * Structure, navigation, grilles et conteneurs principaux
 * @version 2.0
 */

/* === STRUCTURE GÉNÉRALE === */

/* Layout principal */
.main-content {
    min-height: calc(100vh - 80px);
    padding-top: var(--spacing-xl);
    padding-bottom: var(--spacing-2xl);
}

/* Vues principales */
.view {
    display: none;
    opacity: 0;
    transform: translateY(20px);
    transition: all var(--animation-duration) ease;
}

.view.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
    animation: fadeIn 0.6s ease-out;
}

.home-view {
    display: block;
}

/* === HEADER ET NAVIGATION === */

/* Header principal */
.header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background: linear-gradient(135deg, var(--background-card) 0%, var(--background-secondary) 100%);
    box-shadow: var(--shadow-light);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

.header::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--background-fun);
    opacity: 0.05;
    pointer-events: none;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-lg) 0;
    position: relative;
    z-index: 1;
}

/* Logo */
.logo {
    font-size: var(--font-size-2xl);
    font-weight: 800;
    color: var(--primary-color);
    text-decoration: none;
    transition: all var(--animation-duration) ease;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo:hover {
    transform: scale(1.05);
    color: var(--fun-orange);
    text-shadow: 0 0 10px rgba(255, 107, 157, 0.3);
}

/* Navigation */
.nav-buttons {
    display: flex;
    gap: var(--spacing-md);
    align-items: center;
}

.nav-buttons .btn.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--fun-orange) 100%);
    color: white;
    box-shadow: var(--shadow-fun);
    transform: translateY(-2px);
}

/* === SECTIONS HÉRO === */

.hero-section {
    text-align: center;
    padding: var(--spacing-2xl) 0 4rem 0;
    position: relative;
    overflow: visible;
    background: linear-gradient(135deg, var(--background-primary) 0%, var(--background-secondary) 100%);
    border-radius: var(--border-radius-large);
    margin-bottom: var(--spacing-2xl);
}

.hero-section::before {
    content: "📚✨🌟💫🎨📖🎭🚀";
    position: absolute;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.8rem;
    opacity: 0.15;
    animation: heroEmojisFloat 6s ease-in-out infinite;
    letter-spacing: 0.8rem;
    white-space: nowrap;
    z-index: 0;
}

.hero-title {
    font-size: var(--font-size-4xl);
    font-weight: 800;
    margin: 0 0 var(--spacing-md) 0;
    background: var(--background-fun);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: rainbow 5s ease infinite;
    position: relative;
    z-index: 2;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.hero-subtitle {
    font-size: var(--font-size-lg);
    color: var(--text-secondary);
    margin: 0;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
    position: relative;
    z-index: 2;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* === GRILLES ET LAYOUTS === */

/* Grille principale */
.grid {
    display: grid;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-2xl);
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* Grille responsive pour templates */
.story-templates {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-2xl);
}

/* Grille pour bibliothèque */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-lg);
    padding: var(--spacing-lg) 0;
}

/* === SECTIONS ET CONTENEURS === */

/* Section de génération */
.generation-form {
    background: var(--background-card);
    border-radius: var(--border-radius-large);
    padding: var(--spacing-2xl);
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.generation-form::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--background-fun);
    opacity: 0.02;
    pointer-events: none;
}

/* Barre de progression de création */
.creation-progress {
    margin-bottom: var(--spacing-2xl);
    position: relative;
}

.progress-steps {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 2;
    margin-bottom: var(--spacing-lg);
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    flex: 1;
    position: relative;
    transition: all var(--animation-duration) ease;
}

.progress-step.active .step-icon {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--fun-orange) 100%);
    color: white;
    animation: pulse 2s ease-in-out infinite;
}

.progress-step.completed .step-icon {
    background: linear-gradient(135deg, var(--success-color) 0%, #2ecc71 100%);
    color: white;
}

.step-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--background-secondary);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xl);
    font-weight: 700;
    border: 3px solid var(--border-color);
    transition: all var(--animation-duration) ease;
    box-shadow: var(--shadow-light);
}

.step-text {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    transition: color var(--animation-duration) ease;
}

.progress-step.active .step-text {
    color: var(--primary-color);
}

.progress-line {
    position: absolute;
    top: 30px;
    left: 10%;
    right: 10%;
    height: 4px;
    background: var(--background-secondary);
    border-radius: 2px;
    z-index: 1;
}

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

.progress-line-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;
}

/* === READER ET LECTEUR === */

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

.book-title-display {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
    background: var(--background-fun);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.reader-body {
    background: var(--background-card);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    overflow: hidden;
}

.page-container {
    padding: var(--spacing-2xl);
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
}

.page-image {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-medium);
}

.page-text {
    font-size: var(--font-size-lg);
    line-height: 1.6;
    color: var(--text-primary);
    max-width: 600px;
    margin: 0 auto;
}

.page-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    background: var(--background-secondary);
    border-top: 1px solid var(--border-color);
}

.page-counter {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: 600;
}

/* === BIBLIOTHÈQUE === */

.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-xl);
    padding: var(--spacing-lg);
    background: var(--background-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-light);
}

.library-title {
    font-size: var(--font-size-3xl);
    font-weight: 800;
    margin: 0;
    color: var(--text-primary);
}

.library-stats {
    display: flex;
    gap: var(--spacing-lg);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

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

.library-search {
    position: relative;
    max-width: 300px;
}

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

.library-search input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(255, 107, 157, 0.1);
}

.library-search::before {
    content: "🔍";
    position: absolute;
    left: var(--spacing-md);
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--font-size-base);
    z-index: 1;
}

.library-empty {
    text-align: center;
    padding: var(--spacing-2xl);
    color: var(--text-secondary);
}

.library-empty-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-lg);
    opacity: 0.5;
}

.library-empty-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.library-empty-text {
    font-size: var(--font-size-base);
    line-height: 1.6;
    margin-bottom: var(--spacing-lg);
}

/* === FOOTER === */

.footer,
.app-footer {
    background: linear-gradient(135deg, #673ab7 0%, #2c3e50 100%);
    color: white;
    margin-top: 4rem;
    padding: 3rem 0 1rem;
    border-top: 3px solid var(--primary-color);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2.5rem;
}

.footer-section {
    text-align: left;
}

.footer-section h4 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 700;
}

.footer-section p {
    margin-bottom: 1rem;
    opacity: 0.9;
    line-height: 1.5;
}

.footer-description {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 1.5rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.85);
}

.footer-badge {
    margin-top: var(--spacing-md);
}

.version-badge {
    background: var(--accent-color);
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* AI Info section */
.ai-info,
.stats-info {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.ai-model,
.ai-status,
.ai-usage,
.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    border-left: 3px solid var(--primary-color);
}

.ai-label,
.stat-label {
    font-weight: 600;
    opacity: 0.9;
}

.ai-value,
.stat-value {
    font-weight: 700;
    color: var(--accent-color);
}

.status-ready {
    color: #4ecdc4 !important;
}

.status-error {
    color: #ff6b6b !important;
}

.status-loading {
    color: var(--warning-color);
}

/* Features list */
.features-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.features-list li {
    padding: 0.4rem 0;
    opacity: 0.9;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.features-list li:last-child {
    border-bottom: none;
}

.footer-bottom {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

.footer-credits {
    text-align: center;
}

.footer-credits p {
    margin: 0.5rem 0;
    opacity: 0.8;
    font-size: 0.9rem;
}

.footer-tech {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.tech-badge {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all var(--animation-duration) ease;
}

.tech-badge:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-light);
}

/* === RESPONSIVE === */

@media (max-width: 1024px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .story-templates {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: var(--spacing-md);
        padding: var(--spacing-md) 0;
    }

    .nav-buttons {
        order: -1;
        width: 100%;
        justify-content: center;
    }

    .hero-section {
        padding: var(--spacing-lg) 0;
    }

    .hero-title {
        font-size: var(--font-size-3xl);
    }

    .hero-subtitle {
        font-size: var(--font-size-base);
    }

    .generation-form {
        padding: var(--spacing-lg);
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .story-templates {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: var(--spacing-md);
    }

    .library-header {
        flex-direction: column;
        gap: var(--spacing-md);
        text-align: center;
    }

    .library-actions {
        width: 100%;
        justify-content: center;
    }

    .library-search {
        max-width: 100%;
    }

    .progress-steps {
        flex-wrap: wrap;
        gap: var(--spacing-md);
    }

    .progress-step {
        min-width: 120px;
    }

    .step-icon {
        width: 50px;
        height: 50px;
        font-size: var(--font-size-lg);
    }

    .progress-line {
        display: none;
    }

    .reader-header {
        flex-direction: column;
        gap: var(--spacing-md);
        text-align: center;
    }

    .page-container {
        padding: var(--spacing-lg);
    }

    .page-navigation {
        flex-direction: column;
        gap: var(--spacing-md);
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding: 0 1rem;
    }

    .footer-section {
        text-align: center;
    }

    .ai-model,
    .ai-status,
    .ai-usage,
    .stat-item {
        flex-direction: column;
        text-align: center;
        gap: 0.3rem;
    }

    .footer-tech {
        gap: 0.3rem;
    }

    .tech-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }

    /* Theme selector mobile */
    .theme-selector {
        order: -1;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding-top: var(--spacing-md);
    }

    /* Navigation hamburger style on very small screens */
    .nav-buttons {
        flex-wrap: wrap;
        gap: var(--spacing-sm);
        justify-content: center;
    }

    .nav-buttons .btn {
        flex: 0 1 auto;
        min-width: 44px;
        min-height: 44px;
        font-size: var(--font-size-xs);
        padding: var(--spacing-sm);
    }

    /* Hide text on very small screens, keep emoji */
    .nav-buttons .btn {
        font-size: 0;
    }

    .nav-buttons .btn::before {
        font-size: var(--font-size-lg);
    }

    #home-nav-btn::before {
        content: "🏠";
        font-size: 1.2rem;
    }
    #library-nav-btn::before {
        content: "📖";
        font-size: 1.2rem;
    }
    #settings-nav-btn::before {
        content: "⚙️";
        font-size: 1.2rem;
    }
    #stellie-settings-btn::before {
        content: "⭐";
        font-size: 1.2rem;
    }

    .hero-section::before {
        font-size: 2rem;
        letter-spacing: 1rem;
    }

    .library-grid {
        grid-template-columns: 1fr;
    }

    .progress-steps {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-sm);
    }

    /* Theme dropdown mobile positioning */
    .theme-dropdown {
        right: auto;
        left: 50%;
        transform: translateX(-50%) translateY(-10px);
    }

    .theme-dropdown.show {
        transform: translateX(-50%) translateY(5px);
    }
}

/* === PAGE HEADER (Secondary Pages) === */

.page-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--background-secondary);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--primary-color);
    padding: 0.75rem 1rem;
}

.page-header .header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    gap: 1rem;
}

.page-header .back-link {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: var(--background-card);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.page-header .back-link:hover {
    background: var(--primary-color);
    color: white;
    transform: translateX(-3px);
}

.page-header .page-title {
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 600;
}

.page-header .header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Adjust main container to account for fixed header */
.bedtime-container,
.image-creator-container,
.journal-container {
    padding-top: 70px;
}

/* === PAGE FOOTER (Secondary Pages) === */

.page-footer {
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    text-align: center;
    padding: 1.5rem 1rem;
    border-top: 2px solid var(--primary-color, #d64d7a);
    margin-top: auto;
}

.page-footer p {
    margin: 0;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
}

.page-footer a {
    color: #6bc17a;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.page-footer a:hover {
    color: #8fd99e;
    text-decoration: underline;
}

/* Mobile adjustments for page header */
@media (max-width: 600px) {
    .page-header .page-title {
        display: none;
    }

    .page-header .back-link {
        font-size: 0.9rem;
        padding: 0.4rem 0.8rem;
    }
}
