:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel2: #1e242e;
  --line: #2a313c;
  --text: #e8edf3;
  --muted: #93a0b0;
  --accent: #2f9bdd;
  --ok: #2fb97a;
  --warn: #e6a02a;
  --bad: #e24b4b;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: anywhere;          /* nada se sale de su caja */
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px 16px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(14,17,22,.85); backdrop-filter: blur(8px); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
/* El logo es azul sobre blanco: va en una ficha blanca para que se vea en el tema oscuro. */
.logo {
  background: #fff; width: 48px; height: 48px; border-radius: 12px; flex: none;
  display: grid; place-items: center; overflow: hidden;
}
.logo img { width: 40px; height: 40px; display: block; }
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.top-right { display: flex; align-items: center; gap: 14px; }
.logout {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 14px; font-size: 13px; cursor: pointer;
}
.logout:hover { border-color: var(--accent); }
.conn { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.conn .dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--muted); }
.conn.live .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(47,185,122,.15); }

main { padding: 24px; max-width: 1200px; margin: 0 auto; }

.summary { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.summary .pill {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 18px; flex: 1 1 130px; max-width: 220px; min-width: 0;
}
.summary .pill b { font-size: 24px; display: block; }
.summary .pill span { color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 16px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 18px; cursor: pointer; transition: transform .12s, border-color .12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card { min-width: 0; }
.card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card .name { font-weight: 650; font-size: 16px; min-width: 0; flex: 1 1 130px; }
.card .status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; margin-top: 3px; }
.card .status .d { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--muted); }
.card .status.online .d { background: var(--ok); }

.big { display: flex; align-items: flex-end; gap: 12px 18px; flex-wrap: wrap; margin-bottom: 14px; }
.big .metric { flex: 1 1 110px; min-width: 0; }
.metric .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .v.err { color: var(--bad); font-size: 18px; }
.metric .l { color: var(--muted); font-size: 12px; }

.rowline { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 14px; flex-wrap: wrap; font-size: 13px; padding: 5px 0; color: var(--muted); }
.rowline > span { flex: none; }
.rowline b { color: var(--text); font-weight: 600; text-align: right; margin-left: auto; min-width: 0; }

.bar { height: 8px; background: var(--panel2); border-radius: 6px; overflow: hidden; margin: 6px 0 8px; }
.bar > i { display: block; height: 100%; border-radius: 6px; }

.empty { text-align: center; color: var(--muted); padding: 40px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; width: min(920px, 100%); max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal-head h2 { margin: 0; min-width: 0; }
.close { flex: none; background: var(--panel2); border: 0; color: var(--text); width: 36px; height: 36px; border-radius: 10px; font-size: 16px; cursor: pointer; }
.modal-body { padding: 24px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%),1fr)); gap: 12px; margin-bottom: 24px; }
.detail-grid .item { background: var(--panel2); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.detail-grid .item.wide { grid-column: span 2; }
.detail-grid .item .l { color: var(--muted); font-size: 12px; }
.detail-grid .item .v { font-size: 18px; font-weight: 650; margin-top: 2px; }
.charts { display: grid; gap: 18px; }
.chart-box { background: var(--panel2); border-radius: 14px; padding: 14px; height: 220px; }

.name .mac { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .3px; margin-top: 2px; font-family: ui-monospace, Menlo, monospace; }

/* Pantallas estrechas */
@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  main { padding: 16px; }
  .brand h1 { font-size: 18px; }
  .summary { gap: 10px; }
  .summary .pill { padding: 12px 14px; flex-basis: 40%; max-width: none; }
  .modal-body { padding: 16px; }
  .modal-head { padding: 14px 16px; }
  .chart-box { height: 200px; padding: 10px; }
}

/* Pantalla de acceso */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 12px; }
.login-brand .logo img { width: 60px; height: 60px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.login-card input {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 16px;   /* 16px: iOS no hace zoom */
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,155,221,.18); }
.login-card button {
  width: 100%; margin-top: 20px; background: var(--accent); color: #fff; border: 0;
  border-radius: 12px; padding: 13px; font-size: 16px; font-weight: 650; cursor: pointer;
}
.login-card button:disabled { opacity: .6; cursor: default; }
.login-error { margin: 14px 0 0; color: var(--bad); font-size: 13px; }
.login-error[hidden] { display: none; }
