/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: #000;
    color: #222;
    overscroll-behavior: none;
}

a { color: #005bbb; }

/* ─── Login ─────────────────────────────────────────────────── */
.login-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: white;
    border-radius: 20px;
    padding: 28px 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.10);
}
.login-header { text-align: center; margin-bottom: 24px; }
.login-title { margin: 0; font-size: 32px; font-weight: 700; color: #111; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 8px; }
.form-field label { font-size: 14px; font-weight: 600; color: #333; }
.form-field input {
    width: 100%; padding: 14px; border: 1px solid #d9d9d9;
    border-radius: 12px; font-size: 16px; background: #fff; outline: none;
}
.form-field input:focus { border-color: #005bbb; box-shadow: 0 0 0 3px rgba(0,91,187,0.12); }
.login-submit-button {
    width: 100%; padding: 14px 16px; border: 0; border-radius: 12px;
    background: #005bbb; color: white; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 6px;
}
.login-submit-button:hover { opacity: 0.92; }
.form-error-box {
    background: #fdeaea; color: #a12626; border: 1px solid #f1c5c5;
    border-radius: 12px; padding: 12px 14px; font-size: 14px;
}
.field-error { color: #b42318; font-size: 13px; }
@media (max-width: 640px) {
    .login-page { align-items: flex-start; padding-top: 40px; }
    .login-card { border-radius: 18px; padding: 22px 18px; }
    .login-title { font-size: 28px; }
}

/* ─── Admin / form pages ─────────────────────────────────────── */
.admin-page { background: #f5f5f5; min-height: 100dvh; }

.app-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 10px 16px; background: white;
    box-shadow: 0 1px 0 rgba(0,0,0,0.08); position: sticky; top: 0; z-index: 10;
}
.app-toolbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-toolbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.app-toolbar-title {
    margin: 0; font-size: 18px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-icon-link { text-decoration: none; font-size: 20px; display: inline-flex; align-items: center; }
.app-icon-button {
    background: none; border: none; padding: 0; font-size: 20px;
    cursor: pointer; display: inline-flex; align-items: center; color: inherit;
}
.app-back-link { text-decoration: none; color: #005bbb; font-size: 22px; display: inline-flex; align-items: center; }
.app-username-link {
    text-decoration: none; color: #005bbb; font-size: 14px;
    max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-profile-icon { display: none; text-decoration: none; font-size: 20px; }
@media (max-width: 640px) {
    .app-username-link { display: none; }
    .app-profile-icon { display: inline-flex; align-items: center; }
}

.admin-content { padding: 20px 16px; }

.box {
    background: white; border-radius: 12px; padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08); margin-bottom: 20px;
}
.empty-box { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.simple-form-box { max-width: 600px; }
.medium-form-box { max-width: 700px; }

h1, h2 { margin-top: 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="file"] {
    width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 8px; font-size: 15px;
}
input[type="file"] { margin-bottom: 12px; }
form p { margin-bottom: 14px; }
textarea {
    width: 100%; min-height: 120px; padding: 10px; border: 1px solid #ccc;
    border-radius: 8px; resize: vertical; font-family: inherit; font-size: 14px;
}
button {
    padding: 10px 14px; border: 0; border-radius: 8px;
    background: #005bbb; color: white; cursor: pointer; font-size: 15px;
}
.danger-button { background: #c62828; }
.link-button {
    background: none; border: none; padding: 0; color: #005bbb;
    font-size: 14px; cursor: pointer; font-family: inherit;
}
.link-button:hover { text-decoration: underline; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eee; vertical-align: top; }
th { font-size: 14px; }
.yes { color: green; font-weight: bold; }
.no { color: #999; }
.errorlist { color: red; }

/* ─── Albums / folder list (iPhone dark style) ───────────────── */
.folder-list-page { background: #000; min-height: 100dvh; }

.albums-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 8px;
    background: #000;
    position: sticky;
    top: 0;
    z-index: 10;
}
.albums-header-left,
.albums-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 60px;
}
.albums-header-right { justify-content: flex-end; }
.albums-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: white;
    text-align: center;
    flex: 1;
}
.albums-header-icon {
    background: rgba(255,255,255,0.12);
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    text-decoration: none;
    cursor: pointer;
    color: white;
    padding: 0;
    font-family: inherit;
}
.albums-header-icon:active { opacity: 0.6; }

.albums-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 4px 0 32px;
}

.album-card {
    text-decoration: none;
    color: inherit;
    display: block;
}
.album-card:active .album-cover { opacity: 0.75; }

.album-cover {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: #1a1a1a;
    transition: opacity 0.15s;
}
.album-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.album-cover-empty {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #444;
}
.album-cover-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 32px 10px 10px;
    background: linear-gradient(to top, rgba(0,0,0,0.65) 0%, transparent 100%);
    color: white;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    word-break: break-word;
}
.album-cover-empty-label {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    color: #888;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    word-break: break-word;
}

@media (min-width: 600px) {
    .albums-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ─── Photo grid (iPhone reel) ───────────────────────────────── */
.photo-grid-page { background: #000; min-height: 100dvh; position: relative; }

.photo-reel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding-bottom: 88px;
}
.photo-reel-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
    background: #1a1a1a;
    -webkit-tap-highlight-color: transparent;
}
.photo-reel-item img {
    width: 100%; height: 100%; object-fit: cover; display: block;
}
.photo-reel-item:active { opacity: 0.75; }

/* FAB */
.fab-upload {
    position: fixed; bottom: 28px; right: 22px;
    width: 56px; height: 56px; border-radius: 50%;
    background: #005bbb; color: white; font-size: 28px;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 50; transition: transform 0.15s;
}
.fab-upload:active { transform: scale(0.9); }

/* upload sheet */
.upload-sheet-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    z-index: 200; display: flex; align-items: flex-end;
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.upload-sheet-overlay.open { opacity: 1; pointer-events: all; }
.upload-sheet {
    background: white; border-radius: 20px 20px 0 0;
    padding: 20px 20px 44px; width: 100%; position: relative;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
}
.upload-sheet-overlay.open .upload-sheet { transform: translateY(0); }
.upload-sheet-handle {
    width: 36px; height: 4px; background: #ccc; border-radius: 2px;
    margin: 0 auto 16px;
}
.upload-sheet h2 { margin: 0 0 16px; font-size: 18px; }
.upload-sheet-close {
    position: absolute; top: 14px; right: 16px;
    background: #eee; border: none; border-radius: 50%;
    width: 30px; height: 30px; font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; color: #555;
}
.progress-bar-wrapper {
    width: 100%; height: 8px; background: #e0e0e0;
    border-radius: 999px; overflow: hidden; margin-top: 12px;
}
.progress-bar-fill { width: 0%; height: 100%; background: #005bbb; transition: width 0.2s; }
#upload-progress-text { margin-top: 8px; font-size: 14px; color: #555; }

.reel-loader { color: #555; font-size: 13px; text-align: center; padding: 16px; }

/* ─── Fullscreen viewer ──────────────────────────────────────── */
.photo-viewer {
    position: fixed; inset: 0; background: #000;
    z-index: 100; display: flex; flex-direction: column;
    overflow: hidden; touch-action: none;
}
.photo-viewer.hidden { display: none; }

.viewer-swipe-track {
    flex: 1; display: flex; align-items: center;
    position: relative; overflow: visible;
}
.viewer-slide {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    will-change: transform;
    transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
    overflow: hidden;
}
.viewer-slide img {
    max-width: 100%; max-height: 100%;
    object-fit: contain; display: block;
    user-select: none; -webkit-user-drag: none; pointer-events: none;
}

.viewer-close {
    position: absolute;
    top: max(env(safe-area-inset-top, 0px), 12px);
    left: 16px; z-index: 10;
    background: rgba(0,0,0,0.5); border: none; border-radius: 50%;
    width: 36px; height: 36px; color: white; font-size: 20px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.viewer-counter {
    position: absolute;
    top: max(env(safe-area-inset-top, 0px), 12px);
    left: 50%; transform: translateX(-50%);
    z-index: 10; color: white; font-size: 13px; font-weight: 600;
    background: rgba(0,0,0,0.45); padding: 4px 10px;
    border-radius: 20px; white-space: nowrap;
}
.viewer-swipe-hint {
    position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
    color: rgba(255,255,255,0.55); font-size: 12px;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    pointer-events: none; z-index: 10;
    animation: hint-bounce 2.2s ease-in-out infinite;
}
.viewer-swipe-hint::before {
    content: ''; display: block; width: 28px; height: 3px;
    background: rgba(255,255,255,0.45); border-radius: 2px; margin-bottom: 2px;
}
@keyframes hint-bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.55; }
    50% { transform: translateX(-50%) translateY(-6px); opacity: 1; }
}

/* info panel */
.viewer-info-panel {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: rgba(16,16,16,0.97); border-radius: 20px 20px 0 0;
    padding: 12px 20px 44px; color: white;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
    z-index: 20; max-height: 72vh; overflow-y: auto; touch-action: pan-y;
}
.viewer-info-panel.open { transform: translateY(0); }
.viewer-info-handle {
    width: 36px; height: 4px; background: rgba(255,255,255,0.25);
    border-radius: 2px; margin: 0 auto 18px; cursor: grab;
}
.viewer-info-row {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 12px; margin-bottom: 12px;
}
.viewer-info-label { color: rgba(255,255,255,0.45); font-size: 13px; flex-shrink: 0; }
.viewer-info-value { color: white; font-size: 14px; text-align: right; word-break: break-word; }

.viewer-note-area { margin-top: 16px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 16px; }
.viewer-note-label { color: rgba(255,255,255,0.45); font-size: 13px; margin-bottom: 8px; }
.viewer-note-textarea {
    width: 100%; background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.14);
    border-radius: 10px; color: white; padding: 10px 12px; font-size: 14px;
    font-family: inherit; resize: none; min-height: 80px;
}
.viewer-note-textarea::placeholder { color: rgba(255,255,255,0.28); }
.viewer-note-textarea:focus { outline: none; border-color: rgba(255,255,255,0.3); }
.viewer-note-save {
    margin-top: 8px; background: #005bbb; color: white; border: none;
    border-radius: 10px; padding: 10px 16px; font-size: 14px; cursor: pointer; width: 100%;
}
.viewer-note-saved { color: #66bb6a; font-size: 13px; margin-top: 6px; text-align: center; display: none; }
.viewer-delete-btn {
    margin-top: 14px; background: rgba(198,40,40,0.18); color: #ff6b6b;
    border: 1px solid rgba(198,40,40,0.35); border-radius: 10px;
    padding: 10px 16px; font-size: 14px; cursor: pointer; width: 100%;
}

/* ─── Folder toolbar ─────────────────────────────────────────── */
.folder-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.folder-toolbar-back {
    color: white;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    min-width: 80px;
}
.folder-toolbar-back:active { opacity: 0.6; }
.folder-toolbar-title {
    color: white;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 8px;
}
.folder-toolbar-menu-wrap {
    position: relative;
    min-width: 80px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
}
.folder-toolbar-select {
    background: none;
    border: none;
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
}
.folder-toolbar-select:active { opacity: 0.6; }
.folder-toolbar-dots {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    letter-spacing: 2px;
}
.folder-toolbar-dots:active { opacity: 0.6; }
.folder-toolbar-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: rgba(30,30,30,0.97);
    border-radius: 12px;
    min-width: 190px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 100;
}
.folder-toolbar-dropdown.open { display: block; }
.folder-toolbar-dropdown a {
    display: block;
    padding: 13px 16px;
    color: white;
    text-decoration: none;
    font-size: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.folder-toolbar-dropdown a:last-child { border-bottom: none; }
.folder-toolbar-dropdown a:active { background: rgba(255,255,255,0.1); }
.folder-toolbar-dropdown a.danger { color: #ff6b6b; }

/* ─── Select mode ────────────────────────────────────────────── */
.select-bar {
    position: fixed !important;
    bottom: 0; left: 0; right: 0;
    background: rgba(16,16,16,0.97);
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 300;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.select-bar.hidden { display: none; }

#select-count {
    color: rgba(255,255,255,0.7);
    font-size: 14px;
}
.select-bar-delete {
    background: rgba(198,40,40,0.25);
    color: #ff6b6b;
    border: 1px solid rgba(198,40,40,0.4);
    border-radius: 10px;
    padding: 9px 20px;
    font-size: 14px;
    cursor: pointer;
}
.select-bar-delete:disabled { display: none; }

.photo-reel-item.selected::after {
    content: '✓';
    position: absolute;
    inset: 0;
    background: rgba(0, 91, 187, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
    font-weight: 700;
    box-shadow: inset 0 0 0 3px #005bbb;
}