:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1d222b;
  --border: #2a303b;
  --text: #e6e8eb;
  --muted: #8b93a1;
  --accent: #22c55e;
  --accent-text: #06210f;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; margin: 4px 0; }
.grow { flex: 1; }
.logo { font-family: ui-monospace, monospace; color: var(--accent); font-weight: 700; }

button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
button.link { background: none; border: none; color: var(--muted); padding: 4px; }
button.link:hover { color: var(--text); }
button.icon { padding: 4px 9px; background: none; border-color: transparent; font-size: 16px; }
button.icon:hover { border-color: var(--border); }

input, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin-top: 4px;
}
textarea { font-family: ui-monospace, monospace; font-size: 12px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -1px; }
label { display: block; margin: 10px 0; color: var(--muted); font-size: 13px; }

/* Login */
.login { height: 100%; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.card h1 { font-size: 20px; margin: 0 0 12px; }
.card button { width: 100%; margin-top: 8px; padding: 10px; }

/* Layout */
.app { display: flex; height: 100%; height: 100dvh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar header { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.sidebar header strong { flex: 1; }
.sidebar footer { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-top: 1px solid var(--border); }
.sidebar > p { padding: 12px; margin: 0; }
.server-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.server-list li { display: flex; align-items: center; border-radius: var(--radius); }
.server-list li:hover { background: var(--panel-2); }
.server-list .connect { flex: 1; text-align: left; background: none; border: none; padding: 8px 10px; min-width: 0; }
.server-list .connect span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-list .connect .sub { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }
.server-list .edit { opacity: 0; }
.server-list li:hover .edit, .server-list .edit:focus { opacity: 1; }
@media (hover: none) { .server-list .edit { opacity: 1; } }

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 6px; background: var(--panel); border-bottom: 1px solid var(--border); }
.tab-list { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 10px; white-space: nowrap;
  background: none; border: 1px solid transparent; border-radius: var(--radius); color: var(--muted);
}
.tab[aria-selected="true"] { background: var(--bg); border-color: var(--border); color: var(--text); }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.tab.connected .dot { background: var(--accent); }
.tab.error .dot { background: var(--danger); }
.tab .close { padding: 0 5px; border: none; background: none; color: var(--muted); line-height: 1; }
.tab .close:hover { color: var(--text); }

.terminals { flex: 1; position: relative; min-height: 0; }
.term-pane { position: absolute; inset: 0; padding: 6px 0 0 8px; background: var(--bg); }
.term-pane .xterm { height: 100%; }
.welcome { height: 100%; display: grid; place-content: center; text-align: center; padding: 16px; }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 80%, transparent); z-index: 10;
}
.overlay .card { max-width: 460px; }
.overlay code { display: block; word-break: break-all; background: var(--bg); padding: 8px; border-radius: 6px; margin: 8px 0; font-size: 12px; }
.overlay .actions { display: flex; gap: 8px; }
.overlay .actions button { width: auto; flex: 1; }
.overlay.mismatch h2 { color: var(--danger); }

/* Barra de teclas (móvil) */
.keybar { display: flex; gap: 4px; padding: 6px; background: var(--panel); border-top: 1px solid var(--border); overflow-x: auto; }
.keybar button { flex: 1 0 auto; padding: 8px 10px; font-family: ui-monospace, monospace; }
.keybar .mod.active { background: var(--accent); color: var(--accent-text); }

/* Diálogo */
dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.6); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
.row { display: flex; gap: 10px; }
.row .port { width: 100px; }
.segmented { border: none; padding: 0; margin: 10px 0; display: flex; gap: 16px; flex-wrap: wrap; }
.segmented legend { color: var(--muted); font-size: 13px; padding: 0; margin-bottom: 4px; }
.segmented label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--text); }
.segmented input { width: auto; margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

/* Móvil */
@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(300px, 85vw); transform: translateX(-100%); transition: transform .2s; }
  .app.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgb(0 0 0 / .5); }
  .term-pane { padding-left: 4px; }
}
@media (min-width: 761px) {
  .app.sidebar-collapsed .sidebar { display: none; }
}
