:root {
    --bg: #0b1220;
    --panel: #131b2e;
    --panel-alt: #1b2740;
    --border: #24304a;
    --text: #e8ecf4;
    --muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #dc2626;
    --radius: 12px;
}

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

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

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* -- Login ------------------------------------------------------------- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at top, #1e3a8a 0%, transparent 45%), var(--bg);
}
.login-container {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: min(360px, 90vw);
    text-align: center;
}
.login-container h1 { margin-bottom: 24px; font-size: 1.6rem; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}
.login-form button {
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.login-form button:hover { background: var(--accent-hover); }
.login-error { color: #fca5a5; margin-bottom: 14px; font-size: 0.9rem; }

/* -- Top bar ----------------------------------------------------------- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 5;
}
.brand { font-size: 1.2rem; font-weight: 600; }
.top-actions { display: flex; gap: 10px; align-items: center; }

.upload-button {
    background: var(--accent);
    color: #fff;
    padding: 9px 16px;
    border-radius: 10px;
    font-weight: 600;
}
.upload-button:hover { background: var(--accent-hover); }
.secondary-button {
    background: var(--panel-alt);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 9px 14px;
    border-radius: 10px;
}
.secondary-button:hover { background: var(--border); }
.danger-button {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 10px;
}

/* -- Breadcrumb -------------------------------------------------------- */
.breadcrumb {
    padding: 12px 22px;
    color: var(--muted);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 0.9rem;
}
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { color: var(--border); }
.breadcrumb .tag-filter { color: var(--accent); }

/* -- Layout ------------------------------------------------------------ */
.layout { display: flex; align-items: flex-start; }
.sidebar {
    width: 200px;
    flex-shrink: 0;
    padding: 18px 22px;
    position: sticky;
    top: 64px;
}
.sidebar h2 { font-size: 0.8rem; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.tag-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.tag-list a {
    display: block;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.9rem;
}
.tag-list a:hover { background: var(--panel); color: var(--text); }
.tag-list a.active { background: var(--accent); color: #fff; }

.content { flex: 1; padding: 18px 22px; min-width: 0; }

/* -- Folders ----------------------------------------------------------- */
.folders {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.folder-card {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
}
.folder-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.folder-icon { font-size: 1.4rem; }
.folder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-delete {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1rem;
    opacity: 0;
    transition: opacity 0.15s;
}
.folder-card:hover .folder-delete { opacity: 1; }
.folder-delete:hover { color: var(--danger); }

/* -- Selection bar ----------------------------------------------------- */
.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 12px;
}
.select-all { color: var(--muted); font-size: 0.9rem; display: flex; gap: 6px; align-items: center; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* -- Media grid -------------------------------------------------------- */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}
.media-card {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.media-thumb {
    display: block;
    aspect-ratio: 1;
    position: relative;
    background: #000;
}
.media-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.play-badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
    pointer-events: none;
}
.select-box {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
}
.select-box input { width: 18px; height: 18px; cursor: pointer; }
.media-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.card-tag {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.72rem;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.card-tag-remove {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
}
.card-tag-remove:hover { color: var(--danger); }
.tag-edit-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 0.8rem;
    align-self: flex-start;
}
.tag-edit-btn:hover { color: var(--text); }

/* -- Dialogs ----------------------------------------------------------- */
dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    padding: 22px;
    width: min(420px, 90vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h3 { margin-bottom: 16px; }
dialog input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    margin-bottom: 14px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.dialog-actions button, .tag-add-form button {
    padding: 9px 16px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.tag-add-form { display: flex; gap: 8px; }
.tag-add-form input { margin-bottom: 0; }
.current-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.current-tags .chip {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.8rem;
    display: flex;
    gap: 6px;
    align-items: center;
}
.current-tags .chip button {
    background: transparent;
    border: none;
    color: var(--muted);
}
.current-tags .chip button:hover { color: var(--danger); }

/* -- Video overlay ----------------------------------------------------- */
.video-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.video-overlay.hidden { display: none; }
.video-overlay video {
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 8px;
}
.video-close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.8rem;
}

/* -- Upload progress --------------------------------------------------- */
.upload-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    z-index: 60;
    min-width: 220px;
}
.upload-toast .bar {
    height: 6px;
    background: var(--panel-alt);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 8px;
}
.upload-toast .bar span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.2s;
}

/* -- Responsive -------------------------------------------------------- */
@media (max-width: 720px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; position: static; }
    .tag-list { flex-direction: row; flex-wrap: wrap; }
}