:root {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2b2b29;
  --border: #33332f;
  --grid: #2e2e2b;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8e8d85;
  --accent: #3987e5;
  --accent-strong: #2a78d6;
  --accent-track: #184f95;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: rgba(18, 18, 17, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text-primary); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 800;
}
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--text-secondary);
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text-primary); }
.nav a.active { background: var(--surface-3); color: var(--text-primary); }
.topbar-sys { margin-left: auto; display: flex; gap: 18px; align-items: center; }
.mini-meter { display: flex; flex-direction: column; gap: 3px; min-width: 150px; }
.mini-meter .lbl { gap: 8px; }
.mini-meter .lbl { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }
.mini-meter .lbl b { color: var(--text-secondary); font-weight: 600; }
.user-menu { display: flex; align-items: center; gap: 10px; padding-left: 18px; border-left: 1px solid var(--border); }
.role-tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-secondary); }

main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-muted); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.tile .label { font-size: 12px; color: var(--text-muted); }
.tile .value { font-size: 24px; font-weight: 600; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.tile .value small { font-size: 13px; font-weight: 400; color: var(--text-muted); }
.tile .sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ---------- meter ---------- */
.meter { height: 6px; border-radius: 99px; background: var(--accent-track); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s ease; }
.meter.warn > span { background: var(--warning); }
.meter.crit > span { background: var(--critical); }
.meter.thin { height: 4px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--text-secondary); }
.seg button.on { background: var(--surface-3); color: var(--text-primary); }
.search { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 200px; }
.search:focus, .input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- server grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.srv-card { display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: border-color .15s, transform .15s; }
.srv-card:hover { border-color: #4a4a45; }
.srv-card:focus-visible { outline: 2px solid var(--accent); }
.srv-card.is-off { opacity: .82; }
.srv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.srv-name { font-weight: 600; font-size: 15px; }
.srv-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.srv-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.srv-stats .k { font-size: 11px; color: var(--text-muted); }
.srv-stats .v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.srv-actions { display: flex; gap: 6px; }
.srv-actions .btn { flex: 1; }

/* ---------- status badge (icono + texto, nunca solo color) ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px 3px 7px; border-radius: 99px; background: var(--surface-3); white-space: nowrap; }
.status svg { width: 12px; height: 12px; flex: none; }
.status.online { color: var(--good); }
.status.starting, .status.stopping { color: var(--warning); }
.status.offline { color: var(--text-muted); }
.status.crashed { color: var(--critical); }
.status .spin { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); cursor: pointer; font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: #45453f; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.btn.go { background: #0b7a0b; border-color: #0b7a0b; color: #fff; }
.btn.go:hover:not(:disabled) { background: var(--good); border-color: var(--good); }
.btn.danger { color: #ff8a8a; }
.btn.danger:hover:not(:disabled) { background: rgba(208, 59, 59, .15); border-color: var(--critical); }
.btn.solid-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }

/* ---------- detail ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); margin-bottom: 12px; font-size: 13px; }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.detail-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }
.charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1000px) { .charts { grid-template-columns: 1fr; } }
.chart-card { padding: 14px 14px 8px; }
.chart-card .now { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-card .now small { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.chart { width: 100%; height: 120px; display: block; }
.chart text { fill: var(--text-muted); font-size: 10px; font-family: var(--sans); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .12; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--surface-1); stroke-width: 2; }
.chart .limit { stroke: var(--serious); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .limit-label { fill: var(--serious); }
.chart-empty { height: 120px; display: grid; place-items: center; color: var(--text-muted); font-size: 12px; }

#tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  background: #0d0d0c; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--text-primary); box-shadow: 0 6px 20px rgba(0,0,0,.4);
  white-space: nowrap;
}
#tooltip .t { color: var(--text-muted); font-size: 11px; }

/* ---------- console ---------- */
.console-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.console-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); gap: 8px; }
.console {
  height: 460px; overflow-y: auto; margin: 0; padding: 12px 14px;
  background: #0e0e0d; font: 12.5px/1.5 var(--mono); color: #d6d5cf;
  white-space: pre-wrap; word-break: break-word;
}
.console .l-warn { color: var(--warning); }
.console .l-err { color: #ff7b7b; }
.console .l-panel { color: var(--accent); }
.console .l-chat { color: #9fe0a0; }
.console-input { display: flex; border-top: 1px solid var(--border); background: #0e0e0d; }
.console-input span { padding: 10px 0 10px 14px; color: var(--accent); font-family: var(--mono); }
.console-input input { flex: 1; background: none; border: 0; padding: 10px; font-family: var(--mono); font-size: 13px; outline: none; }
.console-input input:disabled { cursor: not-allowed; }
.quick-cmds { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 14px; border-top: 1px solid var(--border); }

.side { display: flex; flex-direction: column; gap: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; text-align: right; word-break: break-all; font-variant-numeric: tabular-nums; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li { display: flex; align-items: center; gap: 8px; }
.avatar { width: 24px; height: 24px; border-radius: 4px; background: var(--surface-3); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--text-secondary); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 500; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- forms ---------- */
.input, select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-secondary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr 160px auto; gap: 10px; align-items: end; }
@media (max-width: 800px) { .form-row { grid-template-columns: 1fr; } }
.error { color: #ff8a8a; font-size: 13px; min-height: 18px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login .brand { justify-content: center; margin-bottom: 6px; font-size: 18px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { max-width: 460px; width: 100%; display: flex; flex-direction: column; gap: 14px; }
.modal p { margin: 0; color: var(--text-secondary); white-space: pre-line; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.callout { display: flex; gap: 10px; padding: 10px 12px; border-radius: 8px; background: rgba(250, 178, 25, .08); border: 1px solid rgba(250, 178, 25, .35); color: var(--text-primary); font-size: 13px; }
.callout svg { flex: none; width: 16px; height: 16px; color: var(--warning); margin-top: 2px; }
.callout.crit { background: rgba(208, 59, 59, .1); border-color: rgba(208, 59, 59, .45); }
.callout.crit svg { color: var(--critical); }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 14px; max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: slidein .2s ease; white-space: pre-line; }
.toast.error { border-left-color: var(--critical); }
.toast.ok { border-left-color: var(--good); }
.toast svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 12px; }
  .topbar-sys { order: 3; width: 100%; margin-left: 0; }
  .user-menu { margin-left: auto; border-left: 0; padding-left: 0; }
  main { padding: 16px; }
}
