/* ===================================================================
   Prospilot Sync Dashboard — Light Premium Theme
   Palette: Cream / Violet / Orange — Questrial + Poppins
   =================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Backgrounds */
  --bg: #FFFCF7;
  --bg-elevated: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FBF7F1;
  --bg-inset: #F7F3EC;
  --bg-sidebar: #FFFFFF;
  --bg-secondary: #F1EDE5;

  /* Borders */
  --border: #E1D6C6;
  --border-subtle: #EDE7DC;
  --border-strong: #D1C4B0;

  /* Text */
  --text: #2C1F3D;
  --text-heading: #241640;
  --text-sec: #605371;
  --text-muted: #A19584;
  --text-disabled: #C7BFB3;

  /* Orange (CTA / highlights) */
  --orange: #FF8E38;
  --orange-hover: #FF9F56;
  --orange-dim: rgba(255, 142, 56, 0.10);
  --orange-glow: rgba(255, 142, 56, 0.20);

  /* Violet (accent) */
  --accent: #5847AC;
  --accent-bright: #8A38F5;
  --accent-soft: #7B6BBF;
  --accent-dim: rgba(88, 71, 172, 0.08);

  /* Semantic */
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.10);
  --green-text: #16a34a;
  --red: #FF5053;
  --red-dim: rgba(255, 80, 83, 0.08);
  --red-glow: rgba(255, 80, 83, 0.15);
  --red-text: #dc2626;
  --yellow: #f59e0b;
  --yellow-dim: rgba(245, 158, 11, 0.10);
  --yellow-text: #d97706;
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.08);

  /* Typography */
  --font-heading: 'Questrial', sans-serif;
  --font-body: 'Poppins', sans-serif;
  --text-xs: 0.65rem;
  --text-sm: 0.75rem;
  --text-base: 0.85rem;
  --text-md: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.5rem;

  /* Radius */
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08);

  /* Transitions */
  --tr: 200ms ease;
  --tr-fast: 100ms ease;
}

html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
h1 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1.25rem;
  color: var(--text-heading);
}
h2 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 1rem;
  color: var(--text-heading);
}
h3 {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
h4 {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}
h5 {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-sec);
  margin-bottom: 0.35rem;
}

/* ===================================================================
   LAYOUT — Sidebar + Content
   =================================================================== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* -- Sidebar -------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 50;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem 1rem;
}
.logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
}

/* -- Sidebar Countdown ---------------------------------------------- */
.sidebar-countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.75rem 1rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}
.sidebar-countdown .countdown {
  color: var(--orange);
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.sidebar-countdown .countdown-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sidebar-countdown .sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  margin-top: 0.25rem;
}
.sidebar-countdown .sync-dot.active {
  background: var(--green);
  animation: sync-glow 2s ease-in-out infinite;
}

/* Countdown-value alias (JS compat) */
.countdown-value {
  color: var(--orange);
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* -- Sidebar Nav ---------------------------------------------------- */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.75rem 0.5rem;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 10px 16px;
  border-radius: var(--radius);
  color: var(--text-sec);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: 500;
  transition: all var(--tr);
  position: relative;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.nav-item svg {
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity var(--tr);
}
.nav-item:hover {
  background: var(--bg-secondary);
  color: var(--text);
}
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: var(--bg-secondary);
  color: var(--accent);
  border-left-color: var(--orange);
  font-weight: 600;
}
.nav-item.active svg {
  opacity: 1;
  color: var(--accent);
}

/* Badge on Problemes */
.nav-badge {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--red);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  line-height: 1;
  animation: badge-pulse 2s ease-in-out infinite;
}
.nav-badge.visible { display: flex; }

/* -- Status widget (bottom) ----------------------------------------- */
.sidebar-status {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sync-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-sm);
  color: var(--text-sec);
}
.sidebar-countdown.syncing { color: var(--orange); }
.sidebar-countdown.syncing .sync-dot {
  background: var(--orange);
  animation: sync-glow 1.5s ease-in-out infinite;
}
.sidebar-countdown.circuit-open { color: var(--red); }
.sidebar-countdown.circuit-open .sync-dot {
  background: var(--red);
  animation: pulse-red 2s ease-in-out infinite;
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.sync-dot.active {
  background: var(--green);
  animation: sync-pulse 1.5s ease-in-out infinite;
}
.countdown {
  font-variant-numeric: tabular-nums;
  color: var(--orange);
  font-weight: 700;
  margin-left: auto;
}
.mode-badge {
  display: none;
  background: var(--orange);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  text-align: center;
  animation: pulse-badge 2s ease-in-out infinite;
}
.mode-badge.visible { display: block; }
.mode-badge.dry-run {
  background: var(--yellow);
  color: var(--text-heading);
}
.mode-badge.production {
  background: var(--green);
  color: #fff;
}
.last-sync {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* -- Content -------------------------------------------------------- */
.content {
  padding: 2rem;
  overflow-y: auto;
  max-width: 1200px;
  background: var(--bg);
}

/* ===================================================================
   PAGE TRANSITIONS
   =================================================================== */
.page { display: none; }
.page.active { display: block; animation: pageIn 0.3s ease; }
.section-title { margin: 1.5rem 0 0.75rem; }

/* ===================================================================
   CONNECTION BANNER
   =================================================================== */
.banner-error {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-size: var(--text-base);
  color: var(--red-text);
  font-weight: 600;
  margin-bottom: 1.5rem;
}
.banner-error.visible { display: flex; }

/* ===================================================================
   KPI CARDS
   =================================================================== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--tr), box-shadow var(--tr), transform var(--tr);
}
.kpi:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.kpi-val {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.25rem;
  color: var(--text-heading);
}
.kpi-val-red { color: var(--red-text); }
.kpi-val-orange { color: var(--orange); }
.kpi-val-violet { color: var(--accent); }
.kpi-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 500;
}
.kpi-bar {
  margin-top: 0.65rem;
  height: 4px;
  border-radius: 2px;
  background: var(--border-subtle);
  overflow: hidden;
}
.kpi-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--green);
  transition: width 0.5s ease;
}
.kpi.has-problems,
.kpi.danger {
  border-color: var(--red);
  background: var(--red-dim);
}
.kpi.pulse {
  animation: pulse-red 3s ease-in-out infinite;
}

/* Health score KPI */
.kpi-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.health-ring-wrap {
  width: 120px;
  height: 120px;
  margin-bottom: 0.5rem;
}
.health-ring-wrap canvas { width: 100%; height: 100%; }

/* ===================================================================
   CHARTS
   =================================================================== */
.charts-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card h3 { margin-bottom: 0.75rem; }
.chart-wrap {
  width: 100%;
  height: 250px;
  position: relative;
}
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ===================================================================
   CLIENT GRID (Overview page)
   =================================================================== */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.5rem;
}
.client-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--text-muted);
  transition: all var(--tr);
  cursor: pointer;
  min-width: 240px;
  box-shadow: var(--shadow-sm);
}
.client-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.client-card.status-green  { border-left-color: var(--green); }
.client-card.status-orange { border-left-color: var(--orange); }
.client-card.status-red    { border-left-color: var(--red); }
/* Freshness indicators — pulsing border when sync is stale */
.client-card.stale-warning { border-color: var(--orange); animation: pulse-border 2s ease-in-out infinite; }
.client-card.stale-critical { border-color: var(--red); animation: pulse-border 1.5s ease-in-out infinite; }
@keyframes pulse-border { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
.client-card-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.client-card-name {
  font-weight: 600;
  font-size: var(--text-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  color: var(--text-heading);
}
.client-card-count {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  color: var(--text-sec);
  white-space: nowrap;
  flex-shrink: 0;
}
.client-card-bar {
  height: 4px;
  background: var(--border-subtle);
  border-radius: 2px;
  overflow: hidden;
  margin: 0.35rem 0;
}
.client-card-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--green);
  transition: width 0.3s ease;
}
.client-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.client-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-sec);
}
.client-card-dot { width: 8px; height: 8px; border-radius: 50%; }
.client-card-dot.green  { background: var(--green); }
.client-card-dot.orange { background: var(--orange); }
.client-card-dot.red    { background: var(--red); }
.client-card-sync {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 0.35rem;
  font-variant-numeric: tabular-nums;
}

/* ===================================================================
   DOT INDICATORS
   =================================================================== */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
  flex-shrink: 0;
  vertical-align: middle;
}
.dot-green  { background: var(--green); }
.dot-orange { background: var(--orange); }
.dot-red    { background: var(--red); }
.dot-blue   { background: var(--blue); }
.dot-violet { background: var(--accent-bright); }
.dot-gray   { background: var(--text-muted); }

/* ===================================================================
   TABLES
   =================================================================== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.table thead {
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 5;
}
.table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-weight: 700;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-sec);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color var(--tr);
}
.table th:hover { color: var(--text-heading); }
.table th.sort-active { color: var(--accent); }
.table th.sort-asc::after { content: ' \25B2'; font-size: 0.55rem; color: var(--accent); }
.table th.sort-desc::after { content: ' \25BC'; font-size: 0.55rem; color: var(--accent); }
.table th .sort-arrow { margin-left: 0.3rem; font-size: 0.55rem; opacity: 0.4; }
.table th.sort-active .sort-arrow { opacity: 1; color: var(--accent); }
.table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--text);
}
.table tbody tr {
  transition: background var(--tr);
  cursor: pointer;
}
.table tbody tr:nth-child(even) { background: var(--bg-inset); }
.table tbody tr:hover { background: var(--bg-secondary); }
.table tbody tr:last-child td { border-bottom: none; }
.table-compact { font-size: var(--text-sm); }
.table-compact td,
.table-compact th { padding: 0.35rem 0.5rem; }

/* Cell name with dot */
.cell-name {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 600;
  color: var(--text-heading);
}

/* Sync bar in table */
.synced-cell { display: flex; align-items: center; gap: 0.4rem; }
.pct-text {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
}
.pct-bar {
  flex: 1;
  height: 4px;
  background: var(--border-subtle);
  border-radius: 2px;
  overflow: hidden;
  min-width: 40px;
}
.pct-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status-dot.green  { background: var(--green); }
.status-dot.orange { background: var(--orange); }
.status-dot.red    { background: var(--red); }

/* Status classes */
.status-green  { color: var(--green-text); }
.status-orange { color: var(--orange); }
.status-red    { color: var(--red-text); }

/* Text colors */
.text-green  { color: var(--green-text); }
.text-orange { color: var(--orange); }
.text-red    { color: var(--red-text); }
.text-muted  { color: var(--text-muted); }
.text-num    { font-variant-numeric: tabular-nums; text-align: right; }

/* Expand/detail row */
.client-row { cursor: pointer; }
.client-row.expanded { background: var(--bg-secondary); }
.detail-row td {
  padding: 0;
  border-bottom: 2px solid var(--accent);
  background: var(--bg-inset);
}
.expand-row td {
  padding: 0;
  border-bottom: 2px solid var(--accent);
  background: var(--bg-inset);
}
.expand-inner {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--text-sec);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.expand-inner .detail-summary { font-weight: 500; color: var(--text); }
.expand-inner .detail-actions { display: flex; flex-direction: column; gap: 0.3rem; }
.detail-action {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-sm);
}
.detail-action .da-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.detail-action .da-time {
  color: var(--text-muted);
  min-width: 70px;
  font-variant-numeric: tabular-nums;
  font-size: 0.7rem;
}
.detail-full-sync {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Client detail (expanded) */
.client-detail {
  padding: 1rem;
  font-size: var(--text-base);
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}
.detail-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.detail-section h4 { margin-bottom: 0.5rem; }
.detail-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
  color: var(--text-sec);
}
.detail-stat:last-child { border-bottom: none; }

/* ===================================================================
   SEARCH / FILTERS
   =================================================================== */
.search-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: var(--text-base);
  color: var(--text);
  font-family: inherit;
  width: 100%;
  max-width: 360px;
  outline: none;
  transition: border-color var(--tr), box-shadow var(--tr);
  margin-bottom: 1rem;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.search-input::placeholder { color: var(--text-disabled); }
.search-big {
  max-width: 100%;
  font-size: var(--text-md);
  padding: 0.75rem 1rem;
}

.filters-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.75rem;
  font-size: var(--text-base);
  color: var(--text);
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color var(--tr);
}
.filter-select:focus { border-color: var(--accent); }

/* ===================================================================
   TIMELINE (Activite)
   =================================================================== */
.timeline {
  position: relative;
  padding-left: 24px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding: 0.6rem 0 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--tr);
}
.timeline-item:hover {
  background: var(--bg-secondary);
  margin: 0 -0.5rem;
  padding-left: calc(0.75rem + 0.5rem);
  padding-right: 0.5rem;
  border-radius: var(--radius);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-dot {
  position: absolute;
  left: -20px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg);
}
.timeline-dot.create   { background: var(--green); }
.timeline-dot.update   { background: var(--blue); }
.timeline-dot.delete   { background: var(--red); }
.timeline-dot.conflict { background: var(--orange); }
.timeline-dot.error    { background: var(--red); animation: dot-pulse 2s ease-in-out infinite; }
.timeline-dot.orphan   { background: var(--accent-bright); }
.timeline-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}
.timeline-row .badge { flex-shrink: 0; }
.timeline-row .tl-client { font-weight: 600; color: var(--text-heading); white-space: nowrap; }
.timeline-row .tl-email {
  color: var(--text-sec);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.timeline-row .tl-time {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-left: auto;
}

/* -- Cycle groups (Activity) ---------------------------------------- */
.cycle-group {
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.cycle-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--bg-card);
  cursor: pointer;
  user-select: none;
  font-size: var(--text-sm);
  color: var(--text-sec);
  transition: background var(--tr);
}
.cycle-header:hover { background: var(--bg-secondary); }
.cycle-toggle { font-size: 0.65rem; color: var(--text-muted); flex-shrink: 0; }
.cycle-time { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.cycle-count { font-weight: 600; color: var(--text-heading); }
.cycle-duration { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.cycle-body {
  padding: 0.25rem 0;
  background: var(--bg-inset);
}
.action-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  font-size: var(--text-sm);
  color: var(--text-sec);
  transition: background var(--tr-fast);
}
.action-item:hover { background: var(--bg-secondary); }
.action-client { font-weight: 600; color: var(--text-heading); white-space: nowrap; }
.action-detail {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.action-time {
  margin-left: auto;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* ===================================================================
   BADGES
   =================================================================== */
.badge {
  display: inline-block;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-creation    { background: var(--green-dim);  color: var(--green-text); }
.badge-maj         { background: var(--blue-dim);   color: var(--blue); }
.badge-suppression { background: var(--red-dim);    color: var(--red-text); }
.badge-conflit     { background: var(--orange-dim); color: var(--orange); }
.badge-erreur      { background: var(--red-dim);    color: var(--red-text); }
.badge-orphelin    { background: var(--accent-dim); color: var(--accent); }

/* Color-keyed badges (used by JS badge() function) */
.badge-green   { background: var(--green-dim);  color: var(--green-text); }
.badge-blue    { background: var(--blue-dim);   color: var(--blue); }
.badge-red     { background: var(--red-dim);    color: var(--red-text); }
.badge-orange  { background: var(--orange-dim); color: var(--orange); }
.badge-violet  { background: var(--accent-dim); color: var(--accent); }
.badge-gray    { background: rgba(161, 149, 132, 0.12); color: var(--text-muted); }

/* ===================================================================
   PROBLEMS PAGE
   =================================================================== */
.problem-section { margin-bottom: 1.25rem; }
.problem-section:empty { display: none; }
.problem-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  cursor: pointer;
  user-select: none;
}
.problem-header-row:hover .problem-title { color: var(--text-heading); }
.problem-icon { font-size: 0.9rem; flex-shrink: 0; }
.problem-title {
  font-weight: 600;
  font-size: var(--text-base);
  flex: 1;
  color: var(--text-sec);
  transition: color var(--tr);
}
.problem-count-badge {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 1.4rem;
  text-align: center;
}
.problem-count-badge.red    { background: var(--red-dim);    color: var(--red-text); }
.problem-count-badge.orange { background: var(--orange-dim); color: var(--orange); }
.problem-chevron { font-size: 0.7rem; color: var(--text-muted); transition: transform 0.2s ease; }
.problem-section.open .problem-chevron { transform: rotate(90deg); }
.problem-body { display: none; }
.problem-section.open .problem-body { display: block; }
.problem-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.problem-table th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-sec);
  border-bottom: 1px solid var(--border);
}
.problem-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-sec);
}
.problem-table tbody tr:last-child td { border-bottom: none; }
.problem-table tbody tr:hover { background: var(--bg-secondary); }

/* Count badge + check mark */
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  font-size: 0.62rem;
  font-weight: 700;
  background: var(--red-dim);
  color: var(--red-text);
  border-radius: var(--radius-full);
  padding: 0 6px;
  margin-left: 0.5rem;
}
.check-ok {
  color: var(--green-text);
  font-weight: 600;
  font-size: var(--text-sm);
  margin-left: 0.5rem;
}

/* System alerts */
.system-alert {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: 0.5rem;
}
.system-alert-red {
  background: var(--red-dim);
  color: var(--red-text);
  border: 1px solid rgba(255, 80, 83, 0.15);
}
.system-alert-orange {
  background: var(--orange-dim);
  color: var(--orange);
  border: 1px solid rgba(255, 142, 56, 0.15);
}

/* ===================================================================
   BUTTONS
   =================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-sec);
  cursor: pointer;
  transition: all var(--tr);
}
.btn:hover {
  background: var(--bg-secondary);
  color: var(--text-heading);
  border-color: var(--border-strong);
}
.btn-sm { padding: 0.2rem 0.5rem; font-size: var(--text-xs); }
.btn-accent {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
  font-weight: 700;
}
.btn-accent:hover {
  background: var(--orange-hover);
  border-color: var(--orange-hover);
  color: #fff;
}
.btn-danger {
  border-color: var(--red);
  color: var(--red-text);
  background: var(--bg-card);
}
.btn-danger:hover { background: var(--red-dim); }
.btn-success {
  border-color: var(--green);
  color: var(--green-text);
  background: var(--green-dim);
}
.btn-success:hover { background: rgba(34, 197, 94, 0.15); }
.link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--tr);
}
.link:hover {
  color: var(--accent-bright);
  text-decoration: underline;
}

/* ===================================================================
   DEBUG PAGE
   =================================================================== */
.debug-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  max-width: 640px;
}
.debug-search .search-input { margin-bottom: 0; flex: 1; max-width: none; }
.debug-block { margin-top: 2rem; }
.debug-block h3 { margin-bottom: 0.75rem; }
.debug-count {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-weight: 500;
}
.debug-row { cursor: pointer; }
.debug-row:hover { background: var(--bg-secondary); }

/* Lead detail split view */
.debug-detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.debug-detail-header h3 { margin-bottom: 0; }
.debug-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--text-sec);
  margin-bottom: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-subtle);
}
.debug-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.debug-pane {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.debug-pane h4 {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}

/* Legacy lead detail grid (compat) */
.lead-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.lead-detail-col {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  overflow-x: auto;
}
.lead-detail-col h4 {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}
.lead-prop {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.78rem;
}
.lead-prop:last-child { border-bottom: none; }
.lead-prop-key { color: var(--text-muted); font-weight: 500; }
.lead-prop-val {
  color: var(--text);
  text-align: right;
  max-width: 60%;
  word-break: break-all;
}
.lead-prop-val.diff-highlight {
  background: var(--orange-dim);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--orange);
}

/* Prop key in tables */
.prop-key {
  color: var(--text-muted);
  font-weight: 500;
  font-size: var(--text-sm);
  white-space: nowrap;
}

/* Diff rows */
.diff-row { background: rgba(255, 142, 56, 0.05); }
.diff-old { color: var(--red-text); }
.diff-new { color: var(--green-text); }

/* Schema diff */
.schema-block {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}
.schema-ok {
  background: var(--green-dim);
  border: 1px solid rgba(34, 197, 94, 0.15);
  color: var(--green-text);
}
.schema-warning {
  background: var(--orange-dim);
  border: 1px solid rgba(255, 142, 56, 0.15);
  color: var(--orange);
}
.schema-details { margin-top: 0.75rem; }
.schema-details summary {
  cursor: pointer;
  color: var(--text-sec);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0.35rem 0;
}
.schema-details summary:hover { color: var(--text-heading); }
.schema-table { width: 100%; }
.schema-row-missing { color: var(--red-text); }
.schema-row-extra { color: var(--orange); }
.schema-row-mismatch { color: var(--orange); }
.schema-row-ok { color: var(--green-text); }

/* ===================================================================
   EMPTY STATES
   =================================================================== */
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-base);
}
.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}
.empty-state-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-sec);
  margin-bottom: 0.35rem;
}
.empty-state-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 400px;
  margin: 0 auto;
}
.empty-state-success { color: var(--green-text); }

/* ===================================================================
   ANIMATIONS
   =================================================================== */
@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 8px 2px rgba(255, 80, 83, 0.10); }
}
@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 80, 83, 0.3); }
  50% { box-shadow: 0 0 0 4px rgba(255, 80, 83, 0); }
}
@keyframes sync-glow {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 8px 3px rgba(255, 142, 56, 0.12); }
}
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
@keyframes sync-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}
@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ===================================================================
   SCROLLBAR
   =================================================================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
* { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); }

/* ===================================================================
   RESPONSIVE -- Tablet (< 1024px)
   =================================================================== */
@media (max-width: 1024px) {
  .app { grid-template-columns: 200px 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .debug-split { grid-template-columns: 1fr; }
  .lead-detail-grid { grid-template-columns: 1fr; }
  .nav-item { font-size: var(--text-sm); padding: 8px 12px; }
  .sidebar-countdown .countdown { font-size: var(--text-lg); }
  .logo-img { height: 28px; }
}

/* ===================================================================
   RESPONSIVE -- Mobile (< 768px)
   =================================================================== */
@media (max-width: 768px) {
  html { font-size: 13px; }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  /* Sidebar becomes top bar */
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 100;
  }
  .sidebar-logo {
    padding: 0.75rem 0.75rem 0.75rem 1rem;
    flex-shrink: 0;
  }
  .logo-img { height: 24px; }

  /* Hide countdown in topbar mode */
  .sidebar-countdown { display: none; }

  .sidebar-nav {
    flex-direction: row;
    gap: 0;
    padding: 0;
    flex-shrink: 0;
    flex: initial;
  }
  .nav-item {
    padding: 0.75rem 0.65rem;
    border-radius: 0;
    font-size: 0;
    gap: 0;
    flex-shrink: 0;
    border-left: none;
  }
  .nav-item svg { width: 20px; height: 20px; }
  .nav-item.active {
    border-bottom: 3px solid var(--orange);
    border-left: none;
    background: transparent;
  }
  .nav-badge {
    position: static;
    transform: none;
    margin-left: 2px;
    min-width: 14px;
    height: 14px;
    font-size: 0.5rem;
  }

  .sidebar-status { display: none; }

  .content { padding: 1rem; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .client-grid { grid-template-columns: 1fr; }
  .lead-detail-grid { grid-template-columns: 1fr; }
  .debug-split { grid-template-columns: 1fr; }
  .table-wrap { margin: 0 -0.5rem; }
  .search-input { max-width: 100%; }
  .debug-search { flex-direction: column; max-width: 100%; }

  .timeline-row { flex-wrap: wrap; }
  .timeline-row .tl-email { flex-basis: 100%; order: 5; padding-left: 0; }
}

/* Extra small -- single KPI column */
@media (max-width: 480px) {
  .kpi-row { grid-template-columns: 1fr; }
}
