/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
    --blue:        #2563EB;
    --blue-hover:  #1D4ED8;
    --bg:          #F8F9FB;
    --surface:     #FFFFFF;
    --border:      #E5E7EB;
    --text:        #111827;
    --muted:       #6B7280;
    --error:       #DC2626;
    --error-bg:    #FEF2F2;
    --radius:      10px;
    --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

html { font-size: 16px; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

img { display: block; max-width: 100%; }

/* ── Navbar ───────────────────────────────────────────────────────────────── */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
    text-decoration: none;
}

.navbar-brand:hover { text-decoration: none; }

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.navbar-user {
    font-size: .875rem;
    color: var(--muted);
}

.nav-link {
    font-size: .875rem;
    color: var(--muted);
}

.nav-link:hover { color: var(--text); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background .15s, opacity .15s;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--blue-hover);
    color: #fff;
    text-decoration: none;
}

.btn-sm { padding: 6px 14px; font-size: .8125rem; }

.btn-full { width: 100%; }

.btn-link {
    background: none;
    border: none;
    color: var(--muted);
    font-size: .875rem;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
}

.btn-link:hover { color: var(--text); }

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,.95);
    color: var(--text);
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
    font-family: inherit;
}

.btn-download:hover {
    background: #fff;
    transform: scale(1.02);
}

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: .875rem;
    margin-bottom: 20px;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #FECACA;
}

/* ── Auth / Upload pages ──────────────────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 61px - 48px);
    padding: 32px 16px;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-logo {
    margin-bottom: 24px;
}

.auth-title {
    font-size: 1.375rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.auth-sub {
    text-align: center;
    color: var(--muted);
    font-size: .9375rem;
    margin-bottom: 28px;
}

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

.auth-alt {
    margin-top: 20px;
    text-align: center;
    font-size: .875rem;
    color: var(--muted);
}

/* ── Form elements ────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
    font-size: .875rem;
    font-weight: 500;
    color: var(--text);
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .9375rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.otp-input {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: 8px;
    text-align: center;
}

/* ── File upload ──────────────────────────────────────────────────────────── */
.upload-card { max-width: 480px; }

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

.upload-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 36px 24px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    color: var(--muted);
    font-size: .9375rem;
    text-align: center;
}

.upload-drop:hover, .upload-drop.dragover {
    border-color: var(--blue);
    background: rgba(37,99,235,.03);
}

.upload-drop.has-file {
    border-color: #10B981;
    background: rgba(16,185,129,.04);
    color: var(--text);
    padding: 12px;
}

.upload-hint { font-size: .8125rem; color: var(--muted); }

.photo-preview {
    display: none;
    width: 100%;
    max-height: 280px;
    object-fit: contain;
    border-radius: 6px;
}

.upload-drop.has-file .photo-preview { display: block; }
.upload-drop.has-file #upload-icon,
.upload-drop.has-file .upload-hint  { display: none; }

.upload-input { display: none; }

.upload-alt {
    margin-top: 16px;
    text-align: center;
    font-size: .8125rem;
    color: var(--muted);
}

/* ── Gallery page ─────────────────────────────────────────────────────────── */
.gallery-page { padding-bottom: 64px; }

/* ── Collection tabs ──────────────────────────────────────────────────────── */
.gallery-tabs {
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 60px;
    z-index: 91;
}

.gallery-tabs::-webkit-scrollbar { display: none; }

.gallery-tabs-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 0;
    justify-content: flex-start;
}

.gallery-tab {
    flex-shrink: 0;
    padding: 10px 20px;
    border-radius: 0;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
    margin-bottom: -1px;
}

.gallery-tab:hover {
    color: var(--blue);
    border-bottom-color: #bfdbfe;
}

.gallery-tab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
    font-weight: 600;
}

.filter-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
    position: sticky;
    top: 98px;
    z-index: 90;
}

.filter-bar-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.filters { display: flex; gap: 10px; }

.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .875rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--blue);
}

.size-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.size-slider {
    width: 120px;
    accent-color: var(--blue);
    cursor: pointer;
}

@media (min-width: 768px) {
    .size-slider { width: 200px; }
}


.gallery-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 28px 24px 0;
}

.gallery-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 20px;
}

.gallery-title {
    font-size: 1.125rem;
    font-weight: 600;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.gallery-ratio {
    font-size: .8125rem;
    font-weight: 400;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 10px;
}

.gallery-count {
    font-size: .875rem;
    color: var(--muted);
}

/* ── Template grid ────────────────────────────────────────────────────────── */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--thumb-size, 260px), 1fr));
    gap: 18px;
}

.template-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.template-card[data-hidden="1"] { display: none; }

.template-preview {
    position: relative;
    aspect-ratio: 4 / 5;
    border-radius: var(--radius);
    overflow: hidden;
    background: #E5E7EB;
    cursor: pointer;
}

.preview-photo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.preview-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.35);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .18s;
}

.template-preview:hover .preview-overlay,
.template-card.overlay-active .preview-overlay { opacity: 1; }

/* ── Download loading overlay ─────────────────────────────────────────────── */
.download-loading {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.download-loading.hidden { display: none; }

.download-loading-box {
    background: var(--surface);
    border-radius: 14px;
    padding: 40px 48px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.download-loading-box p { font-weight: 500; }
.loading-sub { font-size: .875rem; color: var(--muted); font-weight: 400; }

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile image-view page ───────────────────────────────────────────────── */
.image-view-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 48px;
    gap: 20px;
}

.image-view-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px 0;
    color: var(--muted);
    font-size: .9375rem;
}

.image-view-img {
    width: 100%;
    max-width: 480px;
    border-radius: 12px;
    display: block;
    opacity: 0;
}

.image-view-img.loaded { opacity: 1; }

.image-view-hint {
    font-size: .9375rem;
    color: var(--muted);
    text-align: center;
    max-width: 320px;
    line-height: 1.5;
    visibility: hidden;
}

.image-view-hint.visible { visibility: visible; }

/* ── Login nudge banner ───────────────────────────────────────────────────── */
.login-nudge {
    max-width: 1440px;
    margin: 32px auto 0;
    padding: 0 24px;
}

.login-nudge p {
    background: #EFF6FF;
    border: 1px solid #BFDBFE;
    border-radius: 10px;
    padding: 14px 18px;
    font-size: .9375rem;
    color: #1E40AF;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* ── History / submission list ────────────────────────────────────────────── */
.submission-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--border);
}

.submission-row {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    padding: 14px 18px;
    text-decoration: none;
    color: var(--text);
    transition: background .12s;
}

.submission-row:hover { background: var(--bg); }

.submission-thumb {
    width: 52px;
    height: 65px; /* 4:5 */
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg);
}

.submission-thumb img { width: 100%; height: 100%; object-fit: cover; }

.submission-thumb--empty { background: var(--border); }

.submission-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.method-badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 20px;
    width: fit-content;
}

.method-email { background: #DBEAFE; color: #1D4ED8; }
.method-text  { background: #D1FAE5; color: #065F46; }
.method-web   { background: #F3F4F6; color: #374151; }

.submission-id {
    font-size: .8125rem;
    color: var(--muted);
    font-family: monospace;
    letter-spacing: .5px;
}

.submission-arrow { flex-shrink: 0; }

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

/* ── Footer ───────────────────────────────────────────────────────────────── */
.footer {
    border-top: 1px solid var(--border);
    padding: 16px 24px;
    text-align: center;
    font-size: .8125rem;
    color: var(--muted);
    background: var(--surface);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .auth-card { padding: 28px 24px; }
    .template-grid { grid-template-columns: repeat(var(--cols, 2), 1fr); gap: 12px; }
    .filter-bar-inner { gap: 8px; }
    .filters { flex-wrap: wrap; }
    .gallery-tabs-inner { justify-content: center; }
    .navbar-inner { justify-content: center; }
}
