:root {
    --bg: #f5f6f8;
    --card-bg: #ffffff;
    --text: #1f2430;
    --muted: #667085;
    --accent: #2b6cb0;
    --accent-dark: #1a4f85;
    --border: #e2e5ea;
    --danger: #c53030;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.site-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}
.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}
.site-header nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
}
.site-header nav a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.site-header nav a:hover { text-decoration: underline; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.site-footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    padding: 20px;
}

.flash-messages { margin-bottom: 16px; }
.flash {
    background: #fff8e1;
    border: 1px solid #f0d98c;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
}

/* ---------- Homepage category tiles ---------- */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}
.tile {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    display: block;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.tile:hover {
    box-shadow: 0 8px 22px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}
.tile img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
    background: #eee;
}
.tile-placeholder {
    width: 100%;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    background: #eef2f7;
}
.tile-body { padding: 14px 16px; }
.tile-label { font-weight: 700; font-size: 1.1rem; margin-bottom: 4px; }
.tile-count { color: var(--muted); font-size: 0.85rem; }

/* ---------- Search bar ---------- */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.search-bar input[type="text"] {
    flex: 1;
    min-width: 220px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}
.search-bar button {
    padding: 12px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}
.search-bar button:hover { background: var(--accent-dark); }
.clear-link {
    align-self: center;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}

/* ---------- Tag chips (category page) ---------- */
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}
.chip {
    background: #eef2f7;
    color: var(--accent-dark);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    text-decoration: none;
    border: 1px solid transparent;
}
.chip:hover { background: #dde7f2; }
.chip-active {
    background: var(--accent);
    color: white;
}

.result-count {
    color: var(--muted);
    margin: 0 0 16px;
    font-size: 0.9rem;
}

/* ---------- Grid + cards (shared by category/albums pages) ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 18px;
}
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    display: block;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card:hover {
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}
.card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
    background: #eee;
}
.card-placeholder {
    width: 100%;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    background: #eef2f7;
}
.card-body { padding: 10px 12px; }
.card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.tag {
    background: #eef2f7;
    color: var(--accent-dark);
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    text-decoration: none;
}
a.tag:hover { background: #dde7f2; }

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 30px;
    color: var(--muted);
    flex-wrap: wrap;
}
.pagination a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

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

/* ---------- Forms (upload/edit/login/albums) ---------- */
.upload-form {
    display: flex;
    flex-direction: column;
    max-width: 480px;
    gap: 6px;
}
.upload-form label {
    font-weight: 600;
    margin-top: 14px;
}
.upload-form input[type="text"],
.upload-form input[type="password"],
.upload-form input[type="file"],
.upload-form select,
.upload-form textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
}
.upload-form .hint {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 4px 0 0;
}
.upload-form button {
    margin-top: 20px;
    padding: 12px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    align-self: flex-start;
}
.upload-form button:hover { background: var(--accent-dark); }
.upload-form button.danger {
    background: var(--danger);
}
.upload-form button.danger:hover { background: #922626; }

.current-photo { margin-bottom: 10px; }
.current-photo img {
    width: 220px;
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border);
    display: block;
}

.inline-form {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.inline-form input[type="text"] {
    flex: 1;
    min-width: 220px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}
.inline-form button {
    padding: 10px 18px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
.inline-form button:hover { background: var(--accent-dark); }

.album-manage {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.album-manage form { margin: 0; }
.album-manage button.danger { padding: 10px 18px; }

.album-badge {
    display: inline-block;
    color: var(--muted);
    font-size: 0.78rem;
    margin-bottom: 6px;
}
.album-link { margin: 4px 0 14px; }
.album-link a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.album-link a:hover { text-decoration: underline; }
.album-count { color: var(--muted); font-size: 0.82rem; }

/* ---------- Detail page ---------- */
.back-link { margin-bottom: 4px; }
.detail {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
    align-items: flex-start;
}
.detail-media {
    flex: 2;
    min-width: 280px;
}
.detail-img {
    display: block;
    width: 100%;
    max-height: 80vh;
    object-fit: contain;
    background: #111;
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: zoom-in;
}

/* ---------- Fullscreen lightbox ---------- */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 12, 0.94);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px;
    cursor: zoom-out;
}
.lightbox.active { display: flex; }
.lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
    border-radius: 4px;
}
.lightbox-close {
    position: absolute;
    top: 18px;
    right: 26px;
    color: #fff;
    font-size: 2.4rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    font-weight: 300;
}
.detail-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    font-size: 0.9rem;
}
.detail-nav a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.detail-nav .nav-disabled {
    color: var(--border);
    font-weight: 600;
}
.detail-nav .nav-position {
    color: var(--muted);
}

.detail-info { flex: 1; min-width: 240px; }
.detail-info .caption {
    color: var(--text);
    margin: 4px 0 14px;
    line-height: 1.4;
}
.detail-info .meta {
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 16px;
}

.download-box {
    margin-top: 16px;
    padding: 14px;
    background: #eef2f7;
    border-radius: 10px;
}
.download-box .hint {
    margin: 10px 0 0;
    font-size: 0.8rem;
}

.detail-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}
.button-link {
    display: inline-block;
    padding: 10px 18px;
    background: var(--accent);
    color: white;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
}
.button-link:hover { background: var(--accent-dark); }
.detail-actions form { margin: 0; }
.detail-actions button.danger { margin-top: 0; padding: 10px 18px; }

/* ---------- Comments ---------- */
.comments-section {
    margin-top: 40px;
    border-top: 1px solid var(--border);
    padding-top: 24px;
}
.comment {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
}
.comment-name { font-weight: 700; font-size: 0.9rem; }
.comment-text { margin: 4px 0; white-space: pre-wrap; }
.comment-date { color: var(--muted); font-size: 0.78rem; }

.comment-form {
    display: flex;
    flex-direction: column;
    max-width: 480px;
    gap: 6px;
    margin-top: 20px;
}
.comment-form label { font-weight: 600; margin-top: 10px; }
.comment-form input[type="text"],
.comment-form textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
}
.comment-form button {
    margin-top: 16px;
    padding: 10px 18px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    align-self: flex-start;
}
.comment-form button:hover { background: var(--accent-dark); }
.honeypot {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

/* ---------- Stats page ---------- */
.stats-summary {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 30px;
}
.stat-box {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 22px;
    text-align: center;
}
.stat-number { font-size: 1.8rem; font-weight: 700; color: var(--accent-dark); }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.stats-table th, .stats-table td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.stats-table th { background: #eef2f7; }
.stats-table a { color: var(--accent); text-decoration: none; }
.stats-table a:hover { text-decoration: underline; }

code {
    background: #eef2f7;
    padding: 1px 5px;
    border-radius: 4px;
}

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
    .header-inner { flex-direction: column; align-items: flex-start; }
    .detail { flex-direction: column; }
    .detail-img { max-height: 60vh; }
    .stats-summary { flex-direction: column; }
}

/* =====================================================================
   Bulk upload organizer (Flickr-style)
   ===================================================================== */
[hidden] { display: none !important; }

.container-wide {
    max-width: none;
    margin: 0;
    padding: 0;
}

.organizer {
    --o-bg: #232323;
    --o-panel: #1b1b1b;
    --o-line: #333;
    --o-text: #e6e6e6;
    --o-muted: #8d8d8d;
    --o-pink: #ff0084;
    --o-blue: #0063dc;
    background: var(--o-bg);
    color: var(--o-text);
    min-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
}

.o-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: #f2f2f2;
    border-bottom: 1px solid #ddd;
    flex-wrap: wrap;
}
.o-tool {
    background: transparent;
    border: none;
    color: #333;
    font-size: 0.95rem;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
}
.o-tool:hover { background: #e2e2e2; }
.o-toolbar-info { color: #777; font-size: 0.85rem; margin-left: 10px; }
.o-upload {
    margin-left: auto;
    background: var(--o-blue);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.o-upload:hover:not(:disabled) { background: #004fb3; }
.o-upload:disabled { background: #9db9e0; cursor: not-allowed; }

.o-banner {
    padding: 12px 18px;
    font-size: 0.92rem;
    line-height: 1.5;
}
.o-banner a { color: inherit; font-weight: 700; }
.o-banner-ok { background: #1f4d2c; color: #d4f5dc; }
.o-banner-warn { background: #5a4a14; color: #fbefc2; }
.o-banner-error { background: #6b1f1f; color: #ffd9d9; }
.o-link-btn {
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    border-radius: 6px;
    padding: 2px 10px;
    cursor: pointer;
    font-size: 0.82rem;
}

.o-body { display: flex; flex: 1; min-height: 0; }

.o-sidebar {
    width: 290px;
    flex-shrink: 0;
    background: var(--o-panel);
    border-right: 1px solid var(--o-line);
    padding: 6px 0 20px;
}
.o-side-head {
    padding: 18px 20px;
    font-size: 1.15rem;
    color: #aaa;
    border-bottom: 1px solid var(--o-line);
}
.o-side-section {
    padding: 14px 20px;
    border-bottom: 1px solid var(--o-line);
}
.o-side-section label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--o-text);
}
.o-req { color: var(--o-pink); font-size: 0.72rem; margin-left: 6px; }
.o-sidebar select,
.o-sidebar textarea,
.o-sidebar input[type="text"] {
    width: 100%;
    background: #2b2b2b;
    color: var(--o-text);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 9px 10px;
    font-size: 0.92rem;
    font-family: inherit;
}
.o-sidebar textarea { resize: vertical; }
.o-sidebar :disabled { opacity: 0.45; cursor: not-allowed; }
.o-tag-add { display: flex; gap: 6px; }
.o-tag-add button {
    background: #3a3a3a;
    color: var(--o-text);
    border: 1px solid #555;
    border-radius: 6px;
    padding: 0 14px;
    cursor: pointer;
}
.o-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.o-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #3a3a3a;
    border-radius: 999px;
    padding: 3px 4px 3px 11px;
    font-size: 0.82rem;
}
.o-chip-partial { opacity: 0.55; font-style: italic; }
.o-chip button {
    background: #555;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    line-height: 16px;
    padding: 0;
    cursor: pointer;
    font-size: 0.85rem;
}
.o-chip button:hover { background: var(--o-pink); }
.o-side-note { color: var(--o-muted); font-size: 0.8rem; padding: 14px 20px 0; line-height: 1.5; margin: 0; }

.o-main {
    flex: 1;
    padding: 22px;
    min-width: 0;
    position: relative;
}
.o-main.dragging { outline: 3px dashed var(--o-pink); outline-offset: -10px; }

.o-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--o-muted);
    min-height: 320px;
    gap: 6px;
}
.o-empty-icon { font-size: 3rem; }
.o-empty p { margin: 4px 0; }
.o-empty .o-upload { margin: 10px 0; }
.o-empty-hint { font-size: 0.82rem; }

.o-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 22px 18px;
    align-content: start;
}
.o-tile { cursor: pointer; min-width: 0; user-select: none; }
.o-thumb {
    position: relative;
    aspect-ratio: 4 / 3;
    background: #111;
    border: 4px solid #333;
    border-radius: 3px;
    overflow: hidden;
}
.o-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.o-tile:hover .o-thumb { border-color: #555; }
.o-tile.selected .o-thumb { border-color: var(--o-pink); }
.o-tile.flagged .o-thumb { border-color: #e03131; box-shadow: 0 0 0 2px rgba(224,49,49,0.4); }
.o-tile.failed .o-thumb { border-color: #e03131; }
.o-tile.done .o-thumb { border-color: #2f9e44; }
.o-tile.done img { opacity: 0.55; }
.o-tile.done, .o-tile.uploading { cursor: default; }

.o-check {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    border: 2px solid #fff;
    color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.1s;
}
.o-tile:hover .o-check, .o-tile.selected .o-check { opacity: 1; }
.o-tile.selected .o-check { background: var(--o-pink); border-color: var(--o-pink); color: #fff; }
.o-tile.done .o-check, .o-tile.uploading .o-check { display: none; }
@media (hover: none) { .o-check { opacity: 1; } }

.o-overlay {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 6px 8px;
    background: rgba(0,0,0,0.72);
    font-size: 0.78rem;
    display: none;
}
.o-tile.uploading .o-overlay,
.o-tile.done .o-overlay,
.o-tile.failed .o-overlay { display: block; }
.o-bar { height: 4px; background: #444; border-radius: 2px; overflow: hidden; margin-bottom: 4px; }
.o-bar span { display: block; height: 100%; width: 0; background: var(--o-blue); transition: width 0.15s; }
.o-tile.done .o-bar span { background: #2f9e44; }
.o-tile.failed .o-bar { display: none; }
.o-tile.failed .o-msg { color: #ff9b9b; }
.o-tile.done .o-msg { color: #8be0a0; }

.o-title {
    margin-top: 10px;
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 0;
}
.o-title:hover { text-decoration: underline; text-decoration-style: dotted; }
.o-title-input {
    width: 100%;
    margin-top: 8px;
    background: #fff;
    color: #111;
    border: 2px solid var(--o-blue);
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 0.92rem;
    font-weight: 700;
}
.o-sub { color: var(--o-muted); font-size: 0.8rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.o-sub-warn { color: #ffa94d; }

@media (max-width: 800px) {
    .o-body { flex-direction: column; }
    .o-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--o-line); }
    .o-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 12px; }
    .o-upload { margin-left: 0; }
}

/* description line under the title (click to edit, like the title) */
.o-desc {
    color: #cfcfcf;
    font-size: 0.85rem;
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.o-desc:hover { text-decoration: underline; text-decoration-style: dotted; }
.o-desc-empty { color: var(--o-muted); }
.o-desc-input {
    width: 100%;
    background: #fff;
    color: #111;
    border: 2px solid var(--o-blue);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 0.85rem;
}
