/* ============================================================
   Dashboard — Tableau de bord du portefeuille
   Requires: design-system.css loaded first
   ============================================================ */

/* ── Page Layout ────────────────────────────────────────────── */
.dashboard-main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
}

/* ── Sortable column headers ─────────────────────────────────── */
.company-table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.15s;
}
.company-table th.sortable:hover { background: #f0f4ff; }
.company-table th.sort-active    { background: #eef2ff; color: var(--navy-arc); }
.sort-icon { font-style: normal; opacity: 0.7; }

/* ── Filter result count ─────────────────────────────────────── */
.filter-meta {
  font-size: 0.8rem;
  color: #64748b;
  padding: 0.35rem 0.25rem 0.6rem;
  min-height: 1.4rem;
}


/* ── Stats Row ──────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: var(--space-5);
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 150px;
  background: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-6) var(--space-5);
  text-align: center;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  border-top: 3px solid transparent;
  background-image: linear-gradient(#fff, #fff), linear-gradient(135deg, var(--navy-600), var(--navy-400));
  background-origin: border-box;
  background-clip: padding-box, border-box;
  transition: all var(--dur-normal) var(--ease-out);
  animation: fadeInUp var(--dur-slow) var(--ease-out) both;
}

.stat-card:nth-child(1) { animation-delay: 0ms; }
.stat-card:nth-child(2) { animation-delay: 60ms; }
.stat-card:nth-child(3) { animation-delay: 120ms; }
.stat-card:nth-child(4) { animation-delay: 180ms; }
.stat-card:nth-child(5) { animation-delay: 240ms; }

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.stat-card-chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.stat-card-chart canvas {
  max-width: 120px;
  max-height: 120px;
}

.stat-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--navy-700);
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--gray-500);
  margin-top: var(--space-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Filter Bar ─────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  align-items: center;
  animation: fadeInUp var(--dur-slow) var(--ease-out) 300ms both;
}

.filter-input {
  flex: 2;
  min-width: 200px;
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: var(--font-primary);
  color: var(--gray-800);
  transition: all var(--dur-normal) var(--ease-out);
}

.filter-input:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.filter-input::placeholder {
  color: var(--gray-400);
}

.filter-select {
  flex: 1;
  min-width: 140px;
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: var(--font-primary);
  background: #fff;
  color: var(--gray-700);
  transition: all var(--dur-normal) var(--ease-out);
}

.filter-select:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* ── Company Table ──────────────────────────────────────────── */
.table-wrapper {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  animation: fadeInUp var(--dur-slow) var(--ease-out) 360ms both;
}

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

.company-table th {
  background: var(--navy-50);
  color: var(--navy-700);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-4) var(--space-5);
  text-align: left;
  border-bottom: 2px solid var(--navy-100);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.company-table td {
  padding: var(--space-4) var(--space-5);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.company-table tbody tr {
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}

.company-table tbody tr:nth-child(even) {
  background: var(--gray-50);
}

.company-table tbody tr:hover {
  background: var(--navy-50);
}

.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-5) !important;
  color: var(--gray-400);
  font-size: 0.875rem;
}

/* Score bar */
.score-bar-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.score-mini-bar {
  width: 60px;
  height: 5px;
  background: var(--gray-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.score-mini-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width var(--dur-slow) var(--ease-out);
}

/* Risk badge */
.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 700;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.risk-badge.low      { background: var(--success-bg); color: var(--success-text); }
.risk-badge.medium   { background: var(--warning-bg); color: var(--warning-text); }
.risk-badge.high     { background: #fff7ed; color: #9a3412; }
.risk-badge.critical { background: var(--danger-bg);  color: var(--danger-text); }

/* Status badge */
.status-mini-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-mini-badge.draft        { background: var(--gray-100);   color: var(--gray-600); }
.status-mini-badge.submitted    { background: var(--info-bg);    color: var(--info-text); }
.status-mini-badge.under_review { background: var(--warning-bg); color: var(--warning-text); }
.status-mini-badge.approved     { background: var(--success-bg); color: var(--success-text); }
.status-mini-badge.rejected     { background: var(--danger-bg);  color: var(--danger-text); }

/* ── Skeleton Loader ────────────────────────────────────────── */
.dashboard-skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.skeleton-stats-row {
  display: flex;
  gap: var(--space-5);
}

.skeleton-stat {
  flex: 1;
  height: 120px;
  border-radius: var(--radius-md);
}

.skeleton-table {
  height: 300px;
  border-radius: var(--radius-md);
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 40, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-8);
  animation: fadeIn var(--dur-fast) var(--ease-out);
}

.modal-overlay.hidden { display: none; }

.modal-content {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-xl);
  animation: slideUp var(--dur-slow) var(--ease-spring) both;
}

.modal-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--gray-500);
  transition: all var(--dur-fast) var(--ease-out);
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.modal-content h2 {
  margin: 0 0 var(--space-2);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy-800);
  padding-right: var(--space-10);
}

.modal-meta {
  color: var(--gray-500);
  font-size: 0.8125rem;
  margin-bottom: var(--space-6);
}

.modal-section {
  margin-bottom: var(--space-6);
}

.modal-section h3 {
  font-size: 0.8125rem;
  font-weight: 700;
  margin: 0 0 var(--space-3);
  color: var(--navy-700);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--gray-100);
  padding-bottom: var(--space-3);
}

.modal-score-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.modal-score-big {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.modal-eligibility {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.eligibility-chip {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
}

.eligibility-chip.eligible   { background: var(--success-bg); color: var(--success-text); }
.eligibility-chip.ineligible { background: var(--danger-bg);  color: var(--danger-text); }

.modal-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-6);
  flex-wrap: wrap;
  padding-top: var(--space-5);
  border-top: 1px solid var(--gray-100);
}

.modal-status {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  animation: fadeIn var(--dur-normal) var(--ease-out);
}

.modal-status.success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.modal-status.error   { background: var(--danger-bg);  color: var(--danger-text);  border: 1px solid var(--danger-border); }

/* ── Dashboard Error ────────────────────────────────────────── */
.dashboard-error {
  margin-top: var(--space-8);
  padding: var(--space-5);
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.875rem;
}

.dashboard-error.hidden { display: none; }

/* ── Modal Tabs ─────────────────────────────────────────────── */
.modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: var(--space-5);
}
.modal-tab {
  background: none;
  border: none;
  padding: var(--space-3) var(--space-5);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.modal-tab:hover { color: var(--navy-700); }
.modal-tab.active { color: var(--navy-700); border-bottom-color: var(--navy-600); }

/* ── Score History ──────────────────────────────────────────── */
.score-history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-height: 340px;
  overflow-y: auto;
  padding-right: 4px;
}
.score-history-row {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
}
.score-history-date {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.history-latest-badge {
  background: #dcfce7;
  color: #166534;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.score-history-bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.score-history-val {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  min-width: 3rem;
}
.score-history-confidence {
  font-size: 0.65rem;
  font-weight: 600;
  opacity: 0.65;
  margin-left: 2px;
}
.score-history-bar {
  flex: 1;
}
.score-history-loading,
.score-history-empty {
  color: var(--gray-400);
  font-size: 0.875rem;
  padding: var(--space-5) 0;
  text-align: center;
}

/* ── Row Delete Button ──────────────────────────────────────── */
.row-delete-btn {
  background: none;
  border: 1px solid transparent;
  color: #94a3b8;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  transition: all 0.15s;
  line-height: 1;
}
.row-delete-btn:hover {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #dc2626;
}

/* ── Document Analysis History ──────────────────────────────── */
.analysis-history-row {
  border-left: 3px solid var(--navy-400);
}
.analysis-doc-types {
  font-style: italic;
  color: var(--gray-400);
  font-size: 0.72rem;
}
.analysis-grade {
  font-size: 1.1rem;
  font-weight: 800;
  min-width: 2.5rem;
  text-align: center;
}
.analysis-strengths-risks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.analysis-sr-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: var(--space-1);
}
.analysis-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.78rem;
  color: var(--gray-600);
}
.analysis-list.strengths li::marker { color: #059669; }
.analysis-list.risks    li::marker { color: #ef4444; }
.analysis-report-details {
  margin-top: var(--space-3);
  border-top: 1px solid var(--gray-100);
  padding-top: var(--space-2);
}
.analysis-report-details summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--navy-600);
  font-weight: 600;
  user-select: none;
}
.analysis-report-body {
  margin-top: var(--space-3);
  font-size: 0.8rem;
  color: var(--gray-600);
  line-height: 1.65;
  white-space: pre-wrap;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .stats-row {
    flex-direction: column;
  }
  .filter-bar {
    flex-direction: column;
  }
  .filter-input, .filter-select {
    width: 100%;
  }
  .modal-content {
    padding: var(--space-5);
    margin: var(--space-4);
  }
}
