/* ============================================================
   MyAdventureBook — Design System & Component Styles
   ============================================================ */

/* === CSS Variables === */
:root {
    --color-charcoal: #2C3E50;
    --color-cream: #F5F1E8;
    --color-sage: #7A9B8E;
    --color-rust: #C4794E;
    --color-white: #FFFFFF;
    --color-error: #E74C3C;
    --color-success: #27AE60;
    --color-warning: #F39C12;

    --text-primary: var(--color-charcoal);
    --text-secondary: #666;
    --text-muted: #999;
    --bg-primary: var(--color-cream);
    --bg-secondary: var(--color-white);
    --border-color: #E8E4DD;
    --accent-primary: var(--color-rust);
    --accent-secondary: var(--color-sage);

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.16);

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

/* === Reset === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* === Typography === */
h1, h2, h3 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    line-height: 1.2;
}

.literary-text {
    font-family: 'Crimson Text', serif;
}

/* === Auth Screen === */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-charcoal) 0%, #34495E 50%, var(--color-sage) 100%);
    padding: 24px;
}

.auth-container {
    width: 100%;
    max-width: 440px;
}

.auth-brand {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    font-family: 'Cormorant Garamond', serif;
    font-size: 42px;
    font-weight: 700;
    color: var(--color-cream);
    margin-bottom: 8px;
}

.auth-tagline {
    color: rgba(245, 241, 232, 0.7);
    font-size: 16px;
}

.auth-card {
    background: var(--color-white);
    border-radius: var(--radius-xl);
    padding: 32px;
    box-shadow: var(--shadow-lg);
}

.auth-tabs {
    display: flex;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.auth-tab:hover { color: var(--text-primary); }

.auth-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

/* === Forms === */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--color-white);
    transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(196, 121, 78, 0.15);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-error {
    color: var(--color-error);
    font-size: 13px;
    margin-top: 12px;
    min-height: 20px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    text-decoration: none;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--color-white);
}

.btn-primary:hover:not(:disabled) {
    background: #B66A3A;
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
}

.btn-ghost {
    background: transparent;
    color: var(--text-primary);
}

.btn-ghost:hover { background: var(--bg-primary); }

.btn-danger {
    background: var(--color-error);
    color: white;
}

.btn-danger:hover:not(:disabled) { background: #C0392B; }

.btn-full { width: 100%; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    border-radius: var(--radius-sm);
}

.btn-icon:hover { color: var(--accent-primary); background: var(--bg-primary); }

/* === Layout === */
.main-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 24px 16px;
    transition: var(--transition);
    position: fixed;
    height: 100vh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed { width: 80px; padding: 24px 8px; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    font-family: 'Cormorant Garamond', serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-primary);
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-logo { display: none; }

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
    border-radius: var(--radius-sm);
}

.sidebar-toggle:hover { color: var(--accent-primary); }

.nav-section { margin-bottom: 32px; }

.nav-section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.sidebar.collapsed .nav-section-title { display: none; }

.nav-list { list-style: none; }
.nav-item { margin-bottom: 4px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text-primary);
    transition: var(--transition);
    font-size: 14px;
}

.nav-link:hover { background: var(--bg-primary); color: var(--accent-primary); }

.nav-link.active {
    background: var(--accent-primary);
    color: var(--color-white);
    font-weight: 500;
}

.nav-icon { min-width: 20px; display: flex; align-items: center; justify-content: center; }
.nav-label { white-space: nowrap; }
.sidebar.collapsed .nav-label { display: none; }

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

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-secondary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-details { overflow: hidden; }

.user-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar.collapsed .user-details { display: none; }

.content {
    flex: 1;
    margin-left: 280px;
    transition: var(--transition);
}

.content.full-width { margin-left: 80px; }

.main-content {
    padding: 32px;
    min-height: 100vh;
}

/* === Page Header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 32px;
}

.page-header-actions {
    display: flex;
    gap: 12px;
}

/* === Cards === */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

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

.card-body { padding: 24px; }
.card-footer { padding: 16px 24px; border-top: 1px solid var(--border-color); }

/* === Stat Cards === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: 'Cormorant Garamond', serif;
    font-size: 36px;
    font-weight: 700;
    color: var(--accent-primary);
}

/* === Trip Grid === */
.trip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.trip-card {
    cursor: pointer;
}

.trip-card-cover {
    height: 180px;
    background: linear-gradient(135deg, var(--color-sage), var(--color-charcoal));
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.5);
    font-size: 48px;
    position: relative;
    overflow: hidden;
}

.trip-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.trip-card-body {
    padding: 20px;
}

.trip-card-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 6px;
}

.trip-card-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.trip-card-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.trip-card-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* === Status Badge === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-draft { background: #EBF5FB; color: #2980B9; }
.badge-active { background: #EAFAF1; color: #27AE60; }
.badge-completed { background: #FEF9E7; color: #F39C12; }
.badge-compiled { background: #F4ECF7; color: #8E44AD; }
.badge-generating { background: #FDF2E9; color: var(--accent-primary); }

/* === Photo Gallery === */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.photo-card {
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 1;
    position: relative;
    cursor: pointer;
}

.photo-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition);
}

.photo-card:hover img { transform: scale(1.05); }

.photo-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: white;
    font-size: 12px;
    opacity: 0;
    transition: var(--transition);
}

.photo-card:hover .photo-card-overlay { opacity: 1; }

/* === Upload Area === */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-secondary);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent-primary);
    background: rgba(196, 121, 78, 0.05);
}

.upload-area-icon {
    font-size: 48px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.upload-area-text {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.upload-area-hint {
    font-size: 13px;
    color: var(--text-muted);
}

.upload-progress {
    margin-top: 16px;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* === Ghost Writer Style Picker === */
.style-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.style-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    transition: var(--transition);
}

.style-card:hover {
    border-color: var(--accent-secondary);
    box-shadow: var(--shadow-md);
}

.style-card.selected {
    border-color: var(--accent-primary);
    background: rgba(196, 121, 78, 0.05);
}

.style-card-name {
    font-family: 'Cormorant Garamond', serif;
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
}

.style-card-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.style-card-sample {
    font-family: 'Crimson Text', serif;
    font-size: 14px;
    font-style: italic;
    color: var(--text-muted);
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-secondary);
}

/* === Book Viewer === */
.book-viewer {
    max-width: 1000px;
    margin: 0 auto;
}

.book-container {
    background: #1a1a1a;
    border-radius: 4px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    aspect-ratio: 16 / 10;
    position: relative;
}

.book-spread {
    display: flex;
    width: 100%;
    height: 100%;
}

.book-page {
    flex: 1;
    background: var(--color-cream);
    padding: 48px 40px;
    overflow-y: auto;
    position: relative;
}

.book-page:first-child {
    border-right: 1px solid rgba(0,0,0,0.05);
}

.book-page-content {
    font-family: 'Crimson Text', serif;
    font-size: 16px;
    line-height: 1.8;
    color: var(--color-charcoal);
}

.book-page-content h2 {
    font-family: 'Cormorant Garamond', serif;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--color-charcoal);
}

.book-page-content p {
    margin-bottom: 16px;
    text-indent: 2em;
}

.book-page-content p:first-of-type {
    text-indent: 0;
}

.book-page-number {
    position: absolute;
    bottom: 20px;
    font-size: 12px;
    color: var(--text-muted);
}

.book-page:first-child .book-page-number { left: 40px; }
.book-page:last-child .book-page-number { right: 40px; }

.book-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-top: 24px;
}

.book-nav-info {
    font-size: 14px;
    color: var(--text-secondary);
}

/* === Generation Progress === */
.generation-status {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 48px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.generation-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 24px;
}

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

.generation-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 12px;
}

.generation-message {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 24px;
}

/* === Settings === */
.settings-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 32px;
    margin-bottom: 24px;
}

.settings-section h2 {
    font-size: 24px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.settings-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.settings-row .form-group { flex: 1; }

/* === Toast Notifications === */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 300px;
    max-width: 450px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid var(--accent-secondary);
}

.toast.toast-error { border-left-color: var(--color-error); }
.toast.toast-success { border-left-color: var(--color-success); }
.toast.toast-warning { border-left-color: var(--color-warning); }

.toast-message {
    flex: 1;
    font-size: 14px;
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    font-size: 18px;
    line-height: 1;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 0;
}

.modal-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 24px;
    font-weight: 600;
}

.modal-body { padding: 24px; }

.modal-footer {
    padding: 0 24px 24px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 64px 24px;
}

.empty-state-icon {
    font-size: 64px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.empty-state-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state-text {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 24px;
}

/* === Loading === */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 64px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* === Section Transitions === */
.view-enter {
    animation: fadeSlideIn 0.3s ease;
}

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

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        width: 0;
        padding: 0;
        overflow: hidden;
    }

    .sidebar.mobile-open {
        width: 280px;
        padding: 24px 16px;
    }

    .content {
        margin-left: 0 !important;
    }

    .main-content {
        padding: 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .page-header h1 {
        font-size: 24px;
    }

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

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

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

    .book-spread {
        flex-direction: column;
    }

    .book-container {
        aspect-ratio: auto;
    }

    .settings-row {
        flex-direction: column;
    }

    .auth-container {
        max-width: 100%;
    }
}

/* === Utility === */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
