/*
 * gallery.css — gallery grid, theme variables, and shared UI components.
 *
 * Defines the full color system for both light and dark modes using CSS
 * custom properties on :root (light) and [data-theme="dark"]. The data-theme
 * attribute is set by theme.js at runtime and by an inline script in base.html
 * to prevent a flash of unstyled content (FOUC) on page load.
 *
 * Key concepts:
 * - All colors are CSS variables (--bg-primary, --text-primary, etc.).
 *   Components reference these variables rather than hardcoded colors so
 *   theme switching works without touching component styles.
 * - .is-filtered-out uses display:none (not opacity/visibility) so filtered
 *   items take no space in the grid — this keeps gaps uniform.
 * - Text thumbnails render server-sanitized HTML inside a clipped card and
 *   inherit the parent page's theme variables without an embedded document.
 * - .link-chip is shared by caption links in the viewer and by gallery.js
 *   link-URL items; styles live here rather than viewer.css because the
 *   chip style is also used in text post thumbnails.
 *
 * Relations:
 * - static/photos/js/theme.js              — sets data-theme on <html>
 * - media_app/templates/media_app/base.html — FOUC prevention script
 * - media_app/templates/media_app/home.html — grid markup and initialization
 * - static/photos/css/viewer.css            — viewer-specific styles; imports none
 */

/* === Theme Variables — sourced from THEME context processor via base.html === */
/* Light mode vars are set in base.html <style> via {{ THEME.colors.* }} */
/* Dark mode vars are set in base.html [data-theme="dark"] via {{ THEME.dark_colors.* }} */

/* === Theme Utilities (replace inline styles) === */
.bg-theme-primary   { background-color: var(--bg-primary); }
.bg-theme-secondary { background-color: var(--bg-secondary); }
.bg-theme-tertiary  { background-color: var(--bg-tertiary); }
.text-theme-primary { color: var(--text-primary); }
.text-theme-accent  { color: var(--accent-color); }

/* === Media Grid === */
.media-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.media-grid .media-item {
    aspect-ratio: 1 / 1;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.media-grid .media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.media-grid .media-item:hover img {
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .media-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* === Video Thumbnails === */
.video-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.video-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
    width: 100%;
    height: 100%;
}

.video-placeholder .play-icon {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-placeholder .play-icon svg {
    width: 20px;
    height: 20px;
    fill: #1f2937;
    margin-left: 3px;
}

/* === Text Thumbnails === */
.text-thumbnail {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    width: 100%;
    height: 100%;
    padding: 16px;
    transition: transform 0.2s ease;
}

.media-item:hover .text-thumbnail {
    transform: scale(1.05);
}

.text-thumbnail .text-card-content {
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    color: var(--text-primary);
    font: 12px/1.4 system-ui, sans-serif;
}

.text-card-content a {
    color: var(--accent-color);
    text-decoration: none;
}

.text-card-content b,
.text-card-content strong {
    font-weight: 600;
}

.text-card-content code,
.text-card-content pre {
    border-radius: 3px;
    background: color-mix(in srgb, var(--text-primary) 10%, transparent);
    font-family: monospace;
}

.text-card-content code {
    padding: 2px 4px;
}

.text-card-content pre {
    padding: 8px;
}

.text-card-content ul,
.text-card-content ol {
    margin: 4px 0;
    padding-left: 16px;
}

.text-card-content blockquote {
    margin: 4px 0;
    padding-left: 8px;
    border-left: 2px solid var(--accent-color);
    opacity: 0.85;
}

/* === Segmented Control === */
.segmented-control {
    display: inline-flex;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 4px;
    flex-wrap: wrap;
    width: fit-content;
}

.segmented-control button {
    padding: 8px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
    color: var(--text-secondary);
}

.segmented-control button.active {
    background: var(--bg-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    color: var(--text-primary);
}

/* === Expandable Search === */
.search-container {
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 4px;
    transition: all 0.3s ease;
    overflow: hidden;
    width: 44px;
}

.search-container.expanded {
    width: 200px;
}

.search-container input {
    width: 0;
    padding: 8px 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    outline: none;
    transition: width 0.3s ease, padding 0.3s ease;
}

.search-container.expanded input {
    width: 160px;
    padding: 8px;
}

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

.search-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.search-toggle:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* === Link Chips === */
.link-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    margin: 2px 4px;
    background: var(--accent-color);
    color: white !important;
    border-radius: 16px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.link-chip:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.link-chip.link-external {
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-color);
}

.link-chip.link-external::after {
    content: '↗';
    margin-left: 6px;
    font-size: 0.75em;
    opacity: 0.7;
}

.link-chip.link-internal {
    background: var(--accent-color);
    border: 1px solid var(--accent-color);
}

/* === Empty State === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    color: var(--text-muted);
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state-text {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.empty-state-text a {
    color: var(--accent-color);
    text-decoration: none;
}

.empty-state-text a:hover {
    text-decoration: underline;
}

/* === Django Messages === */
.messages {
    margin-bottom: 1rem;
}

.messages li {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    list-style: none;
}

.messages .success {
    background: #dcfce7;
    color: #166534;
}

.messages .error {
    background: #fee2e2;
    color: #991b1b;
}

[data-theme="dark"] .messages .success {
    background: #14532d;
    color: #bbf7d0;
}

[data-theme="dark"] .messages .error {
    background: #7f1d1d;
    color: #fecaca;
}

/* === Metadata Overlay on Hover === */
.media-item .media-meta {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: #fff;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.media-item:hover .media-meta {
    opacity: 1;
}

.media-meta-date {
    font-weight: 500;
}


/* Filtered-out items (tag filter / search) */
.media-item.is-filtered-out {
    display: none;
}

/* Hide metadata overlay for text items - they have their own theming */
.media-item.type-text .media-meta,
.media-item.type-text .media-meta-date {
    display: none !important;
}

/* === Blog Shader Preview === */
.blog-shader-preview {
    position: relative;
    background: #000;
    overflow: hidden;
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
}

.blog-shader-preview .shader-preview-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.blog-shader-preview .shader-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    pointer-events: none;
}

.media-grid .media-item .blog-shader-preview:hover {
    transform: none;
}
