/**
 * Advanced Customer Analysis - Professional Styles
 */

/* Container & Header */
.customer-analysis-pro {
  padding: 0;
  background: #f8fafc;
  min-height: 100vh;
}

.ca-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, #133452 0%, #1a4a6e 100%);
  border-radius: 12px;
  margin-bottom: 24px;
  box-shadow: 0 4px 20px rgba(19, 52, 82, 0.3);
}

.ca-title h2 {
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 4px 0;
}

.ca-title p {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  margin: 0;
}

.ca-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.ca-select {
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
}

.ca-select:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ca-select option {
  color: #133452;
  background: #fff;
}

.ca-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ca-btn-primary {
  background: linear-gradient(135deg, #136a6a, #1d7474);
  color: #fff;
}

.ca-btn-primary:hover {
  background: linear-gradient(135deg, #26a3a3, #136a6a);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(33, 141, 141, 0.4);
}

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

.ca-kpi-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
  border: 1px solid rgba(226, 232, 240, 0.8);
}

.ca-kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.ca-kpi-highlight {
  border-left: 4px solid #ef4444;
  background: linear-gradient(135deg, #fff5f5 0%, #fff 100%);
}

.ca-kpi-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  flex-shrink: 0;
}

.ca-kpi-content {
  display: flex;
  flex-direction: column;
}

.ca-kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #133452;
  line-height: 1.2;
}

.ca-kpi-label {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 500;
  margin-top: 2px;
}

.ca-kpi-subtitle {
  font-size: 0.7rem;
  color: #94a3b8;
}

/* Charts Grid */
.ca-charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.ca-chart-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(226, 232, 240, 0.8);
  overflow: hidden;
}

.ca-chart-large {
  grid-column: span 1;
}

.ca-chart-full {
  grid-column: 1 / -1;
}

.ca-chart-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(135deg, #f8fafc 0%, #fff 100%);
}

.ca-chart-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #133452;
  margin: 0 0 2px 0;
}

.ca-chart-subtitle {
  font-size: 0.75rem;
  color: #94a3b8;
}

.ca-chart-body {
  padding: 16px;
}

.ca-chart-container {
  min-height: 280px;
}

/* Segments Legend */
.ca-segments-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0 0 0;
  border-top: 1px solid #e2e8f0;
  margin-top: 12px;
}

.ca-segment-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f1f5f9;
  border-radius: 20px;
  font-size: 0.8rem;
  color: #475569;
}

.ca-segment-clickable {
  cursor: pointer;
  transition: all 0.2s ease;
}

.ca-segment-clickable:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
}

.ca-segment-icon {
  font-size: 1rem;
}

.ca-segment-arrow {
  color: #94a3b8;
  font-size: 0.7rem;
}

/* Table Card */
.ca-table-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(226, 232, 240, 0.8);
  margin-bottom: 24px;
  overflow: hidden;
}

.ca-table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(135deg, #f8fafc 0%, #fff 100%);
}

.ca-table-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #133452;
  margin: 0;
}

.ca-search {
  padding: 10px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.9rem;
  width: 250px;
  transition: all 0.2s ease;
}

.ca-search:focus {
  outline: none;
  border-color: #136a6a;
  box-shadow: 0 0 0 3px rgba(33, 141, 141, 0.1);
}

.ca-table-body {
  overflow-x: auto;
}

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

.ca-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.ca-table-row {
  cursor: pointer;
  transition: all 0.15s ease;
}

.ca-table-row:hover {
  background: linear-gradient(135deg, #f0fdfa 0%, #f8fafc 100%);
}

.ca-table td {
  padding: 14px 16px;
  font-size: 0.875rem;
  color: #334155;
  border-bottom: 1px solid #e2e8f0;
}

.ca-td-rank {
  width: 50px;
}

.ca-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e2e8f0;
  font-weight: 600;
  font-size: 0.8rem;
  color: #475569;
}

.ca-rank-gold {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #fff;
}
.ca-rank-silver {
  background: linear-gradient(135deg, #cbd5e1, #94a3b8);
  color: #fff;
}
.ca-rank-bronze {
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fff;
}

.ca-td-segment {
  width: 40px;
}

.ca-segment-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 1rem;
}

.ca-segment-vip {
  background: rgba(239, 68, 68, 0.1);
}
.ca-segment-frequente {
  background: rgba(16, 185, 129, 0.1);
}
.ca-segment-ocasional {
  background: rgba(59, 130, 246, 0.1);
}
.ca-segment-novo {
  background: rgba(245, 158, 11, 0.1);
}
.ca-segment-inativo {
  background: rgba(107, 114, 128, 0.1);
}

.ca-td-customer {
  min-width: 180px;
}

.ca-customer-name {
  font-weight: 600;
  color: #133452;
  margin-bottom: 2px;
}

.ca-customer-id {
  font-size: 0.7rem;
  color: #94a3b8;
}

.ca-td-number {
  text-align: right;
  font-family: "Roboto Mono", monospace;
  font-weight: 500;
}

.ca-margin-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.ca-margin-high {
  background: rgba(16, 185, 129, 0.1);
  color: #047857;
}
.ca-margin-medium {
  background: rgba(245, 158, 11, 0.1);
  color: #b45309;
}
.ca-margin-low {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.ca-td-date {
  font-size: 0.8rem;
  color: #64748b;
}

.ca-td-action {
  width: 50px;
  text-align: center;
}

.ca-btn-detail {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0.6;
  transition: all 0.2s ease;
}

.ca-btn-detail:hover {
  opacity: 1;
  transform: scale(1.2);
}

/* Modal */
.ca-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.2s ease;
}

.ca-modal-open {
  display: flex;
}

.ca-modal-content {
  background: #fff;
  border-radius: 16px;
  width: 90%;
  max-width: 700px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.3s ease;
}

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

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

.ca-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, #133452 0%, #1a4a6e 100%);
  color: #fff;
}

.ca-modal-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

.ca-modal-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.5rem;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.ca-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.ca-modal-body {
  padding: 24px;
  max-height: calc(90vh - 80px);
  overflow-y: auto;
}

/* Customer Detail */
.ca-detail {
}

.ca-detail-header {
  margin-bottom: 20px;
}

.ca-detail-info {
  display: flex;
  gap: 12px;
  align-items: center;
}

.ca-detail-id {
  font-size: 0.85rem;
  color: #64748b;
  background: #f1f5f9;
  padding: 6px 12px;
  border-radius: 6px;
}

.ca-detail-status {
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
}

.ca-detail-status.active {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}
.ca-detail-status.new {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.ca-detail-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.ca-detail-kpi {
  background: #f8fafc;
  padding: 16px;
  border-radius: 10px;
  text-align: center;
  border: 1px solid #e2e8f0;
}

.ca-detail-kpi-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: #133452;
}

.ca-detail-kpi-label {
  display: block;
  font-size: 0.7rem;
  color: #64748b;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ca-detail-chart {
  margin-bottom: 24px;
}

.ca-detail-chart h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #133452;
  margin: 0 0 12px 0;
}

.ca-detail-products {
  margin-bottom: 24px;
}

.ca-detail-products h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #133452;
  margin: 0 0 12px 0;
}

.ca-detail-products-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ca-detail-product {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.ca-detail-product-rank {
  width: 24px;
  height: 24px;
  background: #136a6a;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.ca-detail-product-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  color: #334155;
}

.ca-detail-product-volume {
  font-size: 0.9rem;
  font-weight: 600;
  color: #133452;
}

.ca-detail-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.ca-detail-date {
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.ca-detail-date-label {
  font-size: 0.75rem;
  color: #64748b;
  margin-bottom: 4px;
}

.ca-detail-date-value {
  font-size: 1rem;
  font-weight: 600;
  color: #133452;
}

/* Segment Modal */
.ca-segment-modal {
}

.ca-segment-modal-header {
  background: #f8fafc;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.ca-segment-modal-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 12px;
}

.ca-segment-stat {
}

.ca-segment-stat-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: #133452;
}

.ca-segment-stat-label {
  font-size: 0.75rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ca-segment-modal-desc {
  font-size: 0.85rem;
  color: #64748b;
  margin: 0;
}

.ca-segment-modal-search {
  margin-bottom: 16px;
}

.ca-segment-modal-search .ca-search {
  width: 100%;
}

.ca-segment-table-container {
  max-height: 350px;
  overflow-y: auto;
}

/* Tooltip */
.ca-tooltip {
  padding: 12px;
  background: #133452;
  border-radius: 8px;
  color: #fff;
  font-size: 0.85rem;
  min-width: 180px;
}

.ca-tooltip-title {
  font-weight: 600;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.ca-tooltip-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.ca-tooltip-row span {
  color: rgba(255, 255, 255, 0.7);
}

.ca-tooltip-hint {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
  font-style: italic;
}

/* Loading & Error */
.ca-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #64748b;
  font-size: 0.95rem;
}

.ca-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e2e8f0;
  border-top-color: #136a6a;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ca-error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.ca-error-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.ca-error-container h3 {
  margin: 0 0 8px 0;
  color: #133452;
}

.ca-error-container p {
  color: #64748b;
  margin: 0 0 24px 0;
}

.ca-empty {
  padding: 40px 20px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.9rem;
}

.ca-error {
  padding: 40px 20px;
  text-align: center;
  color: #ef4444;
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
  .ca-header {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }

  .ca-controls {
    flex-wrap: wrap;
    justify-content: center;
  }

  .ca-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .ca-charts-row {
    grid-template-columns: 1fr;
  }

  .ca-table-header {
    flex-direction: column;
    gap: 12px;
  }

  .ca-search {
    width: 100%;
  }

  .ca-modal-content {
    width: 95%;
    max-height: 95vh;
  }

  .ca-detail-kpis {
    grid-template-columns: repeat(2, 1fr);
  }
}
