/* Terminal Application Styles - The Rails Way */

/* Custom scrollbar for terminal */
.terminal-output::-webkit-scrollbar {
  width: 8px;
}

.terminal-output::-webkit-scrollbar-track {
  background: var(--color-bg);
  border-left: 1px solid var(--color-fg);
}

.terminal-output::-webkit-scrollbar-thumb {
  background: var(--color-fg);
  opacity: 0.5;
}

.terminal-output::-webkit-scrollbar-thumb:hover {
  background: var(--color-accent);
}

.terminal-line {
  color: var(--color-fg);
  @apply font-mono mb-1;
}

.terminal-line.command {
  color: var(--color-fg);
}

.terminal-line.error {
  color: var(--color-error);
}

.terminal-line.success {
  color: var(--color-success);
}

.terminal-line.system {
  color: var(--color-warning);
}

.terminal-line.hint {
  color: var(--color-hint);
  @apply text-sm;
}

.terminal-line.ai {
  color: var(--color-accent);
}

.terminal-line.box {
  color: var(--color-fg);
}

.terminal-line.prompt {
  color: var(--color-info);
}

.terminal-line.info {
  color: var(--color-info);
}

.terminal-line.text {
  color: var(--color-fg);
}

/* Remove default input/textarea styling */
input[type="text"], textarea {
  caret-color: var(--color-fg);
}

input[type="text"]::placeholder, textarea::placeholder {
  color: transparent;
}

/* Auto-expanding textarea styles */
textarea {
  line-height: 1.5;
  min-height: 1.5em;
  max-height: 200px;
  word-wrap: break-word;
  white-space: pre-wrap;
  vertical-align: top;
}

/* Command input specific textarea styling */
#command_input_container textarea {
  padding-top: 8px;
  padding-bottom: 8px;
}

/* Modal system styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay[style*="display: none"] {
  display: none !important;
}

.terminal-modal {
  background: var(--color-bg);
  border: 2px solid var(--color-fg);
  border-radius: 8px;
  padding: 20px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content {
  color: var(--color-fg);
  @apply font-mono;
}

.modal-title {
  color: var(--color-fg);
  @apply text-center mb-4;
}

.terminal-form .form-group {
  @apply mb-4;
}

.terminal-label {
  color: var(--color-info);
  @apply block mb-2;
}

.terminal-input {
  background-color: var(--color-bg);
  border-color: var(--color-fg);
  color: var(--color-fg);
  caret-color: var(--color-fg);
  @apply w-full border px-3 py-2 font-mono;
}

.terminal-input:focus {
  border-color: var(--color-accent);
  @apply outline-none;
  box-shadow: 0 0 10px var(--color-accent);
}

.form-info {
  color: var(--color-warning);
  @apply text-sm mb-4;
}

.modal-actions {
  @apply flex gap-4 justify-center mt-6;
}

.terminal-button {
  @apply px-4 py-2 font-mono border-2 cursor-pointer;
}

.terminal-button.primary {
  background-color: var(--color-fg);
  color: var(--color-bg);
  border-color: var(--color-fg);
}

.terminal-button.primary:hover {
  background-color: var(--color-accent);
  border-color: var(--color-accent);
}

.terminal-button.secondary {
  background-color: transparent;
  color: var(--color-fg);
  border-color: var(--color-fg);
}

.terminal-button.secondary:hover {
  background-color: var(--color-fg);
  color: var(--color-bg);
}

/* Timer display styles */
#timer-display {
  border-color: var(--color-warning);
  background-color: var(--color-bg);
  @apply border px-2 py-1 rounded;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { border-color: var(--color-warning); }
  50% { border-color: var(--color-accent); }
}

/* Ensure terminal layout stays intact */
#terminal_container {
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  display: flex;
  flex-direction: column;
}

#command_input_container {
  position: sticky;
  bottom: 0;
  z-index: 10;
}

/* Safe area insets for modern mobile devices */
.safe-area-inset-bottom {
  padding-bottom: env(safe-area-inset-bottom);
}

/* Desktop/Mobile prompt visibility */
.desktop-prompt {
  display: inline;
}

@media (max-width: 768px) {
  /* Hide desktop prompt on mobile */
  .desktop-prompt {
    display: none !important;
  }
  
  /* Show placeholder on mobile for command input */
  .mobile-prompt::placeholder {
    color: var(--color-info) !important;
    opacity: 0.7;
  }
  
  /* Hide placeholder when focused on mobile */
  .mobile-prompt:focus::placeholder {
    color: transparent !important;
  }
  
  /* Fix viewport height on mobile */
  #terminal_container {
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height */
    height: -webkit-fill-available; /* iOS Safari */
  }
  
  /* Ensure command input is always visible */
  #command_input_container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-bg);
    border-top: 1px solid var(--color-fg);
    padding: 0.75rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
  
  /* Adjust terminal output to account for fixed input */
  #terminal_output {
    padding-bottom: 120px; /* Space for input area */
  }
  
  /* Make input/textarea more touch-friendly */
  #command_input_container input[type="text"],
  #command_input_container textarea {
    font-size: 16px; /* Prevent zoom on iOS */
    min-height: 44px; /* Touch target size */
    padding: 8px 0;
  }
  
  /* Mobile textarea specific styles */
  #command_input_container textarea {
    max-height: 120px; /* Smaller max height on mobile */
    line-height: 1.4;
  }
  
  /* Smaller help text on mobile */
  #command_input_container .text-xs {
    font-size: 10px;
  }
  
  /* Ensure proper spacing */
  #command_input_container .flex {
    align-items: center;
  }
  
  /* Hide cursor animation on mobile */
  .cursor {
    display: none;
  }
}