/**
 * ==============================================================================
 * DESIGN TOKENS & DESIGN SYSTEM (SEÇÃO 10.1 & 10.2)
 * IPTV Manager SaaS - Enterprise UI Architecture
 * ==============================================================================
 */

:root {
  /* Tipografia */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Espaçamentos */
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.25rem;  /* 20px */
  --space-6: 1.5rem;   /* 24px */
  --space-8: 2rem;     /* 32px */
  --space-10: 2.5rem;  /* 40px */
  --space-12: 3rem;    /* 48px */

  /* Arredondamento (Border Radius) */
  --radius-sm: 0.375rem; /* 6px */
  --radius-md: 0.5rem;   /* 8px */
  --radius-lg: 0.75rem;  /* 12px */
  --radius-xl: 1rem;     /* 16px */
  --radius-full: 9999px;

  /* Transições e Animações */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Tema Claro (Light Mode - Padrão) */
  --bg-app: #f8fafc;
  --bg-body: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;

  --border-subtle: #e2e8f0;
  --border-default: #cbd5e1;
  --border-strong: #94a3b8;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;
  --text-inverse: #ffffff;

  /* Cores de Marca / Ação (Azul Safira / Tech Navy) */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --primary-border: #bfdbfe;
  --primary-text: #1e40af;

  /* Estados e Alertas Semânticos */
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;

  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;

  --info: #0ea5e9;
  --info-bg: #f0f9ff;
  --info-border: #bae6fd;
  --info-text: #0369a1;

  /* Sombras e Elevação */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

  /* Modal Backdrop */
  --backdrop: rgba(15, 23, 42, 0.6);
}

/* Modo Escuro Nativo (Dark Mode via prefers-color-scheme) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-bs-theme="light"]) {
    --bg-app: #0b1120;
    --bg-body: #0b1120;
    --bg-surface: #1e293b;
    --bg-card: #1e293b;
    --bg-surface-elevated: #334155;
    --bg-subtle: #0f172a;
    --bg-hover: #334155;

    --border-subtle: #1e293b;
    --border-default: #334155;
    --border-strong: #475569;

    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --text-subtle: #64748b;
    --text-inverse: #0f172a;

    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-subtle: rgba(59, 130, 246, 0.15);
    --primary-border: #2563eb;
    --primary-text: #93c5fd;

    --success: #34d399;
    --success-bg: rgba(16, 185, 129, 0.15);
    --success-border: #059669;
    --success-text: #6ee7b7;

    --danger: #f87171;
    --danger-bg: rgba(239, 68, 68, 0.15);
    --danger-border: #dc2626;
    --danger-text: #fca5a5;

    --warning: #fbbf24;
    --warning-bg: rgba(245, 158, 11, 0.15);
    --warning-border: #d97706;
    --warning-text: #fde68a;

    --info: #38bdf8;
    --info-bg: rgba(14, 165, 233, 0.15);
    --info-border: #0284c7;
    --info-text: #7dd3fc;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7);

    --backdrop: rgba(0, 0, 0, 0.75);
  }
}

/* Forçado para data-theme="dark" ou data-bs-theme="dark" explicitamente */
[data-theme="dark"],
[data-bs-theme="dark"] {
  --bg-app: #0b1120;
  --bg-body: #0b1120;
  --bg-surface: #1e293b;
  --bg-card: #1e293b;
  --bg-surface-elevated: #334155;
  --bg-subtle: #0f172a;
  --bg-hover: #334155;

  --border-subtle: #1e293b;
  --border-default: #334155;
  --border-strong: #475569;

  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --text-subtle: #64748b;
  --text-inverse: #0f172a;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-subtle: rgba(59, 130, 246, 0.15);
  --primary-border: #2563eb;
  --primary-text: #93c5fd;

  --success: #34d399;
  --success-bg: rgba(16, 185, 129, 0.15);
  --success-border: #059669;
  --success-text: #6ee7b7;

  --danger: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-border: #dc2626;
  --danger-text: #fca5a5;

  --warning: #fbbf24;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --warning-border: #d97706;
  --warning-text: #fde68a;

  --info: #38bdf8;
  --info-bg: rgba(14, 165, 233, 0.15);
  --info-border: #0284c7;
  --info-text: #7dd3fc;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7);

  --backdrop: rgba(0, 0, 0, 0.75);
}

/* ==============================================================================
 * COMPONENTES PADRÃO DO DESIGN SYSTEM
 * ============================================================================== */

/* Container de Toasts Efêmeros */
#toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
  max-width: 400px;
  width: calc(100% - 3rem);
}

.toast-item {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-family);
  font-size: 0.875rem;
  line-height: 1.4;
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-default);
  animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-item.toast-success {
  border-left: 4px solid var(--success);
}
.toast-item.toast-error {
  border-left: 4px solid var(--danger);
}
.toast-item.toast-warning {
  border-left: 4px solid var(--warning);
}
.toast-item.toast-info {
  border-left: 4px solid var(--info);
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toast-close {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0.25rem;
  margin-left: 0.75rem;
  font-size: 1rem;
  line-height: 1;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Custom Standalone Confirmation Modal (Namespaced to avoid clashing with Bootstrap) */
.custom-modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: var(--backdrop);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

.custom-modal-backdrop.active {
  display: flex !important;
  opacity: 1;
  pointer-events: auto;
}

.custom-modal-dialog {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 460px;
  width: 100%;
  padding: 1.75rem;
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-main);
}

.custom-modal-backdrop.active .custom-modal-dialog {
  transform: scale(1);
}

.custom-modal-header {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-main);
}

.custom-modal-body {
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.custom-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.btn-secondary {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-default);
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.btn-secondary:hover {
  background-color: var(--bg-hover);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
  border: none;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}
