/* Global styles and link behavior */
a:visited {
    color: inherit;
}

/* Base body styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    margin: 0;
    padding: 20px;
    background: #f5f5f5;
    font-size: 20px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Home page specific body layout */
body.home {
    max-width: 90%;
    margin: 50px auto;
    text-align: center;
    background: white;
    padding: 32px;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    position: relative;
}

/* Barn promotion button */
.barn-promo {
    position: fixed;
    top: 20px;
    left: 20px;
    background: #dc3545;
    color: white;
    text-decoration: none;
    padding: 16px 24px;
    border-radius: 40px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 28px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
    transition: all 0.2s ease;
    z-index: 1000;
    opacity: 0;
    transform: translateX(-100px);
    display: none;
}

.barn-promo.show-animation {
    display: flex;
    will-change: transform, opacity;
    transform: translateZ(0); /* Force hardware acceleration */
    backface-visibility: hidden; /* Prevent flickering */
    -webkit-transform: translateZ(0); /* Safari specific */
    -webkit-backface-visibility: hidden;
    animation: barnLifecycle 10s ease-out 0.5s forwards;
}

.barn-promo:hover {
    background: #c82333;
    transform: translateY(-2px) scale(1.05) translateZ(0);
    box-shadow: 0 6px 16px rgba(220, 53, 69, 0.4);
    color: white;
    animation-play-state: paused;
}

.barn-icon {
    width: 32px;
    height: 32px;
    filter: brightness(0) invert(1);
}

.barn-icon-footer {
    color: white;
    background: #c82333;
    margin-top: 8px;
}

.barn-text {
    line-height: 1;
    color: white;
}

@keyframes barnLifecycle {
    /* Start: Hidden off-screen */
    0% {
        opacity: 0;
        transform: translateX(-100px) scale(1) translateZ(0);
    }
    
    /* Slide in: 0.5s-1.5s (10% of total) */
    10% {
        opacity: 1;
        transform: translateX(0) scale(1) translateZ(0);
    }
    
    /* Pulse 1: 15%-20% */
    15% {
        transform: translateX(0) scale(1.05) translateZ(0);
    }
    20% {
        transform: translateX(0) scale(1) translateZ(0);
    }
    
    /* Pulse 2: 35%-40% */
    35% {
        transform: translateX(0) scale(1.05) translateZ(0);
    }
    40% {
        transform: translateX(0) scale(1) translateZ(0);
    }
    
    /* Pulse 3: 55%-60% */
    55% {
        transform: translateX(0) scale(1.05) translateZ(0);
    }
    60% {
        transform: translateX(0) scale(1) translateZ(0);
    }
    
    /* Hold steady: 60%-90% */
    90% {
        opacity: 1;
        transform: translateX(0) scale(1) translateZ(0);
    }
    
    /* Fade out: 90%-100% */
    100% {
        opacity: 0;
        transform: translateX(-100px) scale(1) translateZ(0);
        pointer-events: none;
    }
}

/* Make barn promo responsive */
@media (max-width: 480px) {
    .barn-promo {
        top: 10px;
        left: 10px;
        padding: 12px 18px;
        font-size: 22px;
    }

    .barn-icon {
        width: 24px;
        height: 24px;
    }
}

/* Image page specific body layout */
body.image {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

/* Header styles */
.header {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.header h1 {
    margin: 0;
    color: #333;
}

.home-link {
    color: #333;
    text-decoration: none;
    transition: color 0.3s ease;
    font-size: 1.5em;
}

.home-link:hover {
    color: #007cba;
}

.home-link:visited {
    color: #333;
}

/* Upload area styles */
.upload-area {
    border: 3px dashed #ddd;
    border-radius: 16px;
    padding: 60px;
    margin: 24px 0;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.upload-area:hover {
    border-color: #007cba;
    background-color: #f8fbff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.upload-area-small {
    border: 2px dashed #ddd;
    border-radius: 12px;
    padding: 40px;
    margin-top: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.upload-area-small:hover {
    border-color: #007cba;
    background-color: #f8fbff;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.upload-area-small p {
    margin: 0;
    color: #666;
    font-size: 18px;
    font-weight: 500;
    -webkit-font-smoothing: antialiased;
}

.upload-area p {
    color: #666;
    font-size: 20px;
    font-weight: 500;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

.upload-icon {
    margin-bottom: 10px;
    display: block;
}

/* Home page upload icon */
.upload-area .upload-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

/* Image page upload icon */
.upload-area-small .upload-icon {
    font-size: 2.5em;
    margin-bottom: 15px;
}

#fileInput {
    display: none;
}

/* Button styles */
.btn {
    background: #007cba;
    color: white;
    padding: 18px 32px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    min-height: 56px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s ease;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
    -webkit-font-smoothing: antialiased;
}

.btn:hover {
    background: #005a87;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #666;
    text-decoration: none;
    padding: 12px;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    margin: 4px;
    transition: all 0.2s ease;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    text-align: center;
    min-width: 44px;
    min-height: 44px;
    max-height: 44px;
    box-shadow: none;
    -webkit-font-smoothing: antialiased;
    vertical-align: top;
    box-sizing: border-box;
    gap: 8px;
}

.action-btn:hover {
    background: #f5f5f5;
    color: #333;
    border-color: #d1d5db;
    transform: none;
    box-shadow: none;
}

/* Report button specific styling */
#reportBtn {
    background: transparent;
    color: #666;
    border-color: #e1e5e9;
}

/* Icon-only button variant */
.action-btn.icon-only {
    min-width: 44px;
    padding: 12px;
    justify-content: center;
}

/* Button with icon and text */
.action-btn.with-text {
    min-width: auto;
    padding: 12px 16px;
}

/* SVG icon styling within buttons */
.action-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Icon-only buttons hide text on smaller screens */
@media (max-width: 600px) {
    .action-btn.responsive .btn-text {
        display: none;
    }

    .action-btn.responsive {
        min-width: 44px;
        padding: 12px;
    }
}

/* Image container for image page */
.image-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 40px;
    max-width: 90vw;
    max-height: 60vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.image-container img {
    max-width: calc(90vw - 40px);
    max-height: calc(60vh - 40px);
    width: auto;
    height: auto;
    border-radius: 4px;
    object-fit: contain;
}

/* Navigation arrows in header */
.nav-arrow {
    padding: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-arrow:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 1);
    transform: scale(1.15);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.nav-arrow img {
    display: block;
    width: 28px;
    height: 28px;
}

/* Default metadata section for image page */
.metadata {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 24px;
    width: 100%;
    max-width: 600px;
    margin-bottom: 24px;
}

/* Industrial styling for Image Details pane only */
.metadata:first-of-type,
.image-details-pane {
    background: #f8f8f8 !important;
    border: 2px solid #333 !important;
    border-radius: 4px !important;
    padding: 16px !important;
    max-width: 480px !important;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.metadata:first-of-type::before,
.image-details-pane::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    bottom: 4px;
    border: 1px solid #666;
    pointer-events: none;
}

.metadata h2 {
    margin-top: 0;
    color: #333;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 16px;
    font-size: 20px;
    font-weight: 600;
}

/* Industrial header styling for Image Details only - keep normal font */
.metadata:first-of-type h2,
.image-details-pane h2 {
    margin: 0 0 12px 0;
    color: #000;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 12px;
}

.info-label {
    font-weight: 600;
    color: #555;
    font-size: 14px;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    color: #333;
    font-size: 16px;
    font-weight: 500;
}

/* Industrial styling for Image Details data only - compact and monospace */
.metadata:first-of-type .info-grid,
.image-details-pane .info-grid {
    display: block;
    margin-top: 12px;
}

.metadata:first-of-type .info-item,
.image-details-pane .info-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    border-bottom: 1px dotted #666;
    margin-bottom: 2px;
    background: none;
    border-radius: 0;
}

.metadata:first-of-type .info-item:last-child,
.image-details-pane .info-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.metadata:first-of-type .info-label,
.image-details-pane .info-label {
    font-weight: 700;
    color: #000;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-family: 'Courier New', 'Consolas', monospace;
    flex-shrink: 0;
    margin-right: 12px;
    margin-bottom: 0;
}

.metadata:first-of-type .info-value,
.image-details-pane .info-value {
    color: #000;
    font-size: 11px;
    font-weight: 400;
    font-family: 'Courier New', 'Consolas', monospace;
    text-align: right;
    word-break: break-word;
}

.direct-link {
    margin-top: 20px;
    text-align: center;
}

.direct-link a {
    color: #007cba;
    text-decoration: none;
    font-weight: bold;
}

.direct-link a:hover {
    text-decoration: underline;
}

/* Image links section */
.image-links {
    margin-top: 25px;
    margin-bottom: 25px;
}

.image-links h3 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.1em;
}

.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.link-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.image-link {
    display: block;
    background: #007cba;
    color: white;
    text-decoration: none;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 8px;
    transition: background 0.3s ease;
    font-weight: 500;
    min-width: 120px;
}

.image-link:hover {
    background: #005a87;
}

.image-link:visited {
    background: #007cba;
    color: white;
}

.link-desc {
    font-size: 0.85em;
    color: #666;
}

/* Thumbnail grid for home page */
.recent-uploads {
    margin-top: 40px;
    width: 100%;
}

.recent-uploads h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
    font-size: 24px;
}

.thumbnail-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    width: 100%;
    margin: 0 auto;
    justify-content: center;
}

.thumbnail-item {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: 300px;
    flex-shrink: 0;
}

.thumbnail-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.thumbnail-item a {
    display: block;
    text-decoration: none;
    color: inherit;
}

.thumbnail-img {
    width: 100%;
    height: 300px;
    object-fit: cover;
    display: block;
}

.thumbnail-info {
    padding: 12px;
}

.thumbnail-name {
    font-size: 0.9em;
    color: #666;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* QR Modal */
.qr-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.qr-content {
    background: white;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    max-width: 400px;
}

.qr-content h3 {
    margin-top: 0;
}

.close-qr {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 15px;
}


/* Footer */
.site-footer {
    margin-top: 40px;
    padding: 20px;
    text-align: center;
    border-top: 1px solid #eee;
    color: #666;
    font-size: 0.9em;
}

.site-footer p {
    margin: 0;
}

/* Media queries */
@media (max-width: 800px) {
    .thumbnail-grid {
        gap: 15px;
    }

    .thumbnail-item {
        width: 240px;
    }

    .thumbnail-img {
        height: 240px;
    }
}

@media (max-width: 600px) {
    .info-grid {
        grid-template-columns: 1fr;
    }

    body.image {
        padding: 10px;
    }

    .image-container {
        padding: 15px;
        max-height: 50vh;
        margin-bottom: 25px;
        overflow: hidden;
    }

    .image-container img {
        max-width: calc(100vw - 50px);
        max-height: calc(50vh - 30px);
    }

    .metadata {
        padding: 15px;
    }

    .upload-area-small {
        padding: 20px;
    }

    .link-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 500px) {
    .thumbnail-grid {
        gap: 12px;
    }

    .thumbnail-item {
        width: 210px;
    }

    .thumbnail-img {
        height: 210px;
    }
}

/* Image Preview and Editing Styles */
.preview-area {
    margin: 20px 0;
    text-align: center;
}

.preview-image-container {
    border: 2px solid #ddd;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    background: #f9f9f9;
    display: inline-block;
}

.preview-image-container canvas {
    max-width: 100%;
    height: auto;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.edit-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

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

.btn-primary {
    background: #007cba;
    color: white;
}

.btn-primary:hover {
    background: #005a87;
}

.btn-tertiary {
    background: #dc3545;
    color: white;
}

.btn-tertiary:hover {
    background: #c82333;
}

/* Button sizing */
.btn-large {
    padding: 20px 36px;
    font-size: 20px;
    font-weight: 700;
    min-height: 60px;
    border-radius: 14px;
}

/* Select button container centering */
.select-button-container {
    text-align: center;
    margin-top: 20px;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    body {
        padding: 16px;
        font-size: 16px;
    }

    body.home {
        max-width: 95%;
        margin: 20px auto;
        padding: 24px;
    }

    .preview-image-container {
        padding: 20px;
        margin-bottom: 20px;
    }

    .edit-controls {
        gap: 12px;
        margin-bottom: 20px;
    }

    .btn {
        padding: 20px 28px;
        font-size: 18px;
        min-height: 56px;
        border-radius: 14px;
    }

    .btn-large {
        padding: 22px 32px;
        font-size: 20px;
        min-height: 64px;
        border-radius: 16px;
    }

    .action-btn {
        padding: 12px;
        font-size: 14px;
        margin: 6px;
        min-width: 44px;
        min-height: 44px;
        max-height: 44px;
        border-radius: 8px;
        box-sizing: border-box;
    }

    .action-btn.with-text {
        padding: 12px 16px;
        min-width: auto;
    }

    .upload-area {
        padding: 48px 24px;
        margin: 20px 0;
    }

    .upload-area-small {
        padding: 32px 20px;
    }

    .metadata {
        padding: 20px;
        margin-bottom: 20px;
    }

    .metadata h2 {
        font-size: 18px;
        padding-bottom: 12px;
    }

    .info-item {
        padding: 12px;
    }
}

/* iOS specific improvements */
@media (max-width: 768px) and (-webkit-min-device-pixel-ratio: 2) {
    .btn {
        min-height: 60px;
        font-size: 19px;
        padding: 22px 30px;
    }

    .btn-large {
        min-height: 68px;
        font-size: 21px;
        padding: 24px 36px;
    }

    .action-btn {
        min-height: 48px;
        max-height: 48px;
        font-size: 14px;
        padding: 14px;
        min-width: 48px;
        box-sizing: border-box;
    }

    .action-btn.with-text {
        padding: 14px 18px;
        min-width: auto;
    }

    body {
        font-size: 18px;
    }
}