:root {
  --bg-color: #000000;
  --header-bg: rgba(6, 6, 8, 0.96);
  --border-color: rgba(255, 255, 255, 0.12);
  --toolbar-bg: rgba(10, 10, 14, 0.98);
  --btn-bg: rgba(22, 22, 32, 0.9);
  --btn-border: rgba(255, 255, 255, 0.16);
  --btn-text: #ffffff;
  --neon-cyan: #00f3ff;
  --neon-green: #00ff66;
  --neon-pink: #ff0055;
  --neon-yellow: #ffee00;
  --toolbar-height: 52px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background-color: var(--bg-color);
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "JetBrains Mono", monospace;
  height: 100%;
  height: 100dvh;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
}

#terminal-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
  background-color: #000000;
}

/* TOP STATUS BAR */
.term-header {
  min-height: 48px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  /* Clears Telegram WebApp native X and menu buttons */
  padding-top: max(52px, calc(env(safe-area-inset-top, 0px) + 48px));
  padding-bottom: 8px;
  z-index: 50;
  user-select: none;
}

.header-left, .header-right, .header-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff3366;
  box-shadow: 0 0 8px #ff3366;
  transition: all 0.3s ease;
}

.status-indicator.online {
  background: var(--neon-green);
  box-shadow: 0 0 10px var(--neon-green), 0 0 20px var(--neon-green);
}

/* RAINBOW SHINING TITLE */
.rainbow-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ff0055, #ff9900, #ffee00, #00ff66, #00ccff, #7700ff, #ff00ff);
  background-size: 400% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: rainbow-shimmer 6s linear infinite;
}

@keyframes rainbow-shimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 400% 50%; }
}

.status-text {
  font-family: monospace;
  font-size: 10px;
  color: #888899;
}

.hdr-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: #ffffff;
  font-family: monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hdr-btn:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.96);
}

.session-btn {
  background: rgba(0, 243, 255, 0.12);
  border-color: rgba(0, 243, 255, 0.4);
  color: var(--neon-cyan);
}

.session-btn:active {
  background: var(--neon-cyan);
  color: #000;
}

.plus-btn {
  background: rgba(0, 255, 102, 0.12);
  border-color: rgba(0, 255, 102, 0.4);
  color: var(--neon-green);
  padding: 5px 8px;
}

/* MAIN TERMINAL CONTAINER */
#terminal-container {
  flex: 1;
  width: 100%;
  /* Strict bottom margin ensuring the last terminal line is ALWAYS above the action buttons */
  margin-bottom: var(--toolbar-height);
  position: relative;
  background: #000000;
  overflow: hidden;
  padding: 6px 8px 10px 8px;
}

/* XTERM RAINBOW SHINE EFFECT */
.xterm {
  height: 100% !important;
  width: 100% !important;
  background-color: #000000 !important;
  padding: 4px;
}

.xterm-viewport {
  background-color: #000000 !important;
}

.xterm-screen {
  background-color: #000000 !important;
}

/* RAINBOW LETTERS SHINE */
.xterm-rows {
  animation: rainbow-text-cycle 10s linear infinite;
}

@keyframes rainbow-text-cycle {
  0% {
    filter: hue-rotate(0deg) drop-shadow(0 0 3px rgba(255, 0, 128, 0.45));
  }
  50% {
    filter: hue-rotate(180deg) drop-shadow(0 0 4px rgba(0, 255, 255, 0.45));
  }
  100% {
    filter: hue-rotate(360deg) drop-shadow(0 0 3px rgba(255, 0, 128, 0.45));
  }
}

.xterm-rows span {
  text-shadow: 0 0 6px currentColor, 0 0 12px currentColor;
  letter-spacing: 0.5px;
}

/* Rainbow Glowing Cursor */
.xterm .xterm-cursor {
  background: #00f3ff !important;
  box-shadow: 0 0 10px #00f3ff, 0 0 20px #00f3ff;
  animation: rainbow-cursor-pulse 2s linear infinite;
}

@keyframes rainbow-cursor-pulse {
  0% { background: #00f3ff !important; box-shadow: 0 0 10px #00f3ff; }
  33% { background: #ff00ff !important; box-shadow: 0 0 10px #ff00ff; }
  66% { background: #ffee00 !important; box-shadow: 0 0 10px #ffee00; }
  100% { background: #00f3ff !important; box-shadow: 0 0 10px #00f3ff; }
}

/* Custom cyber scrollbar */
.xterm-viewport::-webkit-scrollbar {
  width: 4px;
}

.xterm-viewport::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #ff0055, #00f3ff);
  border-radius: 4px;
}

/* ACTION TOOLBAR - PINNED TO BOTTOM / KEYBOARD TOP */
.toolbar-wrapper {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--toolbar-height);
  background: var(--toolbar-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border-color);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 6px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: bottom 0.08s ease-out;
}

.toolbar-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  width: 100%;
  padding: 4px 2px;
  scrollbar-width: none;
}

.toolbar-scroll::-webkit-scrollbar {
  display: none;
}

.t-btn {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--btn-text);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  transition: all 0.1s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.t-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.3);
}

.t-btn.special {
  color: var(--neon-cyan);
  border-color: rgba(0, 243, 255, 0.35);
}

.t-btn.special.active {
  background: var(--neon-cyan);
  color: #000000;
  box-shadow: 0 0 12px var(--neon-cyan);
}

.t-btn.arrow {
  color: var(--neon-yellow);
  font-size: 15px;
  padding: 5px 12px;
}

.t-btn.danger {
  color: #ff3366;
  border-color: rgba(255, 51, 102, 0.4);
}

.t-btn.danger:active {
  background: #ff3366;
  color: #ffffff;
}

.t-btn.action {
  color: var(--neon-green);
  border-color: rgba(0, 255, 102, 0.3);
}

.t-btn.highlight {
  background: rgba(0, 255, 102, 0.15);
  box-shadow: 0 0 8px rgba(0, 255, 102, 0.3);
}

/* SESSIONS WINDOWS MODAL OVERLAY */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: #090e17;
  border: 1px solid rgba(0, 243, 255, 0.35);
  border-radius: 18px;
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8), 0 0 24px rgba(0, 243, 255, 0.15);
  animation: modalPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 10px;
  margin-bottom: 8px;
}

.modal-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-icon {
  font-size: 18px;
}

.modal-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--neon-cyan);
}

.modal-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.modal-subtitle {
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 12px;
}

.sessions-list-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 50vh;
  padding-right: 4px;
  margin-bottom: 14px;
}

.session-card {
  background: rgba(18, 26, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: all 0.15s ease;
}

.session-card.active-terminal {
  border-color: var(--neon-cyan);
  background: rgba(0, 243, 255, 0.12);
  box-shadow: 0 0 12px rgba(0, 243, 255, 0.2);
}

.session-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  overflow: hidden;
}

.session-name {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.session-preview {
  font-family: monospace;
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-session-open {
  background: rgba(0, 243, 255, 0.2);
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-session-open:active {
  background: var(--neon-cyan);
  color: #000;
}

.btn-session-close {
  background: rgba(255, 51, 102, 0.15);
  border: 1px solid rgba(255, 51, 102, 0.4);
  color: #ff3366;
  font-family: monospace;
  font-size: 13px;
  font-weight: 700;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-session-close:active {
  background: #ff3366;
  color: #fff;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-create-session {
  background: linear-gradient(135deg, rgba(0, 243, 255, 0.25), rgba(0, 255, 102, 0.25));
  border: 1px solid var(--neon-cyan);
  color: #fff;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 4px 14px rgba(0, 243, 255, 0.2);
}

.btn-create-session:active {
  transform: scale(0.97);
  filter: brightness(1.2);
}
