/* LatentBooks Styles - v1.1 */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #d97706;
    --secondary: #9333ea;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-padding-top: 100px;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

@media (min-width: 768px) {
    .container {
        padding: 0 2rem;
    }
}

nav {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

@media (max-width: 640px) {
    .nav-links {
        gap: 1rem;
        font-size: 0.9rem;
    }
}

.logo {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}

/* .nav-links moved and updated with media query above */

.nav-links a {
    color: var(--text);
    text-decoration: none;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--primary);
}

.settings-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.settings-link:hover {
    background-color: #f1f5f9;
}

.settings-icon {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-outline:hover {
    background-color: #f1f5f9;
    border-color: var(--text-muted);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05);
}

.btn-link {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    font-size: 1rem;
    font-family: inherit;
}

.btn-link:hover {
    color: var(--primary);
}

main {
    padding: 8rem 0 4rem 0;
    min-height: calc(100vh - 160px);
}

.hero {
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.hero h1 {
    font-size: 2.25rem;
    margin-bottom: 1rem;
    background: linear-gradient(to right, #4f46e5, #9333ea);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

@media (min-width: 768px) {
    .hero h1 {
        font-size: 3.5rem;
        margin-bottom: 1.5rem;
    }
}

.hero p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

@media (min-width: 768px) {
    .hero p {
        font-size: 1.25rem;
        margin-bottom: 3rem;
    }
}

/* Search Section */
.search-section {
    margin: 2rem 0;
    display: flex;
    justify-content: center;
}

.search-form {
    width: 100%;
    max-width: 600px;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

@media (min-width: 640px) {
    .search-form {
        flex-wrap: nowrap;
    }
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 1rem;
    background: var(--card-bg);
    color: var(--text);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-btn {
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: auto;
}

.clear-btn {
    padding: 0.8rem 1.2rem;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

@media (max-width: 639px) {
    .clear-btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }
}

/* Toggle Buttons */
.toggle-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.toggle-buttons {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    max-width: 400px;
}

.toggle-btn {
    flex: 1;
    padding: 0.6rem 1rem;
    border: none;
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    white-space: nowrap;
}

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

.toggle-label-short {
    display: none;
}

.toggle-label-full {
    display: inline;
}

@media (min-width: 480px) {
    .toggle-buttons {
        width: auto;
    }
    
    .toggle-btn {
        padding: 0.6rem 1.5rem;
        font-size: 1rem;
    }
}

/* Topic Form */
.topic-form {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.05);
    margin: 0;
}

@media (min-width: 640px) {
    .topic-form {
        flex-direction: row;
        padding: 1.5rem;
        gap: 1rem;
    }
}

@media (min-width: 768px) {
    .topic-form {
        padding: 2rem;
    }
}

.topic-input {
    flex: 1;
    background: #ffffff;
    border: 1px solid var(--border);
    padding: 0.8rem;
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 1rem;
    width: 100%;
    min-width: 0;
}

@media (min-width: 640px) {
    .topic-input {
        padding: 1rem;
        font-size: 1.1rem;
    }
}

.topic-input:focus {
    outline: none;
    border-color: var(--primary);
}

.generate-submit-btn {
    padding: 0.8rem 1.5rem;
    width: 100%;
    font-size: 1rem;
}

@media (min-width: 640px) {
    .generate-submit-btn {
        width: auto;
        min-width: 180px;
    }
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05);
}

.book-card {
    height: 380px;
    /* Increased slightly to handle longer titles better */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

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

.title-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 0;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-align: center;
    word-break: break-word;
}

.card-topic {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.card-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: stretch;
    flex-wrap: wrap;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-pending {
    background: #f1f5f9;
    color: #64748b;
}

.status-in_progress {
    background: #eff6ff;
    color: #3b82f6;
    animation: pulse 2s infinite;
}

.status-generating {
    background: #fff7ed;
    color: #ea580c;
    animation: pulse 2s infinite;
}

.status-ready {
    background: #f0fdf4;
    color: #16a34a;
}

.status-error {
    background: #fef2f2;
    color: #dc2626;
}

.messages {
    margin-bottom: 2rem;
}

.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.alert-success {
    background: #f0fdf4;
    border: 1px solid #bbfcce;
    color: #16a34a;
}

.alert-error,
.alert-danger {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
}

.alert-info {
    background: #eff6ff;
    border: 1px solid #dbeafe;
    color: #3b82f6;
}

/* Tabs System */
.tabs-container {
    margin-bottom: 2rem;
}

.tabs-header {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
    .tabs-header {
        gap: 1rem;
    }
}

.tab-btn {
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

@media (min-width: 640px) {
    .tab-btn {
        padding: 1rem 1.5rem;
        font-size: 1.1rem;
    }
}

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

.tab-btn.active {
    color: var(--primary);
}

.tab-btn.active::after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--primary);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

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

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

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}

footer {
    padding: 2rem 0;
    text-align: center;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
}

/* Reader specific theme adjustments */
.toc-pane {
    background: #ffffff !important;
}

.content-pane {
    background: #ffffff !important;
}

#toc-list li:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.markdown-body {
    box-sizing: border-box;
    min-width: 200px;
    max-width: 980px;
    margin: 0 auto;
    padding: 10px;
}

@media (max-width: 767px) {
    .markdown-body {
        padding: 15px;
    }
}

/* Mermaid Diagram Container */
.language-mermaid {
    background: transparent !important;
    border: none !important;
    display: flex;
    justify-content: center;
    margin: 2rem 0;
}

.language-mermaid svg {
    max-width: 100%;
    height: auto;
}

/* Math Rendering Adjustments */
.markdown-body section {
    overflow-x: auto;
    overflow-y: hidden;
    margin: 1.5rem 0;
    padding: 0.5rem 0;
}

.texmath-inline {
    display: inline;
}

/* Book Grid Utility */
.book-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 640px) {
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 2rem;
    }
}

/* Responsive Utilities */
.mobile-only {
    display: block;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none;
    }
}

.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .desktop-only {
        display: block;
    }
}

/* Hide raw mermaid code before rendering */
.language-mermaid:not([data-processed="true"]) {
    display: none;
}