:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f242e;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --accent: #4c8dff;
  --danger: #ff5a5a;
  --border: #2a2f3a;
  --radius: 10px;
}
* { box-sizing: border-box; }
/* The `hidden` attribute must win over the .modal/.lightbox `display:flex` rules
   below — author rules override the UA `[hidden]{display:none}`, so without this
   every modal/lightbox renders on load (the "stuck in User management" bug). */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; white-space: nowrap; }
.search { flex: 1; display: flex; justify-content: center; }
.search input {
  width: min(560px, 100%); padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
.actions { display: flex; align-items: center; gap: 10px; }
.user-pill { color: var(--muted); }
.user-pill b { color: var(--text); }

.btn {
  cursor: pointer; border: 1px solid var(--border); background: var(--accent);
  color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 14px;
}
.btn.ghost { background: transparent; color: var(--text); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* filters */
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-group label { color: var(--muted); font-size: 13px; }
.filters select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px;
}
.filter-group.tags { flex-wrap: wrap; gap: 6px; }
.tag-chip {
  cursor: pointer; padding: 3px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); font-size: 13px; color: var(--muted);
}
.tag-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.active-filter { margin-left: auto; color: var(--muted); font-size: 13px; }
.active-filter button { margin-left: 8px; }

/* grid (masonry via CSS columns) */
main { padding: 16px 18px 60px; }
.grid { column-gap: 12px; column-width: 260px; }
.card {
  break-inside: avoid; margin: 0 0 12px; position: relative;
  border-radius: var(--radius); overflow: hidden; background: var(--panel-2);
  cursor: pointer; border: 1px solid var(--border);
}
.card img { display: block; width: 100%; height: auto; background: var(--panel-2); }
.card.processing { min-height: 160px; }
.card .ph {
  display: flex; align-items: center; justify-content: center; min-height: 160px;
  color: var(--muted); font-size: 13px;
}
.card .badge {
  position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.6);
  color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 6px;
}
.card .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.card .play svg { width: 48px; height: 48px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.6)); opacity: .92; }
.card .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 10px 8px;
  font-size: 13px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sentinel { height: 40px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50; display: flex;
  background: rgba(8,9,12,.94); backdrop-filter: blur(2px);
}
.lb-stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; min-width: 0; overflow: hidden; position: relative; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 92vh; border-radius: 6px; transform-origin: center center; touch-action: none; }
.lb-zoom {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; z-index: 55; user-select: none;
  background: rgba(0,0,0,.6); border: 1px solid var(--border); padding: 6px 8px; border-radius: 999px;
}
.lb-zoom button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; min-width: 30px; height: 28px; padding: 0 8px; cursor: pointer; font-size: 15px; line-height: 1;
}
.lb-zoom button:hover { background: var(--border); }
.lb-zoom #lbZoomLabel { min-width: 50px; text-align: center; font-size: 13px; color: var(--muted); }
.lb-info {
  width: 320px; flex-shrink: 0; padding: 24px 20px; background: var(--panel);
  border-left: 1px solid var(--border); overflow-y: auto;
}
.lb-caption { font-size: 17px; font-weight: 600; margin-bottom: 10px; word-wrap: break-word; }
.lb-meta { color: var(--muted); font-size: 13px; line-height: 1.7; margin-bottom: 12px; }
.lb-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.lb-tags .tag-chip { cursor: default; }
.lb-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.lb-edit { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.lb-edit label, .up-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.lb-edit input, .up-fields input, .up-fields select, .lb-edit select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.lb-close { position: absolute; top: 12px; right: 12px; z-index: 2; }
.lb-close, .lb-nav {
  background: rgba(0,0,0,.4); color: #fff; border: none; cursor: pointer;
  width: 44px; height: 44px; border-radius: 50%; font-size: 26px; line-height: 1;
}
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; }
.lb-prev { left: 14px; }
.lb-next { right: 348px; }

/* modals */
.modal {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); padding: 16px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; width: 380px; max-width: 100%; display: flex; flex-direction: column; gap: 12px;
}
.modal-card.wide { width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-card h2 { margin: 0 0 6px; font-size: 19px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-card input, .modal-card select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px;
}
.modal-err { color: var(--danger); font-size: 13px; min-height: 16px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* upload */
.dropzone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center;
  color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: rgba(76,141,255,.08); }
.dropzone .hint { font-size: 12px; }
.up-fields { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.up-fields label { color: var(--muted); }
.up-list { display: flex; flex-direction: column; gap: 8px; }
.up-row { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.up-row .name { display: flex; justify-content: space-between; gap: 8px; }
.up-row .name .status { color: var(--muted); }
.up-row .name .status.ok { color: #58c873; }
.up-row .name .status.err { color: var(--danger); }
.up-bar { height: 6px; border-radius: 999px; background: var(--border); margin-top: 6px; overflow: hidden; }
.up-bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* admin user management */
.btn.small { padding: 4px 9px; font-size: 12px; }
.admin-add { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.admin-add input[type="text"] {
  flex: 1; min-width: 200px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
}
.au-adminchk { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; }
.au-result {
  background: rgba(76,141,255,.1); border: 1px solid var(--accent); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 13px;
}
.au-pw { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.au-pw code {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 9px; font-size: 14px; word-break: break-all; user-select: all;
}
.admin-users { max-height: 50vh; overflow-y: auto; }
.au-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.au-table th, .au-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
.au-table th { color: var(--muted); font-weight: 600; }
.au-actions { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .lb-info { display: none; }
  .lb-next { right: 14px; }
  .search input { width: 100%; }
}
