/* Componentes reutilizáveis */

/* === FORMULÁRIOS === */
.form-group {
  margin-bottom: var(--space-5);
  text-align: left;
}

.form-group label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  transition: all 0.15s ease;
  outline: none;
}

.form-control:focus {
  border-color: var(--border-input-focus);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px rgba(59, 111, 237, 0.1);
}

.form-control::placeholder {
  color: var(--text-muted);
}

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235A6178' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
}

.form-inline {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* Input com ícone */
.input-icon-wrap {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.form-control-icon {
  padding-left: 42px;
}

.input-icon-wrap:focus-within .input-icon {
  color: var(--color-primary);
}

/* === BOTÕES === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 20px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  border: none;
  line-height: 1;
}

.btn svg { width: 16px; height: 16px; }

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

.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 2px 8px rgba(59, 111, 237, 0.3);
}

.btn-secondary {
  background: var(--bg-table-header);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border-light);
}

.btn-danger {
  background: var(--status-danger);
  color: #fff;
}

.btn-danger:hover {
  background: #cc2d28;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-table-header);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--font-size-xs);
}

.btn-full { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === CARDS === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-6);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
}

.card-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-2);
}

.card-value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
}

.card-delta {
  font-size: var(--font-size-xs);
  font-weight: 600;
  margin-top: var(--space-1);
}

.card-delta.positive { color: var(--status-positive); }
.card-delta.negative { color: var(--status-danger); }
.card-delta.warning { color: var(--status-warning); }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

/* === TABELAS === */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table thead {
  background: var(--bg-table-header);
}

.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-light);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.data-table tbody tr:nth-child(even) {
  background: var(--bg-table-row-alt);
}

.data-table tbody tr:hover {
  background: var(--color-primary-light);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.td-actions {
  display: flex;
  gap: var(--space-2);
}

.td-right { text-align: right; }
.td-center { text-align: center; }
.td-mono { font-family: var(--font-mono); font-size: var(--font-size-xs); }

/* Tabela editável */
.editable-cell {
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.editable-cell:hover {
  background: var(--color-primary-light);
}

.editable-cell.editing {
  padding: 0;
}

.editable-cell input {
  width: 100%;
  padding: 4px 8px;
  border: 2px solid var(--border-input-focus);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  outline: none;
}

.editable-cell.changed {
  border: 1px solid var(--color-primary);
  background: var(--color-primary-light);
}

.computed-cell {
  color: var(--text-muted);
  font-style: italic;
}

/* Header de grupo */
.group-header {
  background: var(--bg-sidebar) !important;
  color: #fff !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: var(--font-size-xs) !important;
}

/* Sticky columns */
.sticky-col {
  position: sticky;
  left: 0;
  background: inherit;
  z-index: 2;
}

.sticky-col-2 {
  position: sticky;
  left: 120px;
  background: inherit;
  z-index: 2;
}

/* === BADGES === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
}

.badge-positive {
  background: var(--status-positive-bg);
  color: var(--status-positive);
}

.badge-warning {
  background: var(--status-warning-bg);
  color: var(--status-warning);
}

.badge-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger);
}

.badge-info {
  background: var(--status-info-bg);
  color: var(--status-info);
}

/* === SEMÁFORO === */
.semaforo-grid {
  display: grid;
  gap: 2px;
}

.semaforo-cell {
  padding: 10px 14px;
  text-align: center;
  font-size: var(--font-size-xs);
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.semaforo-cell:hover {
  opacity: 0.85;
  transform: scale(1.02);
}

.semaforo-green { background: var(--status-positive-bg); color: var(--status-positive); }
.semaforo-yellow { background: var(--status-warning-bg); color: var(--status-warning); }
.semaforo-red { background: var(--status-danger-bg); color: var(--status-danger); }
.semaforo-empty { background: var(--bg-table-row-alt); color: var(--text-muted); }

/* === MODAIS === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  width: 480px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

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

.modal-title {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.modal-close:hover {
  background: var(--bg-table-header);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
}

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

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

/* === TOASTS === */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  box-shadow: var(--shadow-dropdown);
  animation: toastIn 0.3s ease;
  min-width: 280px;
  max-width: 400px;
}

.toast-success { background: var(--status-positive); color: #fff; }
.toast-error { background: var(--status-danger); color: #fff; }
.toast-warning { background: var(--status-warning); color: #fff; }
.toast-info { background: var(--status-info); color: #fff; }

.toast.removing {
  animation: toastOut 0.3s ease forwards;
}

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

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

/* === TABS === */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-light);
  margin-bottom: var(--space-6);
}

.tab {
  padding: 12px 24px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.tab:hover { color: var(--text-primary); }

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* === FILTROS === */
.filters-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.filter-select {
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235A6178' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* === ALERTAS === */
.alert-card {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
}

.alert-card-danger { background: var(--status-danger-bg); border-left: 4px solid var(--status-danger); }
.alert-card-warning { background: var(--status-warning-bg); border-left: 4px solid var(--status-warning); }
.alert-card-positive { background: var(--status-positive-bg); border-left: 4px solid var(--status-positive); }

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

/* === SLIDERS === */
.slider-group {
  margin-bottom: var(--space-4);
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.slider-value {
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  appearance: none;
  background: var(--border-light);
  border-radius: var(--radius-full);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(59, 111, 237, 0.3);
}

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  opacity: 0.4;
}

.empty-state p {
  font-size: var(--font-size-sm);
}

/* === SKELETON === */
.skeleton {
  background: linear-gradient(90deg, var(--bg-table-header) 25%, var(--bg-table-row-alt) 50%, var(--bg-table-header) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

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

.skeleton-line {
  height: 14px;
  margin-bottom: var(--space-3);
}

.skeleton-box {
  height: 80px;
}
