/* Campanhas Comerciais (Fase 3) - evolucao de Eventos. Tokens vem de theme.css. */

/* Abas Eventos | Campanhas | Relatorio | Calendario */
.cp-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--color-border);
  margin: 4px 0 14px;
}

.cp-tab {
  appearance: none;
  border: 1px solid transparent;
  border-bottom: none;
  background: none;
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--color-muted);
  padding: 9px 14px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
}

.cp-tab:hover { color: var(--color-text); background: var(--color-surface-soft); }
.cp-tab.is-active {
  color: var(--color-accent, #0e7c86);
  background: var(--color-surface);
  border-color: var(--color-border);
  margin-bottom: -1px;
  box-shadow: inset 0 -2px 0 var(--color-surface);
}
.cp-tab--link { margin-left: auto; font-weight: 600; }
.cp-tab.is-hidden { display: none; }

.cp-tab-badge {
  background: #B54708;
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cp-tab-badge.is-hidden { display: none; }

.cp-toolbar { margin-bottom: 12px; max-width: 320px; }
.cp-toolbar.is-hidden, .cp-view.is-hidden, #ev-view-events.is-hidden { display: none; }

.cp-view-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.cp-view-lead { margin: 0; color: var(--color-muted); font-size: 0.9rem; max-width: 70ch; }

/* Contadores clicaveis (prioridade: ativas -> pendentes de encerramento -> resultados) */
.cp-counts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.cp-count {
  appearance: none;
  text-align: left;
  font: inherit;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  min-height: 56px;
}
.cp-count strong { font-size: 22px; line-height: 1.1; }
.cp-count span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; color: var(--color-muted); }
.cp-count:hover { border-color: var(--color-border-strong, #cbd5e1); }
.cp-count.is-selected { border-color: var(--color-accent, #0e7c86); box-shadow: 0 0 0 2px var(--color-accent-ring); }
.cp-count.is-alert { background: #FFF6E5; border-color: #F5C26B; }
.cp-count.is-alert strong { color: #B54708; }

/* Lista */
.cp-table td, .cp-table th { vertical-align: top; }
.cp-name { display: block; }
.cp-objective, .cp-clone-tag { display: block; color: var(--color-muted); font-size: 12px; margin-top: 2px; max-width: 42ch; }
.cp-clone-tag { font-style: italic; }
.cp-row.is-attention { background: #FFFBF2; }
.cp-row.is-cancelled { opacity: 0.65; }
.cp-na { color: var(--color-muted); font-size: 0.85em; }
.cp-actions { white-space: nowrap; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cp-link { appearance: none; border: none; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--color-accent, #0e7c86); cursor: pointer; text-align: left; }
.cp-link:hover { text-decoration: underline; }
.cp-learn { max-width: 340px; font-size: 0.88rem; }

.cp-roi { display: inline-flex; flex-direction: column; font-weight: 800; line-height: 1.2; cursor: help; }
.cp-roi small { font-weight: 500; font-size: 11px; color: var(--color-muted); }
.cp-roi--pos { color: #067647; }
.cp-roi--neg { color: #B42318; }
.cp-roi--na { color: var(--color-muted); font-weight: 700; font-size: 0.88rem; }

.cp-stars { color: #F59E0B; letter-spacing: 1px; white-space: nowrap; }
.cp-stars-off { color: #D0D5DD; }

/* Relatorio */
.cp-report-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin: 8px 0 16px;
}
.cp-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.cp-card > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; color: var(--color-muted); }
.cp-card strong { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.cp-card small { font-size: 11px; color: var(--color-muted); }
.cp-card .cp-card-name { font-size: 15px; }
.cp-warn { color: #B54708; }
.cp-subtitle { margin: 14px 0 6px; font-size: 0.95rem; }
.cp-formulas { margin: 14px 0 0; font-size: 12px; color: var(--color-muted); max-width: 90ch; }

/* Modais */
.cp-detail-card, .cp-close-card { width: min(780px, 96vw); max-height: 92vh; overflow-y: auto; }
.cp-clone-card { width: min(520px, 96vw); }
.cp-close-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.cp-close-summary span { color: var(--color-text-soft); }
.cp-close-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px; }
.cp-close-hint { margin: 10px 0 0; }
.cp-field-label { display: block; font-size: 12px; font-weight: 700; color: var(--color-label); margin-bottom: 6px; }
.cp-rating { display: inline-flex; gap: 6px; }
.cp-rating-btn {
  appearance: none;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--color-border-strong, #cbd5e1);
  background: var(--color-surface);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.cp-rating-btn.is-selected { background: #F59E0B; border-color: #D97706; color: #fff; }
.cp-formula { margin: 8px 0 0; font-size: 12px; color: var(--color-muted); }
.cp-next-action {
  margin: 14px 0;
  padding: 10px 12px;
  border-left: 4px solid var(--color-accent, #0e7c86);
  background: var(--color-surface-soft);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cp-next-action span { font-size: 11px; text-transform: uppercase; color: var(--color-muted); }

/* Secao dentro do formulario de evento */
.ev-cp-result { margin-top: 12px; }
.ev-cp-result summary { cursor: pointer; font-weight: 700; font-size: 0.9rem; margin-bottom: 10px; }
.ev-campaign-section.is-hidden, .ev-form-section.is-hidden, label.is-hidden { display: none; }

/* Calendario Comercial: campanhas destacadas por status */
.cc-event-chip--campaign { font-weight: 800; border-left-width: 4px; }
.cc-event-chip.cc-camp-planned,
.cc-legend-chip.cc-camp-planned { background: #fff; color: #6B21A8; border: 1px dashed #9333EA; border-left: 4px solid #9333EA; }
.cc-event-chip.cc-camp-active,
.cc-legend-chip.cc-camp-active { background: #9333EA; color: #fff; border-left-color: #581C87; box-shadow: 0 0 0 2px rgba(147, 51, 234, 0.25); }
.cc-event-chip.cc-camp-needs,
.cc-legend-chip.cc-camp-needs { background: #FFF6E5; color: #93370D; border: 1px solid #F5C26B; border-left: 4px solid #B54708; }
.cc-event-chip.cc-camp-finished,
.cc-legend-chip.cc-camp-finished { background: #E3F5EC; color: #067647; border-left-color: #12B76A; }
.cc-event-chip.cc-camp-cancelled,
.cc-legend-chip.cc-camp-cancelled { background: #F2F4F7; color: #667085; text-decoration: line-through; border-left-color: #98A2B3; }
.cc-legend-sep { width: 1px; background: var(--color-border); align-self: stretch; }
.cc-legend-chip { display: inline-flex; width: 18px; height: 16px; border-radius: 4px; align-items: center; justify-content: center; font-size: 10px; margin-right: 4px; }
.cc-campaign-empty { margin: 4px 0 10px; font-size: 13px; color: var(--color-muted); font-style: italic; }
.cc-campaign-empty.is-hidden { display: none; }
.cc-day-event-card--campaign { border-left: 4px solid #9333EA; background: var(--color-surface); color: var(--color-text); text-decoration: none; }
.cc-day-event-card--campaign.cc-camp-needs { border-left-color: #B54708; }
.cc-day-event-card--campaign.cc-camp-finished { border-left-color: #12B76A; }
.cc-day-event-card--campaign.cc-camp-cancelled { border-left-color: #98A2B3; opacity: 0.8; text-decoration: none; }
.cc-camp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; margin: 8px 0; }
.cc-camp-grid dt { font-size: 11px; text-transform: uppercase; color: var(--color-muted); }
.cc-camp-grid dd { margin: 0; font-weight: 700; font-size: 13px; overflow-wrap: anywhere; }
.cc-camp-next { background: var(--color-surface-soft); border-radius: 6px; padding: 6px 8px; }

/* Dashboard: campanhas ativas da etapa */
.dash-campaigns { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.dash-campaign {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border: 1px solid var(--color-border);
  border-left: 4px solid #9333EA;
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--color-surface);
  font-size: 0.88rem;
}
.dash-campaign-meta { color: var(--color-muted); font-size: 12px; }

/* Mobile: lista vira cards, acoes em linha, relatorio com scroll controlado */
@media (max-width: 768px) {
  .cp-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: thin; }
  .cp-tab { white-space: nowrap; flex: 0 0 auto; }
  .cp-tab--link { margin-left: 0; }
  .cp-toolbar { max-width: none; }
  .cp-view-head .primary-action { width: 100%; }

  #cp-list .table-wrap,
  #cr-table .table-wrap,
  #cr-by-company .table-wrap { overflow: visible; border: none; }
  #cp-list .cp-table,
  #cp-list .cp-table tbody,
  #cr-table .cp-table,
  #cr-table .cp-table tbody,
  #cr-by-company .cp-table,
  #cr-by-company .cp-table tbody { display: block; width: 100%; }
  #cp-list .cp-table thead,
  #cr-table .cp-table thead,
  #cr-by-company .cp-table thead { display: none; }
  .cp-table tr {
    display: block;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--color-surface);
  }
  .cp-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    border: none;
    padding: 5px 0;
    text-align: right;
    min-width: 0;
  }
  .cp-table td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-muted);
  }
  .cp-table td[data-label="Campanha"] { display: block; text-align: left; }
  .cp-table td[data-label="Campanha"]::before { display: none; }
  .cp-table td[data-label="Campanha"] .cp-objective { max-width: none; }
  .cp-table td.cp-actions { justify-content: flex-start; flex-wrap: wrap; padding-top: 10px; }
  .cp-table td.cp-actions::before { display: none; }
  .cp-table .cp-roi { align-items: flex-end; }
  .cp-learn { max-width: none; }

  .cp-report-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cp-card strong { font-size: 17px; }
  .cp-close-card, .cp-detail-card, .cp-clone-card { width: 100vw; max-height: 100vh; border-radius: 0; }
  .cp-rating-btn { width: 46px; height: 46px; }
  .cc-camp-grid { grid-template-columns: 1fr 1fr; }
}
