/**
 * Mediateka Plugin - Public Styles
 */

/* CSS Variables for consistency */
:root {
    --mediateka-primary: #007cba;
    --mediateka-primary-dark: #005a87;
    --mediateka-border: #dee2e6;
    --mediateka-border-radius: 4px;
    --mediateka-bg-light: #f8f9fa;
    --mediateka-text: #495057;
    --mediateka-text-muted: #6c757d;
    --mediateka-spacing: 15px;
    --mediateka-transition: all 0.3s ease;
}

/* Base Form Elements */
.mediateka-form-control {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    font-size: 14px;
    background: #fff;
    transition: var(--mediateka-transition);
}

.mediateka-form-control:focus {
    border-color: var(--mediateka-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(0,124,186,0.25);
}

.mediateka-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--mediateka-text);
    font-size: 14px;
}

.mediateka-btn {
    border: none;
    border-radius: var(--mediateka-border-radius);
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    transition: var(--mediateka-transition);
    display: inline-block;
}

.mediateka-btn-primary {
    background: var(--mediateka-primary);
    color: white;
}

.mediateka-btn-primary:hover {
    background: var(--mediateka-primary-dark);
    color: white;
    text-decoration: none;
}

.mediateka-btn-secondary {
    background: #e2e2e2;
    color: #333;
}

.mediateka-btn-secondary:hover {
    background: #d4d4d4;
}

.mediateka-btn-outline {
    background: #fff;
    color: var(--mediateka-text-muted);
    border: 1px solid var(--mediateka-border);
}

.mediateka-btn-outline:hover {
    background: var(--mediateka-bg-light);
    text-decoration: none;
}

/* Full Width Template Support */
.mediateka-full-width-template {
    width: 100%;
    max-width: none;
}

.mediateka-full-width-template .site-main {
    max-width: 100%;
    width: 100%;
}

.mediateka-full-width-template .mediateka-records {
    max-width: 100%;
    margin: 0 auto;
}

.mediateka-full-width-template .mediateka-main-content {
    gap: 30px;
}

.mediateka-full-width-template .mediateka-sidebar {
    min-width: 280px;
}

.mediateka-full-width-template .entry-title {
    text-align: center;
    margin-bottom: 30px;
}

/* Audio Page Template Support */
.mediateka-page-full-width {
    max-width: 100%;
    width: 100%;
}

.mediateka-page-full-width .mediateka-records {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Hide sidebars on audio page */
body.page-template-page-audio .widget-area {
    display: none;
}

body.page-template-page-audio #content {
    width: 100%;
    max-width: none;
}

.mediateka-main-content {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.mediateka-content-area {
    flex: 1;
    min-width: 0;
}

.mediateka-sidebar {
    width: 250px;
    flex-shrink: 0;
}

/* Sidebar Styles */
.mediateka-sidebar-section {
    background: var(--mediateka-bg-light);
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    padding: 0 20px 20px;
    margin-bottom: 20px;
}

.mediateka-types-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.mediateka-type-item {
    margin: 0;
    padding: 0;
    border-bottom: 1px solid var(--mediateka-border);
}

.mediateka-type-item:last-child {
    border-bottom: none;
}

.mediateka-type-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    text-decoration: none;
    color: #555;
    border-radius: var(--mediateka-border-radius);
    transition: var(--mediateka-transition);
    margin: 2px 0;
}

.mediateka-type-link:hover {
    background-color: #f0f0f0;
    color: var(--mediateka-primary);
    text-decoration: none;
}

.mediateka-type-item.active .mediateka-type-link {
    font-weight: bold;
}

.mediateka-type-count {
    background-color: #ddd;
    color: #666;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: normal;
}

.mediateka-type-item.active .mediateka-type-count {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Card Container */
.mediateka-card {
    background: #fff;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    padding: 20px;
    margin: 20px 0;
}

/* Filters and Search */
.mediateka-filters {
    background: #fff;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    padding: 20px;
}

.mediateka-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--mediateka-spacing);
    align-items: end;
}

.mediateka-form-group {
    display: flex;
    flex-direction: column;
}

.mediateka-form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Search Results Info */
.mediateka-search-results {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    border-radius: var(--mediateka-border-radius);
    padding: 12px 16px;
    margin: var(--mediateka-spacing) 0;
    color: #0c5460;
    font-size: 14px;
}

/* Toolbar */
.mediateka-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
    padding: var(--mediateka-spacing);
    background: var(--mediateka-bg-light);
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
}

.mediateka-results-info {
    font-weight: 600;
    color: var(--mediateka-text);
    font-size: 14px;
}

.mediateka-sorting {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Records List */
.mediateka-list {
    display: grid;
    gap: var(--mediateka-spacing);
    margin: 20px 0;
}

/* Grid View for Infographics */
.mediateka-list.mediateka-grid-view {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin: 20px 0;
    align-items: start;
}

.mediateka-list.mediateka-grid-view .mediateka-item {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    padding: 15px;
    transition: var(--mediateka-transition);
    /* Remove fixed height for variable content */
    height: auto;
    /* Better break-inside behavior */
    break-inside: avoid;
    page-break-inside: avoid;
}

.mediateka-list.mediateka-grid-view .mediateka-item:hover {
    border-color: var(--mediateka-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.mediateka-list.mediateka-grid-view .mediateka-item-image {
    width: 100%;
    /* Dynamic height based on aspect ratio, with min/max limits */
    min-height: 120px;
    max-height: 300px;
    height: auto;
    aspect-ratio: 4/3;
    border-radius: var(--mediateka-border-radius);
    overflow: hidden;
    background: var(--mediateka-bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    order: -1; /* Изображение сверху */
}

.mediateka-list.mediateka-grid-view .mediateka-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mediateka-list.mediateka-grid-view .mediateka-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.mediateka-list.mediateka-grid-view .mediateka-title {
    font-size: 16px;
    margin-bottom: 10px;
    line-height: 1.3;
    /* Ensure title wraps properly */
    word-wrap: break-word;
    hyphens: auto;
}

.mediateka-list.mediateka-grid-view .mediateka-excerpt {
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 10px;
    /* Allow natural content flow without forcing height */
    flex-grow: 0;
    /* Better text wrapping */
    word-wrap: break-word;
    hyphens: auto;
}

.mediateka-list.mediateka-grid-view .mediateka-topics {
    margin-top: auto;
    padding-top: 10px;
}

/* Responsive Grid Adjustments */
@media (max-width: 768px) {
    .mediateka-list.mediateka-grid-view {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .mediateka-list.mediateka-grid-view {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .mediateka-list.mediateka-grid-view .mediateka-item-image {
        min-height: 150px;
        max-height: 250px;
    }
}

/* Variable height content utilities */
.mediateka-grid-view .mediateka-item.short-content .mediateka-excerpt {
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    display: -webkit-box;
}

.mediateka-grid-view .mediateka-item.medium-content .mediateka-excerpt {
    -webkit-line-clamp: 5;
    line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    display: -webkit-box;
}

.mediateka-grid-view .mediateka-item.long-content .mediateka-excerpt {
    -webkit-line-clamp: 7;
    line-clamp: 7;
    -webkit-box-orient: vertical;
    overflow: hidden;
    display: -webkit-box;
}

/* Smooth height transitions */
.mediateka-list.mediateka-grid-view .mediateka-item {
    transition: var(--mediateka-transition), height 0.3s ease;
}

/* Improved text overflow handling */
.mediateka-grid-view .mediateka-title {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.mediateka-item {
    background: #fff;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    padding: 20px;
    transition: var(--mediateka-transition);
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.mediateka-item:hover {
    border-color: var(--mediateka-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mediateka-item-image {
    flex-shrink: 0;
    width: 120px;
    height: 90px;
    border-radius: var(--mediateka-border-radius);
    overflow: hidden;
    background: var(--mediateka-bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mediateka-item-image a {
    display: block;
    width: 100%;
    height: 100%;
}

.mediateka-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--mediateka-transition);
}

.mediateka-item-image:hover img {
    transform: scale(1.05);
}

.mediateka-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    color: var(--mediateka-text-muted);
    border: 1px dashed var(--mediateka-border);
}

.mediateka-placeholder-icon {
    font-size: 24px;
    opacity: 0.6;
}

.mediateka-item-content {
    flex: 1;
    min-width: 0; /* Prevents flexbox overflow */
}

.mediateka-title {
    margin: 0 0 12px 0;
    font-size: 18px;
    line-height: 1.4;
}

.mediateka-title a {
    color: #212529;
    text-decoration: none;
    font-weight: 600;
}

.mediateka-title a:hover {
    color: var(--mediateka-primary);
    text-decoration: underline;
}

.mediateka-excerpt {
    margin: 0 0 12px 0;
    color: var(--mediateka-text);
    line-height: 1.5;
    font-size: 14px;
}

.mediateka-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.mediateka-tag {
    background: #e9ecef;
    color: var(--mediateka-text);
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
}

.mediateka-tag-primary {
    background: #e1f5fe;
    color: #0277bd;
}

/* Pagination */
.mediateka-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin: 25px 0;
    padding-top: 20px;
    border-top: 1px solid #eee;
    flex-wrap: wrap;
}

.mediateka-page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 35px;
    height: 35px;
    padding: 0 10px;
    background: #fff;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    color: var(--mediateka-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: var(--mediateka-transition);
}

.mediateka-page-link:hover {
    background: #e9ecef;
    text-decoration: none;
}

.mediateka-page-link.mediateka-current {
    background: var(--mediateka-primary);
    border-color: var(--mediateka-primary);
    color: white;
}

/* No Results */
.mediateka-no-results {
    text-align: center;
    padding: 40px 20px;
    background: var(--mediateka-bg-light);
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    margin: 20px 0;
    color: var(--mediateka-text-muted);
}

/* Single Record Styles */
.mediateka-single {
    margin: 20px 0;
    padding: 25px;
    background: #fff;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
}

.mediateka-single-title {
    color: #212529;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--mediateka-primary);
    font-weight: 700;
}

.mediateka-single-meta {
    margin-bottom: var(--mediateka-spacing);
    padding: 12px;
    background: var(--mediateka-bg-light);
    border-radius: var(--mediateka-border-radius);
}

.mediateka-single-description {
    line-height: 1.6;
    color: var(--mediateka-text);
    font-size: 15px;
    margin: 20px 0;
}

/* File Downloads */
.mediateka-files-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
}

.mediateka-file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--mediateka-border);
    border-radius: var(--mediateka-border-radius);
    background: #fff;
}

.mediateka-file-item:hover {
    border-color: var(--mediateka-primary);
}

.mediateka-download-link {
    color: var(--mediateka-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
}

.mediateka-download-link:hover {
    color: var(--mediateka-primary-dark);
    text-decoration: underline;
}

.mediateka-file-meta {
    color: var(--mediateka-text-muted);
    font-size: 0.9em;
    font-weight: 500;
}

/* Loading State */
.mediateka-loading {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
}

.mediateka-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--mediateka-primary);
    border-radius: 50%;
    animation: mediateka-spin 1s linear infinite;
}

@keyframes mediateka-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .mediateka-main-content {
        flex-direction: column;
        gap: 20px;
    }
    
    .mediateka-sidebar {
        width: 100%;
        order: -1;
    }
    
    .mediateka-types-menu {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .mediateka-type-item {
        border-bottom: none;
        flex: 0 0 auto;
    }
    
    .mediateka-type-link {
        padding: 8px 12px;
        margin: 0;
        border: 1px solid #ddd;
        border-radius: 20px;
        font-size: 14px;
    }
    
    .mediateka-item {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }
    
    .mediateka-item-image {
        width: 100%;
        height: 200px;
        order: -1;
    }
    
    .mediateka-title {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    .mediateka-excerpt {
        font-size: 13px;
    }
    
    .mediateka-item {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }
    
    .mediateka-item-image {
        width: 100%;
        height: 200px;
        order: -1;
    }
    
    .mediateka-title {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    .mediateka-excerpt {
        font-size: 13px;
    }
    
    /* Grid View Responsive */
    .mediateka-list.mediateka-grid-view {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .mediateka-list.mediateka-grid-view .mediateka-item-image {
        min-height: 100px;
        max-height: 200px;
        aspect-ratio: 4/3;
    }
    
    .mediateka-list.mediateka-grid-view .mediateka-title {
        font-size: 15px;
    }
    
    .mediateka-list.mediateka-grid-view .mediateka-excerpt {
        font-size: 12px;
        line-height: 1.3;
    }
}

@media (max-width: 480px) {
    .mediateka-item {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .mediateka-item-image {
        height: 150px;
    }
    
    .mediateka-title {
        font-size: 15px;
    }
    
    .mediateka-form-row {
        grid-template-columns: 1fr;
    }
    
    .mediateka-form-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    
    .mediateka-toolbar {
        flex-direction: column;
        gap: var(--mediateka-spacing);
        text-align: center;
    }
    
    .mediateka-sorting {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .mediateka-item {
        padding: var(--mediateka-spacing);
    }
    
    .mediateka-title {
        font-size: 16px;
    }
    
    .mediateka-pagination {
        gap: 3px;
    }
    
    .mediateka-page-link {
        min-width: 32px;
        height: 32px;
        font-size: 13px;
    }
    
    .mediateka-file-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
}

@media (max-width: 480px) {
    .mediateka-card {
        padding: var(--mediateka-spacing);
        margin: var(--mediateka-spacing) 0;
    }
    
    .mediateka-form-control {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 10px 14px;
    }
    
    .mediateka-btn {
        padding: 10px 20px;
    }
    
    .mediateka-form-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    /* Grid View для мобильных */
    .mediateka-list.mediateka-grid-view {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .mediateka-list.mediateka-grid-view .mediateka-item-image {
        min-height: 150px;
        max-height: 250px;
        aspect-ratio: 16/9; /* Wider aspect ratio for mobile */
    }
    
    .mediateka-list.mediateka-grid-view .mediateka-title {
        font-size: 16px;
    }
    
    .mediateka-list.mediateka-grid-view .mediateka-excerpt {
        font-size: 13px;
        line-height: 1.4;
    }
}

/* Files download section styles */
.mediateka-single-files {
    margin-bottom: 20px;
}

.mediateka-single-files h3 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #333;
    border-bottom: 2px solid #ddd;
    padding-bottom: 5px;
}

/* Content display section styles */
.mediateka-single-content {
    margin-bottom: 30px;
}

.mediateka-single-content h3 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #333;
    border-bottom: 2px solid #ddd;
    padding-bottom: 5px;
}

.mediateka-content-items {
    margin-bottom: 20px;
}

.mediateka-content-item {
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    padding: 15px;
    background-color: #f9f9f9;
}

.mediateka-content-caption {
    font-weight: bold;
    margin-top: 10px;
    margin-bottom: 0;
    color: #555;
    text-align: center;
}

.mediateka-image-content img {
    display: block;
    margin: 0 auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 3px;
}

.mediateka-pdf-content iframe {
    border-radius: 3px;
}

.mediateka-video-content video,
.mediateka-audio-content audio {
    display: block;
    margin: 0 auto;
}

/* Files list styles */
.mediateka-files-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mediateka-file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    margin-bottom: 5px;
    border-radius: 3px;
    background-color: #fafafa;
}

.mediateka-file-item:hover {
    background-color: #f0f0f0;
}

.mediateka-download-link {
    text-decoration: none;
    color: #0073aa;
    font-weight: 500;
}

.mediateka-download-link:hover {
    text-decoration: underline;
}

.mediateka-file-type {
    color: #666;
    font-size: 0.9em;
    margin-left: 5px;
}

.mediateka-file-size {
    color: #999;
    font-size: 0.85em;
}
