/* ================= COMMAND PILLS STYLING ================= */
/* Unified styling to match freeform prompt pills */

/* Container for command pills */
.command-pills-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px; /* Match freeform pill gap */
  margin-left: 10px;
  margin-bottom: 0;
  min-height: 22px; /* Match freeform pill min-height */
  align-items: center;
  justify-content: flex-start;
  transform: translateY(0px); /* Nudge up by 2px from previous offset */
  transition: width 0.2s ease;
}

/* Default hidden state when no pills (avoid relying on :has) */
.command-pills-container:not(.has-pills) {
  width: 0;
  overflow: hidden;
}

/* When pills are present, expand the container */
.command-pills-container.has-pills {
  width: auto;
  overflow: visible;
}

/* Base pill styling - COMMAND PILLS are 30% bigger than prompt pills */
.command-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between; /* Match freeform */
  gap: 4px; /* +15% */
  padding: 6px 8px; /* +15% */
  border-radius: 16px; /* +15% */
  background: rgba(30, 35, 50, 1) !important; /* Match freeform: Dark grey FULLY OPAQUE */
  border: 1px solid rgba(148, 163, 184, 0.5) !important; /* Match freeform: Light grey outline */
  box-shadow: 0 1px 4px rgba(8, 12, 24, 0.2) !important;
  transition: all 0.5s ease-in-out; /* Match freeform: Smooth 0.5s transition */
  flex-shrink: 0;
  flex-grow: 0;
  max-width: 30%; /* encourage up to 3 per row, allow wrapping */
  width: fit-content;
  min-width: fit-content;
  opacity: 1;
  min-height: 32px; /* +15% */
  overflow: visible;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  font-size: 14px; /* +15% */
  font-weight: 600;
  letter-spacing: 0.2px;
  color: #e5e7eb;
}

/* Hover state - MATCH FREEFORM PROMPT PILLS */
.command-pill:hover {
  transform: translateY(-1px);
  background: rgba(40, 45, 60, 1) !important; /* Match freeform: Slightly lighter on hover */
  border-color: rgba(148, 163, 184, 0.7) !important;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4), 0 4px 12px rgba(59, 130, 246, 0.3) !important; /* Blue glow */
  transition: all 0.3s ease-in-out;
}

/* Blue pill for explicit mode - keep colorful for commands */
.command-pill.explicit-mode {
  background: linear-gradient(135deg, rgba(74, 158, 255, 0.8), rgba(59, 130, 246, 0.8)) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: white;
  box-shadow: 0 1px 4px rgba(74, 158, 255, 0.3) !important;
  border: 1px solid rgba(74, 158, 255, 0.4) !important;
}

.command-pill.explicit-mode:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.9), rgba(37, 99, 235, 0.9)) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5), 0 4px 12px rgba(74, 158, 255, 0.4) !important;
  transform: translateY(-1px);
}

/* Orange pill for multimodal mode - keep colorful for commands */
.command-pill.multimodal-mode {
  background: linear-gradient(135deg, rgba(255, 112, 67, 0.8), rgba(245, 124, 0, 0.8)) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: white;
  box-shadow: 0 1px 4px rgba(255, 112, 67, 0.3) !important;
  border: 1px solid rgba(255, 112, 67, 0.4) !important;
}

.command-pill.multimodal-mode:hover {
  background: linear-gradient(135deg, rgba(245, 124, 0, 0.9), rgba(239, 108, 0, 0.9)) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 0 0 2px rgba(245, 124, 0, 0.5), 0 4px 12px rgba(255, 112, 67, 0.4) !important;
  transform: translateY(-1px);
}

/* Grey pill for commands that don't meet requirements - MATCH FREEFORM STYLE */
.command-pill.requirements-not-met {
  background: rgba(30, 35, 50, 0.5) !important; /* Match freeform empty pill */
  border: 1px dashed rgba(148, 163, 184, 0.3) !important; /* Dashed border to indicate unavailable */
  color: rgba(255, 255, 255, 0.7);
  box-shadow: 0 1px 4px rgba(8, 12, 24, 0.2) !important;
  opacity: 0.6;
}

.command-pill.requirements-not-met:hover {
  background: rgba(40, 45, 60, 0.6) !important;
  border-color: rgba(148, 163, 184, 0.5) !important;
  box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.3), 0 4px 12px rgba(8, 12, 24, 0.3) !important;
  transform: translateY(-1px);
  opacity: 0.7;
}

/* Pill content - MATCH FREEFORM */
.command-pill .pill-content {
  display: flex;
  align-items: center;
  justify-content: space-between; /* Match freeform */
  gap: 2px; /* Match freeform */
  height: 100%;
  width: 100%;
}

/* Command icon */
.command-pill .pill-icon {
  font-size: 8px; /* +15% */
  opacity: 0.9;
}

/* Command text - MATCH FREEFORM */
.command-pill .pill-text {
  font-weight: 600;
  letter-spacing: 0.2px; /* Match freeform */
  display: flex;
  align-items: center;
  height: 100%;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px; /* +15% */
  color: #e5e7eb;
}

/* Delete button - MATCH FREEFORM REMOVE BUTTON */
.command-pill .pill-delete {
  margin-left: 2px;
  font-size: 16px; /* +15% */
  opacity: 0.6;
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px; /* +15% */
  height: 21px; /* +15% */
  flex-shrink: 0;
  background: transparent;
  color: #ffffff; /* White X for command pills */
  line-height: 1;
}

.command-pill .pill-delete:hover {
  opacity: 1;
  background: transparent; /* Keep X clean; entire capsule turns red */
  transform: scale(1.1);
}

/* Red state when hovering X: whole capsule turns red, keep glow */
.command-pill:has(.pill-delete:hover) {
  background: rgba(239, 68, 68, 1) !important; /* Solid red */
  border-color: rgba(239, 68, 68, 1) !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.5), 0 4px 16px rgba(239, 68, 68, 0.4) !important; /* Red glow */
}

.command-pill:has(.pill-delete:hover) .pill-text {
  color: #ffffff !important;
}

.command-pill:has(.pill-delete:hover) .pill-delete {
  color: #ffffff !important; /* keep X white over red */
}

/* Animation for pill appearance */
.command-pill.pill-appearing {
  animation: pillAppear 0.3s ease-out;
}

@keyframes pillAppear {
  0% {
    opacity: 0;
    transform: scale(0.8) translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Animation for pill removal */
.command-pill.pill-removing {
  animation: pillRemove 0.2s ease-in forwards;
}

@keyframes pillRemove {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.8) translateY(-5px);
  }
}

/* Pills container animations */
.command-pills-container.pills-updating {
  transition: all 0.2s ease;
}

/* Responsive adjustments - MATCH FREEFORM */
@media (max-width: 768px) {
  .command-pills-container {
    gap: 6px; /* Keep same gap as desktop to match freeform */
    margin-bottom: 4px;
    transform: translateY(0px); /* Nudge up by 2px from previous offset */
    align-self: center;
    min-height: 22px; /* Match freeform */
  }
  
  .command-pill {
    /* Keep same size as desktop to match freeform */
    padding: 4px 5px;
    font-size: 9px;
    max-width: none;
    min-height: 22px;
    touch-action: manipulation;
  }

  .command-pill .pill-icon {
    font-size: 7px;
  }
  
  .command-pill .pill-delete {
    width: 14px; /* Match freeform */
    height: 14px; /* Match freeform */
    font-size: 11px; /* Match freeform */
    touch-action: manipulation;
  }
  
  /* Ensure pills are easily tappable on mobile */
  .command-pill .pill-delete:hover {
    transform: scale(1.2);
  }
  
  /* Mobile input adjustments */
  .message-input-container:has(.command-pills-container) .message-input {
    margin-left: 11px;
    padding-left: 0;
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

/* Integration with message input */
.message-input-container .command-pills-container {
  margin-bottom: 0;
  padding: 0 0px;
  order: 2; /* place right after + icon and before textarea */
}

/* Move input text closer to pills and remove left padding */
.message-input-container:has(.command-pills-container) .message-input {
  margin-left: 0;
  padding-left: 0;
}

/* When no pills, move text closer to + button */
.message-input-container:not(:has(.command-pills-container)) .message-input {
  margin-left: 0;
  padding-left: 0;
}

/* Ensure pills don't interfere with input focus */
.command-pill:focus {
  outline: none;
}

/* Accessibility improvements */
.command-pill:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* Command hiding in input */
.message-input.has-hidden-commands {
  position: relative;
}

.message-input.has-hidden-commands::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to right, 
    transparent 0%, 
    transparent var(--hide-start, 0%), 
    var(--input-bg, white) var(--hide-start, 0%), 
    var(--input-bg, white) var(--hide-end, 100%), 
    transparent var(--hide-end, 100%)
  );
  pointer-events: none;
  z-index: 1;
}

/* Dark mode support (if needed) */
@media (prefers-color-scheme: dark) {
  .command-pill.explicit-mode {
    box-shadow: 0 2px 8px rgba(74, 158, 255, 0.4);
  }
  
  .command-pill.multimodal-mode {
    box-shadow: 0 2px 8px rgba(255, 112, 67, 0.4);
  }
  
  .message-input.has-hidden-commands::after {
    background: linear-gradient(to right, 
      transparent 0%, 
      transparent var(--hide-start, 0%), 
      var(--input-bg-dark, #1a1a1a) var(--hide-start, 0%), 
      var(--input-bg-dark, #1a1a1a) var(--hide-end, 100%), 
      transparent var(--hide-end, 100%)
    );
  }
}

/* Download spinner styles */
.download-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #ff7043;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: none;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.download-btn.loading {
  opacity: 0.7;
  pointer-events: none;
}