* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #101014;
  --bg-panel: #17171c;
  --bg-hover: #22222a;
  --bg-active: #2a2a33;
  --border: #2c2c35;
  --text: #e8e8ec;
  --text-dim: #8f8f9a;
  --accent: #d97748;
  --green: #3fb950;
  --red: #f85149;
  --keybar-h: 44px;
}
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 100;
}
.login-card {
  display: flex; flex-direction: column; gap: 14px; align-items: center;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px 36px; width: min(90vw, 360px);
}
.login-logo { font-size: 42px; }
.login-card h1 { font-size: 22px; font-weight: 600; }
.login-card p { color: var(--text-dim); font-size: 14px; margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 16px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100dvh; }
.sidebar {
  width: 280px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-panel); border-right: 1px solid var(--border);
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.brand { font-size: 16px; font-weight: 700; }
.machines { flex: 1; overflow-y: auto; padding: 10px; }
.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
}
.conn-status.ok { color: var(--green); }
.conn-status.bad { color: var(--red); }
.link-btn { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 12px; text-decoration: underline; }

.machine-block { margin-bottom: 18px; }
.machine-name {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); padding: 6px 8px; font-weight: 600;
}
.machine-name .dot { margin-left: auto; }
.session-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14px; color: var(--text);
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--bg-active); }
.session-item .sess-icon { opacity: .8; }
.session-item .sess-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .sess-kill {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 13px; padding: 2px 6px; border-radius: 6px; visibility: hidden;
}
.session-item:hover .sess-kill { visibility: visible; }
.session-item .sess-kill:hover { color: var(--red); background: var(--bg); }
.new-session {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 10px; cursor: pointer; font-size: 13px; color: var(--text-dim);
  border: 1px dashed var(--border); margin-top: 4px; background: none; width: 100%;
}
.new-session:hover { color: var(--text); border-color: var(--text-dim); }
.machine-offline-note { font-size: 12px; color: var(--text-dim); padding: 4px 12px; font-style: italic; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg-panel);
  min-height: 48px;
}
.current-title { font-size: 14px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.dot.on { background: var(--green); }
.dot.off { background: var(--red); }
.icon-btn {
  background: none; border: none; color: var(--text); font-size: 18px; cursor: pointer;
  padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--bg-hover); }

.term-wrap { flex: 1; position: relative; padding: 8px 4px 4px 10px; min-height: 0; background: var(--bg); }
#terminal { width: 100%; height: 100%; }
.xterm .xterm-viewport { background: transparent !important; }
.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-dim); text-align: center; font-size: 14px; line-height: 1.6;
}
.empty-icon { font-size: 40px; }

/* ---------- Barra de teclas (móvil) ---------- */
.keybar {
  display: none; gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg-panel); border-top: 1px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.keybar button {
  flex-shrink: 0; min-width: 44px; height: 34px; padding: 0 10px;
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 13px; font-family: ui-monospace, monospace; cursor: pointer;
}
.keybar button:active { background: var(--bg-active); }
.keybar button.toggle.armed { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Móvil ---------- */
.sidebar-backdrop { display: none; }
.only-mobile { display: none; }
@media (max-width: 768px) {
  .only-mobile { display: inline-flex; }
  .keybar { display: flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(82vw, 300px);
    transform: translateX(-105%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  .sidebar.open ~ .sidebar-backdrop, .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
}
