/* ============ Глобальні стилі ============ */
html { height: 100%; margin: 0; }

body {
    min-height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    color: #e0e0e0;
}

:root {
    --bs-warning: #4C7AAA;
    --bs-warning-rgb: 76, 122, 170;
    /* Cards width controls (change these values) */
    --library-card-width: 220px;
    --dovidnyk-card-width: 220px;
    --catalog-card-image-height: 250px;
}

main {
    flex: 1 0 auto;
}

header {
    position: sticky;
    top: 0;
    z-index: 1030;
}

header .navbar {
    position: sticky !important;
    top: 0;
    z-index: 1031;
}

/* ============ Header ============ */
.header-logo {
    height: 50px;
    max-width: 100%;
    object-fit: contain;
}

.header-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 1px;
}

/* ============ Навігація ============ */
.navbar .nav-link {
    font-weight: 500;
    transition: color .2s;
    color: #fff !important;
}
.navbar .nav-link:hover,
.navbar .nav-link:focus {
    color: #4C7AAA !important;
}

.navbar .dropdown-menu {
    background-color: #2b2b2b;
    border: 1px solid #444;
    min-width: 10rem;
}
.navbar .dropdown-item {
    color: #e0e0e0;
}
.navbar .dropdown-item:hover,
.navbar .dropdown-item:focus {
    background-color: #4C7AAA;
    color: #fff;
}
.navbar .dropdown-divider {
    border-color: #444;
}

/* Аватар у навбарі */
.nav-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #4C7AAA;
}
.nav-avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: #555;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    border: 2px solid #4C7AAA;
}

/* ============ Footer ============ */
footer {
    flex-shrink: 0;
}
.telegram-link img {
    width: 24px;
    height: 24px;
    transition: opacity .2s;

}
.telegram-link img:hover { opacity: .7; }
.telegram-link a { margin-left: 10px; }

/* ============ Пошук autocomplete ============ */
#search-suggestions {
    z-index: 1050;
    max-height: 300px;
    overflow-y: auto;
}

/* ============ Пагінатор ============ */
.pagination .page-link {
    background-color: #2b2b2b;
    border-color: #444;
    color: #e0e0e0;
}
.pagination .page-link:hover {
    background-color: #4C7AAA;
    border-color: #4C7AAA;
    color: #fff;
}
.pagination .page-item.active .page-link {
    background-color: #4C7AAA;
    border-color: #4C7AAA;
    color: #fff;
}
.pagination .page-item.disabled .page-link {
    background-color: #2b2b2b;
    border-color: #444;
    color: #777;
}

/* ============ Детальний опис ============ */
.detailed-description {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 0.5rem;
    color: #212529 !important;
    text-align: justify;
    text-justify: inter-word;
}
.detailed-description p,
.detailed-description li,
.detailed-description span,
.detailed-description div,
.detailed-description h1, .detailed-description h2,
.detailed-description h3, .detailed-description h4,
.detailed-description h5, .detailed-description h6 {
    color: #212529 !important;
    text-align: justify;
    text-justify: inter-word;
}
.detailed-description table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    background-color: #fff;
    color: #212529;
    border: 1px solid #dee2e6;
}
.detailed-description table th,
.detailed-description table td {
    border: 1px solid #dee2e6;
    padding: 0.75rem;
    text-align: left;
    color: #212529 !important;
}
.detailed-description table th {
    background-color: #f8f9fa;
    font-weight: bold;
}
.detailed-description table tr:nth-child(even) { background-color: #f8f9fa; }
.detailed-description img,
.detailed-description video {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1rem 0;
}

/* ============ Реєстрація / Вхід ============ */
.auth-form {
    background-color: #2b2b2b !important;
    color: #fff !important;
    border-color: #444 !important;
}
.auth-form .form-label,
.auth-form .form-control::placeholder,
.auth-form small,
.auth-form .form-text,
.auth-form h2,
.auth-form label {
    color: #fff !important;
}
.auth-form .text-danger {
    color: #dc3545 !important;
}
.auth-form .form-control {
    background-color: #333;
    border-color: #555;
    color: #fff;
}
.auth-form .form-control:focus {
    background-color: #333;
    color: #fff;
    border-color: #4C7AAA;
    box-shadow: 0 0 0 .15rem rgba(255,102,0,.25);
}
.auth-form a.text-warning { color: #4C7AAA !important; }

.text-warning {
    color: #4C7AAA !important;
}

.bg-warning {
    background-color: #4C7AAA !important;
}

.border-warning {
    border-color: #4C7AAA !important;
}

.btn-warning {
    background-color: #4C7AAA !important;
    border-color: #4C7AAA !important;
    color: #fff !important;
}
.btn-warning:hover,
.btn-warning:focus,
.btn-warning:active {
    background-color: #3f6891 !important;
    border-color: #3f6891 !important;
    color: #fff !important;
}

.alert-warning {
    background-color: rgba(76, 122, 170, 0.15) !important;
    border-color: #4C7AAA !important;
    color: #d6e4f2 !important;
}

/* ============ Темний фон для сторінок з фільтром ============ */
.library-page,
.dovidnyk-items-page,
.dovidnyk-item-detail-page,
.book-detail-page {
    background-color: #212529;
    color: #fff;
    padding: 1.5rem;
    border-radius: 0.5rem;
}
.library-page .text-muted,
.dovidnyk-items-page .text-muted,
.dovidnyk-item-detail-page .text-muted,
.book-detail-page .text-muted {
    color: #fff !important;
}

/* ============ Утиліти ============ */
.auth-page-wrap {
    min-height: 60vh;
    display: flex;
    justify-content: center;
    align-items: center;
}
.auth-form-box { max-width: 500px; width: 100%; }
.content-narrow { max-width: 900px; }
.card-img-cover { height: 200px; object-fit: cover; }
.card-img-cover-sm { height: 180px; object-fit: cover; }
.avatar-size { width: 150px; height: 150px; object-fit: cover; }
.avatar-placeholder { width: 150px; height: 150px; }
.home-hero {
    background-color: #1f2933;
    background-image:
        linear-gradient(140deg, rgba(76,122,170,0.35) 0%, rgba(31,41,51,0.85) 55%, rgba(20,27,34,0.95) 100%),
        url("../img/favicon.ico");
    background-size: cover, min(320px, 45vw) auto;
    background-position: center, right 180px center;
    background-repeat: no-repeat, no-repeat;
    background-attachment: fixed;
    color: #fff;
    border: 1px solid #444;
    border-radius: 0.75rem;
    padding: 1.75rem;
}
.home-hero-content {
    max-width: 780px;
}
.home-hero-content > * {
    opacity: 0;
    transform: translateY(10px);
    animation: heroFadeIn 0.55s ease-out forwards;
}
.home-hero-content > *:nth-child(2) { animation-delay: 0.08s; }
.home-hero-content > *:nth-child(3) { animation-delay: 0.16s; }

@keyframes heroFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.kpi-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #3c3c3c;
    border-radius: 0.6rem;
    padding: 0.8rem;
}
.kpi-value {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.2;
    color: #4C7AAA;
}

/* Помаранчевий акцент для кнопок */
.text-orange { color: #ffffff !important; }
.btn-outline-warning {
    color: #4C7AAA;
    border-color: #4C7AAA;
}
.btn-outline-warning:hover {
    background-color: #4C7AAA;
    border-color: #4C7AAA;
    color: #fff;
}
.btn-outline-warning.active,
.btn-outline-warning:active {
    background-color: #4C7AAA !important;
    border-color: #4C7AAA !important;
    color: #fff !important;
}

.payment-system-error {
    color: #dc3545 !important;
    border-color: #dc3545 !important;
}

.subscription-manage-btn {
    background-color: #2b2b2b;
    border-color: #2b2b2b;
    color: #fff;
}
.subscription-manage-btn:hover,
.subscription-manage-btn:focus,
.subscription-manage-btn:active {
    background-color: #3a3a3a !important;
    border-color: #3a3a3a !important;
    color: #fff !important;
}

/* ============ Банери ============ */
.banner-slot {
    overflow: hidden;
    border-radius: 0.5rem;
}
.banner-img {
    max-height: 120px;
    width: 100%;
    object-fit: contain;
    border-radius: 0.5rem;
    transition: opacity 0.2s;
}
.banner-img:hover {
    opacity: 0.85;
}
.banner-link {
    display: block;
}

/* ============ Кастомні фільтр-дропдауни ============ */
.filter-dropdown .btn {
    background-color: #2b2b2b;
    border-color: #555;
}
.filter-dropdown .btn:hover,
.filter-dropdown .btn:focus {
    border-color: #4C7AAA;
}
.filter-dropdown {
    position: relative;
}
.filter-dropdown .dropdown-menu {
    width: 100%;
    max-width: 100%;
    max-height: 260px;
    overflow-y: auto;
    overflow-x: hidden;
}
.filter-dropdown-menu {
    background-color: #2b2b2b !important;
    border: 1px solid #444;
    padding: 0.25rem 0;
}
.filter-dropdown-menu .dropdown-item {
    color: #e0e0e0;
    padding: 0.4rem 1rem;
    white-space: normal;
    word-break: break-word;
}
.filter-dropdown-menu .dropdown-item:hover,
.filter-dropdown-menu .dropdown-item:focus {
    background-color: #4C7AAA !important;
    color: #fff !important;
}
.filter-dropdown-menu .dropdown-item.active,
.filter-dropdown-menu .dropdown-item:active {
    background-color: #4C7AAA !important;
    color: #fff !important;
}
.filter-dropdown-scroll {
    max-height: 280px;
    overflow-y: auto;
}
.filter-dropdown-scroll::-webkit-scrollbar {
    width: 6px;
}
.filter-dropdown-scroll::-webkit-scrollbar-track {
    background: #2b2b2b;
}
.filter-dropdown-scroll::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}
.filter-dropdown-scroll::-webkit-scrollbar-thumb:hover {
    background: #4C7AAA;
}

/* ============ Картки ============ */
.card.bg-dark {
    background-color: #2b2b2b !important;
    border-color: #444 !important;
}

/* Dovidnyk cards: ~20% less height */
.dovidnyk-list-card .dovidnyk-list-image {
    height: var(--catalog-card-image-height);
    object-fit: cover;
}
.library-list-card .library-list-image {
    height: var(--catalog-card-image-height);
    object-fit: contain;
    background-color: #fff;
}
.dovidnyk-list-card .card-body {
    padding: 0.65rem 0.75rem;
}
.dovidnyk-list-card .card-footer {
    padding: 0.5rem 0.75rem 0.65rem;
}
.dovidnyk-list-card .card-title {
    line-height: 1.2;
    margin-bottom: 0.4rem !important;
}
.library-list-card .card-title,
.dovidnyk-list-card .card-title {
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Cards width controls for Library and Dovidnyk */
@media (min-width: 768px) {
    .library-grid > .library-grid-col {
        flex: 0 0 var(--library-card-width);
        max-width: var(--library-card-width);
        margin-left: 0;
        margin-right: 0;
    }

    .dovidnyk-grid > .dovidnyk-grid-col {
        width: var(--dovidnyk-card-width) !important;
        flex: 0 0 var(--dovidnyk-card-width) !important;
        max-width: var(--dovidnyk-card-width);
    }
}

.password-toggle-btn {
    min-width: 44px;
}

/* ============ About Page ============ */
.about-content p {
    text-align: justify;
    text-justify: inter-word;
    margin-bottom: 1rem;
    text-indent: 1.25rem;
    line-height: 1.65;
}
.about-content h4 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}
.about-content ul {
    margin-bottom: 1rem;
}
.about-content ul li {
    margin-bottom: 0.35rem;
}
.about-content p.mb-0 {
    text-indent: 0;
}

/* ============ Адаптивність ============ */
@media (max-width: 991px) {
    .header-title { font-size: 1.1rem; }
    .header-logo { height: 50px; }

    .navbar-nav .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        background-color: #2b2b2b;
        border: none;
        box-shadow: none;
        text-align: center;
    }
    .home-hero {
        background-attachment: scroll;
    }
}

@media (prefers-reduced-motion: reduce) {
    .home-hero-content > * {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
}

.mobile-catalog-search {
    display: none;
    position: relative;
    z-index: 1200;
}

@media (max-width: 767px) {
    .header-title { font-size: 0.95rem; }
    .header-logo { height: 40px; }

    .navbar-nav {
        text-align: center;
        gap: 0 !important;
    }

    .navbar-collapse {
        margin-top: .5rem;
    }

    .header-search-form {
        display: none !important;
    }

    .mobile-catalog-search {
        display: block !important;
    }

    .mobile-catalog-search .form-control {
        background-color: transparent !important;
        color: #212529 !important;
    }

    .mobile-catalog-search .form-control::placeholder {
        color: #212529 !important;
        opacity: 0.75;
    }

    .mobile-catalog-search .form-control:focus {
        color: #212529 !important;
    }

    #mobile-dovidnyk-search-suggestions,
    #mobile-library-search-suggestions {
        z-index: 1300 !important;
        max-height: 260px;
        overflow-y: auto;
    }

    footer .container {
        flex-direction: column;
        gap: 8px;
    }

    header .container > .row {
        flex-direction: column;
        text-align: center;
    }
    header .container > .row > div {
        width: 100%;
    }

    .library-grid,
    .dovidnyk-grid {
        --bs-gutter-x: 0.75rem;
        --bs-gutter-y: 0.75rem;
    }

    .library-grid > .library-grid-col {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .dovidnyk-grid > .dovidnyk-grid-col {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .library-list-card .library-list-image {
        height: 200px;
    }

    .dovidnyk-list-card .dovidnyk-list-image {
        height: var(--catalog-card-image-height);
    }

    .detailed-description {
        overflow-x: auto;
    }

    .detailed-description table {
        min-width: 520px;
    }
}

.home-warning-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.home-warning-card {
    width: min(560px, 100%);
    background: #1f1f1f;
    color: #fff;
    border: 1px solid #555;
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.home-warning-title {
    margin-bottom: 10px;
    color: #fff;
}

.home-warning-message {
    line-height: 1.55;
}

.contribute-btn {
    background-color: #1f9d55;
    border: 1px solid #1f9d55;
    color: #fff !important;
}

.contribute-btn:hover,
.contribute-btn:focus {
    background-color: #198754;
    border-color: #198754;
    color: #fff !important;
}
