/* ============================================
   assets/css/main.css - Главен стил (КОРИГИРАН v1.4)
   ============================================ */

   :root {
    --gold: #c9a961;
    --dark-gold: #a68943;
    --red: #8b0000;
    --blue: #16213e;
    --deep-blue: #0f3460;
    --cream: #f8f5ed;
    --white: #ffffff;
    --text-dark: #2c3e50;
    --border: #e0d5b7;
    /* Accessibility (WCAG AA): fixed dark navy that reads >=4.5:1 on top
       of BOTH the light-theme gold (#c9a961) and dark-theme gold (#d4a373)
       button fills, so it does not need a per-theme override like
       --gold-text (defined per-theme in header.php) does. */
    --gold-text: #a68943;
    --gold-fill: #a68943;
    --on-gold: #16213e;
}

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

body {
    font-family: 'Noto Serif', 'Lora', Georgia, serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
}

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

.container-fluid {
    max-width: 100%;
    padding: 0;
}

/* ============================================
   ACCESSIBILITY UTILITIES (Фаза 6)
   ============================================ */

/* Скрива съдържание визуално, но го оставя достъпно за screen readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip-to-content: невидим докато не получи фокус (Tab), после изскача
   най-отгоре — позволява на клавиатурни/screen-reader потребители да
   прескочат повтарящата се навигация на всяка страница. */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 1rem;
    z-index: 10000;
    background: var(--blue);
    color: white;
    padding: 0.85rem 1.5rem;
    border-radius: 0 0 8px 8px;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.2s ease;
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

/* Глобален, брандиран focus ring — вижда се само при клавиатурна
   навигация (:focus-visible), не и при mouse click, за да не променя
   визуалното поведение при обичайно кликане с мишка. Работи навсякъде,
   включително върху бутони/линкове с тъмен ИЛИ светъл фон благодарение
   на outline-offset + двойния (тъмен outline + светъл box-shadow) пръстен. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--gold-text);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s ease;
    text-align: center;
}

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

.btn-primary:hover {
    background: var(--dark-gold);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(201, 169, 97, 0.3);
}

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

.btn-secondary:hover {
    background: var(--deep-blue);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--gold-text);
    color: var(--gold-text);
}

.btn-outline:hover {
    background: var(--gold-fill);
    color: white;
}

.btn-block {
    width: 100%;
    display: block;
}

/* ============================================
   HEADER & NAVBAR
   Стиловете са преместени в header.php
   ============================================ */

/* Ornaments */
.ornament-top,
.ornament-bottom {
    position: absolute;
    left: 0;
    right: 0;
    height: 50px;
    background-image: 
        repeating-linear-gradient(90deg, 
            var(--gold) 0px, 
            var(--gold) 10px, 
            transparent 10px, 
            transparent 20px);
    opacity: 0.1;
}

.ornament-top { top: 0; }
.ornament-bottom { bottom: 0; }

/* Section Titles */
.section-title {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title .icon {
    color: var(--gold);
}

/* Video Cards - КОРИГИРАНИ ЗА THEME SUPPORT */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.video-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    /* Performance: contain изолира layout/paint на картичката от
       останалата страница — hover ефектът (transform: translateY)
       не предизвиква reflow извън границите на самата картичка. */
    contain: layout paint;
}

.video-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 24px var(--shadow);
}

.video-link {
    text-decoration: none;
    color: inherit;
}

.video-thumbnail {
    position: relative;
    padding-top: 56.25%; /* 16:9 aspect ratio */
    overflow: hidden;
    background: #000;
}

.video-thumbnail img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.video-card:hover .video-thumbnail img {
    transform: scale(1.05);
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.video-card:hover .video-overlay {
    opacity: 1;
}

.play-button {
    width: 60px;
    height: 60px;
    background: var(--gold-fill);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.video-duration {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.video-info {
    padding: 1rem;
    background: var(--bg-secondary);
}

.video-title {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-weight: 600;
}

.video-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.video-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.category-card {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 4px 12px var(--shadow);
    transition: all 0.3s ease;
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 24px var(--shadow);
}

.category-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.category-card h3 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.category-card p {
    color: var(--text-secondary);
}

/* Modal Close Button */
.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
    line-height: 1;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Footer */
.main-footer {
    background: var(--deep-blue);
    color: white;
    padding: 3rem 0 1rem;
    margin-top: 4rem;
    /* Performance: footer е ВИНАГИ below-the-fold. content-visibility
       казва на браузъра да пропусне layout/paint изчисления докато
       секцията не е близо до viewport-а — по-бърз initial render.
       contain-intrinsic-size дава приблизителна височина, за да няма
       layout shift когато секцията влезе в scroll обхвата. */
    content-visibility: auto;
    contain-intrinsic-size: auto 600px;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-section h3,
.footer-section h4 {
    color: var(--gold);
    margin-bottom: 1rem;
}

.footer-links {
    list-style: none;
}

.footer-links a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    display: block;
    padding: 0.25rem 0;
    transition: color 0.3s;
}

.footer-links a:hover {
    color: white;
}

.social-links {
    display: flex;
    gap: 1rem;
    font-size: 1.5rem;
}

.footer-bottom {
    text-align: center;
    padding-top: 2rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.footer-verse {
    font-style: italic;
    opacity: 0.8;
    margin-top: 0.5rem;
}

/* Search Results Dropdown */
.search-results-list {
    display: flex;
    flex-direction: column;
}

.search-result-item {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--bg-primary);
}

.search-result-item:last-child {
    border-bottom: none;
}

.result-thumb {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    /* Гарантира постоянен thumbnail размер независимо от дължината
       на съседния текст — без това, тесен overflow-ing родител би
       свил снимката непропорционално. */
    flex-shrink: 0;
}

.result-info {
    flex: 1;
    /* КРИТИЧНО: flex items имат default min-width:auto, което
       предотвратява свиване под intrinsic съдържание width. Дълго
       заглавие (h4 без wrap) кара .result-info да се разшири извън
       границите на родителя (#searchResults, position:absolute
       overlay) — точно причината за "резултатите излизат извън
       очертанията на страницата" на desktop (page-wide horizontal
       scroll). min-width:0 разрешава правилно свиване/пренасяне. */
    min-width: 0;
}

.result-info h4 {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
    /* Defensive: пренася дълги думи/заглавия вместо да overflow-ва
       хоризонтално извън родителския контейнер. */
    overflow-wrap: break-word;
    word-break: break-word;
}

.result-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.result-rating {
    color: var(--gold);
}

.no-results {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
}

/* Notification System */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-secondary);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 9999;
    transform: translateX(400px);
    transition: transform 0.3s ease;
}

.notification.show {
    transform: translateX(0);
}

.notification-success {
    border-left: 4px solid #28a745;
}

.notification-error {
    border-left: 4px solid #dc3545;
}

.notification-info {
    border-left: 4px solid #17a2b8;
}

.notification-warning {
    border-left: 4px solid #ffc107;
}

.notif-icon {
    font-size: 1.5rem;
}

.notif-message {
    color: var(--text-primary);
}

/* Tooltip */
.tooltip {
    position: fixed;
    background: rgba(0,0,0,0.9);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    z-index: 10000;
    pointer-events: none;
    white-space: nowrap;
}

/* Loading States */
.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid rgba(201, 169, 97, 0.3);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive adjustments */
@media (max-width: 768px) {
    .video-grid {
        grid-template-columns: 1fr;
    }
    
    .notification {
        right: 10px;
        left: 10px;
        width: auto;
    }
}

/* ============================================
   THEME-SPECIFIC FIXES - КРИТИЧНО ВАЖНИ
   ============================================ */

/* Светла тема - уверете се че всичко е четимо */
:root[data-theme="light"] .section-title {
    color: #16213e !important;
}

:root[data-theme="light"] .section-title .icon {
    color: var(--gold) !important;
}

:root[data-theme="light"] .video-card {
    background: #ffffff !important;
    color: #2c3e50 !important;
}

:root[data-theme="light"] .video-info {
    background: #ffffff !important;
}

:root[data-theme="light"] .video-title {
    color: #2c3e50 !important;
}

:root[data-theme="light"] .video-meta,
:root[data-theme="light"] .video-desc {
    color: #666 !important;
}

:root[data-theme="light"] .category-card {
    background: #ffffff !important;
}

:root[data-theme="light"] .category-card h3 {
    color: #16213e !important;
}

:root[data-theme="light"] .category-card p {
    color: #666 !important;
}

/* Тъмна тема */
:root[data-theme="dark"] .section-title {
    color: var(--gold) !important;
}

:root[data-theme="dark"] .section-title .icon {
    color: var(--cream) !important;
}

:root[data-theme="dark"] .video-card {
    background: #2a2a2a !important;
    color: #e0e0e0 !important;
}

:root[data-theme="dark"] .video-info {
    background: #2a2a2a !important;
}

:root[data-theme="dark"] .video-title {
    color: #e0e0e0 !important;
}

:root[data-theme="dark"] .video-meta,
:root[data-theme="dark"] .video-desc {
    color: #b0b0b0 !important;
}

:root[data-theme="dark"] .category-card {
    background: #2a2a2a !important;
}

:root[data-theme="dark"] .category-card h3 {
    color: var(--gold) !important;
}

:root[data-theme="dark"] .category-card p {
    color: #b0b0b0 !important;
}