:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --panel: #15171c;
  --panel-2: #1b1d22;
  --border: #2a2d36;
  --text: #e6e6e6;
  --muted: #9aa0a6;
  --primary: #2f7d4a;
  --primary-hover: #379657;
  --danger: #a33b3b;
  --danger-hover: #c14545;
  --warn: #c39a3b;
  --info: #3b7dc3;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin-top: .75rem; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.login-card p { margin: 0 0 1rem; }
.login-card input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .65rem .75rem;
  font-size: 14px;
  margin-bottom: .75rem;
}
.login-card button { width: 100%; }

/* ── App layout ────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  font-size: 1.15rem;
  margin: 0 1.25rem 1.5rem;
  letter-spacing: .02em;
}
.sidebar .brand span { color: var(--muted); font-weight: 400; }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: .5rem 1.25rem;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: var(--text); background: var(--panel-2); }
.sidebar nav a.active {
  color: var(--text);
  background: var(--panel-2);
  border-left-color: var(--primary);
}
.nav-group-label {
  padding: .9rem 1.25rem .25rem;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6a6f7a;
}
.nav-group-label:first-child { padding-top: .25rem; }
.sidebar-foot {
  margin-top: auto;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.content { padding: 1.25rem 1.5rem; min-width: 0; }
.content-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}
.content-head h2 { margin: 0; font-size: 1.3rem; }
.head-meta { display: flex; align-items: center; gap: .75rem; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: .55rem 1rem;
  font-size: 14px;
  cursor: pointer;
}
button:hover { background: var(--primary-hover); }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-hover); }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.ghost:hover { background: var(--panel-2); color: var(--text); }
button.small { padding: .3rem .65rem; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ── Tables ────────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
th, td {
  padding: .55rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  background: var(--panel-2);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: .35rem; }

.empty {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--border);
  color: var(--text);
}
.badge.green  { background: #1f4a31; color: #9ae0b9; }
.badge.amber  { background: #4a3d1f; color: #e0c89a; }
.badge.gray   { background: var(--border); color: var(--muted); }
.badge.blue   { background: #1f354a; color: #9ac4e0; }
.badge.red    { background: #4a1f1f; color: #e09a9a; }

/* ── Disk view ─────────────────────────────────────────────────────────── */
.disk-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.disk-bar {
  background: var(--panel-2);
  border-radius: 999px;
  height: 14px;
  overflow: hidden;
  margin: .75rem 0 .5rem;
}
.disk-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--warn));
  transition: width .3s ease;
}

/* ── Maintenance banner ────────────────────────────────────────────────── */
.maint-banner {
  background: #4a3d1f;
  color: #ffd591;
  border: 1px solid #7a6634;
  border-radius: 6px;
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  font-size: 13px;
}

/* ── Card grid (Sistema / Stats) ───────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .85rem 1rem;
}
.card .label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 0 0 .35rem;
}
.card .value {
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0;
}
.card .sub {
  font-size: 12px;
  color: var(--muted);
  margin: .25rem 0 0;
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .35rem 1rem;
  font-size: 13px;
  margin: .5rem 0 0;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ── Logs viewer pre (matchmaker logs vista, no modal) ─────────────────── */
.logs-pre {
  background: #0a0b0e;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  color: #cfd2d6;
  max-height: 70vh;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Maintenance form ──────────────────────────────────────────────────── */
.form-row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
}
.form-row label {
  display: block;
  margin-bottom: .35rem;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-row textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem .65rem;
  font: 14px/1.5 -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  resize: vertical;
  min-height: 60px;
}

/* ── Modal (logs viewer) ───────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: grid; place-items: center;
  padding: 1rem;
  z-index: 100;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-card header {
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-card header h3 { margin: 0; font-size: 1rem; word-break: break-all; }
.modal-card pre {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  color: #cfd2d6;
  background: #0a0b0e;
  flex: 1;
}
.modal-actions {
  display: flex;
  gap: .5rem;
  align-items: center;
}

/* ── Logs (selección masiva) ───────────────────────────────────────────── */
.logs-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .75rem;
}
.col-checkbox {
  width: 32px;
  text-align: center;
  padding-right: 0;
}
.col-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
}
.col-checkbox input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: .35;
}
.row-selected {
  background: rgba(47, 125, 74, 0.10);
}
.badge-count {
  display: inline-block;
  min-width: 20px;
  padding: 0 .35rem;
  margin-left: .35rem;
  border-radius: 10px;
  background: rgba(255,255,255,0.18);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

/* ── Home: section headings + mini bars + actions card ─────────────────── */
.section-h {
  margin: 1.25rem 0 .5rem;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
}
.section-h:first-child { margin-top: 0; }

.value-sub {
  font-size: .9rem;
  color: var(--muted);
  font-weight: 500;
}

.mini-bar {
  background: var(--panel-2);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
  margin: .35rem 0 .25rem;
}
.mini-bar-fill {
  height: 100%;
  transition: width .3s ease;
}
.mini-bar-fill.low  { background: var(--primary); }
.mini-bar-fill.mid  { background: var(--warn); }
.mini-bar-fill.high { background: var(--danger); }

.card.actions-card .value { font-size: 1rem; }
.card.actions-card button { margin-top: .15rem; }

/* ── Partidos en vivo: grid de campos ──────────────────────────────────── */
.campos-summary {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin: 0 0 1rem;
  font-size: 13px;
}
.campos-summary strong { font-size: 1.1rem; }

.campos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .65rem;
}
.campo-cell {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .65rem .8rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  min-height: 90px;
}
.campo-cell.free {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  min-height: 90px;
}
.campo-cell.occupied.state-playing { border-left: 3px solid #2f7d4a; }
.campo-cell.occupied.state-waiting { border-left: 3px solid #c39a3b; }
.campo-cell.occupied.state-finished { border-left: 3px solid var(--border); opacity: .7; }
.campo-cell.orphan {
  border-left-color: var(--danger);
  background: rgba(163, 59, 59, 0.10);
}
.campo-cell-head-badges {
  display: flex;
  gap: .25rem;
}
.campo-cell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
}
.campo-cell-num {
  font-weight: 600;
  font-size: 13px;
}
.campo-cell-players {
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  align-items: baseline;
}
.campo-cell-players .vs { color: var(--muted); font-size: 11px; }
.campo-cell-players .player { font-weight: 500; }
.campo-cell-meta {
  display: flex;
  gap: .35rem;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}
.campo-cell-actions {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
}

/* ── Logs partidos: filtros y grupos ───────────────────────────────────── */
.logs-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .65rem;
  margin-bottom: .75rem;
  padding: .5rem .75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.logs-filters input[type="search"],
.logs-filters select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem .6rem;
  font: 13px/1.4 inherit;
}
.logs-filters input[type="search"] {
  min-width: 260px;
  flex: 1;
}
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.checkbox-inline input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
}

.logs-table .log-group-header {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.logs-table .match-id {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.log-chevron {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0;
  width: 18px;
  height: 18px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}
.log-chevron:hover { color: var(--text); background: var(--panel-2); }
.log-chevron.expanded { color: var(--text); }
.log-chevron-spacer {
  display: inline-block;
  width: 18px;
  height: 18px;
}
.log-file-line {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: 12px;
  padding: 2px 0 2px 26px; /* indent bajo el chevron */
}
.log-file-actions {
  margin-left: auto;
  display: inline-flex;
  gap: .25rem;
}
.log-file-actions button { padding: 2px 8px; font-size: 11px; }
.log-name-link {
  color: var(--muted);
  text-decoration: none;
}
.log-name-link:hover { color: var(--text); text-decoration: underline; }

.row-has-errors td:first-child + td .match-id { color: #e09a9a; }
.row-has-errors {
  background: rgba(163, 59, 59, 0.06);
}

/* ── Matchmaker logs: health banner ────────────────────────────────────── */
.mm-health {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .65rem .9rem;
  margin-bottom: .85rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.mm-health-ok {
  background: rgba(31, 74, 49, 0.25);
  border-color: #2f5e3f;
  color: #cfeadb;
}
.mm-health-warn {
  background: rgba(74, 61, 31, 0.35);
  border-color: #7a6634;
  color: #ffd591;
}
.mm-health-error {
  background: rgba(74, 31, 31, 0.4);
  border-color: #7a3434;
  color: #ffb5b5;
}
.mm-health-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 13px;
}
.mm-health-icon { font-size: 1.1rem; }
.mm-health-detail {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-size: 12px;
}
.mm-health-detail code {
  background: rgba(0,0,0,0.25);
  padding: .15rem .35rem;
  border-radius: 4px;
  font-size: 11px;
  word-break: break-word;
}

/* ── Orphans: card en Home + banner en grid ────────────────────────────── */
.card.orphans-alert {
  border-color: #7a3434;
  background: rgba(74, 31, 31, 0.25);
}
.card.orphans-alert .value { color: #ffb5b5; }
.card.orphans-alert button { margin-top: .35rem; }
.card.orphans-ok .value { font-size: 1rem; }

.orphan-banner {
  background: rgba(74, 31, 31, 0.4);
  border: 1px solid #7a3434;
  border-radius: 6px;
  padding: .65rem .9rem;
  margin-bottom: .75rem;
  color: #ffb5b5;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

/* ── Matchmaker logs: filtros y color-coding ───────────────────────────── */
.mm-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .65rem;
  margin-bottom: .65rem;
  padding: .5rem .75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.mm-filters select,
.mm-filters input[type="search"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem .6rem;
  font: 13px/1.4 inherit;
}
.mm-filters input[type="search"] { min-width: 240px; flex: 1; }

/* Chips: filtros visibles a la vez en vez de dropdown */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}
.chip {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: .3rem .75rem;
  border-radius: 999px;
  font: 12px/1 inherit;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.chip:hover { color: var(--text); background: var(--border); }
.chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.chip.active:hover { background: var(--primary-hover); }

/* Leyenda de colores de logs matchmaker */
.mm-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .85rem;
  font-size: 11px;
  color: var(--muted);
  padding: .5rem .75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: .5rem;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--border);
}
.legend-dot.ml-error       { background: #ffb5b5; }
.legend-dot.ml-warn        { background: #ffd591; }
.legend-dot.ml-spawn       { background: #9ac4e0; }
.legend-dot.ml-exit        { background: #9ae0b9; }
.legend-dot.ml-admin       { background: #c39ae0; }
.legend-dot.ml-auth        { background: #e0c89a; }
.legend-dot.ml-live        { background: #9adde0; }
.legend-dot.ml-broadcaster { background: #b0b5e0; }
.legend-dot.ml-startup     { background: #d6d6cf; }
.legend-dot.ml-cleanup     { background: #9aa0a6; }
.legend-sep {
  width: 1px;
  height: 12px;
  background: var(--border);
  display: inline-block;
}

/* Cada span se renderiza inline dentro del <pre>. El display block hace que
   cada línea ocupe su altura aunque tenga padding/background. */
.logs-pre span { display: block; }
.ml-info        { color: #cfd2d6; }
.ml-error       { color: #ffb5b5; background: rgba(163, 59, 59, 0.15); }
.ml-warn        { color: #ffd591; background: rgba(195, 154, 59, 0.10); }
.ml-spawn       { color: #9ac4e0; }
.ml-exit        { color: #9ae0b9; }
.ml-admin       { color: #c39ae0; }
.ml-auth        { color: #e0c89a; }
.ml-live        { color: #9adde0; }
.ml-broadcaster { color: #b0b5e0; }
.ml-startup     { color: #d6d6cf; }
.ml-cleanup     { color: #9aa0a6; }
