/* 
 ============================================================================
 Component System Styles
 Modern, component-based CSS with CSS custom properties
 ============================================================================
 */

/* CSS Custom Properties for theming */
:root {
  --component-border-radius: 8px;
  --component-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  --component-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.2);
  --component-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --component-z-index: 1000;
}

/* ============================================================================
 Toast Container
 ============================================================================ */

.toast-container {
  position: fixed;
  z-index: var(--component-z-index);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  max-width: 420px;
  width: 100%;
}

.toast-container-top-right {
  top: 24px;
  right: 24px;
}

.toast-container-top-left {
  top: 24px;
  left: 24px;
}

.toast-container-bottom-right {
  bottom: 24px;
  right: 24px;
}

.toast-container-bottom-left {
  bottom: 24px;
  left: 24px;
}

.toast-container-top-center {
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
}

.toast-container-bottom-center {
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
}

.toast-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

/* ============================================================================
 Toast Item
 ============================================================================ */

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: rgba(18, 18, 26, 0.95);
  border: 1px solid var(--border-color);
  border-radius: var(--component-border-radius);
  box-shadow: var(--component-shadow);
  backdrop-filter: blur(20px);
  animation: toastSlideIn 0.3s ease-out;
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  min-width: 320px;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast-success {
  border-color: rgba(16, 185, 129, 0.3);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(18, 18, 26, 0.95));
}

.toast-error {
  border-color: rgba(239, 68, 68, 0.3);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(18, 18, 26, 0.95));
}

.toast-warning {
  border-color: rgba(245, 158, 11, 0.3);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(18, 18, 26, 0.95));
}

.toast-info {
  border-color: rgba(99, 102, 241, 0.3);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(18, 18, 26, 0.95));
}

.toast-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-icon svg {
  width: 100%;
  height: 100%;
}

.toast-success .toast-icon {
  color: var(--success);
}

.toast-error .toast-icon {
  color: var(--error);
}

.toast-warning .toast-icon {
  color: var(--warning);
}

.toast-info .toast-icon {
  color: var(--primary-light);
}

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.4;
}

.toast-message {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
  word-wrap: break-word;
}

.toast-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  border-radius: 4px;
}

.toast-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.toast-close svg {
  width: 16px;
  height: 16px;
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: currentColor;
  width: 100%;
  opacity: 0.3;
  animation: toastProgress linear forwards;
}

@keyframes toastProgress {
  from {
    width: 100%;
  }
  to {
    width: 0;
  }
}

.toast-progress {
  opacity: 0.5;
}

.toast-success .toast-progress {
  background: var(--success);
}

.toast-error .toast-progress {
  background: var(--error);
}

.toast-warning .toast-progress {
  background: var(--warning);
}

.toast-info .toast-progress {
  background: var(--primary-light);
}

.toast-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.toast-action-btn {
  padding: 6px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.toast-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

/* ============================================================================
 Modal
 ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--component-z-index);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  animation: modalFadeIn 0.2s ease-out;
}

.modal-overlay.modal-backdrop {
  background: rgba(0, 0, 0, 0.7);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--component-border-radius);
  box-shadow: var(--component-shadow-hover);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  animation: modalSlideUp 0.3s ease-out;
  overflow: hidden;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-sm {
  width: 100%;
  max-width: 400px;
}

.modal-md {
  width: 100%;
  max-width: 540px;
}

.modal-lg {
  width: 100%;
  max-width: 720px;
}

.modal-fullscreen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  gap: 16px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.4;
}

.modal-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  border-radius: 6px;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.modal-close svg {
  width: 20px;
  height: 20px;
}

.modal-body {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.modal-footer .btn {
  min-width: 100px;
  justify-content: center;
}

/* ============================================================================
 Modal Types
 ============================================================================ */

.confirm-modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 24px 0;
}

.confirm-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 158, 11, 0.1);
  border-radius: 50%;
  color: var(--warning);
}

.confirm-icon svg {
  width: 32px;
  height: 32px;
}

.confirm-message {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ============================================================================
 Dark Mode Adjustments
 ============================================================================ */

[data-theme="dark"] .modal {
  background: var(--bg-card);
  border-color: var(--border-color);
}

[data-theme="light"] .modal {
  background: #ffffff;
  border-color: #e5e7eb;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .modal-header,
[data-theme="light"] .modal-footer {
  border-color: #e5e7eb;
}

[data-theme="light"] .modal-title {
  color: #111827;
}

[data-theme="light"] .modal-close {
  color: #6b7280;
}

[data-theme="light"] .modal-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #111827;
}

[data-theme="light"] .toast {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .toast-success {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(255, 255, 255, 0.95));
}

[data-theme="light"] .toast-error {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(255, 255, 255, 0.95));
}

[data-theme="light"] .toast-warning {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(255, 255, 255, 0.95));
}

[data-theme="light"] .toast-info {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(255, 255, 255, 0.95));
}

[data-theme="light"] .toast-title {
  color: #111827;
}

[data-theme="light"] .toast-message {
  color: #6b7280;
}

[data-theme="light"] .toast-close {
  color: #9ca3af;
}

[data-theme="light"] .toast-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #111827;
}

[data-theme="light"] .toast-action-btn {
  background: rgba(0, 0, 0, 0.05);
  border-color: #d1d5db;
  color: #111827;
}

[data-theme="light"] .toast-action-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* ============================================================================
 Responsive Design
 ============================================================================ */

@media (max-width: 768px) {
  .toast-container-top-right,
  .toast-container-top-left,
  .toast-container-bottom-right,
  .toast-container-bottom-left {
    left: 16px;
    right: 16px;
  }

  .toast-container-top-center,
  .toast-container-bottom-center {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: calc(100% - 32px);
  }

  .toast {
    min-width: auto;
    padding: 14px;
  }

  .modal-overlay {
    padding: 16px;
  }

  .modal {
    max-height: calc(100vh - 32px);
  }

  .modal-header {
    padding: 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
    flex-direction: column;
    width: 100%;
  }

  .modal-footer .btn {
    width: 100%;
  }
}

/* ============================================================================
 Accessibility
 ============================================================================ */

.toast[role="alert"] {
  border-left: 4px solid;
}

.toast-success[role="alert"] {
  border-left-color: var(--success);
}

.toast-error[role="alert"] {
  border-left-color: var(--error);
}

.toast-warning[role="alert"] {
  border-left-color: var(--warning);
}

.toast-info[role="alert"] {
  border-left-color: var(--primary-light);
}

/* Focus visible for keyboard navigation */
.toast-close,
.modal-close,
.toast-action-btn,
.modal-footer .btn {
  outline: none;
}

.toast-close:focus-visible,
.modal-close:focus-visible,
.toast-action-btn:focus-visible,
.modal-footer .btn:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ============================================================================
 * AI Optimization Suggestions Card
 * ============================================================================ */

.ai-suggestions-section {
  margin-top: 24px;
  animation: fadeIn 0.3s ease-in-out;
}

.ai-suggestions-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.05) 100%);
  border: 1px dashed rgba(99, 102, 241, 0.3);
  border-radius: var(--component-border-radius);
  color: rgba(255, 255, 255, 0.7);
}

.ai-suggestions-placeholder i {
  font-size: 48px;
  margin-bottom: 16px;
  color: rgba(99, 102, 241, 0.5);
}

.ai-suggestions-placeholder h4 {
  margin: 0 0 8px 0;
  color: var(--text-primary);
  font-weight: 600;
}

.ai-suggestions-placeholder p {
  margin: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
}

.ai-optimization-suggestions {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(139, 92, 246, 0.04) 100%);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--component-border-radius);
  padding: 24px;
}

.ai-suggestions-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.ai-suggestions-header h4 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.ai-suggestions-header .ai-icon {
  color: #6366f1;
}

.ai-suggestions-header .confidence-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.2);
  color: #06b6d4;
}

.ai-suggestions-header .confidence-badge.high {
  background: rgba(6, 182, 212, 0.1);
  border-color: rgba(6, 182, 212, 0.2);
  color: #06b6d4;
}

.ai-suggestions-header .confidence-badge.medium {
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}

.ai-suggestions-header .confidence-badge.low {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.2);
  color: #f87171;
}

.ai-suggestion-item {
  padding: 16px;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(99, 102, 241, 0.1);
  border-radius: 6px;
  margin-bottom: 12px;
  transition: var(--component-transition);
}

.ai-suggestion-item:last-of-type {
  margin-bottom: 0;
}

.ai-suggestion-item:hover {
  border-color: rgba(99, 102, 241, 0.3);
  background: rgba(30, 41, 59, 0.8);
  transform: translateX(4px);
}

.ai-suggestion-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.ai-suggestion-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(139, 92, 246, 0.1) 100%);
  color: #818cf8;
}

.ai-suggestion-icon.recommendation {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2) 0%, rgba(34, 211, 238, 0.1) 100%);
  color: #22d3ee;
}

.ai-suggestion-icon.warning {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.2) 0%, rgba(253, 186, 116, 0.1) 100%);
  color: #fbbf24;
}

.ai-suggestion-icon.optimization {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.2) 0%, rgba(192, 132, 252, 0.1) 100%);
  color: #c4b5fd;
}

.ai-suggestion-icon.compatibility {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2) 0%, rgba(74, 222, 128, 0.1) 100%);
  color: #4ade80;
}

.ai-suggestion-icon i {
  font-size: 16px;
}

.ai-suggestion-content {
  flex: 1;
}

.ai-suggestion-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.ai-suggestion-title small {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.5);
  margin-left: 8px;
}

.ai-suggestion-description {
  margin: 6px 0 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.7);
}

.ai-suggestion-improvement {
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(34, 197, 94, 0.1);
  border-left: 3px solid #22c55e;
  border-radius: 4px;
  font-size: 12px;
  color: #86efac;
}

.ai-suggestion-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-suggestion-actions .btn {
  font-size: 12px;
  padding: 6px 12px;
}

.ai-suggestion-actions .btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
}

.ai-suggestion-learning-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin-top: 16px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 20px;
  font-size: 12px;
  color: #a78bfa;
}

.ai-suggestion-learning-badge i {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* ============================================================================
 * Dark/Light Theme Support
 * ============================================================================ */

@media (prefers-color-scheme: light) {
  .ai-suggestions-placeholder {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(139, 92, 246, 0.04) 100%);
    border-color: rgba(99, 102, 241, 0.2);
    color: rgba(0, 0, 0, 0.6);
  }

  .ai-optimization-suggestions {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.04) 0%, rgba(139, 92, 246, 0.02) 100%);
    border-color: rgba(99, 102, 241, 0.15);
  }

  .ai-suggestion-item {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(99, 102, 241, 0.1);
  }

  .ai-suggestion-item:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(99, 102, 241, 0.2);
  }

  .ai-suggestion-title {
    color: var(--text-primary-light, #1a1a2e);
  }

  .ai-suggestion-description {
    color: rgba(0, 0, 0, 0.6);
  }
}

/* ============================================================================
 * Responsive Design
 * ============================================================================ */

@media (max-width: 768px) {
  .ai-suggestions-section {
    margin: 20px 0;
  }

  .ai-optimization-suggestions {
    padding: 16px;
  }

  .ai-suggestion-item {
    padding: 12px;
  }

  .ai-suggestion-header {
    gap: 8px;
  }

  .ai-suggestion-icon {
    width: 32px;
    height: 32px;
  }

  .ai-suggestion-title {
    font-size: 14px;
  }

  .ai-suggestion-description {
    font-size: 12px;
  }
}
