*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0e14;
  --bg2: #111620;
  --bg3: #1a2030;
  --accent: #00d4ff;
  --accent2: #00ff9f;
  --text: #cdd6f4;
  --muted: #6c7396;
  --danger: #f38ba8;
  --warn: #f9e2af;
  --header-h: 50px;
  --toolbar-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
  -webkit-text-size-adjust: none;
  overflow: hidden;
  touch-action: manipulation;
}

/* ── LOGIN ─────────────────────────────────────── */
#view-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  gap: 1.2rem;
  padding: 1.5rem;
}

#view-login h1 {
  font-size: 1.5rem;
  color: var(--accent);
  letter-spacing: 0.05em;
}

#view-login input[type=password] {
  width: 100%;
  max-width: 320px;
  padding: .8rem 1rem;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.1rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
#view-login input[type=password]:focus { border-color: var(--accent); }

#view-login button {
  width: 100%;
  max-width: 320px;
  padding: .8rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .15s;
}
#view-login button:active { opacity: .75; }

#login-error {
  color: var(--danger);
  font-size: .85rem;
  min-height: 1.2em;
  text-align: center;
}

/* ── TERMINAL VIEW ──────────────────────────────── */
#view-term {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* Header */
#term-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  height: var(--header-h);
  padding: 0 .75rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--bg3);
  flex-shrink: 0;
  overflow: hidden;
}

#session-select {
  flex: 1;
  min-width: 0;
  padding: .35rem .6rem;
  background: var(--bg3);
  border: 1px solid var(--muted);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  outline: none;
  cursor: pointer;
}

.hbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--bg3);
  border: 1px solid var(--muted);
  border-radius: 6px;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.hbtn:active { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.hbtn.danger:active { background: var(--danger); border-color: var(--danger); }

/* Terminal container */
#term-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  min-height: 0; /* crucial for flex children in column flex */
}

/* xterm internal elements — must fill the parent */
#term-body > .xterm,
#term-body > .xterm > .xterm-viewport,
#term-body > .xterm > .xterm-screen {
  height: 100% !important;
  width: 100% !important;
}

#term-body .xterm {
  padding: 4px;
  box-sizing: border-box;
}

/* Reconnect banner */
#reconnect-banner {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0;
  background: var(--warn);
  color: var(--bg);
  text-align: center;
  font-size: .8rem;
  font-weight: 600;
  padding: .25rem;
  z-index: 10;
}
#reconnect-banner.visible { display: block; }

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: calc(var(--toolbar-h) + var(--safe-bottom));
  padding: 6px 6px calc(6px + var(--safe-bottom));
  background: var(--bg2);
  border-top: 1px solid var(--bg3);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }

.tkey {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  min-width: 38px;
  padding: 0 10px;
  background: var(--bg3);
  border: 1px solid var(--muted);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition: background .1s, color .1s, border-color .1s;
}
.tkey:active { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.tkey.sticky-active {
  background: var(--accent2);
  color: var(--bg);
  border-color: var(--accent2);
}
.tkey.sep {
  width: 1px; min-width: 1px;
  padding: 0; height: 24px;
  background: var(--bg3);
  border: none;
  border-left: 1px solid var(--muted);
  cursor: default;
  pointer-events: none;
}

/* Session modal */
#modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#modal-overlay.visible { display: flex; }
#modal-box {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 12px;
  padding: 1.5rem;
  width: min(90vw, 340px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
#modal-box h2 { font-size: 1rem; color: var(--accent); }
#modal-name {
  padding: .7rem .9rem;
  background: var(--bg3);
  border: 1px solid var(--muted);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}
#modal-name:focus { border-color: var(--accent); }
.modal-btns { display: flex; gap: .75rem; }
.modal-btns button {
  flex: 1;
  padding: .7rem;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
}
#modal-cancel { background: var(--bg3); color: var(--text); }
#modal-ok { background: var(--accent); color: var(--bg); }

/* Hidden helper */
.hidden { display: none !important; }
