:root {
	--bg: #f4f6fa;
	--surface: #ffffff;
	--subtle: #f7f8fa;
	--field: #f3f4f6;
	--hover: #f6f8fb;
	--border: #e5e7eb;
	--border-strong: #d1d5db;
	--text: #111827;
	--text-2: #374151;
	--muted: #6b7280;
	--faint: #9ca3af;
	--blue: #1d5bd8;
	--blue-hover: #174bb5;
	--blue-soft: #eaf1fd;
	--bar: #3b78e7;
	--orange: #f59e0b;
	--orange-soft: #fef3c7;
	--red: #dc2626;
	--red-soft: #fee2e2;
	--green: #16a34a;
	--green-soft: #dcfce7;
	--purple: #7c3aed;
	--grid: #edf0f4;
	--avatar-bg: #dbe4f3;
	--avatar-fg: #1e3a6e;
	--green-ink: #15803d;
	--red-ink: #b91c1c;
	--orange-ink: #b45309;
	--set-border: #c6d8fa;
	--note-ink: #92400e;
	--danger-border: #fca5a5;
	--toast: #111827;
	--shadow: 0 10px 30px rgba(17, 24, 39, .1);
	--font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	--mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
	color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- каркас ---------- */
.frame { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 16px; padding: 0 20px; position: sticky; top: 0; z-index: 30; }
.logo { display: flex; align-items: center; gap: 8px; color: var(--blue); font-weight: 700; font-size: 16px; text-decoration: none; }
.logo:hover { text-decoration: none; }
.logo svg { width: 20px; height: 20px; stroke-width: 2; }
.env-wrap { position: relative; }
.env { display: inline-flex; align-items: center; gap: 7px; background: var(--field); border: 1px solid transparent; border-radius: 6px; padding: 5px 8px 5px 10px; font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer; letter-spacing: .02em; }
.env:hover { border-color: var(--border-strong); }
.env svg { width: 14px; height: 14px; color: var(--muted); }
.env-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }
.env-dot.off { background: var(--faint); }
.menu .on { font-weight: 600; }
.top-search { margin-left: auto; position: relative; width: 280px; }
.top-search input { width: 100%; height: 34px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px 0 32px; background: var(--surface); font-size: 13px; }
.top-search input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.top-search > svg { position: absolute; left: 9px; top: 8px; width: 16px; height: 16px; color: var(--faint); }
.icon-btn { width: 34px; height: 34px; border: 0; border-radius: 6px; background: none; display: grid; place-items: center; cursor: pointer; color: var(--text-2); }
.icon-btn:hover { background: var(--field); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--avatar-bg); color: var(--avatar-fg); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: none; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer; padding: 3px 6px 3px 3px; border-radius: 20px; position: relative; }
.user-btn:hover { background: var(--field); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); min-width: 220px; padding: 6px; z-index: 40; text-align: left; }
.menu .mh { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu .mh b { display: block; }
.menu .mh small { color: var(--muted); }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 8px; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--text); text-decoration: none; font-size: 13.5px; }
.menu button:hover, .menu a:hover { background: var(--field); text-decoration: none; }
.drop { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; max-height: 360px; overflow-y: auto; z-index: 40; }
.drop a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.drop a:hover, .drop a.sel { background: var(--field); text-decoration: none; }
.drop .none { padding: 10px; color: var(--muted); font-size: 13px; }
.burger { display: none; }

.body { flex: 1; display: flex; min-height: 0; }
.side { width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; }
.side a { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 6px; color: var(--text-2); text-decoration: none; font-size: 14px; margin-bottom: 2px; }
.side a:hover { background: var(--field); color: var(--text); text-decoration: none; }
.side a.on { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.side .sep { height: 1px; background: var(--border); margin: 10px 4px; }
.main { flex: 1; min-width: 0; }
.page { background: var(--surface); min-height: calc(100vh - 56px); border-left: 0; }
.page-head { display: flex; align-items: center; gap: 12px; padding: 16px 24px 0; }
.page-head h1 { font-size: 18px; font-weight: 600; margin: 0; flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.page-head .crumb { color: var(--muted); font-weight: 500; }
.tabs { display: flex; gap: 22px; padding: 0 24px; border-bottom: 1px solid var(--border); margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 0 9px; color: var(--text-2); font-size: 14px; text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.tabs .cnt { color: var(--muted); font-weight: 400; margin-left: 4px; font-size: 12.5px; }
.content { padding: 20px 24px 40px; }

/* ---------- элементы ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 500; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--field); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-hover); }
.btn.ghost { border-color: transparent; background: none; color: var(--blue); padding: 0 8px; }
.btn.ghost:hover { background: var(--blue-soft); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--danger-border); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.input { height: 34px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 0 10px; background: var(--surface); font-size: 13.5px; min-width: 0; }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
select.input { padding-right: 6px; }

.query { display: flex; gap: 10px; margin-bottom: 16px; }
.query .qbox { flex: 1; position: relative; }
.query input { width: 100%; height: 38px; border: 1px solid transparent; background: var(--field); border-radius: 6px; padding: 0 12px 0 36px; font-size: 13.5px; }
.query input:focus { outline: none; background: var(--surface); border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.query .qbox svg { position: absolute; left: 11px; top: 10px; color: var(--faint); width: 17px; height: 17px; }
.query .btn { height: 38px; padding: 0 18px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.fbtn { position: relative; }
.fbtn > button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--subtle); cursor: pointer; font-size: 13px; color: var(--text-2); }
.fbtn > button:hover { border-color: var(--border-strong); background: var(--surface); }
.fbtn > button b { font-weight: 600; color: var(--text); }
.fbtn > button.set { background: var(--blue-soft); border-color: var(--set-border); }
.fbtn > button svg { width: 15px; height: 15px; color: var(--muted); }
.pop { position: absolute; left: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); min-width: 240px; z-index: 35; padding: 6px; }
.pop .opt { display: flex; width: 100%; align-items: center; gap: 8px; border: 0; background: none; padding: 7px 10px; border-radius: 6px; text-align: left; cursor: pointer; font-size: 13.5px; color: var(--text); }
.pop .opt:hover { background: var(--field); }
.pop .opt.on { color: var(--blue); font-weight: 600; }
.pop .opt.on::after { content: "✓"; margin-left: auto; }
.pop .gh { padding: 8px 10px 4px; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pop .scroll { max-height: 340px; overflow-y: auto; }
.pop .row2 { display: grid; gap: 8px; padding: 8px 10px; }
.pop label { font-size: 12.5px; color: var(--muted); display: grid; gap: 4px; }
.pop .sep { height: 1px; background: var(--border); margin: 6px 0; }
.pop .search { width: 100%; margin-bottom: 4px; }
.add-filter { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--blue); font-weight: 500; cursor: pointer; font-size: 13.5px; padding: 6px 8px; border-radius: 6px; }
.add-filter:hover { background: var(--blue-soft); }
.add-filter svg { width: 16px; height: 16px; stroke-width: 2.2; }
.count { color: var(--text-2); font-size: 13.5px; margin-bottom: 14px; }
.count b { font-weight: 600; }
.clear { margin-left: 4px; }

/* ---------- карточки, график, таблица ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px 6px; }
.card-h h3 { margin: 0; font-size: 14.5px; font-weight: 600; flex: 1; }
.card-b { padding: 8px 16px 16px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.grid > .card { margin-top: 0; }

.chart { position: relative; padding: 4px 16px 10px 44px; }
.chart .plot { position: relative; height: 92px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-end; gap: 3px; }
.chart .ylab { position: absolute; left: -36px; width: 28px; text-align: right; font-size: 11px; color: var(--muted); transform: translateY(50%); }
.chart .gl { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--grid); }
.chart .b { flex: 1; display: flex; align-items: flex-end; height: 100%; cursor: pointer; justify-content: center; position: relative; z-index: 1; }
.chart .b i { width: 100%; max-width: 9px; background: var(--bar); border-radius: 2px 2px 0 0; min-height: 0; }
.chart .b:hover i { background: var(--blue-hover); }
.chart .x { position: relative; height: 18px; margin-top: 4px; }
.chart .x span { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.tip { position: absolute; z-index: 5; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 6px; padding: 8px 12px; pointer-events: none; transform: translate(-50%, -100%); white-space: nowrap; }
.tip small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tip b { font-weight: 500; font-size: 13px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); border-top: 1px solid var(--border); background: var(--surface); white-space: nowrap; position: sticky; top: 56px; z-index: 2; }
.tbl td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tbody tr:hover td { background: var(--hover); }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl .nw { white-space: nowrap; }
.tbl .vline { border-right: 1px solid var(--border); }
.card .tbl tr:last-child td { border-bottom: 0; }
.card .tbl th { position: static; border-top: 0; }
.tbl-wrap { overflow-x: auto; }

.ev td { cursor: pointer; }
.ev .exp { width: 30px; padding-right: 0; color: var(--text-2); }
.ev .exp svg { width: 14px; height: 14px; transition: transform .12s; stroke-width: 2.2; }
.ev.open .exp svg { transform: rotate(90deg); }
.ev .msg { color: var(--text-2); overflow-wrap: anywhere; }
.ev .msg a { font-weight: 500; }
.ev .id { color: var(--faint); font-size: 12px; margin-left: 1px; }
.ev .amt { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.ev .ts { white-space: nowrap; color: var(--text-2); font-variant-numeric: tabular-nums; }
.sev { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--text-2); }
.sev .dot { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 10px; font-weight: 700; color: #fff; background: #c4c9d2; }
.sev.chats .dot { background: #60a5fa; }
.sev.admin .dot { background: var(--orange); }
.sev.site .dot { background: var(--red); border-radius: 3px; }
.sev .dot svg { width: 10px; height: 10px; stroke-width: 2.6; }
.detail td { background: var(--subtle); padding: 0 14px 0 44px; cursor: default; }
.detail:hover td { background: var(--subtle) !important; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 16px; padding: 12px 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.detail .acts { display: flex; gap: 8px; padding: 0 0 12px; flex-wrap: wrap; }
.more { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; color: var(--muted); font-size: 13px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 15px; font-weight: 600; margin-bottom: 4px; }

/* значения и бейджи */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 500; background: var(--field); color: var(--text-2); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green-ink); }
.badge.red { background: var(--red-soft); color: var(--red-ink); }
.badge.orange { background: var(--orange-soft); color: var(--orange-ink); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ok { color: var(--green); } .bad { color: var(--red); } .warn { color: var(--orange-ink); }

/* метрики */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--surface); }
.metric small { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 2px; }
.metric b { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* игрок */
.who-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 4px 24px 0; flex-wrap: wrap; }
.fields { width: 100%; border-collapse: collapse; }
.fields td { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.fields tr:last-child td { border-bottom: 0; }
.fields td:first-child { color: var(--muted); width: 50%; }
.fields td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.val { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 6px; padding: 3px 8px; margin: -4px -8px -4px 0; background: none; cursor: default; font-variant-numeric: tabular-nums; color: var(--text); }
button.val { cursor: pointer; }
button.val:hover { border-color: var(--border-strong); background: var(--subtle); }
button.val svg { width: 13px; height: 13px; color: var(--faint); }
.fields tr.editing td { width: auto; text-align: left; padding: 8px 0 10px; color: var(--text); }
.edit-label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.edit-box { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.edit-box .input { flex: 1 1 140px; min-width: 0; height: 30px; font-variant-numeric: tabular-nums; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .sub { color: var(--muted); font-size: 12.5px; }

/* формы */
.form { display: grid; gap: 12px; }
.frow { display: grid; grid-template-columns: 240px 1fr; gap: 12px; align-items: center; font-size: 13.5px; }
.frow > span { color: var(--text-2); }
.frow .input { width: 100%; }
.prize-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.prize-row select.input { width: 200px; }

/* права */
.perm-group { margin-top: 14px; }
.perm-group .gh { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.perm-group .gh button { border: 0; background: none; color: var(--blue); cursor: pointer; font-size: 12.5px; padding: 0; }
.perms { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 16px; }
.perms label { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; font-size: 13.5px; color: var(--text-2); }
.perms input { accent-color: var(--blue); width: 15px; height: 15px; }
.note { background: var(--orange-soft); color: var(--note-ink); border-radius: 6px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 14px; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 32px; }
.login-card .logo { margin-bottom: 22px; }
.login-card h1 { font-size: 20px; font-weight: 600; margin: 0 0 6px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card .btn { width: 100%; height: 40px; }
.login-card .foot { margin-top: 22px; font-size: 13px; color: var(--muted); }
.wait { display: flex; gap: 10px; align-items: center; margin-top: 14px; font-size: 13.5px; color: var(--text-2); }
.err { margin-top: 12px; color: var(--red); font-size: 13.5px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
.loading { display: grid; place-items: center; padding: 70px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 60; background: var(--toast); color: #fff; border-radius: 8px; padding: 10px 16px; font-size: 13.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); max-width: 400px; }
.toast.bad { background: #b91c1c; }


/* ---------- тёмная тема ---------- */
:root[data-theme="dark"] {
	--bg: #0d1117;
	--surface: #161b22;
	--subtle: #1b2129;
	--field: #21262d;
	--hover: #1c232c;
	--border: #2a313b;
	--border-strong: #3a424d;
	--text: #e6edf3;
	--text-2: #c9d1d9;
	--muted: #8b949e;
	--faint: #6e7681;
	--blue: #4c8dff;
	--blue-hover: #6a9fff;
	--blue-soft: rgba(76, 141, 255, .14);
	--bar: #4c8dff;
	--orange: #e3a008;
	--orange-soft: rgba(227, 160, 8, .14);
	--red: #f85149;
	--red-soft: rgba(248, 81, 73, .14);
	--green: #3fb950;
	--green-soft: rgba(63, 185, 80, .14);
	--grid: #222933;
	--avatar-bg: #263248;
	--avatar-fg: #c7d6f5;
	--green-ink: #56d364;
	--red-ink: #ff7b72;
	--orange-ink: #e3b341;
	--set-border: rgba(76, 141, 255, .45);
	--note-ink: #e3b341;
	--danger-border: rgba(248, 81, 73, .5);
	--toast: #2d333b;
	--shadow: 0 12px 32px rgba(0, 0, 0, .45);
	color-scheme: dark;
}
:root[data-theme="dark"] .btn.primary { color: #fff; }
:root[data-theme="dark"] .sev .dot { background: #4a525d; }
:root[data-theme="dark"] .query input:focus,
:root[data-theme="dark"] .input:focus,
:root[data-theme="dark"] .top-search input:focus { background: var(--surface); }
:root[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(.8); }
html { transition: background-color .15s; }

@media (max-width: 900px) {
	.burger { display: grid; }
	.user-btn .uname { display: none; }
	.top-search { width: auto; flex: 1; margin-left: 0; }
	.topbar { padding: 0 10px; gap: 8px; }
	.side { position: fixed; z-index: 45; left: 0; top: 56px; transform: translateX(-100%); transition: transform .18s; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); }
	.side.open { transform: none; }
	.page-head, .content { padding-left: 14px; padding-right: 14px; }
	.tabs { padding: 0 14px; }
	.query { flex-direction: column; }
	.tbl.events th:nth-child(2), .ev td:nth-child(2) { display: none; }
	.kv, .frow { grid-template-columns: 1fr; }
	.detail td { padding-left: 14px; }
	.chart { padding-left: 34px; }
}
