:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --surface: #10141a;
  --raised: #161b23;
  --hover: #1c222c;
  --border: #212833;
  --border-strong: #2f3846;
  --text: #e8ecf2;
  --text-2: #b1bac7;
  --muted: #7d8898;
  --accent: #22c55e;
  --accent-ink: #04210f;
  --ok: #3fb950;
  --bad: #f2645c;
  --busy: #e0a52b;
  --off: #7d8794;
  --info: #6fa8dc;
  --spark: #5d6878;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
}

h1, h2, h3, p, pre { margin: 0; }
[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  flex: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.big { width: 34px; height: 34px; stroke-width: 1.4; }

/* ============ estructura ============ */

.app {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  height: 100%;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px 16px; min-width: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 14.5px; font-weight: 650; }

.logo {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  letter-spacing: -0.5px;
}

.unit {
  color: var(--muted);
  font: 11.5px var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
}

.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--raised); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav-item.active .icon { color: var(--accent); }
.logout { color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
}

.top-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
h1 { font-size: 17px; font-weight: 650; }
h2 { font-size: 13.5px; font-weight: 650; }

.power { display: flex; gap: 8px; }

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 22px 22px;
  overflow: auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}

.card-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-height: 46px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

/* ============ estado ============ */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 11px 3px 9px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, currentColor 45%, transparent);
  background: color-mix(in srgb, currentColor 10%, transparent);
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
}

.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--bad); }
.pill.busy { color: var(--busy); }
.pill.off, .pill.unknown { color: var(--off); }
.pill.busy::before { animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.25; } }

/* ============ botones y campos ============ */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--raised);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #34d36e; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #2a0806; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn.small { padding: 5px 10px; font-size: 13px; }

.btn:focus-visible, .nav-item:focus-visible, input:focus-visible,
textarea:focus-visible, .log:focus-visible, .entry:focus-visible, .crumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="search"], input[type="password"], input[type="text"] {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}

.check input { accent-color: var(--accent); }

/* ============ consola ============ */

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 92px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tile-label { color: var(--muted); font-size: 12.5px; }
.tile-value { font-size: 22px; font-weight: 650; line-height: 1.25; }
.tile-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tile.has-spark { padding-right: 46%; }

.spark {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 42%;
  height: 46px;
  overflow: visible;
  touch-action: none;
}

.spark-line { fill: none; stroke: var(--spark); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark-area { fill: var(--spark); opacity: 0.12; }
.spark-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.spark-cursor { stroke: var(--border-strong); stroke-width: 1; }
.spark-hover { fill: var(--text); stroke: var(--surface); stroke-width: 2; }

.logs { flex: 1; min-height: 280px; display: flex; flex-direction: column; overflow: hidden; }

.conn { font-size: 12.5px; color: var(--muted); margin-right: auto; }
.conn::before { content: "● "; }
.conn.ok::before { color: var(--ok); }
.conn.busy::before { color: var(--busy); }
.conn.bad::before { color: var(--bad); }

#filter { width: 200px; padding: 5px 10px; font-size: 13px; }

.log {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 0;
  background: #07090c;
  font: 12.5px/1.55 var(--mono);
}

.line { display: flex; gap: 12px; padding: 0 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.line:hover { background: #10151c; }
.line .time { flex: none; color: #566171; user-select: none; }
.line.err .msg { color: var(--bad); }
.line.warn .msg { color: var(--busy); }
.line.sys .msg { color: var(--info); font-style: italic; }

.empty { padding: 16px 14px; color: var(--muted); font: 13px var(--sans); }

/* ============ archivos ============ */

.files {
  flex: 1;
  min-height: 340px;
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  gap: 14px;
}

.browser, .editor { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 13px; min-width: 0; }

.crumb {
  padding: 3px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-2);
  font: inherit;
  cursor: pointer;
}

.crumb:hover { background: var(--hover); color: var(--text); }
.crumb:last-of-type { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--muted); }

.entries { flex: 1; min-height: 0; overflow: auto; padding: 6px; }

.entry {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.entry:hover { background: var(--hover); }
.entry.open { background: var(--raised); box-shadow: inset 3px 0 0 var(--accent); }
.entry .icon { color: var(--muted); }
.entry.dir .icon { color: var(--info); }
.entry-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.editor-path { flex: 1; min-width: 0; font: 13px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dirty { color: var(--busy); font-size: 12.5px; }
.dirty::before { content: "● "; }

.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.editor-body { flex: 1; min-height: 0; display: flex; background: #07090c; }

.gutter, .code { font: 13px/1.55 var(--mono); padding: 10px 0; tab-size: 4; }

.gutter {
  flex: none;
  min-width: 48px;
  padding-left: 10px;
  padding-right: 10px;
  overflow: hidden;
  color: #4b5564;
  text-align: right;
  user-select: none;
  border-right: 1px solid var(--border);
}

.code {
  flex: 1;
  min-width: 0;
  padding-left: 12px;
  padding-right: 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  resize: none;
  white-space: pre;
  overflow: auto;
}

.code:focus-visible { outline: none; }

.editor-foot {
  display: flex;
  gap: 16px;
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.editor-foot .hint { margin-left: auto; }

.only-narrow { display: none; }

/* ============ perfil ============ */

.lead { color: var(--text-2); }

.profiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }

.profile { display: flex; flex-direction: column; gap: 16px; padding: 18px; }

.profile-head { display: flex; align-items: center; gap: 14px; min-width: 0; }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  font-size: 26px;
  font-weight: 700;
  overflow: hidden;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.profile-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.profile-name { font-size: 17px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-handle { color: var(--muted); font: 12.5px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.platform {
  align-self: flex-start;
  margin-left: auto;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.field small, .profile small { color: var(--muted); font-size: 12px; }

.photo-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.photo-name { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.profile-actions { display: flex; align-items: center; gap: 12px; }

.callout {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--busy) 40%, transparent);
  background: color-mix(in srgb, var(--busy) 9%, transparent);
  color: var(--text-2);
  font-size: 13px;
}

.callout .icon { color: var(--busy); margin-top: 2px; }
.callout.bad { border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--bad) 9%, transparent); }
.callout.bad .icon { color: var(--bad); }

/* ============ avisos y diálogo ============ */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 36px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--raised);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.45);
  font-size: 13.5px;
}

.toast .icon { margin-top: 2px; }
.toast.ok .icon { color: var(--ok); }
.toast.bad .icon { color: var(--bad); }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .btn { flex: none; }

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--raised);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.6);
}

.dialog::backdrop { background: rgb(4 6 9 / 0.7); }
.dialog h2 { font-size: 16px; margin-bottom: 8px; }
.dialog p { color: var(--text-2); white-space: pre-line; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ============ login ============ */

.login-body { display: flex; align-items: center; justify-content: center; padding: 20px; }

.login {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
}

.login .brand { padding: 0 0 6px; }
.login label { color: var(--text-2); font-size: 13px; margin-bottom: -6px; }
.login input { padding: 10px 12px; }
.login .btn { margin-top: 4px; padding: 10px; }

.error {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--bad) 55%, transparent);
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: #ffc9c5;
  font-size: 13.5px;
}

/* ============ pantallas angostas ============ */

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }

  .side {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .side .brand { flex: none; padding: 0 6px 0 0; }
  .side .brand-text { display: none; }
  .nav { flex-direction: row; }
  .nav-item { gap: 7px; padding: 8px 9px; white-space: nowrap; }
  .nav-item.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .nav-wide { display: none; }
  .logout span { display: none; }

  .top { padding: 10px 14px; }
  .view { padding: 12px 14px 14px; gap: 12px; }
  .power .label { display: none; }
  .power .btn { padding: 8px 12px; }

  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile-value { font-size: 19px; }

  .conn { margin-right: 0; }
  #filter { flex: 1; min-width: 110px; width: auto; }
  .line { gap: 8px; padding: 0 10px; }

  .files { grid-template-columns: minmax(0, 1fr); }
  .files.editing .browser { display: none; }
  .files:not(.editing) .editor { display: none; }
  .only-narrow { display: inline-flex; }
  .editor-foot .hint { display: none; }
}

/* Teléfonos: sin el logo, para que quepan las tres secciones y "Salir". */
@media (max-width: 430px) {
  .side .brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .pill.busy::before { animation: none; }
}
