:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface-2);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius);
  z-index: 9999;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  max-width: 440px;
  font-size: 14px;
}
.toast.error { border-color: var(--danger); background: #2b1215; }
.toast.success { border-color: var(--success); background: #0d2820; }

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #172554 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}
.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--primary);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

.captcha-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.captcha-box {
  flex: 1;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.error-box {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
  color: #fff;
  text-decoration: none;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-full { width: 100%; }
.btn-primary { background: var(--primary); color: #082f49; }
.btn-secondary { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.btn-success { background: var(--success); color: #022c22; }
.btn-warning { background: var(--warning); color: #451a03; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* App Layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  flex-shrink: 0;
}
.sidebar-header { padding: 4px 8px 14px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.sidebar-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.nav-menu { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(56, 189, 248, 0.14); border-color: rgba(56, 189, 248, 0.35); color: var(--primary); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.user-pill { font-size: 13px; color: var(--muted); padding: 0 4px; }

.main-content { flex: 1; padding: 24px 28px; overflow-y: auto; max-width: 1440px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.panel-header h2 { font-size: 22px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 23px; font-weight: 700; margin: 6px 0 2px; }
.stat-sub { font-size: 12px; color: var(--muted); }
.status-online { color: var(--success); }
.status-offline { color: var(--danger); }

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h3 { font-size: 16px; margin-bottom: 12px; }
.card-head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.card-head-row h3 { margin-bottom: 0; }

.inline-form { display: flex; gap: 10px; }
.inline-form input { flex: 1; }

/* Chart & Players */
.metrics-canvas { width: 100%; height: 190px; background: #070d19; border: 1px solid var(--border); border-radius: 8px; display: block; }
.chart-legend { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; }
.dot-ram, .dot-cpu { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot-ram { background: #38bdf8; }
.dot-cpu { background: #10b981; }

.players-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }
.player-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.player-id { font-size: 11px; color: var(--muted); font-family: monospace; }

.console-box {
  background: #050811;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  height: 440px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
}
.rcon-output {
  margin-top: 12px;
  background: #050811;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  color: #86efac;
  white-space: pre-wrap;
}

.checkbox-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: auto; }

/* Mods */
.mod-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.mod-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  gap: 10px;
}
.mod-info { min-width: 0; }
.mod-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mod-id { font-size: 12px; color: var(--primary); font-family: monospace; }

/* Config Editors */
.toolbar-row { display: grid; grid-template-columns: 1fr 260px; gap: 10px; margin-bottom: 12px; }
.search-bar { margin-bottom: 14px; }
.add-key-bar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
}
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.cfg-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.cfg-key { font-size: 13px; font-weight: 600; color: var(--primary); word-break: break-all; }
.cfg-desc { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.raw-editor {
  height: 55vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

/* Backups & Audit */
.backups-list { display: flex; flex-direction: column; gap: 10px; }
.backup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.backup-meta { font-size: 12px; color: var(--muted); }

.audit-table-wrap { overflow-x: auto; }
.audit-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.audit-table th, .audit-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.audit-table th { color: var(--muted); font-weight: 600; }
.badge-ok { color: var(--success); font-weight: 600; }
.badge-fail { color: var(--danger); font-weight: 600; }

@media (max-width: 820px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .toolbar-row, .add-key-bar, .two-col { grid-template-columns: 1fr; }
}
