/* ============================================================
   components.css — Componentes reutilizáveis do systemg
   Consome apenas variáveis de theme.css
   ============================================================ */

/* ── Reset base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--font);
  font-size: var(--text-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary-600); text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: var(--font); font-size: inherit; }
input, textarea, select { font-family: var(--font); }

/* ── Tipografia ─────────────────────────────────────────────── */
.text-display { font-size: var(--text-display); font-weight: var(--fw-black); letter-spacing: var(--tracking-tight); }
.text-h1 { font-size: var(--text-h1); font-weight: var(--fw-black); letter-spacing: -0.02em; }
.text-h2 { font-size: var(--text-h2); font-weight: var(--fw-bold); }
.text-h3 { font-size: var(--text-h3); font-weight: var(--fw-semi); }
.text-body { font-size: var(--text-body); font-weight: var(--fw-regular); color: var(--ink-2); }
.text-label {
  font-size: var(--text-label);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--ink-3);
}

/* ── Botões ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px var(--space-5);
  border-radius: var(--r-pill);
  font-weight: var(--fw-bold);
  font-size: var(--text-sm);
  font-family: var(--font);
  transition: all 0.15s ease;
  cursor: pointer;
  white-space: nowrap;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}
.btn-primary:hover { background: var(--primary-600); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--ink-3); }

.btn-ghost {
  background: var(--surf-2);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--border); }

.btn-danger {
  background: var(--neg-soft);
  color: var(--neg);
}
.btn-danger:hover { background: #f8d0d0; }

.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

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

.btn-icon {
  padding: var(--space-2);
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  justify-content: center;
}

/* ── Inputs ─────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--ink-2);
}

.input, .select, .textarea {
  width: 100%;
  padding: 10px var(--space-3);
  background: var(--surf-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-input);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.16);
}
.textarea { resize: vertical; min-height: 80px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238A93A6' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.input-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-3); }

/* Tipo toggle (entrada/saída) */
.tipo-toggle { display: flex; border: 1.5px solid var(--border); border-radius: var(--r-input); overflow: hidden; }
.tipo-toggle button { flex: 1; padding: 10px; font-size: var(--text-sm); font-weight: var(--fw-semi); color: var(--ink-3); background: var(--surf-2); transition: all 0.15s; }
.tipo-toggle button.active.entrada { background: var(--pos-soft); color: var(--pos); }
.tipo-toggle button.active.saida   { background: var(--neg-soft); color: var(--neg); }

/* ── Badges de status ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-pago, .badge-recebido { background: var(--status-pago-bg); color: var(--status-pago); }
.badge-previsto  { background: var(--status-previsto-bg); color: var(--status-previsto); }
.badge-atrasado  { background: var(--status-atrasado-bg); color: var(--status-atrasado); }
.badge-conciliado { background: var(--status-conciliado-bg); color: var(--status-conciliado); }
.badge-entrada   { background: var(--pos-soft); color: var(--pos); }
.badge-saida     { background: var(--neg-soft); color: var(--neg); }
.badge-pendente  { background: var(--warn-soft); color: var(--warn-dark); }

/* ── Cards de KPI ───────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-3);
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-inner);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  box-shadow: var(--shadow-sm);
}
.kpi-card-highlight {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
  color: #fff;
  border-color: transparent;
}
.kpi-card-highlight .kpi-label { color: rgba(255,255,255,0.75); }
.kpi-card-highlight .kpi-value { color: #fff; }
.kpi-card-highlight .kpi-sub   { color: #fff !important; }
.kpi-card-highlight .kpi-delta { color: rgba(255,255,255,0.9); }

.kpi-label {
  font-size: var(--text-xs);
  font-weight: var(--fw-semi);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.kpi-value {
  font-size: 22px;
  font-weight: var(--fw-black);
  letter-spacing: var(--tracking-tight);
  color: var(--ink);
  line-height: 1;
}
.kpi-delta {
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
}
.kpi-delta.pos { color: var(--pos); }
.kpi-delta.neg { color: var(--neg); }
.kpi-delta.neutral { color: var(--ink-3); }

/* ── Tabelas ─────────────────────────────────────────────────── */
.tbl-wrap {
  background: var(--surface);
  border-radius: var(--r-inner);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

table { width: 100%; border-collapse: collapse; }

thead th {
  background: var(--surf-2);
  padding: 10px var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--ink-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.right { text-align: right; }

tbody td {
  padding: 12px var(--space-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--ink);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surf-2); }

.td-valor { font-weight: var(--fw-bold); font-size: var(--text-body); text-align: right; white-space: nowrap; }
.td-valor.pos { color: var(--pos); }
.td-valor.neg { color: var(--neg); }

.tbl-icon {
  width: 32px; height: 32px;
  border-radius: var(--r-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tbl-icon.entrada { background: var(--pos-soft); color: var(--pos); }
.tbl-icon.saida   { background: var(--neg-soft); color: var(--neg); }

/* Tabela editável (DRE, Equipe, etc.) */
.tbl-edit td { padding: 4px var(--space-2); }
.tbl-edit thead th { background: var(--primary); color: #fff; border-bottom: none; }
.tbl-edit thead th:first-child { border-radius: var(--r-inner) 0 0 0; }
.tbl-edit thead th:last-child  { border-radius: 0 var(--r-inner) 0 0; }
.tbl-total td { background: var(--surf-2); font-weight: var(--fw-bold); font-size: var(--text-sm); }
.tbl-group td { background: var(--surf-2); font-size: var(--text-xs); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); border-bottom: none; }
.tbl-sub td { font-weight: var(--fw-bold); border-top: 2px solid var(--border); }
.tbl-pct td { font-style: italic; color: var(--ink-3); font-size: var(--text-xs); border: none; background: transparent; padding: 2px var(--space-4) 8px; }
.tbl-ll td { background: var(--ink) !important; color: #fff !important; font-weight: var(--fw-bold); }
.dre-pos { color: var(--pos); font-weight: var(--fw-semi); }
.dre-neg { color: var(--neg); font-weight: var(--fw-semi); }
.dre-zero { color: var(--border); }

.inp-num {
  width: 96px;
  text-align: right;
  padding: 4px 6px;
  background: #FFFBEB;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  font-size: var(--text-xs);
  font-family: var(--font);
  color: var(--ink);
  outline: none;
}
.inp-num:focus { border-color: var(--primary); }
.inp-text {
  padding: 4px 6px;
  background: var(--surf-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  font-size: var(--text-xs);
  font-family: var(--font);
  color: var(--ink);
  outline: none;
  width: 100%;
}
.inp-text:focus { border-color: var(--primary); }

/* ── Cards de conta/cartão ───────────────────────────────────── */
.account-card {
  border-radius: var(--r-card);
  padding: var(--space-5) var(--space-6);
  color: #fff;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.account-card-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
}
.account-card-dark {
  background: #16203A;
}
.account-card-add {
  background: transparent;
  border: 2px dashed var(--border);
  color: var(--ink-3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.account-card-add:hover { border-color: var(--primary); color: var(--primary); }

/* ── Gráficos ────────────────────────────────────────────────── */
.chart-wrap {
  background: var(--surface);
  border-radius: var(--r-inner);
  border: 1px solid var(--border);
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow-sm);
}
.chart-wrap canvas { max-height: 300px; }
.chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.chart-title { font-size: var(--text-h3); font-weight: var(--fw-bold); color: var(--ink); }
.chart-subtitle { font-size: var(--text-xs); color: var(--ink-3); margin-top: 2px; }
.chart-legend { display: flex; gap: var(--space-4); }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--ink-2); font-weight: var(--fw-semi); }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.chart-legend-line { width: 16px; height: 2.5px; border-radius: 2px; }

/* ── Alertas ─────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 13px var(--space-5);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  margin-bottom: var(--space-3);
}
.alert-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--r-xs);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.alert-body { flex: 1; }
.alert-title { font-weight: var(--fw-bold); }
.alert-desc { color: var(--ink-2); margin-top: 2px; }
.alert-action { font-size: var(--text-xs); font-weight: var(--fw-bold); cursor: pointer; white-space: nowrap; }

.alert-danger  { background: var(--neg-soft);  border: 1px solid #F6C9CA; }
.alert-danger  .alert-icon { color: var(--neg); }
.alert-danger  .alert-title { color: #B5363B; }
.alert-danger  .alert-action { color: var(--neg); }
.alert-warn    { background: var(--warn-soft);  border: 1px solid #F6E2B5; }
.alert-warn    .alert-icon { color: var(--warn-dark); }
.alert-warn    .alert-title { color: var(--warn-dark); }
.alert-warn    .alert-action { color: var(--warn-dark); }
.alert-success { background: var(--pos-soft);   border: 1px solid #B4DBCB; }
.alert-success .alert-icon { color: var(--pos); }
.alert-success .alert-title { color: #0B6E35; }

/* ── Section header ──────────────────────────────────────────── */
.sec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-3);
  flex-wrap: wrap;
}
.sec-title { font-size: var(--text-h3); font-weight: var(--fw-bold); color: var(--ink); }
.sec-sub { font-size: var(--text-xs); color: var(--ink-3); margin-top: 2px; }
.sec-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* ── Filtros ─────────────────────────────────────────────────── */
.filters-bar { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); align-items: center; }
.filters-bar .input, .filters-bar .select { width: auto; font-size: var(--text-xs); padding: 7px 10px; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 32, 58, 0.55);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  animation: fadeIn 0.18s ease;
}
.modal-overlay.hidden { display: none; }

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

.modal-box {
  background: var(--surface);
  border-radius: var(--r-card);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
  box-shadow: var(--shadow-lg);
}
.modal-box-lg { max-width: 780px; }

.modal-header {
  display: flex;
  align-items: center;
  padding: var(--space-5) var(--space-6);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
  border-radius: var(--r-card) var(--r-card) 0 0;
  gap: var(--space-3);
}
.modal-header h3 { font-size: var(--text-h3); font-weight: var(--fw-semi); color: #fff; flex: 1; }
.modal-close {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1rem;
  cursor: pointer; border: none;
  transition: background 0.15s;
}
.modal-close:hover { background: rgba(255,255,255,0.3); }
.modal-body { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.modal-footer { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-2); }

/* ── Toast ───────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px var(--space-5);
  border-radius: var(--r-pill);
  font-size: var(--text-sm);
  font-weight: var(--fw-semi);
  color: #fff;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.2s ease;
  white-space: nowrap;
}
.toast-success { background: var(--pos); }
.toast-error   { background: var(--neg); }
.toast-warn    { background: var(--warn-dark); }
.toast-info    { background: var(--ink); }

/* ── Pílulas de navegação interna ────────────────────────────── */
.sub-tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-5); flex-wrap: wrap; }
.sub-tab {
  padding: 6px var(--space-4);
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  border: 1.5px solid var(--border);
  color: var(--ink-2);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
}
.sub-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.sub-tab:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-14) var(--space-6);
  text-align: center;
  color: var(--ink-3);
}
.empty-state-icon { font-size: 40px; margin-bottom: var(--space-3); opacity: 0.5; }
.empty-state-title { font-size: var(--text-h3); font-weight: var(--fw-semi); color: var(--ink-2); margin-bottom: var(--space-2); }
.empty-state-desc { font-size: var(--text-sm); color: var(--ink-3); }

/* ── Spinner ─────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── WhatsApp pendente card ──────────────────────────────────── */
.wa-card {
  background: var(--surface);
  border-radius: var(--r-inner);
  border: 1px solid var(--border);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
}
.wa-card-img { width: 100%; max-height: 200px; object-fit: cover; border-radius: var(--r-sm); margin-bottom: var(--space-3); }
.wa-card-fields { display: grid; grid-template-columns: 130px 1fr; gap: 6px var(--space-3); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.wa-card-fields label { font-weight: var(--fw-semi); color: var(--ink-2); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; padding-top: 10px; }
.wa-card-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }

/* ── Funil visual ────────────────────────────────────────────── */
.funil-bar { display: flex; flex-direction: column; gap: 4px; margin: var(--space-4) 0; }
.funil-step { display: flex; align-items: center; gap: var(--space-3); }
.funil-track { flex: 1; height: 8px; background: var(--border); border-radius: var(--r-pill); overflow: hidden; }
.funil-fill { height: 100%; border-radius: var(--r-pill); background: var(--primary); transition: width 0.4s ease; }
.funil-label { font-size: var(--text-xs); font-weight: var(--fw-semi); color: var(--ink-2); width: 160px; }
.funil-count { font-size: var(--text-xs); font-weight: var(--fw-bold); color: var(--ink); width: 48px; text-align: right; }

/* ── Role badges ─────────────────────────────────────────────── */
.role-admin   { background: var(--neg-soft); color: #b91c1c; }
.role-gestor  { background: var(--pos-soft); color: #065f46; }
.role-colaborador { background: #DBEAFE; color: #1e40af; }
.role-visualizador { background: var(--surf-2); color: var(--ink-2); }
