/* ══════════════════════════════════════════════════════════════════
   GALLERY APP  –  Mobile-first styles
   Palette: purple-indigo gradient (#6C63FF → #A78BFA) + neutrals
   ══════════════════════════════════════════════════════════════════ */

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

:root {
    --primary: #6C63FF;
    --primary-dark: #5548e8;
    --primary-soft: #ede9fe;
    --accent: #A78BFA;
    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;

    --bg: #f5f4ff;
    --surface: #ffffff;
    --surface2: #f0eeff;
    --border: #e4e1ff;

    --txt-main: #1e1b4b;
    --txt-sub: #6b7280;
    --txt-hint: #a5b4fc;

    --nav-h: 64px;
    --header-h: 56px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 2px 8px rgba(108, 99, 255, 0.10);
    --shadow-md: 0 6px 24px rgba(108, 99, 255, 0.16);
    --shadow-lg: 0 12px 40px rgba(108, 99, 255, 0.22);

    --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    -webkit-text-size-adjust: 100%;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    background: var(--bg);
    color: var(--txt-main);
    height: 100%;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ────────────────────────────────────────────────────── */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    z-index: 100;
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-shadow: var(--shadow-md);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.header-logo {
    width: 30px;
    height: 30px;
    color: #fff;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.header-logo svg {
    width: 100%;
    height: 100%;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.3px;
}

/* ── Main scrollable area ───────────────────────────────────────── */
.app-main {
    position: fixed;
    top: var(--header-h);
    bottom: var(--nav-h);
    left: 0;
    right: 0;
    overflow: hidden;
}

/* ── Pages ──────────────────────────────────────────────────────── */
.page {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px 24px;
    opacity: 0;
    transform: translateY(18px);
    pointer-events: none;
    transition: opacity var(--transition), transform var(--transition);
    -webkit-overflow-scrolling: touch;
}

.page.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* ── Drop zone ──────────────────────────────────────────────────── */
.drop-zone {
    position: relative;
    background: var(--surface);
    border: 2.5px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), transform var(--transition);
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.drop-zone:active {
    transform: scale(0.98);
}

.drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: var(--shadow-md);
}

.drop-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-soft), var(--border));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    margin-bottom: 6px;
}

.drop-icon svg {
    width: 30px;
    height: 30px;
}

.drop-label {
    font-size: 16px;
    font-weight: 600;
    color: var(--txt-main);
}

.drop-hint {
    font-size: 12px;
    color: var(--txt-sub);
    text-align: center;
    line-height: 1.5;
}

.file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

/* ── Section title ──────────────────────────────────────────────── */
.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 22px 2px 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--txt-sub);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge {
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 99px;
    padding: 1px 7px;
    min-width: 20px;
    text-align: center;
}

/* ── Preview grid (before upload) ──────────────────────────────── */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.preview-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    aspect-ratio: 1;
    background: var(--surface2);
    box-shadow: var(--shadow-sm);
}

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

.preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, 0.55);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}

/* ── Upload action button ───────────────────────────────────────── */
.upload-action {
    margin-top: 20px;
    display: flex;
    justify-content: center;
}

/* ── Progress list ──────────────────────────────────────────────── */
.progress-list {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.progress-item {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.progress-file-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.progress-filename {
    font-size: 13px;
    font-weight: 500;
    color: var(--txt-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70%;
}

.progress-percent {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}

.progress-track {
    width: 100%;
    height: 6px;
    background: var(--surface2);
    border-radius: 99px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width 0.25s ease;
}

.progress-item.done .progress-fill {
    background: var(--success);
    width: 100% !important;
}

.progress-item.error .progress-fill {
    background: var(--error);
}

.progress-status {
    font-size: 11px;
    margin-top: 6px;
    color: var(--txt-sub);
}

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

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

/* ── Image grid wrapper ────────────────────────────────────────────── */
.image-grid {
    display: flex;
    flex-direction: column;
}

/* ── Date group ───────────────────────────────────────────────────── */
.date-group {
    margin-bottom: 4px;
}

.date-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--txt-sub);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 14px 2px 8px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 5;
}

/* ── Masonry grid per date ───────────────────────────────────────────── */
.date-masonry {
    columns: 2;
    column-gap: 8px;
}

/* skeleton loading strip */
.grid-loading-wrap {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.img-card {
    break-inside: avoid;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface2);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    -webkit-tap-highlight-color: transparent;
    display: block;
}

.img-card:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-md);
}

.img-card img {
    width: 100%;
    height: auto;
    max-height: 220px;
    object-fit: cover;
    display: block;
    border-radius: var(--radius-sm);
}

/* ── Download popup ─────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 40, 0.55);
    z-index: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    transform: translateY(40px);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
}

.modal-backdrop.open .modal-card {
    transform: translateY(0);
}

.modal-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 99px;
    margin: 12px auto 0;
    flex-shrink: 0;
}

.modal-body {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px 14px;
}

.modal-file-icon {
    width: 44px;
    height: 44px;
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    flex-shrink: 0;
}
.modal-file-icon svg { width: 22px; height: 22px; }

.modal-filename {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--txt-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.modal-actions {
    display: flex;
    gap: 10px;
    padding: 0 20px;
}

.modal-cancel { flex: 1; }

#modalDownloadBtn {
    text-decoration: none;
    flex: 2;
    justify-content: center;
}

/* ── Skeleton loading ───────────────────────────────────────────── */
.grid-loading {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.skeleton-card {
    border-radius: var(--radius-sm);
    aspect-ratio: 1;
    background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.load-sentinel {
    height: 1px;
    width: 100%;
}

/* ── Empty state ───────────────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 24px;
    gap: 12px;
    color: var(--txt-sub);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--border);
}

.empty-state p {
    font-size: 16px;
    font-weight: 600;
}

.empty-state span {
    font-size: 13px;
}

/* ── Bottom navigation ──────────────────────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    z-index: 200;
    box-shadow: 0 -4px 20px rgba(108, 99, 255, 0.08);
    /* Safe area for notched phones */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--txt-sub);
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
    padding: 0 0 2px;
    position: relative;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 40px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
    transition: transform var(--transition);
}

.nav-item.active::before {
    transform: translateX(-50%) scaleX(1);
}

.nav-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition);
}

.nav-icon svg {
    width: 100%;
    height: 100%;
}

.nav-item.active .nav-icon {
    transform: scale(1.12);
}

.nav-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 28px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
    -webkit-tap-highlight-color: transparent;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.btn-primary svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-primary:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-sm);
}

.btn-primary:disabled {
    opacity: 0.45;
    pointer-events: none;
}

.btn-primary.btn-sm {
    padding: 9px 16px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.btn-primary.btn-sm svg {
    width: 15px;
    height: 15px;
}

.btn-ghost {
    background: none;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.btn-ghost:active {
    background: var(--primary-soft);
}

/* ── Toast ──────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: calc(var(--nav-h) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    width: calc(100% - 32px);
    max-width: 380px;
}

.toast {
    background: var(--txt-main);
    color: #fff;
    border-radius: var(--radius-md);
    padding: 13px 18px;
    font-size: 14px;
    font-weight: 500;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 4px solid var(--accent);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--error);
}

.toast.warning {
    border-left-color: var(--warning);
}

.toast.hide {
    animation: toastOut 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(10px);
    }
}

/* ── Utility ────────────────────────────────────────────────────── */
.hidden {
    display: none !important;
}