/* Página móvil de Terminal de Carlos. Los colores los manda el PC (tema
   activo) al conectar; estos son los del tema Claude (oscuro) por si acaso. */
:root {
  --bg: #262624;
  --surface: #1f1e1d;
  --surface2: #30302e;
  --surface3: #3a3937;
  --border: #3d3c39;
  --text: #eeece2;
  --muted: #a8a69d;
  --accent: #d97757;
  --accent2: #e8a87c;
  --danger: #e5534b;
  --onAccent: #1a1917;
  --vh: 100dvh; /* alto visible real (cambia con el teclado) */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font-ui); font-size: 15px;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; font-size: inherit; }
.muted { color: var(--muted); }
code { font-family: var(--font-mono); font-size: .9em; }

#app { position: fixed; inset: 0; height: var(--vh); display: flex; flex-direction: column; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- Barra superior ---------- */
.bar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--sat) + 6px) 8px 6px; min-height: 48px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.bar-logo { color: var(--accent); font-size: 22px; padding: 0 4px; }
.bar-title { flex: 1; min-width: 0; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-title { display: flex; flex-direction: column; line-height: 1.2; }
.term-title small { font-weight: 400; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex-shrink: 0; min-width: 38px; height: 38px; padding: 0 8px;
  border: none; border-radius: 10px; background: transparent; color: var(--muted);
  font-size: 18px; cursor: pointer;
}
.icon-btn:active { background: var(--surface2); }
.icon-btn.on { color: var(--accent); background: var(--surface2); }
.icon-btn.danger:active { background: var(--danger); color: #fff; }
#term-font-down, #term-font-up { font-size: 13px; font-weight: 600; }

.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); margin: 0 6px; transition: background .2s; }
.conn.on { background: #6fcf7a; }

/* ---------- Acceso ---------- */
#view-login { align-items: center; justify-content: center; padding: 24px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-logo { color: var(--accent); font-size: 48px; line-height: 1; }
.login h1 { margin: 0; font-size: 22px; font-weight: 600; }
.login p { margin: 0; font-size: 14px; }
#login-code {
  padding: 14px; text-align: center; font-family: var(--font-mono); font-size: 22px; letter-spacing: 3px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; outline: none;
}
#login-code:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; }

.btn-primary {
  padding: 13px 18px; border: none; border-radius: 12px;
  background: var(--accent); color: var(--onAccent); font-weight: 600; font-size: 15px; cursor: pointer;
}
.btn-primary:active { filter: brightness(.9); }
.btn-primary:disabled { opacity: .55; }
.btn-ghost {
  padding: 13px 18px; border: 1px solid var(--border); border-radius: 12px;
  background: transparent; color: var(--text); font-size: 15px; cursor: pointer;
}
.btn-ghost:active { background: var(--surface2); }

/* ---------- Lista de sesiones ---------- */
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px calc(var(--sab) + 84px); }
.list-hint { margin: 0 4px 10px; font-size: 12.5px; }
.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); cursor: pointer;
  text-align: left; width: 100%;
}
.card:active { background: var(--surface2); }
.card-icon { grid-row: span 2; font-size: 22px; color: var(--muted); width: 28px; text-align: center; }
.card.claude .card-icon { color: var(--accent); }
.card-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { grid-column: 2; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-side { grid-row: span 2; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.badge { font-size: 10.5px; padding: 2px 7px; border-radius: 99px; background: var(--bg); color: var(--accent); white-space: nowrap; }
.badge.warn { color: #ffd54a; }
.badge.bell { background: var(--accent); color: var(--onAccent); }
.state { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.state.busy::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.state.bell::before { background: #ffd54a; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.card-prompt { grid-column: 2 / span 2; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty { text-align: center; padding: 40px 12px; }
.empty-star { color: var(--accent); font-size: 40px; }
.empty p { margin: 6px 0; }

.fab {
  position: absolute; left: 16px; right: 16px; bottom: calc(var(--sab) + 16px);
  padding: 15px; border: none; border-radius: 14px;
  background: var(--accent); color: var(--onAccent); font-weight: 600; font-size: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); cursor: pointer;
}
.fab:active { filter: brightness(.9); }

/* ---------- Nueva sesión ---------- */
.new-form { display: flex; flex-direction: column; gap: 10px; padding-bottom: calc(var(--sab) + 20px); }
.lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; margin-top: 6px; }
#new-search, #new-prompt {
  width: 100%; padding: 11px 12px; font-family: inherit; font-size: 15px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; outline: none;
}
#new-search:focus, #new-prompt:focus { border-color: var(--accent); }
#new-prompt { resize: vertical; min-height: 90px; }
.plist { display: flex; flex-direction: column; gap: 4px; max-height: 42vh; overflow-y: auto; }
.pitem {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border: 1px solid transparent; border-radius: 12px; background: var(--surface);
  text-align: left; cursor: pointer;
}
.pitem.selected { border-color: var(--accent); }
.pitem .pi-icon { color: var(--muted); width: 18px; text-align: center; }
.pitem.claude .pi-icon { color: var(--accent); }
.pitem .pi-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pitem .pi-badge { font-size: 10.5px; color: var(--muted); background: var(--bg); padding: 2px 7px; border-radius: 99px; max-width: 90px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
#launch-info { margin: 0; font-size: 13px; }
.new-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

/* ---------- Terminal ---------- */
#term-wrap { flex: 1; min-height: 0; padding: 6px 4px 4px 8px; background: var(--bg); overflow: hidden; }
#term { height: 100%; }
#term .xterm { height: 100%; }
.xterm .xterm-viewport { background-color: transparent !important; }

.keys {
  display: flex; gap: 6px; padding: 6px 8px; overflow-x: auto; scrollbar-width: none;
  background: var(--surface); border-top: 1px solid var(--border);
  position: relative; z-index: 2; /* siempre por encima de la terminal */
}
.keys::-webkit-scrollbar { display: none; }
.keys button {
  flex-shrink: 0; min-width: 44px; height: 36px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface2); color: var(--text);
  font-family: var(--font-mono); font-size: 13px; cursor: pointer;
}
.keys button:active { background: var(--accent); color: var(--onAccent); }

.input-bar {
  display: flex; align-items: flex-end; gap: 8px; margin: 0;
  padding: 8px 8px calc(var(--sab) + 8px);
  background: var(--surface);
  position: relative; z-index: 2;
}
#input {
  flex: 1; min-width: 0; max-height: 120px; padding: 10px 12px; resize: none;
  font-family: inherit; font-size: 15px; line-height: 1.35;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 12px; outline: none;
}
#input:focus { border-color: var(--accent); }
.send {
  width: 42px; height: 42px; flex-shrink: 0; border: none; border-radius: 12px;
  background: var(--accent); color: var(--onAccent); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.send:active { filter: brightness(.9); }

/* ---------- Avisos ---------- */
#toast {
  position: absolute; left: 50%; bottom: calc(var(--sab) + 90px); transform: translateX(-50%);
  max-width: 90%; padding: 9px 14px; border-radius: 99px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.4); pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#offline {
  position: absolute; left: 0; right: 0; top: calc(var(--sat) + 48px); z-index: 40;
  padding: 6px 12px; text-align: center; font-size: 12.5px;
  background: var(--danger); color: #fff;
}
