/* === Variables === */
:root {
    --bg: #ffffff;
    --bg2: #f8f9fa;
    --fg: #1a1a2e;
    --fg2: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #eff6ff;
    --success: #059669;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --max-width: 1200px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --bg2: #1e293b;
        --fg: #e2e8f0;
        --fg2: #94a3b8;
        --border: #334155;
        --accent: #60a5fa;
        --accent-hover: #93bbfd;
        --accent-light: #1e3a5f;
        --shadow: 0 1px 3px rgba(0,0,0,0.3);
    }
}

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

/* === Base === */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container { max-width: var(--max-width); margin: 0 auto; padding: 0 1.5rem; width: 100%; }

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

/* === Header === */
.header {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; }
.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--fg);
    text-decoration: none;
}
.logo:hover { color: var(--accent); }
.nav-link { margin-left: 1.5rem; color: var(--fg2); font-weight: 500; }
.nav-link:hover { color: var(--accent); }

/* === Main === */
.main { padding: 2rem 0; flex: 1; }

/* === Footer === */
.footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    text-align: center;
    color: var(--fg2);
    font-size: 0.85rem;
    margin-top: auto;
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.6rem 1.4rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: var(--success); color: #fff; }
.btn-secondary:hover { opacity: 0.9; color: #fff; }

/* === Catalog header === */
.catalog-header {
    margin-bottom: 1.5rem;
}
.catalog-header h1 { font-size: 1.8rem; margin-bottom: 0.25rem; }
.catalog-subtitle { color: var(--fg2); }

/* === Search === */
.search-box {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--fg);
    margin-bottom: 1rem;
    transition: border-color 0.15s;
}
.search-box:focus { outline: none; border-color: var(--accent); }

/* === Filters === */
.filters { margin-bottom: 1rem; }

/* Алфавит */
.alphabet {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    margin-bottom: 0.75rem;
}
.letter-btn {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--fg2);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.letter-btn:hover, .letter-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.category-filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.category-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--fg);
    font-size: 0.9rem;
    min-width: 250px;
    flex: 1;
    max-width: 400px;
}
.category-select:focus { outline: none; border-color: var(--accent); }

.results-count {
    color: var(--fg2);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

/* === Books table === */
.books-table { width: 100%; border-collapse: collapse; }
.books-table th, .books-table td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.books-table th {
    background: var(--bg2);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--fg2);
    position: sticky;
    top: 60px;
}
.books-table tbody tr { transition: background 0.1s; }
.books-table tbody tr:hover { background: var(--accent-light); }
.title-cell a { color: var(--fg); font-weight: 500; }
.title-cell a:hover { color: var(--accent); }
.category-cell { color: var(--fg2); font-size: 0.9rem; }
.size-cell { color: var(--fg2); font-size: 0.9rem; white-space: nowrap; }

/* === Book page === */
/* === Breadcrumb === */
.breadcrumb {
    font-size: 0.9rem;
    color: var(--fg2);
    margin-bottom: 1rem;
}

/* === Floating back button === */
.floating-back {
    position: fixed;
    left: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent);
    color: #fff;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 1.2rem;
    box-shadow: var(--shadow);
    transition: opacity 0.15s;
    z-index: 50;
}
.floating-back:hover { opacity: 0.85; color: #fff; }

.book-header { margin-bottom: 2rem; }
.book-header h1 { font-size: 1.6rem; margin-bottom: 1rem; line-height: 1.3; }
.book-meta { display: flex; flex-wrap: wrap; gap: 1rem; color: var(--fg2); margin-bottom: 1.25rem; }
.meta-item { font-size: 0.9rem; }
.book-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* === PDF viewer === */
.reader-section { margin-top: 2rem; }
.reader-section h2 { margin-bottom: 1rem; }
.pdf-viewer-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.pdf-viewer {
    width: 100%;
    height: 80vh;
    border: none;
}

/* === Back to top === */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--accent);
    color: #fff;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 1.2rem;
    box-shadow: var(--shadow);
    transition: opacity 0.15s;
    z-index: 50;
}
.back-to-top.visible { display: flex; }
.back-to-top:hover { opacity: 0.85; color: #fff; }

/* === Responsive === */
@media (max-width: 768px) {
    .hero h1 { font-size: 1.6rem; }
    .header-inner { flex-direction: column; gap: 0.5rem; }
    .nav-link { margin-left: 0; margin-right: 1rem; }
    .books-table thead { display: none; }
    .books-table tr {
        display: block;
        padding: 0.75rem 0;
        border-bottom: 1px solid var(--border);
    }
    .books-table td { display: block; padding: 0.15rem 0; border: none; }
    .title-cell { font-size: 1rem; margin-bottom: 0.25rem; }
    .category-cell::before { content: "📁 "; }
    .size-cell::before { content: "💾 "; }
    .category-select { min-width: 100%; }
    .book-meta { flex-direction: column; gap: 0.4rem; }
}
