/**
 * Dashboard Clipping ISAC 2025 - Components
 * Buttons, Selects, and Interactive Elements
 */

/* ============================================================================
   Dashboard Filters Section
   ========================================================================= */

.dashboard-filters-section {
  margin-bottom: var(--space-6);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
  overflow: visible;
  position: relative;
  z-index: 10;
}

/* Desktop: hide collapsible header, show filters directly */
.dash-filters-header {
  display: none;
}

.dashboard-filters-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: flex-end;
  justify-content: flex-start;
}

.dashboard-filters-container .filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 200px;
}

.dashboard-filters-container .filter-group label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--gray-700);
}

/* Collapsible header elements (used on mobile) */
.dash-filters-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.dash-filters-left h3 {
  font-size: var(--text-base);
  font-weight: var(--font-bold);
  color: var(--gray-900);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.dash-filters-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.dash-filters-summary .no-filters {
  font-size: var(--text-xs);
  color: var(--gray-500);
}

.dash-filters-summary .filter-chip {
  font-size: var(--text-xs);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--primary-color);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

/* ============================================================================
   Buttons
   ========================================================================= */

.btn-primary,
.btn-secondary,
.btn-ghost {
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  cursor: pointer;
  transition: all var(--transition-base);
  border: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary-color);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: transparent;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
}

.btn-secondary:hover {
  background: var(--primary-color);
  color: #fff;
  border-color: var(--primary-color);
  box-shadow: var(--shadow-md);
}

.btn-ghost {
  background: transparent;
  color: var(--isac-blue-primary);
}

.btn-ghost:hover {
  background: var(--gray-50);
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled,
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-danger:hover {
  background: var(--danger-dark);
  box-shadow: var(--shadow-md);
}

.icon {
  font-size: var(--text-lg);
}

/* ============================================================================
   Select
   ========================================================================= */

/* ============================================================================
   Theme Toggle
   ========================================================================= */

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Theme Toggle Switch — same visual as mini-toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.theme-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle-track {
  position: relative;
  width: 40px;
  height: 20px;
  border-radius: 10px;
  background: var(--gray-300);
  border: 1px solid var(--gray-400);
  box-sizing: border-box;
  transition: background var(--transition-base), border-color var(--transition-base);
}

.theme-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-base);
  z-index: 2;
}

.theme-toggle-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  z-index: 1;
  transition: opacity var(--transition-base);
  line-height: 0;
}

/* Sun — right side, visible in light mode */
.theme-toggle-sun {
  right: 4px;
  color: var(--gray-500);
  opacity: 1;
}

.theme-toggle-sun svg {
  width: 10px;
  height: 10px;
}

/* Moon — left side, hidden in light mode */
.theme-toggle-moon {
  left: 4px;
  color: var(--gray-100);
  opacity: 0;
}

.theme-toggle-moon svg {
  width: 9px;
  height: 9px;
}

/* Checked = dark mode */
.theme-toggle input:checked ~ .theme-toggle-track {
  background: var(--primary-color);
  border-color: var(--primary-dark);
}

.theme-toggle input:checked ~ .theme-toggle-track .theme-toggle-thumb {
  transform: translateX(20px);
}

.theme-toggle input:checked ~ .theme-toggle-track .theme-toggle-sun {
  opacity: 0;
}

.theme-toggle input:checked ~ .theme-toggle-track .theme-toggle-moon {
  opacity: 1;
}

/* ============================================================================
   Select (Cross-browser)
   ========================================================================= */

.select-primary,
.filter-select,
.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236B7280' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

[data-theme="dark"] .select-primary,
[data-theme="dark"] .filter-select,
[data-theme="dark"] .form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239CA3AF' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
}

.select-primary {
  padding: var(--space-2) var(--space-4);
  padding-right: 36px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--gray-700);
  background-color: var(--white);
  cursor: pointer;
  transition: all var(--transition-base);
  min-width: 200px;
}

.select-primary:hover {
  border-color: var(--isac-blue-light);
}

.select-primary:focus {
  outline: none;
  border-color: var(--isac-blue-primary);
  box-shadow: 0 0 0 3px rgba(30, 90, 142, 0.1);
}

/* ============================================================================
   Month Tabs
   ========================================================================= */

.month-tabs {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-2);
  background: var(--gray-100);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-6);
}

.month-tab {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: transparent;
  color: var(--gray-600);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.month-tab:hover {
  background: var(--white);
  color: var(--gray-900);
}

.month-tab.active {
  background: var(--isac-blue-primary);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}

/* ============================================================================
   Tooltips
   ========================================================================= */

.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip-content {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: var(--white);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  z-index: 1000;
}

.tooltip:hover .tooltip-content {
  opacity: 1;
}

.tooltip-content::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--gray-900);
}

/* ============================================================================
   Progress Bars
   ========================================================================= */

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--gray-200);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--isac-blue-primary);
  border-radius: var(--radius-xl);
  transition: width var(--transition-slow);
}

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

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

.progress-fill.negative {
  background: var(--danger);
}

/* ============================================================================
   Stat Boxes
   ========================================================================= */

.stat-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  background: var(--gray-50);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--gray-600);
  font-weight: var(--font-medium);
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--gray-900);
  font-family: var(--font-numbers);
}

.stat-bar {
  flex: 1;
  margin: 0 var(--space-4);
}

/* ============================================================================
   Legend
   ========================================================================= */

.chart-legend {
  display: flex;
  gap: var(--space-4);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--space-4);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-sm);
}

.legend-label {
  font-size: var(--text-sm);
  color: var(--gray-600);
}

.legend-value {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--gray-900);
  font-family: var(--font-numbers);
}

/* ============================================================================
   Empty State
   ========================================================================= */

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
}

.empty-icon {
  font-size: var(--text-5xl);
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--gray-900);
  margin-bottom: var(--space-2);
}

.empty-message {
  font-size: var(--text-base);
  color: var(--gray-600);
}

/* ============================================================================
   Alert Messages
   ========================================================================= */

.alert {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: start;
  gap: var(--space-3);
}

.alert-icon {
  font-size: var(--text-xl);
  flex-shrink: 0;
}

.alert-content {
  flex: 1;
}

.alert-title {
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-1);
}

.alert-message {
  font-size: var(--text-sm);
}

.alert-info {
  background: var(--info-light);
  border-left: 4px solid var(--info);
  color: #1E40AF;
}

.alert-success {
  background: var(--success-light);
  border-left: 4px solid var(--success);
  color: #065F46;
}

.alert-warning {
  background: var(--warning-light);
  border-left: 4px solid var(--warning);
  color: #92400E;
}

.alert-danger {
  background: var(--danger-light);
  border-left: 4px solid var(--danger);
  color: #991B1B;
}

/* ============================================================================
   Divider
   ========================================================================= */

.divider {
  height: 1px;
  background: var(--gray-200);
  margin: var(--space-6) 0;
}

.divider-vertical {
  width: 1px;
  height: auto;
  background: var(--gray-200);
  margin: 0 var(--space-4);
}

/* ============================================================================
   Skeleton Loader
   ========================================================================= */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-200) 25%,
    var(--gray-100) 50%,
    var(--gray-200) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 16px;
  margin-bottom: var(--space-2);
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: var(--space-3);
}

.skeleton-card {
  height: 200px;
}

/* ============================================================================
   Animations
   ========================================================================= */

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

.fade-in {
  animation: fadeIn var(--transition-slow) ease-out;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.slide-in-right {
  animation: slideInRight var(--transition-slow) ease-out;
}

/* ============================================================================
   Print Styles
   ========================================================================= */

@media print {
  .dashboard-header,
  .dashboard-footer,
  .btn-primary,
  .btn-secondary,
  .filter-group,
  .tabs-navigation,
  .modal-form-overlay,
  .modal-overlay,
  .theme-toggle,
  .pagination-container {
    display: none !important;
  }

  body {
    background: white;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  section {
    page-break-inside: avoid;
  }

  .print-chart-image {
    max-width: 100%;
    height: auto;
    page-break-inside: avoid;
  }

  .tab-content {
    display: none !important;
  }

  .tab-content.active {
    display: block !important;
  }
}

/* ============================================================================
   Modal de Confirmacao
   ========================================================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-base);
  pointer-events: none;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 420px;
  width: 90%;
  transform: translateY(20px);
  transition: transform var(--transition-base);
}

.modal-overlay.visible .modal-card {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6) var(--space-3);
}

.modal-header h3 {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--gray-900);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: var(--text-2xl);
  color: var(--gray-400);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--gray-700);
}

.modal-body {
  padding: var(--space-3) var(--space-6);
}

.modal-body p {
  font-size: var(--text-base);
  color: var(--gray-600);
  margin: 0;
}

.modal-footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-3) var(--space-6) var(--space-5);
}

.modal-confirm-danger {
  background: var(--danger) !important;
  color: var(--white) !important;
}

.modal-confirm-danger:hover {
  opacity: 0.9;
}

/* ============================================================================
   Modal de Indicador
   ========================================================================= */

.indicator-modal-card {
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.indicator-modal-body {
  padding: var(--space-3) var(--space-6) var(--space-5);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.indicator-modal-body h4 {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--isac-blue-primary);
  margin: var(--space-4) 0 var(--space-2);
}

.indicator-modal-body h4:first-child {
  margin-top: 0;
}

.indicator-modal-body p {
  font-size: var(--text-sm);
  color: var(--gray-600);
  line-height: 1.6;
  margin: 0 0 var(--space-3);
}

.indicator-modal-body code {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm, 4px);
  padding: 2px 6px;
  font-size: var(--text-xs);
  font-family: var(--font-numbers);
  color: var(--isac-blue-primary);
}

.indicator-modal-icon {
  color: var(--isac-teal);
  display: flex;
  align-items: center;
}

/* ============================================================================
   Toast Notifications
   ========================================================================= */

.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--white);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-xl);
  font-size: var(--text-sm);
  color: var(--gray-700);
  pointer-events: auto;
  max-width: 420px;
  min-width: 280px;
  transform: translateX(100%);
  opacity: 0;
  transition: transform var(--transition-slow), opacity var(--transition-slow);
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-icon {
  flex-shrink: 0;
  font-size: var(--text-lg);
  line-height: 1;
}

.toast-message {
  flex: 1;
  line-height: 1.4;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: var(--text-lg);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.toast-close:hover {
  color: var(--gray-700);
}

.toast.toast-error {
  border-left: 4px solid var(--danger);
  background: var(--danger-light);
}

.toast.toast-success {
  border-left: 4px solid var(--success);
  background: var(--success-light);
}

.toast.toast-warning {
  border-left: 4px solid var(--warning);
  background: var(--warning-light);
}

.toast.toast-info {
  border-left: 4px solid var(--info);
  background: var(--info-light);
}

@media (max-width: 480px) {
  .toast-container {
    left: var(--space-3);
    right: var(--space-3);
    top: var(--space-3);
  }

  .toast {
    max-width: none;
    min-width: auto;
  }
}
