/* css/style.css */
/* MASTER STYLESHEET */

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: #2c3e50;
    overflow-x: hidden;
    color: #333;
}

/* Mobile-specific optimizations */
body.mobile-optimized {
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

body.mobile-optimized * {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

/* Pan mode styles */
body.pan-mode .stamp {
    pointer-events: none !important;
}

body.pan-mode .canvas-container {
    cursor: grab !important;
}

body.pan-mode.dragging .canvas-container {
    cursor: grabbing !important;
}

/* Header */
.header {
    background: linear-gradient(135deg, #8B0000, #DC143C);
    color: white;
    padding: 20px;
    text-align: center;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    /* Calculate header height dynamically or use a fixed height */
    /* Let's assume a fixed height for now */
    height: 100px; /* Example fixed height */
}

.header h1 {
    margin-bottom: 8px;
    font-size: 28px;
    font-weight: bold;
}

.header p {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 10px;
}

.header-links {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.header-links a {
    color: white;
    text-decoration: none;
    font-size: 14px;
    opacity: 0.8;
    transition: opacity 0.3s;
}

.header-links a:hover {
    opacity: 1;
}

/* Search bar - Desktop version */
.search-bar.moveable {
    position: fixed;
    top: 15px !important;
    right: 20px;
    z-index: 1001;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    min-width: 220px;
    width: 280px;
    user-select: none;
    border: 2px solid transparent;
    transition: border-color 0.3s;
    resize: none;
}

.search-bar.moveable:hover {
    border-color: rgba(139,0,0,0.3);
}

.search-bar.moveable.dragging {
    border-color: #8B0000;
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    transform: scale(1.02);
}

.search-bar.moveable.resizing {
    border-color: #228B22;
    box-shadow: 0 4px 15px rgba(34, 139, 34, 0.3);
}

/* Drag handle */
.search-bar.moveable .drag-handle {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 8px;
    background: #bbb;
    border-radius: 4px;
    cursor: grab;
    transition: all 0.3s;
    border: 1px solid #999;
}

.search-bar.moveable .drag-handle:hover {
    background: #8B0000;
    height: 10px;
    top: -13px;
}

.search-bar.moveable .drag-handle:active {
    cursor: grabbing;
    background: #DC143C;
}

.search-bar.moveable .drag-handle::before {
    content: '';
    position: absolute;
    top: -15px;
    left: -20px;
    right: -20px;
    bottom: -10px;
}

/* Resize handle */
.resize-handle {
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 60%;
    cursor: ew-resize;
    background: transparent;
    border-radius: 0 5px 5px 0;
}

.resize-handle:hover {
    background: rgba(34, 139, 34, 0.2);
}

.resize-handle::after {
    content: '⋮⋮';
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%) rotate(90deg);
    font-size: 12px;
    color: #999;
    letter-spacing: -2px;
}

.resize-handle:hover::after {
    color: #228B22;
}

/* Search input */
.search-bar input {
    width: calc(100% - 20px);
    padding: 10px;
    border: 2px solid #8B0000;
    border-radius: 5px;
    font-size: 14px;
    outline: none;
}

.search-bar input:focus {
    border-color: #DC143C;
}

#searchInfo {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
    display: none;
}

.search-help {
    font-size: 10px;
    color: #999;
    margin-top: 5px;
}

/* Controls */
.controls {
    position: fixed;
    /* Adjust top based on header height */
    top: 120px; /* Example: 100px header height + 20px margin */
    right: 20px;
    z-index: 1000;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.zoom-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.zoom-btn {
    padding: 10px 15px;
    background: #8B0000;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 12px;
    transition: background-color 0.3s;
    touch-action: manipulation;
}

.zoom-btn:hover {
    background: #A00000;
}

.zoom-btn:active {
    background: #660000;
    transform: scale(0.98);
}

.zoom-info {
    text-align: center;
    font-size: 11px;
    color: #666;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

/* Canvas container */
.canvas-container {
    position: absolute;
    /* === FIX: Adjust top based on header height === */
    top: 100px; /* Make this match the .header height */
    left: 0;
    width: 100vw;
    /* === FIX: Adjust height to fill remaining space === */
    height: calc(100vh - 100px); /* Subtract header height */
    overflow: hidden;
    cursor: grab;
    background: #34495e;
    will-change: transform;
}

.canvas-container:active {
    cursor: grabbing;
}

/* Stamp grid */
.stamp-grid {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    transition: transform 0.1s ease-out;
    display: flex;
    flex-wrap: wrap;
    width: 3000px; /* Adjust if needed */
    /* === FIX: Add padding-top === */
    padding: 20px 20px 20px 20px; /* Add top padding (20px) */
    gap: 2px;
    will-change: transform;
}

/* Mobile optimized transform */
.mobile-optimized .stamp-grid {
    transition: none;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

/* Loading message */
#loadingMessage {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 18px;
    text-align: center;
}

/* Individual stamps */
.stamp {
    width: 80px;
    height: 100px;
    background: white;
    border: 2px solid #2c3e50;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    will-change: transform;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

/* Mobile optimized stamp interactions */
.mobile-optimized .stamp {
    transition: transform 0.1s ease;
}

.mobile-optimized .stamp:active {
    transform: scale(1.05);
}

.stamp:hover {
    transform: scale(1.1);
    z-index: 100;
    border-color: #FFD700;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.5);
}

/* Disable hover effects on mobile */
.mobile-optimized .stamp:hover {
    transform: none;
    border-color: #2c3e50;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.stamp img {
    width: 100%;
    height: 80%;
    object-fit: cover;
    border-radius: 3px 3px 0 0;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

.stamp-info {
    padding: 2px 4px;
    font-size: 8px;
    font-weight: bold;
    color: #333;
    text-align: center;
    background: rgba(255,255,255,0.9);
    line-height: 1.1;
}

/* Decade markers */
.decade-marker {
    width: 100%;
    height: 30px;
    background: linear-gradient(135deg, #8B0000, #DC143C);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    margin: 15px 0 5px 0;
    border-radius: 5px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    flex-basis: 100%;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.modal-stamp {
    width: 200px;
    height: 250px;
    background: #f8f9fa;
    border: 4px solid #333;
    border-radius: 10px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.modal-stamp img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 30px;
    cursor: pointer;
    color: #666;
    transition: color 0.3s;
    touch-action: manipulation;
}

.close:hover {
    color: #000;
}

.stamp-details {
    text-align: left;
    margin: 20px 0;
}

.stamp-details p {
    margin: 8px 0;
    font-size: 14px;
}

.modal-footer {
    font-style: italic;
    color: #666;
    font-size: 12px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

/* Info sections */
.info-section {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 2000;
    overflow-y: auto;
    padding: 120px 20px 20px;
    -webkit-overflow-scrolling: touch;
}

.info-content {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    padding: 40px;
    border-radius: 15px;
}

.info-content h2 {
    color: #8B0000;
    margin-bottom: 20px;
    font-size: 24px;
}

.info-content h3 {
    color: #333;
    margin: 25px 0 15px 0;
    font-size: 18px;
}

.info-content p, .info-content li {
    line-height: 1.6;
    margin-bottom: 10px;
}

.info-content ol, .info-content ul {
    margin-left: 20px;
    margin-bottom: 20px;
}

.info-content pre {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto;
    font-size: 12px;
    border: 1px solid #e9ecef;
}

.info-content code {
    background: #f8f9fa;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

/* Search highlighting */
.stamp.search-match {
    border-color: #B8860B !important;
    box-shadow: 0 0 10px rgba(184, 134, 11, 0.6) !important;
    z-index: 200;
}

.stamp.search-current {
    border-color: #FFD700 !important;
    box-shadow: 0 0 20px rgba(255, 215, 0, 1) !important;
    z-index: 300;
}

/* Lazy loading styles */
.lazy-load {
    background: #f0f0f0;
    transition: opacity 0.3s;
}

.stamp img.lazy-load {
    opacity: 0.5;
}

.stamp img:not(.lazy-load) {
    opacity: 1;
}

/* Loading indicator */
.loading-batch {
    width: 100%;
    text-align: center;
    padding: 20px;
    color: white;
    font-size: 14px;
    background: rgba(0,0,0,0.3);
    border-radius: 5px;
    margin: 10px 0;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ffffff40;
    border-top: 2px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

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

/* Desktop navigation styles */
.nav-section {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.timeline-overview {
    flex: 1;
}

.nav-label {
    font-size: 11px;
    color: #666;
    margin-bottom: 4px;
    font-weight: 500;
    text-transform: uppercase;
}

.timeline-canvas {
    position: relative;
    width: 100%;
    height: 40px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
}

.timeline-canvas:hover {
    background: #e9ecef;
}

.timeline-viewport {
    position: absolute;
    top: 0;
    background: #DC143C;
    height: 100%;
    min-width: 8px;
    border-radius: 8px;
    opacity: 0.7;
    outline: 1px solid rgba(255, 255, 255, 0.9);
    pointer-events: none;
}

.timeline-preview {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(0, 123, 255, 0.4);
    border: 1px dashed #007bff;
    border-radius: 8px;
    pointer-events: none;
    display: none;
}

.cursor-controls {
    flex-shrink: 0;
}

.cursor-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.cursor-row {
    display: flex;
    gap: 2px;
}

.cursor-btn {
    width: 24px;
    height: 24px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #333;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.cursor-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.cursor-btn:active {
    background: #dee2e6;
    transform: scale(0.95);
}

.cursor-btn.center-btn {
    background: #8B0000;
    color: white;
    border-color: #6a0000;
}

.cursor-btn.center-btn:hover {
    background: #A00000;
}

.nav-options {
    border-top: 1px solid #eee;
    padding-top: 10px;
    margin-top: 10px;
}

.nav-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    cursor: pointer;
    margin-bottom: 5px;
    touch-action: manipulation;
}

.nav-help {
    font-size: 10px;
    color: #999;
    text-align: center;
}

/* Print styles */
@media print {
    .header, .search-bar, .controls {
        display: none;
    }
    
    .canvas-container {
        position: static;
        height: auto;
        overflow: visible;
    }
    
    .stamp-grid {
        transform: none !important;
        position: static;
    }
}

/* ===============================================
=== NEW MOBILE-FIRST STYLES ARE BELOW ===
===============================================
*/

/* By default (on desktop), hide the mobile view */
#mobile-view {
    display: none;
}

/* This is the fix for the iPad Pro.
  We now use the .is-mobile-device class (set by app.js)
  instead of a CSS-only @media query. This respects our
  robust JavaScript-based device detection.
*/
body.is-mobile-device {

    /* 1. HIDE ALL DESKTOP ELEMENTS */
    .header,
    .search-bar,
    .controls,
    .canvas-container,
    .info-section {
        display: none !important; /* Hide all desktop stuff */
    }

    /* 2. SHOW THE NEW MOBILE VIEW */
    #mobile-view {
        display: flex; /* Show our new mobile-friendly UI */
        flex-direction: column;
        width: 100%;
        /* Use 100dvh (dynamic viewport height) to account
          for mobile browser URL bars appearing and disappearing.
        */
        height: 100dvh; 
        background-color: #f4f4f4;
    }

    /* 3. STYLE THE MOBILE VIEW */
    .mobile-header {
        padding: 15px;
        background-color: #A92C2C; /* Match your site's red */
        color: white;
        text-align: center;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        position: -webkit-sticky; /* Safari */
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .mobile-header h1 {
        margin: 0;
        font-size: 1.2rem;
    }

    #mobile-search-input {
        width: 90%;
        padding: 12px;
        margin: 15px auto;
        font-size: 1rem;
        border: 1px solid #ccc;
        border-radius: 8px;
        display: block;
        -webkit-appearance: none; /* Fix iOS styling */
        position: -webkit-sticky; /* Safari */
        position: sticky;
        /* Adjust top based on header height + margin */
        top: 15px; 
        z-index: 9;
        background: #f4f4f4; /* Match background to hide content scrolling under */
    }
    
    #mobile-results {
        flex: 1; /* Make the results grid fill the remaining space */
        overflow-y: auto; /* Allow scrolling */
        padding: 10px;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
        /* === FIX: Add padding at the bottom for pagination bar === */
        padding-bottom: 120px; 
    }
    
    .info-text {
        text-align: center;
        color: #555;
        grid-column: 1 / -1; /* Span full width */
        padding-top: 20px;
    }

    .mobile-stamp {
        background: #fff;
        border: 1px solid #ddd;
        border-radius: 8px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        padding: 10px;
        cursor: pointer;
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        max-height: 188px !important;
    }
    
    .mobile-stamp img {
        width: 100%;
        height: 90px; /* Give image a consistent height */
        object-fit: contain;
        border-radius: 4px;
        margin-bottom: 8px; /* Space below image */
    }
    
    .mobile-stamp .stamp-info-bottom {
        /* This wrapper holds the title and ID */
        margin-top: auto; /* Push this to the bottom */
    }
    
    .mobile-stamp .stamp-title {
        font-size: 0.85rem; /* Revert font size */
        font-weight: bold;
        margin: 0 0 4px 0; /* Revert margin */
        color: #333;
        line-height: 1.2;
        /* Allow 2 lines */
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        height: 2.4em; /* 1.2em * 2 lines */
    }
    
    .mobile-stamp .stamp-id {
        font-size: 0.8rem; /* Revert font size */
        color: #777;
        margin: 0;
    }
    
    /* === Placeholder styles === */
    .mobile-stamp.mobile-placeholder {
        background: #FF1493; /* Bright pink from your screenshot */
        color: white;
        justify-content: center; /* Center placeholder text vertically */
        min-height: 150px; /* Give placeholders a min-height */
    }
    
    .mobile-placeholder .placeholder-text {
        font-weight: bold;
        font-size: 1rem;
        text-align: center;
        line-height: 1.3;
        padding: 5px;
    }

    .mobile-placeholder .placeholder-soon {
        font-size: 0.8rem;
        font-style: italic;
        font-weight: normal;
        opacity: 0.8;
        margin-top: 5px; /* Space below topic */
        text-align: center;
    }
    
    .mobile-placeholder .stamp-id-placeholder {
        /* This was part of the buggy version, remove it */
        display: none; 
    }
    
    /* This helper is used by the onerror handler */
    .mobile-stamp .img-error-placeholder {
        display: none; /* Hide by default */
        /* Make it fill the image area */
        height: 90px; 
        margin-bottom: 8px;
        /* Re-style as a placeholder */
        background: #FF1493;
        color: white;
        border-radius: 4px;
        /* Flex to center content */
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    /* 4. RESTYLE THE EXISTING MODAL FOR MOBILE */
    /* This makes your existing desktop modal look good on mobile */
    .modal-content {
        width: 90%;
        max-height: 85vh;
        overflow-y: auto;
    }

    .modal-stamp img {
        width: 80%;
        margin: 0 auto;
    }

    /* === NEW: PAGINATION STYLES === */
    #mobile-pagination-controls {
        padding: 15px;
        background: #fff;
        border-top: 1px solid #ddd;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: -webkit-sticky; /* Safari */
        position: sticky;
        bottom: 0;
        z-index: 10;
    }

    .page-btn {
        padding: 10px 16px;
        background-color: #A92C2C;
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 1rem;
        font-weight: bold;
        cursor: pointer;
    }

    .page-btn:disabled {
        background-color: #ccc;
        cursor: not-allowed;
    }

    .page-info {
        font-size: 0.9rem;
        font-weight: bold;
        color: #333;
    }
}

