/* ==================== Global Styles ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #f9f8f6;
    --bg-secondary: #ffffff;
    --text-primary: #333;
    --text-secondary: #666;
    --border-color: #e0e0e0;
    --accent: #3498db;
    --accent-dark: #2980b9;
    --header-bg: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    --header-text: #ffffff;
    --header-offset: 13rem;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #404040;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);
}

/* ==================== Header ==================== */
.header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 1.5rem 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-height: fit-content;
    box-shadow: var(--shadow);
    z-index: 100;
}

body.dark-mode .header {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
}

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

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.header h1 {
    font-family: 'Georgia', serif;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.header p {
    font-size: 1rem;
    opacity: 0.9;
    font-weight: 300;
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--header-text);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.icon-btn.hidden {
    display: none;
}

/* ==================== Search Bar ==================== */
.search-container {
    max-width: 1200px;
    margin: 1.5rem auto 0;
    padding: 0 1rem;
    position: relative;
    display: flex;
    gap: 0.5rem;
}

.search-bar {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.search-bar:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.search-clear {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: none;
}

.search-clear:hover {
    color: var(--accent);
}

.search-clear.active {
    display: block;
}

/* ==================== View Controls ==================== */
.view-controls {
    max-width: 1200px;
    margin: 1rem auto;
    padding: 0 1rem;
    display: flex;
    gap: 0.5rem;
}

.view-mode-btn {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.view-mode-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.view-mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ==================== Sidebar Navigation ==================== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 2px solid var(--border-color);
    overflow-y: auto;
    z-index: 95;
    margin-top: 0;
    padding-top: var(--header-offset);
    transition: transform 0.3s ease;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: var(--header-offset);
    background: var(--bg-secondary);
    z-index: 96;
}

.sidebar-header h3 {
    font-family: 'Georgia', serif;
    font-size: 1.3rem;
    color: var(--text-primary);
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-primary);
    cursor: pointer;
    display: none;
}

.sidebar-nav {
    padding: 1rem 0;
}

.sidebar-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
    cursor: pointer;
    font-size: 0.95rem;
}

.sidebar-link:hover {
    background: rgba(52, 152, 219, 0.1);
    border-left-color: var(--accent);
    color: var(--accent);
}

.sidebar-link.active {
    background: rgba(52, 152, 219, 0.2);
    border-left-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-stats {
    padding: 1rem;
    border-top: 2px solid var(--border-color);
    margin-top: auto;
    font-size: 0.85rem;
    color: var(--text-secondary);
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary);
}

.sidebar-toggle-btn {
    display: none;
    position: fixed;
    bottom: 2rem;
    left: 1rem;
    z-index: 90;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
}

.sidebar-toggle-btn:hover {
    transform: scale(1.1);
}

.sidebar-toggle-btn.mobile-only {
    display: none;
}

/* ==================== Main Layout with Sidebar ==================== */
body {
    --sidebar-width: 280px;
    display: flex;
    flex-direction: column;
}

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 2px solid var(--border-color);
    overflow-y: auto;
    z-index: 95;
    padding-top: var(--header-offset);
    transition: transform 0.3s ease;
}

/* Desktop: Sidebar always visible */
@media (min-width: 1025px) {
    .sidebar {
        transform: translateX(0) !important;
    }
}

.container {
    max-width: 1200px;
    margin-top: calc(var(--header-offset) + 1rem);
    margin-left: var(--sidebar-width);
    padding: 0 1rem;
    transition: margin-left 0.3s ease;
    flex: 1;
}

.sidebar.mobile-hidden {
    transform: translateX(-100%);
}

/* ==================== Navigation (removed - replaced by sidebar) ==================== */
.nav-categories {
    display: none;
}

/* ==================== Container ==================== */
.gallery {
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

/* ==================== Gallery View Modes ==================== */
/* Grid View (Default) */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

/* Masonry View */
body:has(.view-mode-btn[data-mode="masonry"].active) .image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-auto-rows: 220px;
    gap: 1rem;
    grid-auto-flow: dense;
}

body:has(.view-mode-btn[data-mode="masonry"].active) .image-card {
    position: relative;
}

body:has(.view-mode-btn[data-mode="masonry"].active) .image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

body:has(.view-mode-btn[data-mode="masonry"].active) .image-info {
    display: none;
}

/* List View */
body:has(.view-mode-btn[data-mode="list"].active) .image-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

body:has(.view-mode-btn[data-mode="list"].active) .image-card {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 1rem;
    align-items: center;
    background: var(--bg-secondary);
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

body:has(.view-mode-btn[data-mode="list"].active) .image-card:hover {
    box-shadow: var(--shadow);
    transform: translateX(4px);
}

body:has(.view-mode-btn[data-mode="list"].active) .image-card img {
    height: 100px;
    width: 120px;
    object-fit: cover;
    border-radius: 4px;
}

body:has(.view-mode-btn[data-mode="list"].active) .image-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ==================== Gallery Section ==================== */
.gallery-section {
    animation: fadeIn 0.5s ease;
}

.gallery-section.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-title {
    font-family: 'Georgia', serif;
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 3px solid var(--accent);
    display: inline-block;
}

.image-card {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: var(--shadow);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.image-card:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.image-card.favorited {
    position: relative;
}

.image-card.favorited::after {
    content: '❤️';
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 1.5rem;
    z-index: 10;
}

.image-card img {
    width: 100%;
    height: 220px;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.image-card:hover img {
    transform: scale(1.1);
}

.image-info {
    display: none;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.image-filename {
    font-size: 0.85rem;
    color: var(--text-secondary);
    word-break: break-all;
    white-space: normal;
}

.image-error {
    opacity: 0.4;
    cursor: default;
}

.no-images {
    text-align: center;
    padding: 2rem;
    color: #999;
}

/* ==================== Lightbox ==================== */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.3s ease;
    flex-direction: column;
}

.lightbox.active {
    display: flex;
}

.lightbox-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    flex: 1;
    max-height: 70vh;
}

.lightbox-image {
    max-width: 80%;
    max-height: 100%;
    object-fit: contain;
    animation: zoomIn 0.3s ease;
}

.lightbox-details {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 1.5rem;
    border-radius: 8px;
    width: 280px;
    max-height: 100%;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.lightbox-details h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    border-bottom: 2px solid rgba(52, 152, 219, 0.5);
    padding-bottom: 0.75rem;
}

.lightbox-detail-item {
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.lightbox-detail-label {
    color: rgba(255, 255, 255, 0.6);
    font-weight: 600;
}

.lightbox-detail-value {
    color: #3498db;
    word-break: break-word;
}

.ocr-text-loading,
.ocr-text-empty {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.75);
    line-height: 1.4;
}

.ocr-text-editor {
    width: 100%;
    min-height: 150px;
    max-height: 260px;
    resize: vertical;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.18);
    color: white;
    padding: 0.6rem;
    font-size: 0.82rem;
    line-height: 1.4;
    margin-top: 0.35rem;
}

.ocr-text-editor:focus {
    outline: 2px solid rgba(52, 152, 219, 0.6);
    outline-offset: 1px;
}

@keyframes zoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.lightbox-close:hover {
    color: var(--accent);
    transform: rotate(90deg);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    font-size: 1.5rem;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 4px;
    z-index: 10;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.4);
}

.lightbox-nav.prev {
    left: 1rem;
}

.lightbox-nav.next {
    right: 1rem;
}

.lightbox-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.lightbox-bottom {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.lightbox-caption {
    color: white;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.75rem 1rem;
    border-radius: 4px;
    text-align: center;
    font-size: 0.9rem;
    word-break: break-word;
}

.lightbox-share {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.share-btn {
    background: rgba(52, 152, 219, 0.3);
    border: 1px solid rgba(52, 152, 219, 0.5);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.share-btn:hover {
    background: rgba(52, 152, 219, 0.6);
    border-color: rgba(52, 152, 219, 0.8);
}

.share-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.keyboard-hints {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8rem;
    text-align: center;
    padding: 0.5rem;
}

/* ==================== Loading Indicator ==================== */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
}

.loading.hidden {
    display: none;
}

.spinner {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.loading p {
    color: var(--text-primary);
    font-weight: 500;
}

/* ==================== Search Results & Favorites ==================== */
.search-results {
    margin: 2rem 0;
}

.search-results.hidden {
    display: none;
}

.search-info {
    padding: 1rem;
    background: rgba(52, 152, 219, 0.1);
    border-left: 4px solid var(--accent);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.search-result-meta {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.search-result-snippet {
    margin-top: 0.4rem;
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==================== Footer ==================== */
.footer {
    background: var(--bg-secondary);
    border-top: 2px solid var(--border-color);
    padding: 2rem 0;
    margin-top: 4rem;
}

.footer-stats {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    text-align: center;
}

/* ==================== Toast Notifications ==================== */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--accent);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: slideIn 0.3s ease;
    display: none;
}

.toast.show {
    display: block;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ==================== Responsive Design ==================== */

/* Tablet and Medium Screens */
@media (max-width: 1024px) {
    .sidebar {
        width: 250px;
        --sidebar-width: 250px;
    }

    .container {
        margin-left: 250px;
    }

    .lightbox-main {
        gap: 1rem;
    }

    .lightbox-details {
        width: 250px;
    }
}

/* Tablet */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.8rem;
    }

    .header-top {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header p {
        font-size: 0.9rem;
    }

    .search-bar {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
    }

    .view-mode-btn {
        padding: 0.4rem 0.75rem;
        font-size: 1rem;
    }

    .section-title {
        font-size: 1.4rem;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 1rem;
    }

    .image-card img {
        height: 150px;
    }

    /* Hide sidebar on tablet - can be toggled */
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-hidden {
        transform: translateX(-100%);
    }

    .sidebar-toggle-btn.mobile-only {
        display: block;
    }

    .container {
        margin-left: 0;
        margin-top: calc(var(--header-offset) + 1rem);
    }

    .lightbox-nav {
        padding: 0.75rem;
        font-size: 1.2rem;
    }

    .lightbox-nav.prev {
        left: 0.5rem;
    }

    .lightbox-nav.next {
        right: 0.5rem;
    }

    .lightbox-close {
        top: 0.5rem;
        right: 0.5rem;
        font-size: 1.5rem;
    }

    .lightbox-main {
        flex-direction: column;
        gap: 0;
    }

    .lightbox-details {
        width: 100%;
        max-height: 200px;
    }

    .toast {
        right: 1rem;
        left: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-section,
    .lightbox,
    .lightbox-image,
    .image-card,
    .image-card img,
    .sidebar-link,
    .lightbox-close,
    .lightbox-nav,
    .spinner,
    .back-to-top,
    .toast {
        animation: none;
        transition: none;
    }
}

/* Mobile */
@media (max-width: 480px) {
    :root {
        --header-offset: 10rem;
    }

    .header {
        padding: 1rem 0;
    }

    .header-content {
        padding: 0 0.75rem;
    }

    .header h1 {
        font-size: 1.3rem;
    }

    .header p {
        display: none;
    }

    .header-controls {
        gap: 0.25rem;
    }

    .icon-btn {
        padding: 0.4rem 0.6rem;
        font-size: 1rem;
    }

    .search-container {
        margin: 1rem auto 0;
        padding: 0 0.75rem;
    }

    .search-bar {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
    }

    .view-controls {
        margin: 0.75rem auto;
        padding: 0 0.75rem;
    }

    .view-mode-btn {
        flex: 1;
        padding: 0.4rem 0.5rem;
    }

    .section-title {
        font-size: 1.2rem;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }

    .image-card img {
        height: 100px;
    }

    .sidebar {
        width: 100%;
        padding-top: 4rem;
    }

    .sidebar-toggle-btn {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }

    .lightbox-nav {
        padding: 0.5rem;
        font-size: 1rem;
    }

    .lightbox-main {
        max-height: 60vh;
    }

    .lightbox-image {
        max-width: 95%;
    }

    .lightbox-details {
        display: none;
    }

    .lightbox-bottom {
        gap: 0.5rem;
    }

    .lightbox-caption {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .share-btn {
        flex: 1;
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
    }

    .keyboard-hints {
        font-size: 0.7rem;
    }

    .toast {
        right: 0.5rem;
        left: 0.5rem;
        bottom: 1rem;
        font-size: 0.9rem;
    }

    .back-to-top {
        bottom: 1rem;
        right: 1rem;
        width: 40px;
        height: 40px;
    }
}
