:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1d2330; --muted: #6b7385; --border: #e2e5eb;
  --accent: #3b5bdb; --accent-text: #fff; --ok: #2b8a3e; --ko: #c92a2a; --warn-bg: #fff4e0;
  --ig: #d6249f; --fb: #1877f2; --local: #868e96;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --surface: #1b1f29; --text: #e6e8ee; --muted: #9aa1b2; --border: #2c3240;
    --accent: #7491ff; --accent-text: #0d1020; --ok: #69db7c; --ko: #ff8787; --warn-bg: #3a2e14;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: .9em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); } .ko { color: var(--ko); }

.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { padding: .35rem .75rem; border-radius: 6px; color: var(--text); }
.topbar nav a.active { background: var(--accent); color: var(--accent-text); }
.topbar nav a:hover { text-decoration: none; background: var(--bg); }
.topbar nav a.active:hover { background: var(--accent); }
.badge { display: inline-block; min-width: 1.4em; padding: 0 .35em; margin-left: .2em; border-radius: 1em; background: var(--ko); color: #fff; font-size: .75em; text-align: center; }

.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.layout { display: grid; grid-template-columns: 230px 1fr; gap: 2rem; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .container { padding: 1rem; } }

.sidebar h3:first-child { margin-top: 0; }
.coll-list { list-style: none; margin: 0; padding: 0; }
.coll-list a { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .6rem; border-radius: 6px; color: var(--text); }
.coll-list a span { color: var(--muted); font-size: .85em; }
.coll-list a.active { background: var(--accent); color: var(--accent-text); }
.coll-list a.active span { color: inherit; }
.coll-list a:hover { text-decoration: none; background: var(--surface); }
.coll-list a.active:hover { background: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { padding: .2rem .65rem; border: 1px solid var(--border); border-radius: 1em; color: var(--text); font-size: .85em; background: var(--surface); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

input[type=text], input[type=search], input[type=date], input[type=datetime-local], input[type=password], input[type=file], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; max-width: 100%;
}
textarea { width: 100%; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); padding: .45rem 1rem; border-radius: 6px; display: inline-block; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.danger { background: var(--ko); border-color: var(--ko); color: #fff; }
button.small { padding: .2rem .6rem; font-size: .85em; }
.btn:hover { text-decoration: none; }
.btn-link { align-self: center; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.filters input[type=search] { flex: 1 1 220px; }
.filters label { display: flex; align-items: center; gap: .3rem; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.thumb { position: relative; padding: 0; border: 0; border-radius: 0; background: #000; aspect-ratio: 9 / 12; width: 100%; display: block; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.thumb:hover img { transform: scale(1.03); }
.nothumb { color: #fff; font-size: 2.5rem; display: grid; place-items: center; height: 100%; opacity: .6; }
.dur { position: absolute; right: .4rem; bottom: .4rem; background: rgba(0,0,0,.75); color: #fff; font-size: .75rem; padding: 0 .35rem; border-radius: 4px; }
.meta { padding: .6rem .75rem .75rem; display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.meta .title { font-weight: 600; line-height: 1.3; word-break: break-word; }
.meta .sub { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: .85em; }
.meta .coll { background: var(--bg); padding: 0 .45rem; border-radius: 4px; color: var(--text); }
.meta .date { margin-left: auto; color: var(--muted); }
.meta .fname { font-family: ui-monospace, Consolas, monospace; font-size: .9em; word-break: break-all; }
.meta .actions { margin-top: auto; padding-top: .3rem; display: flex; gap: .75rem; font-size: .85em; }
.pf { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 4px; color: #fff; font-size: .7em; font-weight: 700; flex: none; }
.pf-instagram { background: var(--ig); } .pf-facebook { background: var(--fb); } .pf-local { background: var(--local); }

.pager { display: flex; gap: .3rem; justify-content: center; margin: 1.5rem 0; flex-wrap: wrap; }
.pager a, .pager span { padding: .3rem .7rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.pager a.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.empty { padding: 2.5rem; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

dialog#player { padding: 0; border: 0; border-radius: var(--radius); background: #000; max-width: min(96vw, 1100px); width: auto; }
dialog#player::backdrop { background: rgba(0,0,0,.8); }
dialog#player video { display: block; max-width: 100%; max-height: 85vh; margin: 0 auto; }
.player-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .5rem .75rem; color: #fff; background: #111; }
.player-head button { background: transparent; border: 0; color: #fff; font-size: 1.2rem; padding: 0 .3rem; }

.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid var(--border); background: var(--surface); }
.alert.success { border-left: 4px solid var(--ok); }
.alert.error { border-left: 4px solid var(--ko); }
.alert.warn { background: var(--warn-bg); border-left: 4px solid #f08c00; }
.alert .err { color: var(--ko); font-size: .9em; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.steps .panel { margin: 0; }
.steps ol { padding-left: 1.2rem; margin: 0; }
.steps li { margin-bottom: .4rem; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack + .stack { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.stack label { display: flex; flex-direction: column; gap: .3rem; }
.stack label.check, label.check { flex-direction: row; align-items: flex-start; gap: .5rem; }
.stack button { align-self: flex-start; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row label { flex: 1; }
form.inline { display: flex; gap: .5rem; align-items: center; margin: 0; }

.tools { display: flex; flex-direction: column; gap: .9rem; }
.tools form { margin: 0; }
.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.log { max-height: 220px; overflow: auto; font-size: .85em; margin: .5rem 0 0; padding-left: 1.5rem; }
.log .ko { color: var(--ko); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 1.5rem 0 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.tabs a span { font-size: .8em; background: var(--bg); padding: 0 .4em; border-radius: 1em; }
.bulk { margin-bottom: .75rem; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.table td.url { max-width: 420px; word-break: break-all; }
.table td.url .pf { margin-right: .3rem; }
.table pre { white-space: pre-wrap; font-size: .8em; max-width: 480px; max-height: 200px; overflow: auto; }
@media (max-width: 800px) { .table { display: block; overflow-x: auto; } }

.edit-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 460px); gap: 1.5rem; align-items: start; }
.edit-layout video { width: 100%; max-height: 70vh; background: #000; border-radius: var(--radius); }
@media (max-width: 900px) { .edit-layout { grid-template-columns: 1fr; } }
.danger-zone { display: flex; gap: 1rem; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 1.5rem; }

body.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
body.login form { width: min(360px, 100%); }
