/*
 * Foundry - Cloud Agent Platform
 * Custom styles (Tailwind handles most styling)
 */

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

.safe-bottom {
  padding-bottom: env(safe-area-inset-bottom);
}

.safe-left {
  padding-left: env(safe-area-inset-left);
}

.safe-right {
  padding-right: env(safe-area-inset-right);
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #1f2937;
}

::-webkit-scrollbar-thumb {
  background: #4b5563;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Hide scrollbar for tab navigation */
.scrollbar-hide::-webkit-scrollbar {
  display: none;
}

.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Vertical writing mode for collapsed icebox */
.writing-vertical {
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

/* Scroll snap utilities for mobile badge rows */
.snap-x {
  scroll-snap-type: x mandatory;
}

.snap-start {
  scroll-snap-align: start;
}

/* Slide-in animation for new agent cards */
@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-20px);
    max-height: 0;
    margin-top: 0;
  }
  to {
    opacity: 1;
    transform: translateY(0);
    max-height: 500px;
    margin-top: 1rem;
  }
}

.agent-card-slide-in {
  animation: slideInFromTop 0.4s ease-out forwards;
}

/* Agent chain connector lines - ensure they're visible */
.agent-chain-connector {
  pointer-events: none;
}

/* Terminal styles */
.xterm {
  padding: 8px;
}

.xterm-viewport {
  overflow-y: auto !important;
}

/* ================================================
   Chain Destruction Animations
   ================================================ */

/* Pulsing border effect during destruction */
@keyframes chainDestroyPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.4);
    border-color: rgba(249, 115, 22, 0.6);
  }
  50% {
    box-shadow: 0 0 20px 4px rgba(249, 115, 22, 0.3);
    border-color: rgba(239, 68, 68, 0.8);
  }
}

.chain-destroy-pulse {
  animation: chainDestroyPulse 1.5s ease-in-out infinite;
  border-color: rgba(249, 115, 22, 0.6) !important;
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .chain-destroy-pulse {
    animation: none;
    border-color: rgba(249, 115, 22, 0.8) !important;
  }
}

/* Card dissolve/fade-out animation */
@keyframes chainCardDissolve {
  0% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
  30% {
    opacity: 0.8;
    transform: scale(0.98);
    filter: blur(1px);
  }
  100% {
    opacity: 0;
    transform: scale(0.92) translateY(-10px);
    filter: blur(4px);
    max-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
}

.chain-card-dissolve {
  animation: chainCardDissolve 0.6s ease-out forwards;
  pointer-events: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .chain-card-dissolve {
    animation: none;
    opacity: 0;
    display: none;
  }
}

/* Header dissolve animation */
@keyframes chainHeaderDissolve {
  0% {
    opacity: 1;
    transform: scaleY(1);
    max-height: 200px;
  }
  100% {
    opacity: 0;
    transform: scaleY(0);
    max-height: 0;
    margin: 0;
    padding: 0;
  }
}

.chain-header-dissolve {
  animation: chainHeaderDissolve 0.4s ease-out forwards;
  transform-origin: top;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .chain-header-dissolve {
    animation: none;
    display: none;
  }
}

/* Header destroying state - red tint */
.chain-header-destroying {
  background: linear-gradient(to right, rgba(239, 68, 68, 0.1), rgba(249, 115, 22, 0.1)) !important;
  border-color: rgba(249, 115, 22, 0.5) !important;
}

/* Container during destruction */
.chain-destroying {
  position: relative;
}

/* Particle animation for overlay */
@keyframes particleFloat {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-60px) rotate(180deg);
    opacity: 0;
  }
}

.chain-destroy-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.chain-destroy-particle {
  position: absolute;
  bottom: 20%;
  background: linear-gradient(to top, #f97316, #fbbf24);
  border-radius: 50%;
  animation: particleFloat 2s ease-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .chain-destroy-particle {
    display: none;
  }
}

/* Overlay spinner pulse effect */
.chain-destroy-spinner {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chain-destroy-spinner {
    animation: none;
  }
}

/* Final destruction flash effect */
@keyframes destructionFlash {
  0% {
    background-color: transparent;
  }
  50% {
    background-color: rgba(249, 115, 22, 0.3);
  }
  100% {
    background-color: transparent;
  }
}

.chain-destruction-complete {
  animation: destructionFlash 0.5s ease-out;
}

/* Toast notification for chain destruction success */
.chain-destroy-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(135deg, rgba(31, 41, 55, 0.95) 0%, rgba(17, 24, 39, 0.95) 100%);
  border: 1px solid rgba(249, 115, 22, 0.3);
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px rgba(249, 115, 22, 0.1);
  color: #f3f4f6;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}

.chain-destroy-toast-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.chain-destroy-toast-hiding {
  transform: translateX(-50%) translateY(100%);
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .chain-destroy-toast {
    transition: opacity 0.15s ease-out;
  }

  .chain-destroy-toast-visible {
    transform: translateX(-50%) translateY(0);
  }

  .chain-destroy-toast-hiding {
    transform: translateX(-50%) translateY(0);
  }
}

/* Chain header destroying state */
.chain-header-destroying {
  position: relative;
  pointer-events: none;
}

.chain-header-destroying::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%);
  border-radius: 0.5rem;
  animation: chainDestroyPulse 1.5s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .chain-header-destroying::after {
    animation: none;
  }
}

/* ================================================
   Expert Portal: Light Mode Overrides
   ================================================
   When <html> has class "light", these descendant
   selectors override the dark Tailwind utilities.
   Specificity: .light .bg-gray-800 > .bg-gray-800
   ================================================ */

/* --- Page backgrounds --- */
.light.bg-gray-900 {
  background-color: #f9fafb; /* gray-50 */
}

.light .bg-gray-800 {
  background-color: #ffffff;
}

.light .bg-gray-800\/50 {
  background-color: #ffffff;
}

.light .bg-gray-700 {
  background-color: #f3f4f6; /* gray-100 */
}

.light .bg-gray-700\/50,
.light .bg-gray-700\/30 {
  background-color: #f3f4f6;
}

.light .bg-gray-900 {
  background-color: #f9fafb;
}

/* --- Gradients --- */
.light .bg-gradient-to-br.from-gray-800 {
  --tw-gradient-from: #ffffff;
}

.light .bg-gradient-to-br.to-gray-900 {
  --tw-gradient-to: #f9fafb;
}

/* --- Borders --- */
.light .border-gray-700,
.light .border-gray-700\/50 {
  border-color: #e5e7eb; /* gray-200 */
}

.light .border-gray-600,
.light .border-gray-600\/50 {
  border-color: #d1d5db; /* gray-300 */
}

/* --- Text colors --- */
.light .text-white {
  color: #111827; /* gray-900 */
}

.light .text-gray-200 {
  color: #374151; /* gray-700 */
}

.light .text-gray-300 {
  color: #4b5563; /* gray-600 */
}

.light .text-gray-400 {
  color: #6b7280; /* gray-500 */
}

.light .text-gray-500 {
  color: #9ca3af; /* gray-400 */
}

.light .text-gray-600 {
  color: #9ca3af;
}

/* --- Placeholder --- */
.light .placeholder-gray-500::placeholder {
  color: #9ca3af;
}

/* --- Hover states --- */
.light .hover\:bg-gray-600:hover {
  background-color: #e5e7eb;
}

.light .hover\:bg-gray-700:hover {
  background-color: #e5e7eb;
}

.light .hover\:text-gray-300:hover {
  color: #374151;
}

.light .hover\:text-gray-400:hover {
  color: #4b5563;
}

.light .hover\:text-gray-200:hover {
  color: #374151;
}

.light .hover\:text-white:hover {
  color: #111827;
}

/* --- Focus ring offset (match light bg) --- */
.light .focus\:ring-offset-gray-800 {
  --tw-ring-offset-color: #ffffff;
}

/* --- Dashed drop-zone borders --- */
.light .border-dashed.border-gray-600\/50 {
  border-color: #d1d5db;
}

.light .hover\:border-sky-500\/50:hover {
  border-color: rgba(14, 165, 233, 0.5);
}

.light .hover\:bg-sky-500\/5:hover {
  background-color: rgba(14, 165, 233, 0.05);
}

/* --- Checkbox backgrounds --- */
.light .bg-gray-700.text-sky-500 {
  background-color: #f3f4f6;
}

/* --- Scrollbar (light) --- */
.light ::-webkit-scrollbar-track {
  background: #f9fafb;
}

.light ::-webkit-scrollbar-thumb {
  background: #d1d5db;
}

.light ::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* --- Input text color --- */
.light input,
.light textarea,
.light select {
  color: #111827;
}

/* --- Keep text/icons white inside colored buttons --- */
.light .bg-sky-600,
.light .bg-sky-500,
.light .hover\:bg-sky-500:hover,
.light .bg-amber-600,
.light .hover\:bg-amber-700:hover,
.light .bg-red-600,
.light .hover\:bg-red-600:hover {
  color: #ffffff;
}

.light .from-sky-600 .text-white,
.light .bg-sky-600 .text-white {
  color: #ffffff;
}

/* --- Desktop recording button: blue with white icon in light mode --- */
.light .record-area {
  background-color: #eff6ff; /* blue-50 */
  border-color: #bfdbfe; /* blue-200 */
}

.light .record-btn.bg-gray-700 {
  background-color: #0284c7; /* sky-600 */
  border-color: #0284c7;
}

.light .record-btn.bg-gray-700 svg {
  color: #ffffff;
}
