/**
 * Organism: KeywordSelectionModal
 * Styles pour la modal de sélection de mots-clés
 */

/* Overlay */
.keyword-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  padding: 20px;
  overflow-y: auto;
}

.keyword-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Modal Container */
.keyword-modal {
  background: white;
  border-radius: 12px;
  max-width: 1400px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.keyword-modal-overlay.active .keyword-modal {
  transform: scale(1);
}

/* Header */
.keyword-modal-header {
  padding: 24px 30px;
  border-bottom: 2px solid #e9ecef;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.keyword-modal-title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #212529;
  display: flex;
  align-items: center;
  gap: 10px;
}

.keyword-modal-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #6c757d;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.keyword-modal-close:hover {
  background: #f8f9fa;
  color: #212529;
}

/* Body */
.keyword-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 30px;
}

/* Loading */
.keyword-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 20px;
}

.keyword-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #e9ecef;
  border-top-color: #007bff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Analysis Summary */
.analysis-summary {
  background: #f8f9fa;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 30px;
}

.summary-title {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 600;
  color: #212529;
}

.summary-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.geo-section {
  font-size: 15px;
  line-height: 1.6;
  color: #495057;
}

.geo-section strong {
  color: #212529;
}

.geo-cities, .geo-areas {
  margin-top: 8px;
  color: #6c757d;
}

.summary-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 8px;
}

.summary-info-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border: 1px solid #dee2e6;
  padding: 12px 16px;
  border-radius: 8px;
}

.info-icon {
  font-size: 24px;
}

.info-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-label {
  font-size: 12px;
  color: #6c757d;
}

.info-value {
  font-size: 16px;
  font-weight: 600;
  color: #212529;
}

/* Keywords Section */
.keywords-section-title {
  margin: 0 0 20px 0;
  font-size: 20px;
  font-weight: 600;
  color: #212529;
}

.keywords-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Keyword Card */
.keyword-card {
  background: white;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.keyword-card:hover {
  border-color: #007bff;
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
  transform: translateY(-2px);
}

.keyword-card.selected {
  border-color: #007bff;
  background: linear-gradient(135deg, rgba(0, 123, 255, 0.05) 0%, rgba(0, 86, 179, 0.05) 100%);
  box-shadow: 0 4px 16px rgba(0, 123, 255, 0.2);
}

.keyword-card.selected::before {
  content: '✓';
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  background: #007bff;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 18px;
}

/* Keyword Header */
.keyword-header {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.keyword-rank-badge {
  background: #495057;
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Styles spéciaux pour le top 3 avec médailles */
.keyword-rank-badge.rank-1 {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  color: #000;
  box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
}

.keyword-rank-badge.rank-2 {
  background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
  color: #000;
  box-shadow: 0 2px 8px rgba(192, 192, 192, 0.4);
}

.keyword-rank-badge.rank-3 {
  background: linear-gradient(135deg, #cd7f32 0%, #e09856 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(205, 127, 50, 0.4);
}


.keyword-source-badge {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}

/* Keyword Text */
.keyword-text {
  margin: 0 0 12px 0;
  font-size: 22px;
  font-weight: 600;
  color: #212529;
  line-height: 1.3;
}

.keyword-card.selected .keyword-text {
  color: #007bff;
}

/* USP */
.keyword-usp {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #fff3cd;
  border-left: 4px solid #ffc107;
  border-radius: 6px;
  font-size: 14px;
  color: #856404;
}

/* Metrics */
.keyword-metrics {
  margin-bottom: 16px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
}

.metrics-header {
  margin-bottom: 12px;
  color: #6c757d;
  font-weight: 600;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: white;
  border-radius: 6px;
  border: 1px solid #dee2e6;
}

.metric-item.has-data {
  background: #e7f5ff;
  border-color: #74c0fc;
}

.metric-icon {
  font-size: 18px;
}

.metric-label {
  font-size: 11px;
  color: #6c757d;
  font-weight: 500;
}

.metric-value {
  font-size: 15px;
  font-weight: 700;
  color: #212529;
}

.metric-item.has-data .metric-value {
  color: #1971c2;
}

/* Explanation */
.keyword-explanation {
  margin-bottom: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.6;
  color: #495057;
}

/* Sources */
.keyword-sources {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: #6c757d;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Custom Keyword Section */
.custom-keyword-section {
  padding: 20px 30px;
  border-top: 2px solid #e9ecef;
  background: #f8f9fa;
}

.custom-keyword-divider {
  text-align: center;
  position: relative;
  margin-bottom: 20px;
}

.custom-keyword-divider span {
  background: #f8f9fa;
  padding: 0 15px;
  color: #6c757d;
  font-weight: 600;
  font-size: 13px;
  position: relative;
  z-index: 1;
}

.custom-keyword-divider::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: #dee2e6;
  z-index: 0;
}

.custom-keyword-input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.custom-keyword-label {
  font-weight: 600;
  font-size: 14px;
  color: #212529;
}

.custom-keyword-input {
  padding: 12px 16px;
  border: 2px solid #dee2e6;
  border-radius: 6px;
  font-size: 14px;
  transition: all 0.2s ease;
  background: white;
}

.custom-keyword-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.custom-keyword-hint {
  color: #6c757d;
  font-size: 12px;
}

/* Footer */
.keyword-modal-footer {
  padding: 20px 30px;
  border-top: 2px solid #e9ecef;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.keyword-modal-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 120px;
}

.keyword-modal-btn.primary {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  color: white;
}

.keyword-modal-btn.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

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

.keyword-modal-btn.secondary {
  background: #f8f9fa;
  color: #495057;
  border: 1px solid #dee2e6;
}

.keyword-modal-btn.secondary:hover {
  background: #e9ecef;
}

/* Error State */
.keyword-error-state {
  padding: 60px 20px;
  text-align: center;
  color: #6c757d;
}

.keyword-error-state h3 {
  font-size: 24px;
  margin-bottom: 12px;
  color: #dc3545;
}

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

/* Responsive */
@media (max-width: 768px) {
  .keyword-modal {
    margin: 10px;
    max-height: 95vh;
  }

  .keyword-modal-header {
    padding: 20px;
  }

  .keyword-modal-body {
    padding: 20px;
  }

  .keyword-modal-title {
    font-size: 20px;
  }

  .keyword-text {
    font-size: 18px;
  }

  .summary-info-grid {
    grid-template-columns: 1fr;
  }

  .keyword-metrics {
    flex-direction: column;
    gap: 8px;
  }
}

/* ========================================
   SOURCE LEGEND
   ======================================== */

.source-legend {
  margin-bottom: 20px;
  padding: 14px 18px;
  background: #ffffff;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  border-left: 4px solid #007bff;
}

.source-legend-title {
  font-size: 12px;
  font-weight: 600;
  color: #495057;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.source-legend-items {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.source-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.source-legend-text {
  font-size: 13px;
  color: #6c757d;
}

/* ========================================
   TABLE LAYOUT (New)
   ======================================== */

/* Keywords Table */
.keywords-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 13px;
}

.keywords-table thead th {
  background: #f8f9fa;
  padding: 12px 8px;
  text-align: center;
  font-weight: 600;
  border-bottom: 2px solid #dee2e6;
  color: #495057;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

/* Fond pour colonnes DataForSEO */
.keywords-table thead th.dataforseo-col {
  background: linear-gradient(180deg, #e3f2fd 0%, #bbdefb 100%);
  color: #0d47a1;
  border-left: 1px solid #90caf9;
  border-right: 1px solid #90caf9;
}

/* Fond pour colonnes Google Search Console */
.keywords-table thead th.gsc-col {
  background: linear-gradient(180deg, #e8f5e9 0%, #c8e6c9 100%);
  color: #1b5e20;
  border-left: 1px solid #81c784;
  border-right: 1px solid #81c784;
}

.keywords-table thead th .metric-source {
  display: block;
  font-size: 9px;
  font-weight: 500;
  color: #6c757d;
  text-transform: none;
  margin-top: 2px;
  letter-spacing: 0;
}

.keywords-table tbody .keyword-table-row {
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 1px solid #e9ecef;
}

/* Dégradés subtils pour le podium (style JO) */
.keywords-table tbody .keyword-table-row.rank-1 {
  background: linear-gradient(to right, rgba(255, 215, 0, 0.08), rgba(255, 215, 0, 0.02));
}

.keywords-table tbody .keyword-table-row.rank-2 {
  background: linear-gradient(to right, rgba(192, 192, 192, 0.1), rgba(192, 192, 192, 0.02));
}

.keywords-table tbody .keyword-table-row.rank-3 {
  background: linear-gradient(to right, rgba(205, 127, 50, 0.08), rgba(205, 127, 50, 0.02));
}

/* Fonds subtils par source de données */
.keywords-table tbody .keyword-table-row.source-search-console {
  background: linear-gradient(to right, rgba(212, 237, 218, 0.15), rgba(212, 237, 218, 0.03));
}

.keywords-table tbody .keyword-table-row.source-agent {
  background: linear-gradient(to right, rgba(204, 229, 255, 0.15), rgba(204, 229, 255, 0.03));
}

.keywords-table tbody .keyword-table-row.source-page {
  background: linear-gradient(to right, rgba(255, 243, 205, 0.15), rgba(255, 243, 205, 0.03));
}

.keywords-table tbody .keyword-table-row:hover {
  background: #f8f9fa !important;
}

.keywords-table tbody .keyword-table-row.selected {
  background: #e7f5ff !important;
  border-left: 3px solid #007bff;
}

.keywords-table tbody .keyword-table-row td {
  padding: 12px 8px;
  vertical-align: middle;
  text-align: center;
}

/* Fond subtil pour colonnes DataForSEO dans le corps */
.keywords-table tbody .keyword-table-row td.dataforseo-cell {
  background: rgba(227, 242, 253, 0.25);
  border-left: 1px solid rgba(144, 202, 249, 0.3);
  border-right: 1px solid rgba(144, 202, 249, 0.3);
}

/* Fond subtil pour colonnes GSC dans le corps */
.keywords-table tbody .keyword-table-row td.gsc-cell {
  background: rgba(232, 245, 233, 0.25);
  border-left: 1px solid rgba(129, 199, 132, 0.3);
  border-right: 1px solid rgba(129, 199, 132, 0.3);
}

/* Garder les fonds lors du hover et de la sélection */
.keywords-table tbody .keyword-table-row:hover td.dataforseo-cell {
  background: rgba(227, 242, 253, 0.4);
}

.keywords-table tbody .keyword-table-row:hover td.gsc-cell {
  background: rgba(232, 245, 233, 0.4);
}

.keywords-table tbody .keyword-table-row.selected td.dataforseo-cell {
  background: rgba(227, 242, 253, 0.5);
}

.keywords-table tbody .keyword-table-row.selected td.gsc-cell {
  background: rgba(232, 245, 233, 0.5);
}

/* Ligne d'explication (toute la largeur) */
.keyword-explanation-row {
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
}

.keyword-explanation-row .explanation-full-cell {
  padding: 10px 16px;
  font-size: 12px;
  color: #495057;
  line-height: 1.5;
  border-left: 3px solid #6c757d;
}

.keyword-explanation-row .explanation-full-cell strong {
  color: #212529;
  font-weight: 600;
  margin-right: 6px;
}

/* Quand la ligne principale est sélectionnée, colorer aussi l'explication */
.keyword-table-row.selected + .keyword-explanation-row {
  background: #e7f5ff;
}

.keyword-table-row.selected + .keyword-explanation-row .explanation-full-cell {
  border-left-color: #007bff;
}

/* Dégradés pour les lignes d'explication du podium */
.keyword-table-row.rank-1 + .keyword-explanation-row {
  background: linear-gradient(to right, rgba(255, 215, 0, 0.05), rgba(255, 215, 0, 0.01));
}

.keyword-table-row.rank-2 + .keyword-explanation-row {
  background: linear-gradient(to right, rgba(192, 192, 192, 0.06), rgba(192, 192, 192, 0.01));
}

.keyword-table-row.rank-3 + .keyword-explanation-row {
  background: linear-gradient(to right, rgba(205, 127, 50, 0.05), rgba(205, 127, 50, 0.01));
}

/* Column Widths */
.keywords-table .rank-col {
  width: 50px;
  text-align: center;
}

.keywords-table .keyword-col {
  width: 20%;
  min-width: 150px;
  text-align: left;
}

.keywords-table .source-col {
  width: 60px;
  text-align: center;
}

.keywords-table .metric-col {
  width: 80px;
  text-align: center;
  font-size: 11px;
}

/* Badges Compacts */
.keyword-rank-badge-small {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: #495057;
  color: white;
}

.keyword-rank-badge-small.rank-1 {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  color: #000;
}

.keyword-rank-badge-small.rank-2 {
  background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
  color: #000;
}

.keyword-rank-badge-small.rank-3 {
  background: linear-gradient(135deg, #cd7f32 0%, #e09856 100%);
  color: #fff;
}

.source-badge-small {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: #e9ecef;
  color: #495057;
}

/* Couleurs spécifiques par source */
.source-badge-small.source-search-console {
  background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
  color: #155724;
  border: 1px solid #a3d5a9;
}

.source-badge-small.source-agent {
  background: linear-gradient(135deg, #cce5ff 0%, #b8daff 100%);
  color: #004085;
  border: 1px solid #9fcdff;
}

.source-badge-small.source-page {
  background: linear-gradient(135deg, #fff3cd 0%, #ffe8a1 100%);
  color: #856404;
  border: 1px solid #f5d78e;
}

.metric-cell.has-data {
  color: #007bff;
  font-weight: 600;
}

.metric-cell.no-data {
  color: #adb5bd;
  font-style: italic;
  font-size: 11px;
}

/* Custom Keyword Input in Footer */
.keyword-modal-footer {
  padding: 16px 30px;
  border-top: 2px solid #e9ecef;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.custom-keyword-input-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 700px;
}

.custom-keyword-label-inline {
  font-size: 13px;
  font-weight: 600;
  color: #495057;
  white-space: nowrap;
}

.custom-keyword-input-inline {
  flex: 1;
  min-width: 300px;
  padding: 10px 14px;
  border: 2px solid #dee2e6;
  border-radius: 6px;
  font-size: 14px;
  transition: all 0.2s ease;
}

.custom-keyword-input-inline:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.footer-buttons {
  display: flex;
  gap: 12px;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .keywords-table .explanation-col {
    display: none;
  }
  
  .keywords-table .keyword-col {
    width: 40%;
  }
}

@media (max-width: 768px) {
  .keyword-modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .custom-keyword-input-footer {
    width: 100%;
  }

  .footer-buttons {
    width: 100%;
    justify-content: stretch;
  }

  .footer-buttons button {
    flex: 1;
  }
}

