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

:root {
    --bg: #0a0a0a;
    --surface: #1a1a1a;
    --surface2: #2a2a2a;
    --text: #e0e0e0;
    --text-muted: #888;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --radius: 8px;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.2s;
    color: var(--text);
    background: var(--surface2);
}

.btn:active { opacity: 0.8; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 14px; }
.btn-block { display: block; width: 100%; }

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.login-container h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.login-form .form-group {
    margin-bottom: 16px;
}

.login-form input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--surface2);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.login-form input:focus {
    border-color: var(--primary);
}

.alert {
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.alert.error {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    background: var(--surface);
    border-bottom: 1px solid var(--surface2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 18px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.username {
    color: var(--text-muted);
    font-size: 14px;
}

/* Settings panel */
.settings-panel {
    background: var(--surface);
    border-bottom: 1px solid var(--surface2);
    padding: 16px;
}

.settings-content h3 {
    margin-bottom: 8px;
}

.retention-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 12px 0;
}

.retention-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}

.retention-input {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
}

.input-field {
    padding: 8px 12px;
    border: 1px solid var(--surface2);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.input-field:focus {
    border-color: var(--primary);
}

.retention-field {
    width: 80px;
    text-align: center;
}

.retention-label {
    font-size: 14px;
    color: var(--text-muted);
}

.retention-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Upload area */
.upload-area {
    padding: 24px 16px;
    text-align: center;
    border-bottom: 1px solid var(--surface2);
    transition: background 0.2s;
}

.upload-area.drag-over {
    background: rgba(59, 130, 246, 0.1);
}

.btn-upload {
    padding: 14px 32px;
    font-size: 17px;
}

.hint {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 8px;
}

/* Upload progress */
.upload-progress {
    padding: 12px 16px;
    background: var(--surface);
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--surface2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0;
    transition: width 0.3s;
}

#progress-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    gap: 8px;
    border-bottom: 1px solid var(--surface2);
    flex-wrap: wrap;
}

.toolbar-left {
    flex: 1;
    min-width: 0;
}

.photo-count-text {
    font-size: 13px;
    color: var(--text-muted);
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.date-field {
    width: 130px;
    padding: 5px 8px;
    font-size: 13px;
    color-scheme: dark;
}

.sort-btn {
    white-space: nowrap;
    font-size: 13px !important;
    padding: 5px 8px !important;
}

/* Date header */
.date-header {
    padding: 10px 16px 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg);
    position: sticky;
    top: 52px;
    z-index: 10;
}

/* Photo grid */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 0 2px 2px;
}

@media (min-width: 768px) {
    .photo-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1024px) {
    .photo-grid { grid-template-columns: repeat(6, 1fr); }
}

.photo-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--surface);
    cursor: pointer;
}

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

.photo-item:active img {
    transform: scale(0.95);
}

.photo-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 6px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    font-size: 11px;
    display: flex;
    justify-content: space-between;
    opacity: 0;
    transition: opacity 0.2s;
}

.photo-item:hover .photo-info {
    opacity: 1;
}

/* Video play badge */
.video-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 18px;
    line-height: 40px;
    text-align: center;
    pointer-events: none;
    z-index: 1;
}

.photo-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.photo-size {
    color: var(--text-muted);
    margin-left: 4px;
    flex-shrink: 0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state p:first-child {
    font-size: 18px;
    margin-bottom: 8px;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 20px 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
}

.page-info {
    color: var(--text-muted);
    font-size: 14px;
}

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    font-size: 14px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lightbox-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.lightbox-body img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.lightbox-footer {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
}

/* Disk usage */
.disk-info {
    margin: 8px 0;
}

.disk-bar {
    width: 100%;
    height: 8px;
    background: var(--surface2);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}

.disk-fill {
    height: 100%;
    background: #22c55e;
    transition: width 0.5s;
    border-radius: 4px;
}

.disk-fill.disk-warn { background: #f59e0b; }
.disk-fill.disk-danger { background: var(--danger); }

#disk-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* Upload buttons */
.upload-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-folder {
    background: var(--surface2);
}

/* Batch action bar */
.batch-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--primary);
    color: #fff;
    position: sticky;
    top: 52px;
    z-index: 99;
}

#batch-count {
    font-size: 14px;
    font-weight: 600;
}

.batch-actions {
    display: flex;
    gap: 8px;
}

.batch-bar .btn {
    color: #fff;
    background: rgba(255,255,255,0.2);
}

.batch-bar .btn-danger {
    background: var(--danger);
}

.batch-bar .btn-ghost {
    background: transparent;
}

/* Select checkbox overlay - always visible, large tap target */
.select-check {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2.5px solid rgba(255,255,255,0.8);
    background: rgba(0,0,0,0.35);
    color: transparent;
    font-size: 18px;
    line-height: 31px;
    text-align: center;
    z-index: 2;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.select-check:active {
    transform: scale(0.9);
}

.select-check.checked {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.photo-item.selected {
    outline: 3px solid var(--primary);
    outline-offset: -3px;
}

.photo-item.selected img {
    opacity: 0.7;
}

/* Back button */
.back-btn {
    font-size: 18px;
    margin-right: 4px;
    text-decoration: none;
}

/* Folder section */
.folder-section {
    border-bottom: 1px solid var(--surface2);
}

.folder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 4px;
}

.section-title {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.folder-list {
    display: flex;
    flex-direction: column;
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text);
    border-bottom: 1px solid var(--surface2);
    transition: background 0.15s;
}

.folder-item:active {
    background: var(--surface);
}

.folder-icon {
    font-size: 20px;
}

.folder-name {
    flex: 1;
    font-size: 15px;
}

.folder-count {
    color: var(--text-muted);
    font-size: 13px;
}

.folder-menu-btn {
    padding: 4px 8px;
    font-size: 16px;
}

/* Move dialog */
.move-dialog-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 340px;
    max-height: 60vh;
    overflow-y: auto;
}

.move-dialog-content h3 {
    margin-bottom: 12px;
}

.move-folder-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.move-folder-option {
    display: block;
    width: 100%;
    padding: 12px 14px;
    text-align: left;
    background: var(--surface2);
    border: none;
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
}

.move-folder-option:active {
    background: var(--primary);
    color: #fff;
}

/* Per-file upload progress */
.file-progress-list {
    margin-top: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.file-progress-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--surface2);
}

.fp-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 8px;
}

.fp-status {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
}

.fp-pending { color: var(--text-muted); }
.fp-uploading { color: var(--primary); }
.fp-done { color: #22c55e; }
.fp-fail { color: var(--danger); }
