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

:root {
    --bg: #ffffff; --bg2: #f5f5f4; --bg3: #efede8;
    --text: #1a1a18; --text2: #6b6b67; --text3: #aaa;
    --border: rgba(0,0,0,0.1); --border2: rgba(0,0,0,0.18);
    --radius: 8px; --radius-lg: 12px;
    --danger-bg: #fcebeb; --danger-text: #a32d2d; --danger-border: rgba(163,45,45,0.25);
    --info-bg: #e6f1fb; --info-text: #185fa5;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1c1c1a; --bg2: #252523; --bg3: #2c2c2a;
        --text: #f0ede8; --text2: #a0a09a; --text3: #666;
        --border: rgba(255,255,255,0.1); --border2: rgba(255,255,255,0.18);
        --danger-bg: #2a1212; --danger-text: #f09595; --danger-border: rgba(240,149,149,0.25);
        --info-bg: #0c1f33; --info-text: #85b7eb;
    }
}

body { font-family: system-ui, -apple-system, sans-serif; color: var(--text); background: var(--bg); font-size: 15px; line-height: 1.6; }

a { color: inherit; text-decoration: none; }

#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 0.5px solid var(--border); flex-wrap: wrap; background: var(--bg); }
.toolbar h1 { font-size: 15px; font-weight: 500; flex: 1; min-width: 100px; }

.btn { background: transparent; border: 0.5px solid var(--border2); border-radius: var(--radius); padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--text); transition: background 0.12s; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--bg2); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: 0.85; }
.btn.danger { color: var(--danger-text); border-color: var(--danger-border); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { padding: 4px 10px; font-size: 12px; }

.view-tabs { display: flex; gap: 4px; }
.tab { background: transparent; border: none; cursor: pointer; padding: 6px 10px; font-size: 13px; color: var(--text2); border-radius: var(--radius); transition: background 0.12s; }
.tab.active { background: var(--bg2); color: var(--text); font-weight: 500; }
.tab:hover { background: var(--bg2); }

.main { display: flex; flex: 1; overflow: hidden; }

.sidebar { width: 220px; min-width: 220px; border-right: 0.5px solid var(--border); padding: 12px 0; overflow-y: auto; background: var(--bg); }
.sidebar-label { font-size: 10px; color: var(--text3); padding: 6px 16px 4px; text-transform: uppercase; letter-spacing: 0.06em; white-space: normal; overflow: visible; word-break: break-word; }

.source-item { display: flex; align-items: center; justify-content: space-between; padding: 7px 12px; cursor: pointer; border-radius: var(--radius); margin: 1px 6px; transition: background 0.1s; gap: 4px; }
.source-item:hover { background: var(--bg2); }
.source-item.active { background: var(--bg2); }
.gallery-link { font-size: 14px; color: var(--text3); padding: 2px 4px; border-radius: 4px; transition: background 0.1s, color 0.1s; flex-shrink: 0; }
.gallery-link:hover { background: var(--bg3); color: var(--text); }

.src-count { font-size: 11px; color: var(--text2); background: var(--bg3); padding: 2px 7px; border-radius: 10px; }

.content { flex: 1; padding: 16px 20px; overflow-y: auto; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 280px; gap: 12px; color: var(--text2); }
.icon { font-size: 28px; opacity: 0.35; }

.stats-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.stat-card { background: var(--bg2); border-radius: var(--radius); padding: 10px 16px; }
.stat-label { font-size: 11px; color: var(--text2); margin-bottom: 2px; }
.stat-val { font-size: 20px; font-weight: 500; }

.search-bar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.search-bar input[type=text] { flex: 1; min-width: 180px; padding: 6px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 13px; }
.search-bar input[type=text]:focus { outline: none; border-color: var(--text2); }

.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; }

.post-card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; cursor: pointer; transition: border-color 0.12s; position: relative; }
.post-card:hover { border-color: var(--border2); }
.post-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--bg2); }
.thumb-placeholder { width: 100%; aspect-ratio: 1; background: var(--bg2); display: flex; align-items: center; justify-content: center; color: var(--text3); font-size: 11px; }
.post-meta { padding: 8px 10px; }
.post-id { font-size: 11px; color: var(--text2); }
.post-tags { font-size: 11px; color: var(--text3); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-top: 2px; }
.post-rating { position: absolute; top: 6px; right: 6px; font-size: 10px; padding: 2px 5px; border-radius: 4px; font-weight: 500; }
.rating-s { background: #c0dd97; color: #3b6d11; }
.rating-q { background: #fac775; color: #854f0b; }
.rating-e { background: #f7c1c1; color: #a32d2d; }

.post-list { display: flex; flex-direction: column; gap: 6px; }
.post-row { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 9px 14px; display: flex; align-items: center; gap: 12px; cursor: pointer; transition: border-color 0.12s; }
.post-row:hover { border-color: var(--border2); }
.row-id { font-size: 12px; color: var(--text2); min-width: 50px; }
.row-tags { font-size: 13px; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-score { font-size: 12px; color: var(--text2); min-width: 40px; text-align: right; }
.row-rating { font-size: 11px; padding: 2px 7px; border-radius: 4px; font-weight: 500; }

.error-msg { background: var(--danger-bg); border: 0.5px solid var(--danger-border); color: var(--danger-text); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; margin-bottom: 12px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 24px; width: 420px; max-width: 95vw; max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 16px; font-weight: 500; margin-bottom: 16px; }
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-field label { font-size: 13px; color: var(--text2); }
.form-field input { padding: 7px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 14px; }
.form-field input:focus { outline: none; border-color: var(--text2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.post-detail-img { width: 100%; max-height: 320px; object-fit: contain; background: var(--bg2); border-radius: var(--radius); margin-bottom: 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin-bottom: 14px; }
.detail-row { display: flex; flex-direction: column; gap: 1px; }
.detail-label { font-size: 11px; color: var(--text3); }
.detail-value { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-chip { display: inline-block; background: var(--bg2); border: 0.5px solid var(--border); border-radius: 4px; padding: 2px 7px; font-size: 11px; margin: 2px; color: var(--text2); }

/* ── Gallery ── */
.filter-tabs { display: flex; gap: 2px; padding: 6px 20px; border-bottom: 0.5px solid var(--border); background: var(--bg); flex-shrink: 0; }
.filter-tab { padding: 5px 14px; font-size: 13px; border-radius: var(--radius); color: var(--text2); transition: background 0.12s, color 0.12s; display: flex; align-items: center; gap: 6px; }
.filter-tab:hover { background: var(--bg2); color: var(--text); }
.filter-tab.active { background: var(--bg2); color: var(--text); font-weight: 500; }
.filter-badge { font-size: 11px; padding: 1px 6px; border-radius: 10px; font-weight: 400; }
.unseen-badge { background: var(--bg3); color: var(--text2); }
.fav-badge { background: #fac775; color: #854f0b; }
.best-badge { background: #c0dd97; color: #3b6d11; }
#galleryApp { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.gallery-search { display: flex; gap: 8px; align-items: center; flex: 1; max-width: 420px; }
.gallery-search input[type=text] { flex: 1; padding: 6px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 13px; }
.gallery-search input[type=text]:focus { outline: none; border-color: var(--text2); }
.gallery-count { font-size: 12px; color: var(--text2); white-space: nowrap; }

.media-grid { flex: 1; overflow-y: auto; padding: 16px 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-content: start; }

.media-tile { position: relative; border-radius: var(--radius-lg); overflow: hidden; cursor: pointer; background: var(--bg2); border: 0.5px solid var(--border); aspect-ratio: 1; transition: border-color 0.12s, transform 0.12s; }
.media-tile:hover { border-color: var(--border2); transform: scale(1.02); }
.media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

.tile-video-thumb { width: 100%; height: 100%; position: relative; display: flex; align-items: center; justify-content: center; background: var(--bg3); }
.tile-video-thumb img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.play-badge { position: relative; z-index: 1; width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff; }

.tile-overlay { position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,0.55) 0%, transparent 50%); opacity: 0; transition: opacity 0.15s; display: flex; flex-direction: column; justify-content: flex-end; padding: 8px; }
.media-tile:hover .tile-overlay { opacity: 1; }
.tile-meta { display: flex; align-items: center; gap: 6px; }
.tile-id { font-size: 11px; color: rgba(255,255,255,0.85); }
.tile-dim { font-size: 10px; color: rgba(255,255,255,0.6); margin-top: 2px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 16px; border-top: 0.5px solid var(--border); }
.page-info { font-size: 13px; color: var(--text2); }

/* ── Lightbox ── */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 200; display: flex; align-items: center; justify-content: center; }
.lightbox.hidden { display: none; }

.lb-close { position: fixed; top: 16px; right: 20px; background: rgba(255,255,255,0.1); border: none; color: #fff; font-size: 20px; cursor: pointer; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: background 0.12s; }
.lb-close:hover { background: rgba(255,255,255,0.2); }

.lb-nav { position: fixed; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.08); border: none; color: #fff; font-size: 36px; cursor: pointer; width: 52px; height: 72px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; transition: background 0.12s; }
.lb-nav:hover { background: rgba(255,255,255,0.18); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }

.lb-inner { display: flex; flex-direction: column; align-items: center; width: 100%; max-height: 90vh; gap: 8px; padding: 0 16px; box-sizing: border-box; }




.lb-error { color: #f09595; font-size: 13px; padding: 20px; }

.lb-info { background: rgba(255,255,255,0.06); border-radius: var(--radius); padding: 10px 14px; max-width: 96vw; width: 100%; box-sizing: border-box; }
.lb-info-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.lb-score { font-size: 12px; color: rgba(255,255,255,0.7); }
.lb-dim { font-size: 12px; color: rgba(255,255,255,0.5); }
.lb-tags { margin-bottom: 10px; }
.lb-tags .tag-chip { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.15); color: rgba(255,255,255,0.75); }
.lb-actions { display: flex; gap: 8px; }
.lb-actions .btn { color: rgba(255,255,255,0.8); border-color: rgba(255,255,255,0.2); }
.lb-actions .btn:hover { background: rgba(255,255,255,0.1); }

/* ── Tile state indicators ── */
.tile-state-badges { position: absolute; top: 6px; left: 6px; display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.state-badge { font-size: 11px; font-weight: 500; padding: 2px 5px; border-radius: 4px; line-height: 1; }
.badge-best { background: #c0dd97; color: #3b6d11; }
.badge-fav  { background: #fac775; color: #854f0b; }
.badge-seen { background: rgba(0,0,0,0.35); color: rgba(255,255,255,0.85); }

/* Seen tiles dimmed slightly */
.media-tile.is-seen { opacity: 0.6; }
.media-tile.is-seen:hover { opacity: 1; }

/* Favourite ring */
.media-tile.is-fav  { border-color: #ef9f27; }
.media-tile.is-best { border-color: #639922; border-width: 2px; }

/* ── Lightbox action buttons ── */
.lb-fav-btn  { min-width: 100px; }
.lb-best-btn { min-width: 80px; }
.lb-btn-fav  { background: #fac775 !important; color: #854f0b !important; border-color: #ef9f27 !important; }
.lb-btn-best { background: #c0dd97 !important; color: #3b6d11 !important; border-color: #639922 !important; }

/* ── Icon buttons in sidebar ── */
.icon-btn { background: transparent; border: none; cursor: pointer; font-size: 13px; padding: 2px 5px; color: var(--text3); border-radius: 4px; transition: background 0.1s, color 0.1s; flex-shrink: 0; line-height: 1; }
.icon-btn:hover { background: var(--bg3); color: var(--text); }

/* ── Form row (side-by-side fields) ── */
.form-row { display: flex; gap: 10px; }

/* ── Lightbox position indicator ── */
.lb-position { font-size: 12px; color: rgba(255,255,255,0.45); margin-left: auto; }

/* ── Sidebar source counts ── */
.src-link { flex:1; display:flex; align-items:center; justify-content:space-between; gap:6px; overflow:hidden; min-width:0; }
.src-badges { display:flex; align-items:center; gap:4px; flex-shrink:0; }
.src-unseen { font-size:11px; font-weight:500; background:#fac775; color:#854f0b; padding:2px 6px; border-radius:10px; }
.src-count  { font-size:11px; color:var(--text2); background:var(--bg3); padding:2px 6px; border-radius:10px; }

/* ── Source name full display ── */
.src-name { font-size:13px; font-weight:500; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; min-width:0; flex:1; }

/* ── Drag reorder ── */
.source-item[draggable] { cursor:grab; }
.source-item.dragging { opacity:0.4; }
.source-item.drag-over { outline:1.5px dashed var(--border2); background:var(--bg2); }

/* ── Modal sizes ── */
.modal-lg { width: 540px; max-width: 96vw; }
.field-hint { color:var(--text3); font-size:11px; font-weight:400; }

/* ── Clip indicator badge ── */
.badge-clip { background:rgba(255,120,0,0.75); color:#fff; }

/* ── Lightbox scrollable oversized media ── */




/* ── Sidebar resizer ── */
.sidebar-resizer {
    width: 4px; cursor: col-resize; background: transparent;
    transition: background 0.15s; flex-shrink: 0;
}
.sidebar-resizer:hover, .sidebar-resizer:active { background: var(--border2); }

/* ── Tag ban button ── */
.tag-chip-bannable { display: inline-flex; align-items: center; gap: 3px; }
.tag-ban-btn {
    background: none; border: none; cursor: pointer; padding: 0 1px;
    font-size: 13px; line-height: 1; color: var(--text3); font-weight: 500;
    transition: color 0.1s;
}
.tag-ban-btn:hover { color: var(--danger-text); }

/* ── Home tile state badges (positioned like gallery) ── */
.post-card .tile-state-badges { position: absolute; top: 6px; left: 6px; display: flex; flex-direction: column; gap: 3px; }

/* ── Home list rows: seen dimming + fav/best borders matching gallery tiles ── */
.post-row.is-seen  { opacity: 0.6; }
.post-row.is-seen:hover { opacity: 1; }
.post-row.is-fav   { border-color: #ef9f27; }
.post-row.is-best  { border-color: #639922; border-width: 2px; }

/* ── Tag clone button (+) ── */
.tag-clone-btn {
    background: none; border: none; cursor: pointer; padding: 0 2px 0 3px;
    font-size: 13px; line-height: 1; color: var(--text3); font-weight: 500;
    transition: color 0.1s;
}
.tag-clone-btn:hover { color: var(--color-text-info, #185fa5); }

/* ── Clone option radio rows ── */
.clone-option {
    display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
    padding: 10px 12px; border: 0.5px solid var(--border); border-radius: var(--radius);
    transition: background 0.1s;
}
.clone-option:hover { background: var(--bg2); }
.clone-option input[type=radio] { margin-top: 2px; flex-shrink: 0; }

/* ── Filter bar (tabs + actions) ── */
.filter-bar { display: flex; align-items: center; justify-content: space-between; border-bottom: 0.5px solid var(--border); background: var(--bg); flex-shrink: 0; padding-right: 16px; }
.filter-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* ── Zoom slider row ── */
.lb-zoom-row { display: flex; align-items: center; gap: 10px; padding: 4px 8px; background: rgba(255,255,255,0.05); border-radius: var(--radius); width: 100%; max-width: 96vw; box-sizing: border-box; }
.lb-zoom-label { font-size: 12px; color: rgba(255,255,255,0.6); white-space: nowrap; }
.lb-zoom-row input[type=range] { flex: 1; }
#lbZoomVal { font-size: 12px; color: rgba(255,255,255,0.7); min-width: 38px; text-align: right; }

/* ── Lightbox media ── */
.lb-media-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    max-height: 68vh;
    width: 100%;
    box-sizing: border-box;
    border-radius: var(--radius);
}
/* Wide images: scroll horizontally, align from left so scrollbar is reachable */
.lb-media-wrap.is-wide {
    justify-content: flex-start;
    align-items: flex-start;
}
/* Tall images: scroll vertically, align from top */
.lb-media-wrap.is-tall {
    align-items: flex-start;
    justify-content: center;
}
.lb-media {
    display: block;
    max-width: min(94vw, 1400px);
    max-height: 68vh;
    object-fit: contain;
    border-radius: var(--radius);
    flex-shrink: 0;
}
.lb-media.wide-img { max-width: none; max-height: 65vh; width: auto; height: auto; }
.lb-media.tall-img { max-height: none; max-width: min(94vw, 1400px); width: auto; height: auto; }
video.lb-media { max-width: min(90vw, 1000px); max-height: 68vh; }

/* ── Settings page ── */
.settings-card { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; }
.settings-card-title { font-size: 14px; font-weight: 500; margin-bottom: 8px; }
.settings-desc { font-size: 13px; color: var(--text2); line-height: 1.5; margin-bottom: 0; }

.backend-option {
    flex: 1; display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
    border: 0.5px solid var(--border2); border-radius: var(--radius); cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}
.backend-option:hover { background: var(--bg3); }
.backend-option.active { border-color: var(--text2); background: var(--bg); }
.backend-option input[type=radio] { margin-top: 3px; flex-shrink: 0; }
.backend-option label { cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.backend-option strong { font-size: 13px; }
.backend-option .settings-desc { font-size: 11px; }
