@font-face {
  font-family: "Space Grotesk";
  src: local("Space Grotesk"), local("SpaceGrotesk");
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: local("IBM Plex Mono"), local("IBMPlexMono");
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --bg-strong: #efe4d4;
  --panel: rgba(255, 255, 255, 0.85);
  --panel-strong: rgba(255, 255, 255, 0.95);
  --accent: #f25f5c;
  --accent-strong: #f7a072;
  --text: #1f1d1a;
  --muted: #6f6a63;
  --terminal-bg: #0f1213;
  --terminal-border: #1f2528;
  --terminal-text: #d6e2dd;
  --shadow: 0 18px 40px rgba(31, 25, 19, 0.18);
  --success: #2a9d8f;
  --danger: #a13b3b;
}

* {
  box-sizing: border-box;
}

/* Desactivar pull-to-refresh del navegador */
html, body {
  overscroll-behavior: none;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 20% 20%, #fff6e8, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(
      rgba(0, 0, 0, 0.04) 1px,
      transparent 1px
    ),
    linear-gradient(90deg, rgba(0, 0, 0, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  pointer-events: none;
  opacity: 0.35;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: var(--shadow);
  position: relative;
}

.header-content {
  display: contents;
}

.toggle-header {
  display: none;
}

/* Header colapsado */
.topbar.collapsed .header-content {
  display: none;
}

.topbar.collapsed {
  padding: 6px 12px;
  justify-content: center;
}

.topbar.collapsed .toggle-header {
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(242, 95, 92, 0.55);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.title {
  font-size: 1.05rem;
  font-weight: 600;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
}

.status-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--panel-strong);
  color: var(--muted);
}

.status-pill[data-state="connected"] {
  background: rgba(42, 157, 143, 0.15);
  color: #1d5c53;
  border-color: rgba(42, 157, 143, 0.35);
}

.status-pill[data-state="connecting"] {
  background: rgba(247, 160, 114, 0.2);
  color: #8b4c2f;
  border-color: rgba(247, 160, 114, 0.45);
}

.status-pill[data-state="offline"] {
  background: rgba(161, 59, 59, 0.12);
  color: #813535;
  border-color: rgba(161, 59, 59, 0.3);
}


.cli-shortcuts {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.cli-button {
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  background: linear-gradient(135deg, var(--panel-strong), var(--panel));
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.cli-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  border-color: var(--accent);
}

.cli-button:active {
  transform: translateY(0);
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.top-actions button {
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: none;
}

.top-actions .primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(242, 95, 92, 0.25);
}

.top-actions .ghost {
  background: var(--panel-strong);
  color: var(--text);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.top-actions button:hover {
  transform: translateY(-1px);
}

.tabs {
  display: flex;
  gap: 10px;
  padding: 12px 20px 0;
  overflow-x: auto;
}

.tab {
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  padding: 8px 18px 8px 14px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab.active {
  color: #fff;
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  box-shadow: 0 10px 30px rgba(242, 95, 92, 0.3);
}

.tab-close {
  margin-left: 10px;
  font-weight: 700;
}

.terminal-area {
  flex: 1;
  padding: 8px;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.welcome-card {
  max-width: 640px;
  padding: 32px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow);
}

.welcome-card h1 {
  margin: 0 0 10px 0;
  color: var(--accent);
  font-size: 2rem;
}

.welcome-card p {
  margin: 0 0 24px 0;
  color: var(--muted);
}

.hint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.hint-card {
  padding: 16px;
  border-radius: 16px;
  background: var(--panel-strong);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.hint-card h3 {
  margin: 0 0 6px 0;
  font-size: 1rem;
}

.hint-card p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

body.modal-open {
  overflow: hidden;
}

.dir-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 18, 19, 0.35);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 300;
}

.dir-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.dir-modal-card {
  width: min(760px, 94vw);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--panel-strong);
  border-radius: 24px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dir-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.dir-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.dir-modal-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
}

.dir-close {
  border: none;
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
}

.dir-modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dir-search {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.dir-search input {
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

.dir-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(242, 95, 92, 0.15);
}

.dir-list {
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  max-height: 40vh;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dir-item {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.dir-item:hover {
  background: rgba(242, 95, 92, 0.08);
}

.dir-item.focused {
  border-color: rgba(242, 95, 92, 0.5);
  background: rgba(242, 95, 92, 0.12);
}

.dir-item.selected {
  border-color: rgba(42, 157, 143, 0.45);
  background: rgba(42, 157, 143, 0.16);
}

.dir-item .dir-name {
  font-weight: 600;
  color: var(--text);
}

.dir-item .dir-path {
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
}

.dir-empty {
  display: none;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 8px 0;
}

.dir-modal-footer {
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dir-selected {
  font-size: 0.85rem;
  color: var(--muted);
}

.dir-selected span {
  color: var(--text);
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
}

.dir-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.dir-action {
  flex: 0 0 auto;
}

.dir-shell {
  border-radius: 12px;
  padding: 8px 14px;
  font-weight: 600;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dir-shell:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(31, 25, 19, 0.12);
}

.terminal-session {
  display: none;
  height: 100%;
}

.terminal-session.active {
  display: block;
  height: 100%;
}

.terminal-xterm {
  background: var(--terminal-bg);
  border: 1px solid var(--terminal-border);
  border-radius: 18px;
  padding: 12px;
  overflow: hidden;
  height: 100%;
  box-sizing: border-box;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  cursor: default;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.terminal-xterm:hover {
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  border-color: rgba(88, 166, 255, 0.3);
}

.terminal-xterm .xterm {
  height: 100%;
}

.terminal-xterm .xterm-viewport {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
}

.terminal-xterm .xterm-screen {
  padding: 4px;
}

/* Overlay para bloquear touch en terminal */
.terminal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: transparent;
  touch-action: pan-y;
}

/* Ocultar overlay cuando teclado está activo */
.keyboard-active .terminal-overlay {
  display: none;
}

/* Permitir scroll cuando teclado virtual está activo */
.keyboard-active {
  overflow: auto !important;
}

.keyboard-active .app {
  overflow: visible !important;
  min-height: 100%;
}

/* Hacer terminal-xterm position relative para el overlay */
.terminal-xterm {
  position: relative;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 960px;
  margin: 0 auto 10px;
}

.quick-actions button {
  border-radius: 999px;
  padding: 8px 16px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.quick-actions button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(31, 25, 19, 0.12);
}

.control-pad {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 960px;
  margin: 0 auto 4px;
  align-items: center;
}

.control-row {
  display: flex;
  gap: 8px;
}

.control-key {
  min-width: 64px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.control-key.wide {
  min-width: 140px;
}

.keyboard-toggle {
  min-width: 64px;
  font-size: 1.3rem;
  padding: 10px;
}

.keyboard-toggle.active {
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(242, 95, 92, 0.35);
  transform: scale(1.05);
}

.control-key:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(31, 25, 19, 0.12);
}

.control-key:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-container {
  padding: 8px 12px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-sizing: border-box;
}

.input-wrapper {
  display: flex;
  gap: 10px;
  max-width: 960px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 16px;
  padding: 12px;
  transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
}

#command-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 1rem;
  resize: none;
  outline: none;
  max-height: 200px;
}

#command-input::placeholder {
  color: var(--muted);
}

.send-button {
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
  transform: scale(1.02);
  box-shadow: 0 8px 20px rgba(242, 95, 92, 0.25);
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 8px;
}

@media (max-width: 720px) {
  .topbar {
    padding: 10px 12px;
  }

  .dir-modal {
    padding: 12px;
  }

  .dir-modal-card {
    width: 96vw;
    max-height: 90vh;
    border-radius: 20px;
  }

  .dir-modal-header,
  .dir-modal-body,
  .dir-modal-footer {
    padding: 12px 14px;
  }

  .dir-list {
    max-height: 46vh;
  }

  .quick-actions {
    margin: 0 0 4px 0;
    gap: 4px;
    width: 100%;
  }

  .quick-actions button {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .welcome-card h1 {
    font-size: 1.6rem;
  }
}

/* Pantallas muy pequeñas */
@media (max-width: 400px) {
  .control-key {
    padding: 8px 2px;
    font-size: 0.75rem;
  }

  .keyboard-toggle {
    padding: 8px 2px;
    font-size: 1rem;
  }

  .control-pad {
    gap: 3px;
  }

  .control-row {
    gap: 3px;
  }
}

/* Móviles muy pequeños (altura) */
@media (max-height: 700px) and (max-width: 720px) {
  .control-key {
    padding: 10px 4px !important;
  }
}

@media (max-height: 600px) and (max-width: 720px) {
  .control-key {
    padding: 8px 4px !important;
  }
}

/* Optimización para móvil */
@media (max-width: 720px) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
  }

  .app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .topbar {
    flex-shrink: 0;
    padding: 8px 10px;
    gap: 6px 10px;
  }

  .toggle-header {
    display: block;
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(0,0,0,0.1);
    border-radius: 6px;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 10;
  }

  .topbar.collapsed .toggle-header {
    position: static;
    width: 100%;
    height: 24px;
  }

  .header-content {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    align-items: center;
    width: 100%;
    padding-right: 32px;
  }

  .topbar.collapsed .header-content {
    display: none;
  }

  .brand .subtitle {
    display: none;
  }

  .title {
    font-size: 0.9rem;
  }

  .status-pill {
    padding: 4px 8px;
    font-size: 0.7rem;
  }

  .cli-button {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .top-actions button {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .tabs {
    flex-shrink: 0;
    padding: 6px 10px 0;
  }

  .tab {
    padding: 6px 12px 6px 10px;
    font-size: 0.8rem;
  }

  /* Terminal area - altura calculada por JS */
  .terminal-area {
    padding: 4px;
  }

  .terminal-xterm {
    border-radius: 12px !important;
    padding: 6px !important;
  }

  .terminal-xterm .xterm-viewport {
    border-radius: 0 0 12px 12px;
  }

  /* Footer - ajustes móvil */
  .input-container {
    padding: 3px 4px 4px 4px !important;
  }

  .quick-actions {
    margin: 0 0 2px 0 !important;
    min-height: 0 !important;
  }

  .quick-actions:empty {
    display: none;
  }

  .control-pad {
    display: flex !important;
    flex-direction: column !important;
    gap: 4px !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .control-row {
    display: flex !important;
    flex-direction: row !important;
    gap: 4px !important;
    width: 100% !important;
  }

  .control-key {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    padding: 14px 4px !important;
    font-size: 1rem !important;
  }

  .keyboard-toggle {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    padding: 14px 4px !important;
    font-size: 1.2rem !important;
  }
}
