/* ==========================================================================
  MANUAL THEME OVERRIDES
  ========================================================================== */

/* Theme class overrides - these take precedence over media queries */
.theme-light {
  /* Light mode colors - Modern neutral palette */
  --modal-bg: hsl(0, 0%, 100%);
  --modal-bg-secondary: hsl(220, 13%, 98%);
  --modal-text: hsl(220, 9%, 9%);
  --modal-text-secondary: hsl(220, 9%, 46%);
  --modal-border: hsl(220, 13%, 91%);
  --modal-border-strong: hsl(220, 13%, 85%);
  --modal-hover: hsl(220, 13%, 95%);
  --modal-hover-strong: hsl(220, 13%, 90%);
  --modal-focus: hsl(212, 50%, 55%);
  --modal-focus-ring: hsla(212, 50%, 55%, 0.08);
  --modal-shadow: 
    0 1px 3px hsla(220, 9%, 9%, 0.08),
    0 4px 12px hsla(220, 9%, 9%, 0.12),
    0 16px 24px hsla(220, 9%, 9%, 0.16);
  --modal-divider: var(--modal-border);
}

.theme-dark {
  /* Dark mode colors - Modern dark palette */
  --modal-bg: hsl(220, 13%, 9%);
  --modal-bg-secondary: hsl(220, 13%, 11%);
  --modal-text: hsl(220, 9%, 96%);
  --modal-text-secondary: hsl(220, 9%, 65%);
  --modal-border: hsl(220, 13%, 18%);
  --modal-border-strong: hsl(220, 13%, 24%);
  --modal-hover: hsl(220, 13%, 15%);
  --modal-hover-strong: hsl(220, 13%, 20%);
  --modal-focus: hsl(212, 80%, 65%);
  --modal-focus-ring: hsla(212, 80%, 65%, 0.1);
  --modal-shadow: 
    0 1px 3px hsla(0, 0%, 0%, 0.12),
    0 4px 12px hsla(0, 0%, 0%, 0.24),
    0 16px 24px hsla(0, 0%, 0%, 0.36);
  --modal-divider: var(--modal-border);
}

/* Theme-specific resize handle colors */
.theme-light .translation-modal__text-container::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23757575' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 0.6;
}

.theme-light .translation-modal__text-container:hover::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23333333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 1;
}

.theme-light .translation-modal__text-container:active::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23005fcc' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 1;
}

.theme-dark .translation-modal__text-container::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 0.7;
}

.theme-dark .translation-modal__text-container:hover::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23cccccc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 1;
}

.theme-dark .translation-modal__text-container:active::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%2366aaff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 1;
}

/* ==========================================================================
  MODAL COMPONENT STYLES
  ========================================================================== */

:root {
  /* Modal specific variables using modern design tokens */
  --modal-width: 440px;
  --modal-max-width: 90vw;
  --modal-max-height: 80vh;
  --modal-border-radius: 12px;
  --modal-padding: 1.25rem;
  --modal-header-height: 56px;
  --modal-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --modal-scale-transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Modal z-index values */
  --modal-backdrop-z: 999998;
  --modal-z: 999999;
  
  /* Light mode colors - Modern neutral palette */
  --modal-bg: hsl(0, 0%, 100%);
  --modal-bg-secondary: hsl(220, 13%, 98%);
  --modal-text: hsl(220, 9%, 9%);
  --modal-text-secondary: hsl(220, 9%, 46%);
  --modal-border: hsl(220, 13%, 91%);
  --modal-border-strong: hsl(220, 13%, 85%);
  --modal-hover: hsl(220, 13%, 95%);
  --modal-hover-strong: hsl(220, 13%, 90%);
  --modal-focus: hsl(212, 50%, 55%);
  --modal-focus-ring: hsla(212, 50%, 55%, 0.08);
  --modal-shadow: 
    0 1px 3px hsla(220, 9%, 9%, 0.08),
    0 4px 12px hsla(220, 9%, 9%, 0.12),
    0 16px 24px hsla(220, 9%, 9%, 0.16);
  --modal-divider: var(--modal-border);
}

/* Modal backdrop */
.translation-modal-backdrop {
  position: fixed !important;
  inset: 0 !important;
  z-index: var(--modal-backdrop-z) !important;
  background-color: transparent !important;
  pointer-events: none !important;
}



/* Main modal container */
.translation-modal {
  width: var(--modal-width);
  max-width: var(--modal-max-width);
  min-height: 240px; /* Slightly increased minimum height */
  max-height: none;
  position: fixed !important;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  overflow: visible;
  border-radius: var(--modal-border-radius);
  z-index: var(--modal-z) !important;
  transition: var(--modal-transition);
  background-color: var(--modal-bg);
  color: var(--modal-text);
  border: 1px solid var(--modal-border);
  box-shadow: var(--modal-shadow);
  cursor: default;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: 'rlig' 1, 'calt' 1;
}

/* Theme transition animations for smooth theme switching */
.translation-modal,
.translation-modal *,
.translation-modal__header,
.translation-modal__content,
.translation-modal__footer,
.translation-modal__text-container {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

/* Modal animations */
.translation-modal.modal-entering {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.96) translateY(8px);
}

.translation-modal.modal-entered {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1) translateY(0);
}

.translation-modal.modal-exiting {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.96) translateY(8px);
}

/* Selective CSS isolation - only reset what's necessary */
.translation-modal * {
  box-sizing: border-box !important;
}

/* Modal header */
.translation-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--modal-padding);
  min-height: var(--modal-header-height);
  user-select: none;
  cursor: move;
  background-color: var(--modal-bg-secondary);
  border-bottom: 1px solid var(--modal-border);
  border-top-left-radius: var(--modal-border-radius);
  border-top-right-radius: var(--modal-border-radius);
  flex-shrink: 0;
}

.translation-modal__title {
  font-weight: 600;
  font-size: 16px;
  color: var(--modal-text);
  margin: 0;
  letter-spacing: -0.01em;
}

.translation-modal__close-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--modal-text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.translation-modal__close-btn:hover {
  background-color: var(--modal-hover);
  color: var(--modal-text);
}

.translation-modal__close-btn:active {
  background-color: var(--modal-hover-strong);
  transform: scale(0.95);
}

/* Modal content area */
.translation-modal__content {
  display: flex;
  flex-direction: column;
  padding: var(--modal-padding);
  gap: 20px;
  overflow: visible;
  flex-grow: 1;
  background: var(--modal-bg);
}

/* Text sections */
.translation-modal__section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.translation-modal__section-title {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--modal-text-secondary);
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.translation-modal__text-container {
  padding: 14px !important;
  border: 1px solid var(--modal-border) !important;
  border-radius: 8px 8px 0px 8px !important;
  scrollbar-gutter: stable;
  width: 100% !important;
  min-height: 120px !important;
  max-height: 500px !important;
  overflow: auto !important;
  resize: vertical !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
  background: var(--modal-bg) !important;
  color: var(--modal-text) !important;
  font-family: inherit !important;
  font-size: 14px !important;
  line-height: 1.6 !important;
  box-sizing: border-box !important;
  min-width: 100px !important;
  outline: none !important;
  word-break: break-word !important;
  white-space: pre-wrap !important;
  /* Optimize for resize performance */
  will-change: height !important;
}

/* Hover state for text containers */
.translation-modal__text-container:hover {
  border-color: var(--modal-border-strong);
  background-color: var(--modal-bg-secondary);
}

/* Resizing state optimization - disable expensive effects during resize */
.translation-modal__text-container:active:not(:focus) {
  transition: none !important;
  border-color: var(--modal-border-strong);
}

/* Active resize state */
.translation-modal__text-container:active {
  border-color: var(--modal-focus);
  box-shadow: 0 0 0 2px var(--modal-focus-ring);
}

/* Focus state for better accessibility */
.translation-modal__text-container:focus {
  border-color: var(--modal-focus) !important;
  box-shadow: 0 0 0 2px var(--modal-focus-ring) !important;
}


/* Performance optimization: disable expensive effects during text container resize */
.translation-modal:has(.translation-modal__text-container:active) {
  transition: none !important;
}

.translation-modal:has(.translation-modal__text-container:active) .translation-modal__header,
.translation-modal:has(.translation-modal__text-container:active) .translation-modal__content,
.translation-modal:has(.translation-modal__text-container:active) .translation-modal__footer {
  transition: none !important;
}

/* Re-enable transitions after resize */
.translation-modal .translation-modal__text-container:not(:active) {
  transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
}

/* Custom resize handle styling using SVG icon */
.translation-modal__text-container::-webkit-resizer {
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23757575' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 0 0 0px 0;
  transition: all 0.15s ease;
  cursor: nw-resize;
  opacity: 0.6;
}

.translation-modal__text-container:hover::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23333333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 1;
}

.translation-modal__text-container:active::-webkit-resizer {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23005fcc' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  opacity: 1;
}

/* Divider */
.translation-modal__divider {
  width: 90% !important;
  height: 1px !important;
  align-self: center !important;
  opacity: 0.8 !important;
  background-color: var(--modal-divider) !important;
}

/* Modal footer */
.translation-modal__footer {
  display: flex !important;
  gap: 8px !important;
  padding: 8px 12px !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex-wrap: wrap !important;
  min-height: var(--modal-header-height) !important;
  border-top: 1px solid var(--modal-border) !important;
  background-color: var(--modal-bg) !important;
  flex-shrink: 0 !important;
}

/* Copy buttons */
.translation-modal__copy-btn {
  padding: 8px 16px !important;
  min-width: 100px !important;
  height: 36px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  border: 1px solid var(--modal-border) !important;
  border-radius: 6px !important;
  background-color: var(--modal-bg) !important;
  color: var(--modal-text) !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1) !important;
  letter-spacing: 0.01em !important;
}

.translation-modal__copy-btn:hover {
  background-color: var(--modal-hover) !important;
  border-color: var(--modal-border-strong) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px hsla(220, 9%, 9%, 0.08) !important;
}

.translation-modal__copy-btn:active {
  transform: translateY(0) !important;
  box-shadow: 0 1px 4px hsla(220, 9%, 9%, 0.08) !important;
}

/* Scrollbar styles */
.translation-modal *::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.translation-modal *::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 4px;
}

.translation-modal *::-webkit-scrollbar-thumb {
  background-color: var(--modal-border-strong);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
  transition: background-color 0.15s ease;
}

.translation-modal *::-webkit-scrollbar-thumb:hover {
  background-color: var(--modal-text-secondary);
}

.translation-modal * {
  scrollbar-width: thin;
  scrollbar-color: var(--modal-border-strong) transparent;
}

/* Dark mode specific adjustments */
@media (prefers-color-scheme: dark) {
  :root {
    /* Dark mode colors - Modern dark palette */
    --modal-bg: hsl(220, 13%, 9%);
    --modal-bg-secondary: hsl(220, 13%, 11%);
    --modal-text: hsl(220, 9%, 96%);
    --modal-text-secondary: hsl(220, 9%, 65%);
    --modal-border: hsl(220, 13%, 18%);
    --modal-border-strong: hsl(220, 13%, 24%);
    --modal-hover: hsl(220, 13%, 15%);
    --modal-hover-strong: hsl(220, 13%, 20%);
    --modal-focus: hsl(212, 80%, 65%);
    --modal-focus-ring: hsla(212, 80%, 65%, 0.1);
    --modal-shadow: 
      0 1px 3px hsla(0, 0%, 0%, 0.12),
      0 4px 12px hsla(0, 0%, 0%, 0.24),
      0 16px 24px hsla(0, 0%, 0%, 0.36);
    --modal-divider: var(--modal-border);
  }
  
  .translation-modal *::-webkit-scrollbar-thumb {
    background-color: var(--modal-border-strong);
  }
  
  .translation-modal *::-webkit-scrollbar-thumb:hover {
    background-color: var(--modal-text-secondary);
  }
  
  .translation-modal * {
    scrollbar-color: var(--modal-border-strong) transparent;
  }
  
  /* Dark mode resizer adjustments */
  .translation-modal__text-container::-webkit-resizer {
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    opacity: 0.7;
  }
  
  .translation-modal__text-container:hover::-webkit-resizer {
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%23cccccc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    opacity: 1;
  }
  
  .translation-modal__text-container:active::-webkit-resizer {
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15L15 21M21 8L8 21' stroke='%2366aaff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    opacity: 1;
  }
}

/* Forced colors mode (accessibility) */
@media (forced-colors: active) {
  .translation-modal *::-webkit-scrollbar-thumb {
    background-color: ButtonText;
  }
  
  .translation-modal * {
    scrollbar-color: ButtonText transparent;
  }
}

/* Responsive design improvements */
@media (max-width: 480px) {
  :root {
    --modal-width: 95vw;
    --modal-padding: 1rem;
    --modal-border-radius: 8px;
  }
  
  .translation-modal {
    margin: 1rem;
    max-height: 90vh;
  }
  
  .translation-modal__header {
    min-height: 48px;
  }
  
  .translation-modal__title {
    font-size: 15px;
  }
  
  .translation-modal__close-btn {
    width: 28px;
    height: 28px;
    font-size: 18px;
  }
  
  .translation-modal__content {
    gap: 16px;
  }
  
  .translation-modal__copy-btn {
    height: 40px !important;
    font-size: 14px !important;
    min-width: 80px !important;
  }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .translation-modal,
  .translation-modal *,
  .translation-modal-backdrop {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
  :root {
    --modal-border: currentColor;
    --modal-border-strong: currentColor;
    --modal-focus: Highlight;
    --modal-focus-ring: transparent;
  }
  
  .translation-modal__text-container:focus {
    outline: 2px solid Highlight !important;
    box-shadow: none !important;
  }
}

/* Modern glass morphism effect (optional enhancement) */
@supports (backdrop-filter: blur(10px)) {
  .translation-modal {
    background-color: var(--modal-bg);
    /* Removed backdrop-filter since we want users to interact with multiple selections */
  }
  
  .translation-modal__header {
    background-color: var(--modal-bg-secondary);
  }
}

/* Loading state animation for copy buttons */
.translation-modal__copy-btn.loading {
  opacity: 0.7 !important;
  pointer-events: none !important;
}

.translation-modal__copy-btn.loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  display: inline-block;
  animation: spin 1s linear infinite;
  margin-left: 6px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Enhanced focus ring for better accessibility */
.translation-modal *:focus-visible {
  outline: 2px solid var(--modal-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Dragging state */
.translation-modal.is-dragging {
  transition: none;
  cursor: grabbing;
  user-select: none;
}

.translation-modal.is-dragging * {
  cursor: grabbing !important;
  user-select: none !important;
}
