/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-error: #dc2626;
    --color-success: #16a34a;
    --color-overlay: rgba(0, 0, 0, 0.85);
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
    --min-touch: 44px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== Utilities ===== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--min-touch);
    min-height: var(--min-touch);
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
}

.btn-small {
    min-height: var(--min-touch);
    min-width: var(--min-touch);
    padding: 8px 14px;
    font-size: 0.875rem;
}

/* ===== Form Elements ===== */
.input-field,
.select-field {
    width: 100%;
    min-height: var(--min-touch);
    padding: 10px 14px;
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    -webkit-appearance: none;
    appearance: none;
}

.input-field:focus,
.select-field:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-color: var(--color-primary);
}

.select-field {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 4 3.5-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

/* ===== Screens ===== */
.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* ===== Login Screen ===== */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

#login-screen:not(.active) {
    display: none;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 32px 24px;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--color-text-muted);
    margin-bottom: 24px;
    font-size: 0.9375rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.error-message {
    color: var(--color-error);
    font-size: 0.875rem;
    margin-top: 4px;
}

/* ===== App Header ===== */
.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-title {
    font-size: 1.125rem;
    font-weight: 700;
    margin-right: auto;
}

/* ===== Tab Navigation ===== */
.tab-nav {
    display: flex;
    gap: 4px;
}

.tab-btn {
    min-width: var(--min-touch);
    min-height: var(--min-touch);
    padding: 8px 16px;
    font-size: 0.9375rem;
    font-weight: 500;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.tab-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.tab-btn.active {
    background: var(--color-primary);
    color: #fff;
}

/* ===== Tab Panels ===== */
.tab-panel {
    display: none;
    padding: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

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

/* ===== Upload Area ===== */
.upload-area {
    max-width: 600px;
    margin: 0 auto;
}

.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 24px;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    text-align: center;
    transition: border-color 0.2s, background-color 0.2s;
}

.drop-zone.drag-over {
    border-color: var(--color-primary);
    background: rgba(37, 99, 235, 0.05);
}

.drop-zone-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--color-text);
}

.drop-zone-subtext {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.drop-zone-info {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    margin-top: 8px;
}

.file-select-btn {
    cursor: pointer;
}

/* ===== Upload Queue ===== */
.upload-queue {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upload-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.upload-item-name {
    flex: 1;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-item-progress {
    width: 80px;
    height: 6px;
    background: var(--color-border);
    border-radius: 3px;
    overflow: hidden;
}

.upload-item-progress-bar {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.3s;
}

.upload-item-status {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    min-width: 48px;
    text-align: right;
}

.upload-item-status.success {
    color: var(--color-success);
}

.upload-item-status.error {
    color: var(--color-error);
}

.upload-submit-btn {
    margin-top: 16px;
    width: 100%;
}

/* ===== Upload Progress (Task 4.7) ===== */
.upload-progress-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.upload-progress-item .upload-item-name {
    flex: 1;
    min-width: 100px;
}

.upload-progress-bar-container {
    width: 120px;
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}

.upload-progress-bar {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    transition: width 0.2s ease;
}

.upload-progress-text {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    min-width: 36px;
    text-align: right;
}

.upload-progress-status {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    width: 100%;
    margin-top: 4px;
}

.upload-progress-item.upload-complete .upload-progress-bar {
    background: var(--color-success);
}

.upload-progress-item.upload-complete .upload-progress-status {
    color: var(--color-success);
    font-weight: 500;
}

.upload-progress-item.upload-failed .upload-progress-bar {
    background: var(--color-error);
}

.upload-progress-item.upload-failed .upload-progress-status {
    color: var(--color-error);
}

@media (min-width: 768px) {
    .upload-progress-item {
        flex-wrap: nowrap;
    }

    .upload-progress-status {
        width: auto;
        margin-top: 0;
        min-width: 180px;
    }
}

/* ===== Gallery ===== */
.gallery-controls {
    margin-bottom: 16px;
}

.filter-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-group .select-field {
    width: auto;
    min-width: 120px;
    flex: 1;
    max-width: 200px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

@media (min-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
}

@media (min-width: 1025px) {
    .gallery-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--color-border);
    cursor: pointer;
}

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

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

.gallery-item-date {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: #fff;
    font-size: 0.75rem;
    text-align: center;
}

.gallery-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 64px 24px;
    text-align: center;
    color: var(--color-text-muted);
}

.gallery-load-more {
    display: flex;
    justify-content: center;
    padding: 24px 0;
}

/* ===== Lightbox ===== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--color-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox[hidden] {
    display: none;
}

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

.lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-btn {
    position: absolute;
    min-width: var(--min-touch);
    min-height: var(--min-touch);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1001;
    transition: background-color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-close-btn {
    top: 16px;
    right: 16px;
    font-size: 2rem;
}

.lightbox-nav-btn {
    top: 50%;
    transform: translateY(-50%);
    font-size: 2.5rem;
}

.lightbox-prev-btn {
    left: 16px;
}

.lightbox-next-btn {
    right: 16px;
}

.lightbox-loading,
.lightbox-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    text-align: center;
}

.lightbox-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* ===== Responsive Adjustments ===== */

/* Small phones (320px minimum) */
@media (max-width: 374px) {
    .app-header {
        padding: 8px 12px;
    }

    .app-title {
        font-size: 1rem;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 0.875rem;
    }

    .tab-panel {
        padding: 12px;
    }

    .drop-zone {
        padding: 32px 16px;
    }

    .login-container {
        padding: 24px 16px;
    }
}

/* Tablet and up */
@media (min-width: 768px) {
    .drop-zone {
        padding: 64px 32px;
    }

    .tab-panel {
        padding: 24px;
    }

    .login-container {
        padding: 40px 32px;
    }

    .filter-group .select-field {
        flex: 0;
    }
}

/* Large desktop */
@media (min-width: 1440px) {
    .tab-panel {
        padding: 32px;
    }

    .gallery-grid {
        gap: 20px;
    }
}

/* Ensure no horizontal overflow at any viewport */
#app {
    overflow-x: hidden;
    width: 100%;
    min-width: 320px;
}
