* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #111;
    color: #eee;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Nav */
nav {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    gap: 20px;
}
.nav-title { font-weight: 700; font-size: 18px; }
.nav-links { display: flex; gap: 12px; flex: 1; }
.nav-links a {
    color: #888;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
}
.nav-links a.active { color: #fff; background: #333; }
#logout-btn {
    background: none;
    border: 1px solid #555;
    color: #aaa;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}
.login-form {
    background: #1a1a1a;
    padding: 40px;
    border-radius: 12px;
    width: 100%;
    max-width: 360px;
}
.login-form h1 { margin-bottom: 24px; font-size: 24px; }
.login-form input {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 16px;
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    color: #eee;
    font-size: 16px;
}
.login-form button {
    width: 100%;
    padding: 12px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
}
.login-form .error { color: #ef4444; margin-top: 12px; font-size: 14px; }

/* Gallery */
.gallery-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 20px;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
}
.gallery-controls input,
.gallery-controls select {
    padding: 8px 12px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #eee;
    font-size: 14px;
}
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 4px;
    padding: 4px;
}
.gallery-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
    background: #222;
}
.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.gallery-item .badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}
.gallery-item .selected {
    outline: 3px solid #2563eb;
}
.month-header {
    grid-column: 1 / -1;
    padding: 16px 12px 8px;
    font-size: 16px;
    font-weight: 600;
    color: #aaa;
}

/* Viewer overlay */
.viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.viewer-overlay img,
.viewer-overlay video {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
}
.viewer-close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 32px;
    color: #fff;
    cursor: pointer;
    background: none;
    border: none;
    z-index: 101;
}
.viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 48px;
    color: #fff;
    cursor: pointer;
    background: none;
    border: none;
    padding: 20px;
    z-index: 101;
}
.viewer-prev { left: 0; }
.viewer-next { right: 0; }

/* Upload */
.upload-container { padding: 20px; max-width: 800px; margin: 0 auto; }
.upload-dropzone {
    border: 2px dashed #444;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    margin-bottom: 20px;
}
.upload-dropzone.dragover { border-color: #2563eb; background: #1a1a3a; }
.upload-input-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 16px;
}
.upload-btn {
    display: inline-block;
    padding: 8px 20px;
    background: #2563eb;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    user-select: none;
}
.upload-btn:hover { background: #1d4ed8; }
.upload-summary {
    padding: 10px 0;
    font-size: 14px;
    color: #aaa;
    margin-bottom: 8px;
}
.upload-retry-btn {
    padding: 8px 20px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 12px;
}
.upload-retry-btn:hover { background: #b91c1c; }
.upload-list { list-style: none; }
.upload-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #1a1a1a;
    border-radius: 8px;
    margin-bottom: 8px;
}
.upload-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .progress-bar {
    width: 120px;
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
}
.upload-item .progress-bar .fill { height: 100%; background: #2563eb; transition: width 0.2s; }
.upload-item .status { font-size: 13px; color: #888; width: 80px; text-align: right; }

/* Tags */
.tag-bar {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    background: #1a1a2a;
    border-bottom: 1px solid #333;
    align-items: center;
}
.tag-bar input {
    padding: 6px 10px;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: #eee;
}
.tag-bar button {
    padding: 6px 14px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.tag-pill {
    display: inline-block;
    background: #333;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 13px;
    margin: 2px;
}

/* Responsive */
@media (max-width: 600px) {
    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    nav { flex-wrap: wrap; }
}

/* ── View toggle ── */
.view-toggle { margin-left: auto; display: inline-flex; gap: 4px; }
.view-toggle button { background: #eee; color: #333; border: 1px solid #ccc; border-radius: 6px; padding: 6px 10px; cursor: pointer; }
.view-toggle button.active { background: #0066cc; color: #fff; border-color: #0066cc; }

/* ── Pager ── */
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 20px; }
.pager button { background: #0066cc; color: #fff; border: none; border-radius: 6px; padding: 8px 16px; cursor: pointer; font-size: 14px; }
.pager button:disabled { background: #ccc; cursor: default; }
.pager-info { color: #555; font-size: 14px; }

/* ── List view ── */
.gallery-list { list-style: none; margin: 0; padding: 0; }
.gallery-list .list-month { font-weight: 600; color: #444; background: #f3f3f3; padding: 8px 16px; margin-top: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid #eee; cursor: pointer; }
.list-item:hover { background: #f7f9fc; }
.list-item.selected { background: #e3f0ff; }
.list-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; flex-shrink: 0; background: #eee; }
.list-meta { display: flex; flex-direction: column; min-width: 0; }
.list-name { font-size: 14px; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 12px; color: #888; }

/* ── Library total count ── */
.gallery-summary { padding: 8px 16px 0; color: #555; font-size: 13px; }

/* ── Pull-to-refresh indicator ── */
.ptr-indicator {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%) translateY(-40px);
    opacity: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    font-size: 13px;
    color: #555;
    pointer-events: none;
    will-change: transform, opacity;
}
.ptr-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #cbd5e1;
    border-top-color: #2563eb;
    border-radius: 50%;
}
.ptr-indicator.armed .ptr-spinner { border-top-color: #16a34a; }
.ptr-indicator.spinning .ptr-spinner { animation: ptr-spin 0.7s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }
