:root {
  --bg: #0b1120;
  --bg2: #0f172a;
  --panel: #111a2e;
  --panel2: #16213a;
  --line: #1f2b45;
  --line2: #2a3a5c;
  --text: #e2e8f0;
  --muted: #8b9ab5;
  --dim: #5d6b86;
  --accent: #38bdf8;
  --accent2: #0ea5e9;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --violet: #a78bfa;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
input, select, textarea, button { font: inherit; color: inherit; }
::selection { background: #38bdf855; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #26344f; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #33466b; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px;
  border-radius: 8px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text);
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: #1c2947; border-color: #3a4c72; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #04121f; font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: #fecaca; border-color: #7f1d1d; background: #2a1215; }
.btn.danger:hover { background: #3b1519; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--panel2); color: var(--text); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 13px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--panel2); color: var(--text); }
.input, select.input, textarea.input {
  height: 34px; padding: 0 11px; border-radius: 8px; border: 1px solid var(--line2);
  background: var(--bg2); outline: none; min-width: 0;
}
textarea.input { height: auto; padding: 10px; }
.input:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px #0ea5e933; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; user-select: none; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #0ea5e922, transparent), radial-gradient(900px 500px at 110% 110%, #a78bfa1a, transparent), var(--bg); }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; padding: 28px; border-radius: 16px;
  background: #0f172acc; border: 1px solid var(--line); box-shadow: 0 30px 80px #0008; backdrop-filter: blur(10px); }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input { height: 40px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line2); background: var(--bg); outline: none; }
.login-card input:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px #0ea5e933; }
.login-card .btn { height: 40px; justify-content: center; }
.err { color: #fca5a5; min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 9px; padding: 18px 18px 14px; font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand small { font-weight: 500; color: var(--dim); font-size: 11px; margin-left: auto; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand.big { font-size: 22px; justify-content: center; padding: 0 0 8px; }
.logo { color: var(--accent); font-size: .95em; }
nav { display: grid; gap: 2px; padding: 6px 10px; }
nav a { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 8px; color: var(--muted); font-weight: 500; }
nav a:hover { background: var(--panel); color: var(--text); }
nav a.active { background: linear-gradient(90deg, #0ea5e926, #0ea5e90d); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
nav a.active svg { color: var(--accent); }
.side-foot { margin-top: auto; padding: 12px; display: grid; gap: 8px; border-top: 1px solid var(--line); }
.side-foot .btn { justify-content: flex-start; }
.mini { display: grid; gap: 7px; font-size: 12px; color: var(--muted); }
.mini .row { display: grid; grid-template-columns: 34px 1fr 38px; align-items: center; gap: 8px; }
.mini .row span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.ver { font-size: 11px; color: var(--dim); text-align: center; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 22px; border-bottom: 1px solid var(--line); flex: none; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.view { flex: 1; overflow: auto; padding: 20px 22px 30px; min-height: 0; }
.mobile-only { display: none; }

/* ---------- cards / dashboard ---------- */
.grid { display: grid; gap: 14px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; display: flex; align-items: center; gap: 8px; }
.card h3 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }
.big-num { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.sub { color: var(--muted); font-size: 12.5px; }
.spark { width: 100%; height: 56px; display: block; margin-top: 10px; }
.chart { width: 100%; height: 170px; display: block; }
.bar { height: 6px; background: #1b2740; border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: var(--accent); transition: width .5s; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 4px; margin-top: 10px; }
.cores i { height: 26px; border-radius: 4px; background: #1b2740; position: relative; overflow: hidden; }
.cores i b { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); opacity: .85; transition: height .5s; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
table.fixed { table-layout: fixed; }
table.fixed td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.alert { padding: 10px 14px; border-radius: 9px; border: 1px solid #78350f; background: #2a1d0c; color: #fde68a; margin-bottom: 14px; }

/* ---------- tables ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { position: sticky; top: 0; background: #131d33; z-index: 1; text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
th.sort { cursor: pointer; } th.sort:hover { color: var(--text); }
td { padding: 8px 12px; border-bottom: 1px solid #172238; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #142039; }
tr.sel { background: #0ea5e91f !important; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono, .mono { font-family: var(--mono); font-size: 12.5px; }
td.muted { color: var(--muted); }
td.actions { text-align: right; white-space: nowrap; }
td.trunc { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #1b2740; color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: #4ade80; background: #052e1a; } .badge.bad { color: #f87171; background: #2c0e0e; }
.badge.warn { color: #fbbf24; background: #2a1d06; } .badge.info { color: #7dd3fc; background: #082236; }
.badge.plain::before { display: none; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: #1b2740; color: var(--muted); }

/* ---------- files ---------- */
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 14px; min-width: 0; }
.crumbs a { padding: 4px 7px; border-radius: 6px; color: var(--text); }
.crumbs a:hover { background: var(--panel2); }
.crumbs span { color: var(--dim); }
.fname { display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.fname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fname svg { width: 20px; height: 20px; }
.fname .d { color: #60a5fa; } .fname .f { color: #94a3b8; } .fname .l { color: var(--violet); }
.fname small { color: var(--dim); font-size: 12px; }
.files-table td:first-child { width: 32px; padding-right: 0; }
.drop-hint { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #0b1120cc; border: 3px dashed var(--accent); font-size: 20px; pointer-events: none; }
.uploads { position: fixed; right: 18px; bottom: 18px; width: 320px; z-index: 40; display: grid; gap: 6px; }
.upl { background: var(--panel2); border: 1px solid var(--line2); border-radius: 9px; padding: 10px 12px; font-size: 12.5px; }
.upl .bar { margin-top: 6px; }

/* ---------- terminal ---------- */
.term-view { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.term-tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); background: var(--bg2); flex: none; overflow-x: auto; }
.term-tab { display: flex; align-items: center; gap: 8px; padding: 7px 10px 7px 14px; border-radius: 8px 8px 0 0; color: var(--muted); cursor: pointer; border: 1px solid transparent; border-bottom: 0; white-space: nowrap; }
.term-tab.active { background: #05080f; color: var(--text); border-color: var(--line); }
.term-tab .x { border: 0; background: none; color: var(--dim); cursor: pointer; padding: 0 3px; font-size: 15px; line-height: 1; }
.term-tab .x:hover { color: var(--bad); }
.term-host { flex: 1; position: relative; background: #05080f; min-height: 0; }
.term-pane { position: absolute; inset: 0; padding: 8px 4px 4px 10px; }
.term-status { position: absolute; right: 14px; top: 10px; z-index: 5; }

/* ---------- logs/output ---------- */
.output { background: #05080f; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; overflow: auto; max-height: calc(100vh - 210px); margin: 0; }
.output .e { color: #fca5a5; } .output .w { color: #fcd34d; } .output .ts { color: var(--dim); }

/* ---------- modal / toasts / context ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 60; background: #02061799; backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; animation: fade .12s; }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; width: 100%; max-width: 460px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 30px 80px #000a; }
.modal.wide { max-width: 1100px; height: calc(100vh - 32px); }
.modal header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal header .sp { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.modal .body { padding: 16px; overflow: auto; display: grid; gap: 12px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.editor-wrap { flex: 1; display: flex; min-height: 0; background: #05080f; }
.editor-wrap .gutter { padding: 12px 8px 12px 12px; color: var(--dim); text-align: right; font-family: var(--mono); font-size: 13px; line-height: 20px; user-select: none; overflow: hidden; white-space: pre; min-width: 48px; }
.editor-wrap textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--text); font-family: var(--mono); font-size: 13px; line-height: 20px; padding: 12px; white-space: pre; overflow: auto; tab-size: 4; }
.preview { flex: 1; display: grid; place-items: center; background: #05080f; overflow: auto; min-height: 0; }
.preview img, .preview video { max-width: 100%; max-height: 100%; }
.preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.perm-grid { display: grid; grid-template-columns: auto repeat(3, 1fr); gap: 8px 10px; align-items: center; font-size: 13px; }
.perm-grid b { color: var(--muted); font-weight: 500; }
.toasts { position: fixed; top: 14px; right: 14px; z-index: 80; display: grid; gap: 8px; width: min(380px, calc(100vw - 28px)); }
.toast { padding: 11px 14px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line2); box-shadow: 0 10px 30px #0008; font-size: 13.5px; animation: slide .18s; white-space: pre-wrap; overflow-wrap: anywhere; }
.toast.ok { border-color: #166534; } .toast.bad { border-color: #991b1b; background: #1f0f12; }
.ctx { position: fixed; z-index: 70; min-width: 190px; background: var(--panel2); border: 1px solid var(--line2); border-radius: 10px; padding: 5px; box-shadow: 0 16px 40px #000a; }
.ctx button { display: flex; width: 100%; align-items: center; gap: 9px; padding: 8px 10px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left; }
.ctx button:hover { background: #22305180; }
.ctx button.danger { color: #fca5a5; }
.ctx hr { border: 0; border-top: 1px solid var(--line2); margin: 4px 2px; }
.spinner { width: 16px; height: 16px; border: 2px solid #ffffff33; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- roles ---------- */
.role-admin .owner-only { display: none !important; }
[data-mode="games"] .vps-only, [data-mode="vps"] .games-only { display: none !important; }
[data-mode="games"] .logo { color: #a78bfa; }
.nav-sep { margin: 12px 11px 4px; font-size: 11px; letter-spacing: .8px; text-transform: uppercase; color: var(--dim); }

/* ---------- game servers ---------- */
.gs-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.gs-card { display: grid; gap: 8px; transition: border-color .15s; }
.gs-card:hover { border-color: var(--line2); }
.gs-head { display: flex; justify-content: space-between; align-items: center; }
.gs-name { font-size: 15.5px; font-weight: 650; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-name:hover { color: var(--accent); }
.gs-addr { cursor: pointer; }
.gs-addr:hover { color: var(--accent); }
.gs-meta { min-height: 18px; }
.gs-bars { display: grid; gap: 6px; }
.gs-bars > div { display: grid; grid-template-columns: 34px 1fr 64px; align-items: center; gap: 8px; }
.gs-bars > div span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.gs-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.gs-actions a:last-child { margin-left: auto; }
.gs-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.gs-title { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.gs-live { display: flex; gap: 18px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.gs-live b { color: var(--text); font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; color: var(--muted); cursor: pointer; font-weight: 550; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.gs-console { display: flex; flex-direction: column; height: calc(100vh - 240px); min-height: 320px; background: #05080f; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.gs-term { flex: 1; min-height: 0; padding: 8px 4px 4px 10px; }
.gs-cmd { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-top: 1px solid var(--line); background: #0a1020; }
.gs-cmd > span { color: var(--accent); font-size: 18px; }
.gs-cmd .input { flex: 1; background: transparent; border-color: transparent; }
.gs-cmd .input:focus { box-shadow: none; border-color: var(--line2); }
.lbl { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 55; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 20px 0 60px #000a; }
  .mobile-only { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .view { padding: 14px 16px 24px; }
  .two { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
