* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-color: #f5f5f5;
    --text-color: #333;
    --accent-color: #4a90e2;
    --lightbox-bg: rgba(0, 0, 0, 0.95);
    --border-color: #ddd;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: 100vh;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 2px;
    color: var(--text-color);
    word-break: break-word;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 4rem 0;
}

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

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

.empty-state {
    text-align: center;
    padding: 4rem 0;
    color: #999;
    font-size: 1.2rem;
}

/* Gallery Grid */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* Improve gallery item touch targets on mobile */
.gallery-item {
    touch-action: manipulation;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    aspect-ratio: 1;
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

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

/* Lightbox */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--lightbox-bg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-controls {
    margin-top: 1.5rem;
    text-align: center;
}

.download-btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--accent-color);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 1rem;
    transition: background 0.3s ease;
}

.download-btn:hover {
    background: #357abd;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 3rem;
    color: white;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.lightbox-close:hover {
    transform: scale(1.2);
}

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

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

.lightbox-prev {
    left: 30px;
}

.lightbox-next {
    right: 30px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem 0.75rem;
    }
    
    header {
        margin-bottom: 2rem;
    }
    
    header h1 {
        font-size: 1.75rem;
        letter-spacing: 1px;
        padding: 0 0.5rem;
    }
    
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 0.75rem;
    }
    
    .gallery-item {
        border-radius: 6px;
    }
    
    .empty-state {
        padding: 2rem 1rem;
        font-size: 1rem;
    }
    
    .loading {
        padding: 2rem 0;
    }
    
    .loading p {
        font-size: 0.9rem;
    }
    
    /* Lightbox mobile improvements */
    .lightbox-content {
        max-width: 95vw;
        max-height: 95vh;
        padding: 0 0.5rem;
    }
    
    .lightbox-content img {
        max-height: 80vh;
    }
    
    .lightbox-controls {
        margin-top: 1rem;
        width: 100%;
    }
    
    .download-btn {
        padding: 0.875rem 1.25rem;
        font-size: 0.95rem;
        min-height: 44px; /* Touch target size */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .lightbox-nav {
        font-size: 2rem;
        padding: 0.875rem 1rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .lightbox-prev {
        left: 5px;
    }
    
    .lightbox-next {
        right: 5px;
    }
    
    .lightbox-close {
        top: 10px;
        right: 10px;
        font-size: 2.5rem;
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .container {
        padding: 0.75rem 0.5rem;
    }
    
    header {
        margin-bottom: 1.5rem;
    }
    
    header h1 {
        font-size: 1.5rem;
        letter-spacing: 0.5px;
    }
    
    .gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .lightbox-prev {
        left: 0;
        padding: 0.75rem 0.5rem;
    }
    
    .lightbox-next {
        right: 0;
        padding: 0.75rem 0.5rem;
    }
    
    .lightbox-close {
        top: 5px;
        right: 5px;
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        font-size: 2rem;
    }
    
    .lightbox-content img {
        max-height: 75vh;
    }
}

/* Admin Pages */
.admin-container {
    max-width: 600px;
    margin: 4rem auto;
    padding: 2rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.1);
    position: relative;
}

@media (max-width: 768px) {
    .admin-container {
        margin: 2rem auto;
        padding: 1.5rem;
        border-radius: 0;
        box-shadow: none;
        min-height: calc(100vh - 4rem);
    }
}

@media (max-width: 480px) {
    .admin-container {
        margin: 1rem auto;
        padding: 1rem;
        min-height: calc(100vh - 2rem);
    }
}

.admin-container h1 {
    margin-bottom: 2rem;
    text-align: center;
    color: var(--text-color);
    font-size: 1.75rem;
    word-break: break-word;
}

@media (max-width: 480px) {
    .admin-container h1 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input {
    width: 100%;
    padding: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px; /* Touch target size for mobile */
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

@media (max-width: 480px) {
    .form-group input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

.btn {
    width: 100%;
    padding: 0.875rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s ease;
    min-height: 44px; /* Touch target size */
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover {
    background: #357abd;
}

.btn:active {
    transform: scale(0.98);
}

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

.error-message {
    color: #e74c3c;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.success-message {
    color: #27ae60;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

/* Upload Page */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 3rem;
    text-align: center;
    margin-bottom: 2rem;
    transition: border-color 0.3s ease, background 0.3s ease;
    cursor: pointer;
    touch-action: manipulation;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent-color);
    background: rgba(74, 144, 226, 0.05);
}

@media (max-width: 768px) {
    .upload-area {
        padding: 2rem 1.5rem;
    }
    
    .upload-area p {
        font-size: 0.95rem;
        margin: 0.5rem 0;
    }
}

@media (max-width: 480px) {
    .upload-area {
        padding: 1.5rem 1rem;
        margin-bottom: 1.5rem;
    }
    
    .upload-area p {
        font-size: 0.9rem;
    }
}

.upload-area input[type="file"] {
    display: none;
}

.upload-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}

@media (max-width: 480px) {
    .upload-preview {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-top: 1.5rem;
    }
}

.preview-item {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    aspect-ratio: 1;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .remove-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(231, 76, 60, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.preview-item .remove-btn:active {
    transform: scale(0.9);
}

.upload-progress {
    margin-top: 1rem;
    display: none;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--accent-color);
    transition: width 0.3s ease;
    width: 0%;
}

.logout-btn {
    position: fixed;
    top: 1rem;
    right: 1rem;
    padding: 0.625rem 1rem;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 80px;
    z-index: 100;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    font-size: 0.9rem;
}

.logout-btn:hover {
    background: #c0392b;
}

.logout-btn:active {
    transform: scale(0.95);
}

@media (max-width: 768px) {
    .logout-btn {
        top: 0.75rem;
        right: 0.75rem;
        padding: 0.5rem 0.875rem;
        font-size: 0.85rem;
        min-width: 70px;
    }
}

@media (max-width: 480px) {
    .logout-btn {
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        min-width: 65px;
        min-height: 36px;
    }
}

/* Admin Tabs */
.admin-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    color: #666;
    transition: all 0.3s ease;
    touch-action: manipulation;
    min-height: 44px;
}

.tab-btn:hover {
    color: var(--text-color);
    background: rgba(74, 144, 226, 0.05);
}

.tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    font-weight: 500;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    font-weight: 400;
}

@media (max-width: 480px) {
    .tab-btn {
        padding: 0.625rem 1rem;
        font-size: 0.9rem;
        flex: 1;
    }
    
    .tab-content h2 {
        font-size: 1.25rem;
    }
}

/* Manage Images Grid */
.images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.manage-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    aspect-ratio: 1;
}

.manage-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.manage-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.manage-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(231, 76, 60, 0.9);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    font-weight: 500;
}

.manage-item:hover .manage-overlay {
    opacity: 1;
}

.delete-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.manage-overlay span:not(.delete-icon) {
    font-size: 0.9rem;
}

@media (max-width: 480px) {
    .images-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .manage-overlay {
        opacity: 0.95;
        font-size: 0.85rem;
    }
    
    .delete-icon {
        font-size: 1.5rem;
    }
}