/* ===================================================
   Plex-Inspired Dark Theme for Ebook Library
   =================================================== */

/* CSS Custom Properties */
:root {
    --bg-primary: #1f2326;
    --bg-secondary: #282c34;
    --bg-tertiary: #313640;
    --bg-hover: #3a3f4b;
    --bg-input: #3a3f4b;
    --text-primary: #eaeaea;
    --text-secondary: #a2a2a2;
    --text-muted: #7a7a7a;
    --accent: #e5a00d;
    --accent-hover: #cc8c00;
    --accent-subtle: rgba(229, 160, 13, 0.1);
    --border: #3a3f4b;
    --border-light: #444a55;
    --shadow: rgba(0, 0, 0, 0.4);
    --shadow-lg: rgba(0, 0, 0, 0.6);
    --radius: 6px;
    --radius-lg: 10px;
    --success: #4caf50;
    --success-bg: rgba(76, 175, 80, 0.12);
    --error: #ef5350;
    --error-bg: rgba(239, 83, 80, 0.12);
    --info: #42a5f5;
    --info-bg: rgba(66, 165, 245, 0.12);
}

/* Base styles */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--accent);
}

/* Navigation */
.navbar {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px var(--shadow);
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: -0.02em;
}

.navbar-brand:hover {
    color: var(--accent-hover);
}

.navbar-search {
    flex: 1;
    max-width: 420px;
}

.navbar-search input {
    width: 100%;
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.875rem;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.navbar-search input::placeholder {
    color: var(--text-muted);
}

.navbar-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

/* Navbar logout */
.navbar-logout {
    margin: 0;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    padding: 0.4rem 0.9rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

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

/* Container */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

/* Ebook grid layout */
.ebook-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
}

/* Grid item */
.ebook-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: var(--radius);
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.ebook-card:hover {
    background: var(--bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

/* Thumbnail styling */
.ebook-card img,
.ebook-thumbnail {
    width: 140px;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
    transition: box-shadow 0.2s ease;
}

.ebook-card:hover img,
.ebook-card:hover .ebook-thumbnail {
    box-shadow: 0 4px 16px var(--shadow-lg);
}

/* Lazy loading image styles */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded,
img[loading="lazy"][src] {
    opacity: 1;
}

/* Ebook title below thumbnail */
.ebook-card-title {
    margin-top: 0.6rem;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.3;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    color: var(--text-secondary);
}

.ebook-card:hover .ebook-card-title {
    color: var(--text-primary);
}

/* Meta text below card title (e.g. ebook count for folders) */
.ebook-card-meta {
    margin-top: 0.2rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* Folder sections */
.folder-section {
    margin-bottom: 2.5rem;
}

.folder-section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.folder-section-header h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
}

.folder-section-header h2 a {
    color: var(--text-primary);
    text-decoration: none;
}

.folder-section-header h2 a:hover {
    color: var(--accent);
}

.folder-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* Breadcrumb navigation */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 0;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    list-style: none;
}

.breadcrumb a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s ease;
}

.breadcrumb a:hover {
    color: var(--accent);
}

.breadcrumb-separator {
    color: var(--text-muted);
    margin: 0 0.25rem;
}

.breadcrumb-current {
    color: var(--text-primary);
    font-weight: 500;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 5rem 2rem;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 1.1rem;
    margin: 0;
}

/* Detail page */
.detail-page {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2.5rem;
    margin-top: 1rem;
}

.detail-cover-image {
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px var(--shadow-lg);
    width: 280px;
    height: auto;
}

.detail-info {
    min-width: 0;
}

.detail-title {
    margin: 0 0 0.5rem 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.detail-author {
    margin: 0 0 1.5rem 0;
    font-size: 1rem;
    color: var(--text-secondary);
}

.detail-synopsis {
    margin-bottom: 1.5rem;
}

.detail-synopsis h2,
.detail-metadata h2 {
    margin: 0 0 0.75rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.detail-synopsis p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.7;
}

.detail-metadata {
    margin-bottom: 1.5rem;
}

.detail-metadata dl {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1.5rem;
}

.detail-metadata dt {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

.detail-metadata dd {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Buttons */
.detail-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.1s ease;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #1a1a1a;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: #1a1a1a;
}

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

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

/* Error page */
.error-page {
    text-align: center;
    padding: 5rem 2rem;
}

.error-code {
    font-size: 4rem;
    font-weight: 800;
    color: var(--accent);
    margin: 0 0 0.5rem 0;
}

.error-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.75rem 0;
}

.error-message {
    color: var(--text-secondary);
    margin: 0 0 2rem 0;
    font-size: 1rem;
}

.error-home-link {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    background: var(--accent);
    color: #1a1a1a;
    border-radius: var(--radius);
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s ease;
}

.error-home-link:hover {
    background: var(--accent-hover);
    color: #1a1a1a;
}

/* Search results overlay */
.search-results-overlay {
    min-height: 200px;
}

.search-no-results {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
    font-size: 1.1rem;
}

.search-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
}

.search-result-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: var(--radius);
    transition: background 0.2s ease, transform 0.2s ease;
}

.search-result-card:hover {
    background: var(--bg-hover);
    transform: translateY(-2px);
}

.search-result-thumbnail {
    width: 140px;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
}

.search-result-title {
    margin-top: 0.6rem;
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.3;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    color: var(--text-secondary);
}

.search-result-meta {
    margin-top: 0.25rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
        padding: 0.75rem 1rem;
    }

    .navbar-search {
        max-width: 100%;
        order: 3;
        width: 100%;
    }

    .container {
        padding: 1rem;
    }

    .ebook-grid,
    .search-results-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 14px;
    }

    .detail-page {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .detail-cover {
        display: flex;
        justify-content: center;
    }

    .detail-cover-image {
        width: 200px;
    }

    .detail-actions {
        justify-content: center;
    }

    .detail-metadata dl {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .ebook-grid,
    .search-results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .ebook-card img,
    .ebook-thumbnail,
    .search-result-thumbnail {
        width: 120px;
        height: 170px;
    }
}
