/* =========================================
   BookSmart AI — Premium Design System
   ========================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---- CSS Custom Properties ---- */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(31, 41, 55, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.04);
    --bg-glass-border: rgba(255, 255, 255, 0.08);
    --bg-input: rgba(15, 23, 42, 0.8);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-accent: #818cf8;

    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
    --accent-gradient-hover: linear-gradient(135deg, #818cf8 0%, #a78bfa 50%, #c4b5fd 100%);

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --info: #3b82f6;

    --border-color: rgba(255, 255, 255, 0.06);
    --border-subtle: rgba(255, 255, 255, 0.03);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--accent-glow);

    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

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

/* ---- Background Gradient ---- */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(59, 130, 246, 0.04) 0%, transparent 50%);
    z-index: 0;
    pointer-events: none;
    animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }

    100% {
        transform: translate(-2%, -2%) rotate(1deg);
    }
}

/* ---- Layout ---- */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px 80px;
}

/* ---- Hero Section ---- */
.hero {
    text-align: center;
    padding: 60px 0 40px;
}

.hero-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 24px;
    background: var(--accent-gradient);
    margin-bottom: 24px;
    font-size: 36px;
    box-shadow: var(--shadow-glow);
    animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: var(--shadow-glow);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 50px var(--accent-glow);
    }
}

.hero h1 {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}

.hero p {
    font-size: 1.15rem;
    color: var(--text-secondary);
    max-width: 520px;
    margin: 0 auto;
    font-weight: 300;
}

.hero-brand {
    font-size: 0.9rem !important;
    color: var(--text-muted) !important;
    margin-top: 8px !important;
    font-weight: 400 !important;
}

.hero-brand a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.hero-brand a:hover {
    color: var(--accent-primary-hover);
    text-decoration: underline;
}

/* ---- Glass Card ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: all var(--transition-base);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.card-header .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    font-size: 18px;
}

.card-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.card-header .badge {
    margin-left: auto;
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-glass);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* ---- Form Elements ---- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-group label .required {
    color: var(--error);
    font-size: 0.7rem;
}

input[type="text"],
textarea,
select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    outline: none;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

select {
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8.5L1 3.5h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

/* ---- Range Slider ---- */
.range-group {
    display: flex;
    align-items: center;
    gap: 14px;
}

.range-group input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    outline: none;
}

.range-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-gradient);
    cursor: pointer;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.range-value {
    min-width: 36px;
    text-align: center;
    font-weight: 600;
    color: var(--accent-primary);
    font-size: 1.1rem;
}

/* ---- Toggle Switch ---- */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.toggle-row .toggle-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toggle-row .toggle-label span:first-child {
    font-weight: 500;
    font-size: 0.95rem;
}

.toggle-row .toggle-label span:last-child {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    transition: all var(--transition-base);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text-muted);
    top: 2px;
    left: 3px;
    transition: all var(--transition-base);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(23px);
    background: white;
}

/* ---- Custom Outline Editor ---- */
.outline-editor {
    display: none;
    margin-top: 20px;
    animation: slideDown 0.4s ease;
}

.outline-editor.visible {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.outline-textarea {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    min-height: 280px;
    line-height: 1.7;
    tab-size: 4;
}

.outline-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.outline-validation {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-top: 10px;
    display: none;
}

.outline-validation.valid {
    display: block;
    background: var(--success-bg);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.outline-validation.invalid {
    display: block;
    background: var(--error-bg);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--error);
}

/* ---- API Key Input ---- */
.api-key-group {
    display: none;
    animation: slideDown 0.3s ease;
}

.api-key-group.visible {
    display: block;
}

input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    outline: none;
}

input[type="password"]:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--accent-gradient-hover);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

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

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

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

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.82rem;
}

.btn-lg {
    padding: 16px 40px;
    font-size: 1.05rem;
    border-radius: var(--radius-md);
}

.generate-section {
    text-align: center;
    margin: 12px 0 32px;
}

/* ---- Progress Section ---- */
.progress-section {
    display: none;
}

.progress-section.visible {
    display: block;
    animation: slideDown 0.5s ease;
}

/* Pipeline Steps */
.pipeline {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 24px;
}

.pipeline-step {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    transition: all var(--transition-base);
}

.pipeline-step.active {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.3);
}

.pipeline-step.completed {
    background: var(--success-bg);
    border-color: rgba(16, 185, 129, 0.2);
}

.pipeline-step.error {
    background: var(--error-bg);
    border-color: rgba(239, 68, 68, 0.2);
}

.step-indicator {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    color: var(--text-muted);
    transition: all var(--transition-base);
}

.pipeline-step.active .step-indicator {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    animation: stepPulse 1.5s ease-in-out infinite;
}

.pipeline-step.completed .step-indicator {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

@keyframes stepPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 var(--accent-glow);
    }

    50% {
        box-shadow: 0 0 0 8px transparent;
    }
}

.step-info {
    flex: 1;
}

.step-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.step-status {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.pipeline-step.active .step-status {
    color: var(--accent-primary-hover);
}

.pipeline-step.completed .step-status {
    color: var(--success);
}

/* Log Panel */
.log-panel {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    max-height: 240px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.8;
}

.log-entry {
    display: flex;
    gap: 10px;
    padding: 2px 0;
    animation: logFadeIn 0.3s ease;
}

@keyframes logFadeIn {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.log-time {
    color: var(--text-muted);
    flex-shrink: 0;
}

.log-phase {
    color: var(--accent-primary);
    font-weight: 500;
    min-width: 90px;
    flex-shrink: 0;
}

.log-message {
    color: var(--text-secondary);
}

/* ---- Download Section ---- */
.download-section {
    display: none;
}

.download-section.visible {
    display: block;
    animation: slideDown 0.5s ease;
}

.download-result {
    text-align: center;
    padding: 20px 0;
}

.download-result .success-icon {
    font-size: 48px;
    margin-bottom: 16px;
    animation: bounceIn 0.6s ease;
}

@keyframes bounceIn {
    0% {
        transform: scale(0);
    }

    60% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.download-result h3 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.download-result .subtitle {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.download-buttons {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: all var(--transition-base);
}

.download-btn.docx {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: white;
}

.download-btn.docx:hover {
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.4);
    transform: translateY(-2px);
}

.download-btn.md {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
}

.download-btn.md:hover {
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
    transform: translateY(-2px);
}

/* Chapters summary */
.chapters-list {
    margin-top: 24px;
    text-align: left;
}

.chapters-list h4 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 500;
}

.chapter-tag {
    display: inline-block;
    padding: 6px 12px;
    margin: 3px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* ---- Error Banner ---- */
.error-banner {
    display: none;
    padding: 16px 20px;
    background: var(--error-bg);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    color: var(--error);
    margin-bottom: 20px;
}

.error-banner.visible {
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideDown 0.3s ease;
}

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ---- Footer ---- */
.footer {
    text-align: center;
    padding: 40px 0 20px;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.footer a {
    color: var(--accent-primary);
    text-decoration: none;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .hero h1 {
        font-size: 2rem;
    }

    .hero p {
        font-size: 1rem;
    }

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

    .card {
        padding: 20px;
    }

    .app-container {
        padding: 0 16px 60px;
    }

    .download-buttons {
        flex-direction: column;
        align-items: center;
    }

    .pipeline-step {
        padding: 10px 14px;
    }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}