:root {
    --bg: #f5f6fa;
    --card: #ffffff;
    --ink: #1d2233;
    --muted: #6b7286;
    --line: #e6e8ef;
    --brand: #5b4cf0;
    --brand-soft: #eeecfe;
    --side: #151827;
    --ok: #12a150;
    --ok-soft: #e6f6ed;
    --err: #d93a3a;
    --err-soft: #fdeaea;
    --amber: #c27a00;
    --amber-soft: #fff4dc;
    --radius: 14px;
}
* { 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(--ink); }
a { color: inherit; text-decoration: none; }
code { background: var(--bg); padding: 1px 6px; border-radius: 5px; font-size: .85em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.block { display: block; }
.center { display: block; text-align: center; margin-top: 14px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; flex-shrink: 0; background: var(--side); color: #c9cde0;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.logo { padding: 24px 22px; color: #fff; font-weight: 700; font-size: 1.15rem; border-bottom: 1px solid #23273a; }
.logo small { display: block; font-weight: 400; font-size: .78rem; color: #8288a3; letter-spacing: .05em; text-transform: uppercase; }
.sidebar nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; margin-bottom: 2px; font-size: .93rem; }
.sidebar nav a:hover { background: #1f2336; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.ico { width: 20px; text-align: center; opacity: .85; }
.me { display: flex; align-items: center; gap: 10px; padding: 16px; border-top: 1px solid #23273a; font-size: .9rem; }
.me strong { display: block; color: #fff; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.logout { margin-left: auto; font-size: 1.2rem; color: #8288a3; }
.logout:hover { color: #fff; }

.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 18px 32px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 1.35rem; margin: 0; flex: 1; }
.menu-btn { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; }
.content { padding: 28px 32px 60px; }

/* ---------- Pieces ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card-head h2 { font-size: 1.05rem; margin: 0; }
.link { color: var(--brand); font-weight: 500; font-size: .9rem; }
.link:hover { text-decoration: underline; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.grid-2 .card { margin-bottom: 0; }
.span-2 { grid-column: 1 / -1; }
.edit-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; color: var(--muted); font-size: .88rem; }
.stat span { display: block; font-size: 1.7rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.stat small { display: block; margin-top: 4px; font-size: .78rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--brand); color: #fff; border: 0; border-radius: 10px;
    padding: 10px 18px; font: 600 .92rem/1 inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: .8rem; border-radius: 8px; }
.btn-light { background: var(--brand-soft); color: var(--brand); }
.btn-danger { background: var(--err-soft); color: var(--err); }
.btn-block { width: 100%; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: .93rem; }
.alert-success { background: var(--ok-soft); color: var(--ok); }
.alert-error { background: var(--err-soft); color: var(--err); }

.badge { white-space: nowrap; display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.badge-s3 { background: var(--amber-soft); color: var(--amber); }
.badge-local { background: var(--brand-soft); color: var(--brand); }
.role-tag { display: inline-block; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; padding: 1px 7px; border-radius: 6px; margin-left: 4px; background: #2a2f47; color: #aab0cc; }
.main .role-tag { background: var(--bg); color: var(--muted); }
.role-admin, .main .role-admin { background: var(--amber-soft); color: var(--amber); }
.dot::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c3c7d4; margin-right: 6px; }
.dot.on::before { background: var(--ok); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.dim { opacity: .55; }
.actions { white-space: nowrap; text-align: right; }
.actions form { display: inline-block; margin: 0 0 0 4px; }

.thumb { position: relative; display: grid; place-items: center; width: 54px; height: 54px; border-radius: 10px; overflow: hidden; background: var(--bg); cursor: zoom-in; flex-shrink: 0; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb i { position: absolute; color: #fff; font-style: normal; font-size: .8rem; text-shadow: 0 1px 4px #000; }
.thumb b { font-size: .7rem; color: var(--err); }

.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.recent li:last-child { border-bottom: 0; }
.recent li > div { flex: 1; min-width: 0; }
.recent strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent small { color: var(--muted); }

.bar-row { display: grid; grid-template-columns: 120px 1fr 36px; align-items: center; gap: 12px; padding: 7px 0; font-size: .9rem; }
.bar { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar-row b { text-align: right; }

.pager { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pager a { min-width: 34px; text-align: center; padding: 6px 10px; border-radius: 8px; background: var(--bg); font-size: .88rem; }
.pager a.active { background: var(--brand); color: #fff; }

/* ---------- Forms ---------- */
.form label, .auth-card label { display: block; font-size: .88rem; font-weight: 500; margin-bottom: 16px; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
    display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; color: var(--ink);
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input:disabled { background: var(--bg); color: var(--muted); }
input[type=file] { margin-top: 8px; font-size: .88rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.narrow { max-width: 480px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px; }
.filters input, .filters select { width: auto; margin: 0; flex: 1 1 150px; }
.filters input[type=search] { flex: 2 1 240px; }

.dropzone {
    display: block; position: relative; border: 2px dashed var(--line); border-radius: var(--radius);
    padding: 34px 20px; text-align: center; cursor: pointer; transition: .15s; background: #fafbff;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone strong { display: block; font-size: 1rem; }
.dropzone small { color: var(--muted); font-weight: 400; }
.file-list { margin-top: 10px; font-size: .85rem; font-weight: 400; color: var(--brand); }

.upload-status[hidden] { display: none; }
.upload-status { display: flex; align-items: center; gap: 12px; margin: 10px 0 16px; font-size: .88rem; }
.progress { flex: 1; height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

.preview-card img, .preview-card video { width: 100%; border-radius: 10px; background: #000; max-height: 420px; object-fit: contain; }
.preview-card dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: .88rem; margin: 16px 0 0; }
.preview-card dt { color: var(--muted); }
.preview-card dd { margin: 0; font-weight: 500; }

/* ---------- Settings ---------- */
.storage-now { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: .88rem; }
.storage-now .big { display: block; font-size: 1.6rem; font-weight: 700; color: var(--ink); }
.storage-now small { display: block; }
.migrate { margin-top: 18px; padding: 16px; border-radius: 12px; background: var(--amber-soft); }
.migrate p { margin: 0 0 8px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.form .choice-item { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; margin: 0; }
.choice-item:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice-item input { margin-top: 4px; }
.choice-item small { display: block; color: var(--muted); font-weight: 400; margin-top: 2px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px 4px; margin: 0 0 18px; }
fieldset[hidden] { display: none; }
legend { padding: 0 6px; font-weight: 600; font-size: .9rem; }

/* ---------- Auth ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: linear-gradient(135deg, #151827, #2b2570); }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 18px; padding: 34px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-card h1 { margin: 0 0 4px; font-size: 1.5rem; }
.auth-card > p { margin: 0 0 22px; }

/* ---------- Preview modal ---------- */
.preview { position: fixed; inset: 0; background: rgba(10, 12, 20, .88); z-index: 100; display: grid; place-items: center; padding: 24px; }
.preview[hidden] { display: none; }
.preview-body img, .preview-body video { max-width: 92vw; max-height: 88vh; border-radius: 10px; }
.preview-close { position: absolute; top: 14px; right: 22px; background: none; border: 0; color: #fff; font-size: 2.2rem; cursor: pointer; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
    .grid-2, .edit-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
    .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
    .menu-btn { display: block; }
    .topbar { padding: 14px 16px; }
    .topbar .btn { padding: 8px 12px; font-size: .82rem; }
    .content { padding: 18px 14px 50px; }
    .row, .choice { grid-template-columns: 1fr; }
}

/* ---------- API keys ---------- */
.badge-api { background: #e8f4ff; color: #1769c2; }
.new-key { background: #10142a; color: #e7e9f5; border-radius: var(--radius); padding: 22px 24px; margin-bottom: 22px; border: 1px solid #2f3660; }
.new-key h2 { margin: 0 0 4px; font-size: 1.1rem; color: #fff; }
.new-key p { margin: 6px 0 12px; color: #b9bfd9; }
.new-key code { background: #1b2142; color: #9fe8b6; }
.new-key .small code { color: #c9cde6; word-break: break-all; }
.copy-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.copy-row code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 10px 12px; border-radius: 10px; font-size: .88rem; display: block; }
.api-toggle { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.status { font-weight: 700; font-size: .8rem; padding: 2px 8px; border-radius: 6px; }
.status.s2 { background: var(--ok-soft); color: var(--ok); }
.status.s4 { background: var(--amber-soft); color: var(--amber); }
.status.s5 { background: var(--err-soft); color: var(--err); }

/* ---------- Developer docs ---------- */
.docs-page { background: #fff; }
.docs { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.docs-nav { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 26px 20px; border-right: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; gap: 18px; }
.logo-d { font-weight: 700; font-size: 1.05rem; }
.logo-d small { display: block; font-weight: 500; color: var(--muted); font-size: .8rem; }
.docs-nav nav { display: grid; gap: 2px; }
.docs-nav nav a { padding: 7px 10px; border-radius: 8px; font-size: .9rem; color: var(--muted); }
.docs-nav nav a:hover { background: #fff; color: var(--ink); }
.docs-body { max-width: 880px; padding: 40px clamp(18px, 5vw, 64px) 100px; }
.docs-body h1 { font-size: 2.2rem; margin: 0 0 8px; letter-spacing: -.02em; }
.lead-d { font-size: 1.1rem; color: var(--muted); margin: 0 0 20px; }
.docs-body section { padding-top: 26px; margin-top: 10px; border-top: 1px solid var(--line); }
.docs-body h2 { font-size: 1.35rem; display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.docs-body h3 { font-size: 1rem; margin: 20px 0 8px; }
.docs-body p, .docs-body li { color: #3b4155; }
.docs-body .table { margin: 10px 0 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.params td:first-child { white-space: nowrap; width: 1%; }
.code { position: relative; margin: 10px 0 16px; }
.code pre { margin: 0; background: #10142a; color: #dfe3f5; padding: 16px 18px; border-radius: 12px; overflow-x: auto; font: 13.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.code .copy { position: absolute; top: 8px; right: 8px; background: #252c52; color: #cfd4ee; border: 0; border-radius: 7px; padding: 4px 10px; font-size: .75rem; cursor: pointer; }
.code .copy:hover { background: var(--brand); color: #fff; }
.m { font: 700 .72rem/1 ui-monospace, Menlo, monospace; padding: 5px 8px; border-radius: 6px; letter-spacing: .03em; }
.m.get { background: #e6f6ed; color: #12804a; }
.m.post { background: #e8f0ff; color: #2456c7; }
.m.patch { background: #fff4dc; color: #a86700; }
.m.delete { background: #fdeaea; color: #c62f2f; }
@media (max-width: 860px) {
    .docs { grid-template-columns: 1fr; }
    .docs-nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .docs-nav nav { display: none; }
}
.keys-top { margin-bottom: 22px; }
.badge-admin { background: #f3e8ff; color: #7c2bd9; }
