/* ============================================================
   Precifika – Service Intelligence CSS
   Componentes: match card, save-to-library modal,
   smart suggestions, badges de performance, dashboard analítico.
   ============================================================ */

/* ════════════════════════════════════════════════════════════
   1. MATCH CARD (inline no builder – detecção de similares)
   ════════════════════════════════════════════════════════════ */

.si-match-card {
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 200;
  width: max(320px, 100%);
  max-width: 520px;
  background: #fff;
  border: 1.5px solid #c4b5fd;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.13), 0 2px 8px rgba(0,0,0,0.07);
  margin-top: 6px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.si-match-card--visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

/* Header */
.si-match-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px 8px;
  background: linear-gradient(90deg, #ede9fe 0%, #f5f3ff 100%);
  border-bottom: 1px solid #e9d5ff;
}
.si-match-icon  { font-size: 13px; }
.si-match-title {
  flex: 1;
  font-size: 11.5px;
  font-weight: 600;
  color: #5b21b6;
}
.si-match-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #a78bfa;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.si-match-close:hover { background: #ddd6fe; color: #5b21b6; }

/* Top match row */
.si-match-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.si-match-top:hover { background: #faf5ff; }

.si-match-info  { flex: 1; min-width: 0; }
.si-match-name  {
  font-size: 13px;
  font-weight: 600;
  color: #1e1b4b;
  line-height: 1.3;
  word-break: break-word;
}
.si-match-meta  {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
}
.si-match-cat {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  background: #ede9fe;
  color: #5b21b6;
  text-transform: capitalize;
}
.si-match-unit {
  font-size: 10.5px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
}
.si-match-price {
  font-size: 11px;
  font-weight: 600;
  color: #059669;
  background: #d1fae5;
  padding: 2px 7px;
  border-radius: 4px;
}
.si-match-desc {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
  line-height: 1.4;
}

/* Score ring */
.si-match-score-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.si-match-score-ring {
  position: relative;
  width: 40px;
  height: 40px;
}
.si-score-svg  { width: 40px; height: 40px; transform: rotate(-90deg); }
.si-score-bg   {
  fill: none;
  stroke: #ede9fe;
  stroke-width: 3;
}
.si-score-fill {
  fill: none;
  stroke: #7c3aed;
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dasharray 0.5s ease;
}
.si-score-val {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5px;
  font-weight: 700;
  color: #5b21b6;
}
.si-score-label {
  font-size: 9.5px;
  color: #9ca3af;
  text-align: center;
}

/* Actions */
.si-match-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 10px;
  border-top: 1px solid #f3f0ff;
}
.si-btn-use {
  flex: 1;
  padding: 7px 12px;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.si-btn-use:hover { background: #6d28d9; transform: translateY(-1px); }
.si-btn-use:active { transform: translateY(0); }

.si-btn-dismiss {
  background: none;
  border: 1px solid #e5e7eb;
  color: #6b7280;
  border-radius: 8px;
  font-size: 11.5px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.si-btn-dismiss:hover { background: #f9fafb; border-color: #d1d5db; color: #374151; }

/* Others */
.si-match-others {
  padding: 8px 12px 10px;
  border-top: 1px solid #f5f3ff;
}
.si-others-label {
  font-size: 10.5px;
  font-weight: 600;
  color: #9ca3af;
  display: block;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.si-match-alt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 3px;
}
.si-match-alt:hover { background: #faf5ff; }
.si-match-alt-name {
  font-size: 12px;
  color: #374151;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.si-match-alt-score {
  font-size: 10.5px;
  font-weight: 600;
  color: #7c3aed;
  background: #ede9fe;
  padding: 1px 6px;
  border-radius: 20px;
  margin-left: 8px;
  flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════
   2. MODAL "SALVAR NA BIBLIOTECA"
   ════════════════════════════════════════════════════════════ */

.si-save-lib-overlay {
  align-items: center !important;
}
.si-save-lib-modal-inner {
  max-width: 540px;
  width: 100%;
  animation: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
}
.si-modal--visible .si-save-lib-modal-inner {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.si-stl-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: linear-gradient(90deg, #fef3c7 0%, #fffbeb 100%);
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: #92400e;
  line-height: 1.5;
}
.si-stl-notice i {
  color: #d97706;
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ════════════════════════════════════════════════════════════
   3. SUGESTÕES INTELIGENTES (Library Picker)
   ════════════════════════════════════════════════════════════ */

.lp-smart-section {
  margin-bottom: 14px;
}

.si-smart-loading {
  padding: 12px;
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
}

.si-smart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.si-smart-title {
  font-size: 12px;
  font-weight: 700;
  color: #7c3aed;
  display: flex;
  align-items: center;
  gap: 5px;
}
.si-smart-title i { color: #f59e0b; }

.si-smart-tabs {
  display: flex;
  gap: 4px;
}
.si-smart-tab {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1.5px solid #e5e7eb;
  background: none;
  color: #6b7280;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.si-smart-tab.active,
.si-smart-tab:hover {
  background: #7c3aed;
  color: #fff;
  border-color: #7c3aed;
}

.si-suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.si-suggest-chip {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 10px;
  background: #f9fafb;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  cursor: pointer;
  min-width: 120px;
  max-width: 200px;
  transition: all 0.15s;
}
.si-suggest-chip:hover {
  border-color: #c4b5fd;
  background: #faf5ff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(124,58,237,0.08);
}
.si-suggest-chip--sel {
  border-color: #7c3aed;
  background: #ede9fe;
}
.si-suggest-name {
  font-size: 12px;
  font-weight: 600;
  color: #1e1b4b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.si-suggest-stats {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.si-suggest-uses, .si-suggest-rate, .si-suggest-price {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
}
.si-suggest-uses  { background: #dbeafe; color: #1d4ed8; }
.si-suggest-rate  { background: #d1fae5; color: #065f46; }
.si-suggest-price { background: #f3f4f6; color: #374151; font-weight: 600; }

/* Divider antes da lista principal */
.lp-smart-section + div::before {
  content: '';
  display: block;
}

/* ════════════════════════════════════════════════════════════
   4. BADGES DE PERFORMANCE NA BIBLIOTECA
   ════════════════════════════════════════════════════════════ */

.si-lib-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.si-lib-badge {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 600;
  white-space: nowrap;
}
.si-lib-badge--uses  { background: #dbeafe; color: #1d4ed8; }
.si-lib-badge--rate  { background: #f3f4f6; color: #6b7280; }
.si-lib-badge--rate.si-lib-badge--rate-hi { background: #d1fae5; color: #065f46; }
.si-lib-badge--value { background: #fef9c3; color: #92400e; }

/* ════════════════════════════════════════════════════════════
   5. DASHBOARD ANALÍTICO
   ════════════════════════════════════════════════════════════ */

/* Painel container no dashboard */
.si-analytics-panel {
  background: #fff;
  border: 1px solid var(--gray-100, #f1f5f9);
  border-radius: 16px;
  padding: 20px 24px;
  margin-top: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

/* Loading / Empty states */
.si-dash-loading, .si-dash-empty {
  text-align: center;
  padding: 32px 16px;
  color: #9ca3af;
  font-size: 13px;
}
.si-dash-loading i, .si-dash-empty i {
  font-size: 28px;
  display: block;
  margin-bottom: 10px;
  color: #c4b5fd;
}
.si-dash-empty p { line-height: 1.6; }
.si-dash-empty small { font-size: 11.5px; color: #b0b8c5; }

/* KPI cards analíticos */
.si-dash-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.si-dash-kpi {
  background: #f9fafb;
  border: 1px solid #f1f5f9;
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
}
.si-dash-kpi--green { border-color: #d1fae5; background: #f0fdf4; }
.si-dash-kpi--blue  { border-color: #dbeafe; background: #eff6ff; }

.si-dash-kpi-val {
  font-size: 20px;
  font-weight: 800;
  color: #1e1b4b;
  line-height: 1.2;
  word-break: break-all;
}
.si-dash-kpi--green .si-dash-kpi-val { color: #065f46; }
.si-dash-kpi--blue  .si-dash-kpi-val { color: #1d4ed8; }

.si-dash-kpi-lbl {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
  line-height: 1.3;
}
.si-dash-kpi-lbl small { font-size: 10px; color: #9ca3af; display: block; }

/* Charts grid */
.si-dash-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 720px) {
  .si-dash-charts { grid-template-columns: 1fr; }
}

.si-dash-chart-card {
  background: #f9fafb;
  border: 1px solid #f1f5f9;
  border-radius: 12px;
  padding: 16px;
}
.si-dash-chart-title {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.si-dash-chart-title i { color: #7c3aed; }

/* Ranking table card */
.si-dash-table-card {
  background: #f9fafb;
  border: 1px solid #f1f5f9;
  border-radius: 12px;
  padding: 16px;
}
.si-dash-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.si-rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.si-rank-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1.5px solid #e5e7eb;
  white-space: nowrap;
}
.si-rank-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
  vertical-align: middle;
}
.si-rank-table tbody tr:hover td { background: #f5f3ff; }
.si-rank-table tbody tr:last-child td { border-bottom: none; }

.si-rank-pos {
  font-weight: 800;
  color: #6b7280;
  width: 28px;
  text-align: center;
}
.si-rank-table tbody tr:nth-child(1) .si-rank-pos { color: #f59e0b; font-size: 14px; }
.si-rank-table tbody tr:nth-child(2) .si-rank-pos { color: #9ca3af; }
.si-rank-table tbody tr:nth-child(3) .si-rank-pos { color: #b45309; }

.si-rank-name {
  font-weight: 600;
  color: #1e1b4b;
  max-width: 180px;
  word-break: break-word;
}
.si-rank-cat {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 20px;
  background: #ede9fe;
  color: #5b21b6;
  font-weight: 600;
  white-space: nowrap;
}
.si-rank-num {
  text-align: right;
  white-space: nowrap;
  font-feature-settings: 'tnum';
}
.si-rank-rate {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: #f3f4f6;
  color: #6b7280;
  white-space: nowrap;
}
.si-rank-rate--hi  { background: #d1fae5; color: #065f46; }
.si-rank-rate--mid { background: #fef3c7; color: #92400e; }

/* ════════════════════════════════════════════════════════════
   6. RESPONSIVIDADE MOBILE
   ════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {

  /* Match card */
  .si-match-card {
    width: calc(100vw - 32px);
    max-width: 100%;
    left: -8px;
    border-radius: 12px;
  }

  /* Modal salvar na biblioteca – bottom sheet */
  .si-save-lib-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .si-save-lib-modal-inner {
    max-width: 100%;
    width: 100%;
    border-radius: 18px 18px 0 0 !important;
    max-height: 92vh;
    overflow-y: auto;
  }

  /* Sugestões chips: scroll horizontal */
  .si-suggest-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .si-suggest-chip { flex-shrink: 0; }

  /* Painel analítico */
  .si-analytics-panel { padding: 14px 12px; }
  .si-dash-kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .si-dash-kpi-val { font-size: 16px; }

  /* Ranking table: scroll horizontal */
  .si-dash-table-wrap { overflow-x: auto; }

  /* Smart tabs: scroll horizontal */
  .si-smart-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-nowrap: nowrap;
  }
  .si-smart-tab { flex-shrink: 0; }

  /* Score ring menor no mobile */
  .si-match-score-ring { width: 34px; height: 34px; }
  .si-score-svg { width: 34px; height: 34px; }
  .si-score-val { font-size: 8px; }
}

@media (max-width: 400px) {
  .si-dash-kpis { grid-template-columns: 1fr; }
  .si-match-actions { flex-direction: column; }
  .si-btn-use, .si-btn-dismiss { width: 100%; justify-content: center; }
}
