/* ============================================================
   JDR Monitor — pure HTML/CSS implementation
   Charte : simplibot.fr/journal-de-reves (cream + taupe doré)
   Typo   : DM Serif Display + DM Sans + JetBrains Mono
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=DM+Serif+Display:ital@0;1&family=JetBrains+Mono:wght@400..600&display=swap');

:root {
  --cream:        #faf8f5;
  --cream-deep:   #f3efe8;
  --paper:        #ffffff;

  --ink:          #1a1a2e;
  --ink-soft:     #2a2a3e;
  --slate:        #6b6b80;
  --mist:         #9a9aae;

  --taupe:        #b8977e;
  --taupe-light:  #c7b299;
  --taupe-dark:   #a07f64;

  --sage:         #8b9d7e;
  --terracotta:   #c97a5d;
  --plum:         #9c7baa;
  --teal:         #5e9b95;

  --line:         rgba(26, 26, 46, 0.08);
  --line-soft:    rgba(26, 26, 46, 0.04);
  --line-gold:    rgba(184, 151, 126, 0.25);

  --shadow:       0 1px 2px rgba(26, 26, 46, 0.04), 0 4px 16px rgba(26, 26, 46, 0.04);
  --radius:       12px;
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-deep) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  font-feature-settings: "tnum";
  min-height: 100vh;
}

a { color: var(--taupe-dark); text-decoration: none; transition: color 200ms; }
a:hover { color: var(--ink); }

/* ============================================================
   HEADER
   ============================================================ */

header.app {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 30px 56px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: inline-block;
  background: var(--cream);
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(184, 151, 126, 0.25);
  border: 1px solid var(--line-gold);
}

h1.brand-title {
  margin: 0;
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: clamp(26px, 3vw, 36px);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
h1.brand-title em {
  color: var(--taupe);
  font-style: italic;
}

.brand-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--slate);
}

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

.run-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--slate);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.run-badge svg { color: var(--taupe); }
.run-badge strong {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 11.5px;
  color: var(--ink);
  letter-spacing: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--slate);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mist); }
.status .dot.ok { background: var(--sage); box-shadow: 0 0 0 3px rgba(139, 157, 126, 0.18); }
.status .dot.err { background: var(--terracotta); box-shadow: 0 0 0 3px rgba(201, 122, 93, 0.18); }

.btn-refresh {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--slate);
  border-radius: 50%;
  cursor: pointer;
  transition: all 200ms;
}
.btn-refresh:hover { border-color: var(--taupe); color: var(--taupe); transform: rotate(60deg); }

select.period {
  padding: 7px 30px 7px 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5L6 7.5L9 4.5' stroke='%236b6b80' stroke-width='1.4' fill='none'/></svg>");
  background-position: right 11px center;
  background-repeat: no-repeat;
}

/* ============================================================
   KPI ROW
   ============================================================ */

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.kpi {
  padding: 30px 28px;
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: start;
  position: relative;
  transition: background 240ms;
}
.kpi:last-child { border-right: none; }
.kpi:hover { background: rgba(184, 151, 126, 0.05); }
.kpi::before {
  content: '';
  position: absolute; top: 0; left: 50%;
  width: 32px; height: 1px;
  background: var(--taupe);
  transform: translateX(-50%) scaleX(0);
  transition: transform 400ms cubic-bezier(0.65, 0, 0.35, 1);
}
.kpi:hover::before { transform: translateX(-50%) scaleX(1); }

.kpi-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--taupe);
  margin-top: 6px;
  flex-shrink: 0;
}
.kpi-icon.success { color: #6f8265; border-color: rgba(139, 157, 126, 0.3); }
.kpi-icon.today { color: var(--teal); border-color: rgba(94, 155, 149, 0.3); }
.kpi-icon.duration { color: var(--plum); border-color: rgba(156, 123, 170, 0.3); }

.kpi-content { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi-value {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: clamp(32px, 3.4vw, 44px);
  line-height: 1;
  letter-spacing: -0.025em;
}
.kpi-label {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--slate);
  text-transform: uppercase;
  margin-top: 8px;
}
.kpi-sub {
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 12.5px;
  color: var(--slate);
  margin-top: 2px;
}
.kpi-sub.up { color: #6f8265; font-style: normal; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; font-weight: 500; }
.kpi-sub.down { color: var(--terracotta); font-style: normal; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; font-weight: 500; }

/* ============================================================
   SECTION & CHART CARDS
   ============================================================ */

section.block {
  padding: 36px 56px 24px;
  border-bottom: 1px solid var(--line);
}

.block-title {
  margin: 0 0 22px;
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-weight: 400;
  font-size: 16px;
  color: var(--taupe);
  display: flex;
  align-items: center;
  gap: 14px;
}
.block-title::before { content: ''; width: 28px; height: 1px; background: var(--taupe); opacity: 0.55; }
.block-title::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-gold) 0%, transparent 100%); }

.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.cards.three { grid-template-columns: repeat(3, 1fr); }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  transition: border-color 240ms, box-shadow 240ms;
}
.card:hover { border-color: var(--line-gold); box-shadow: 0 1px 2px rgba(26,26,46,0.04), 0 12px 32px rgba(184, 151, 126, 0.07); }
.card.wide { grid-column: span 2; }
.cards.three .card.wide { grid-column: span 3; }

.card::before, .card::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  pointer-events: none;
  opacity: 0.6;
}
.card::before { top: 0; right: 0; border-top: 1px solid var(--line-gold); border-right: 1px solid var(--line-gold); }
.card::after  { bottom: 0; left: 0; border-bottom: 1px solid var(--line-gold); border-left: 1px solid var(--line-gold); }

.card > header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 16px 22px 10px;
  border-bottom: 1px solid var(--line-soft);
}
.card > header h3 {
  margin: 0;
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: 16.5px;
  letter-spacing: -0.005em;
}
.card-sub {
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 12px;
  color: var(--slate);
  text-align: right;
  font-feature-settings: "tnum";
}

.chart-body {
  padding: 16px 22px 16px;
  height: 280px;
  position: relative;
}
.card.wide .chart-body { height: 320px; }

/* ============================================================
   BAR CHART (HTML/CSS — no Chart.js)
   ============================================================ */

.barchart {
  height: 100%;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
}

.barchart .yaxis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--slate);
  padding-bottom: 26px;
}

.barchart .plot {
  position: relative;
  display: flex;
  flex-direction: column;
}

.barchart .grid {
  position: absolute;
  inset: 0 0 26px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}
.barchart .grid > div { border-bottom: 1px dashed rgba(26, 26, 46, 0.06); height: 0; }

.barchart .bars {
  position: relative;
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding-bottom: 26px;
  z-index: 1;
}

.bar-col {
  flex: 1;
  height: 100%;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: stretch;
  min-width: 0;
}

.bar {
  width: 100%;
  background: var(--taupe);
  border-radius: 3px 3px 0 0;
  position: relative;
  transition: filter 200ms;
  cursor: pointer;
  min-height: 2px;
}
.bar:hover { filter: brightness(1.08) saturate(1.1); }

.bar-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.bar-stack > .seg { width: 100%; }

.bar-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  background: var(--ink);
  color: var(--cream);
  border-radius: 5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms;
  z-index: 10;
}
.bar:hover .bar-tooltip,
.bar-stack:hover .bar-tooltip { opacity: 1; }

.xlabels {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 4px;
  height: 22px;
  align-items: center;
}
.xlabels > div {
  flex: 1;
  text-align: center;
  font-family: 'DM Sans', sans-serif;
  font-size: 10px;
  color: var(--slate);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
}

/* ============================================================
   LINE CHART (SVG line + area + HTML dots)
   ============================================================ */

.linechart .line-area {
  position: relative;
  flex: 1;
  margin-bottom: 26px;
  z-index: 1;
}
.line-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.line-dot {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--paper);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(26, 26, 46, 0.15);
  cursor: pointer;
  transition: transform 160ms ease;
  z-index: 2;
}
.line-dot:hover {
  transform: translate(-50%, -50%) scale(1.55);
  z-index: 5;
}
.line-dot::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  background: var(--ink);
  color: var(--cream);
  border-radius: 5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}
.line-dot:hover::after { opacity: 1; }

/* Empty state */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--slate);
  pointer-events: none;
}
.empty-emoji { font-size: 28px; }
.empty-text { font-family: 'DM Serif Display', serif; font-style: italic; font-size: 13.5px; }

/* Bar legend (for stacked daily) */
.bar-legend {
  display: flex;
  gap: 14px;
  margin-bottom: 8px;
  padding: 0 6px;
  font-size: 11px;
  color: var(--slate);
  flex-wrap: wrap;
}
.bar-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.bar-legend .swatch { width: 10px; height: 10px; border-radius: 2px; }

/* ============================================================
   DOUGHNUT (SVG)
   ============================================================ */

.doughnut-wrap {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 14px;
  padding: 4px 0;
}
.doughnut {
  width: 100%;
  height: 100%;
  max-height: 200px;
  display: block;
  margin: 0 auto;
}
.doughnut-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  font-size: 11.5px;
  color: var(--slate);
}
.doughnut-legend span { display: inline-flex; align-items: center; gap: 6px; }
.doughnut-legend .swatch { width: 10px; height: 10px; border-radius: 50%; }

/* ============================================================
   HEATMAP
   ============================================================ */

.heatmap {
  display: grid;
  grid-template-columns: 38px repeat(24, 1fr);
  gap: 3px;
  padding: 6px 6px 0;
}
.heatmap .lbl {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  color: var(--slate);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 24px;
}
.heatmap .lbl.day {
  justify-content: flex-end;
  padding-right: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.heatmap .cell {
  height: 24px;
  border-radius: 3px;
  background: rgba(26, 26, 46, 0.04);
  position: relative;
  transition: transform 150ms;
  cursor: pointer;
}
.heatmap .cell.l1 { background: rgba(184, 151, 126, 0.18); }
.heatmap .cell.l2 { background: rgba(184, 151, 126, 0.36); }
.heatmap .cell.l3 { background: rgba(184, 151, 126, 0.55); }
.heatmap .cell.l4 { background: rgba(184, 151, 126, 0.75); }
.heatmap .cell.l5 { background: linear-gradient(135deg, var(--taupe-light) 0%, var(--taupe) 100%); }
.heatmap .cell:hover { transform: scale(1.16); z-index: 5; outline: 1px solid var(--taupe); }
.heatmap .cell::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  background: var(--ink);
  color: var(--cream);
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms;
  z-index: 10;
}
.heatmap .cell:hover::after { opacity: 1; }

/* ============================================================
   TABLES
   ============================================================ */

section.tableblock {
  padding: 32px 56px;
  border-bottom: 1px solid var(--line);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
}
.section-head h2 {
  margin: 0;
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-style: italic;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 13px;
  font-size: 11.5px;
  font-weight: 600;
  background: rgba(201, 122, 93, 0.12);
  color: var(--terracotta);
  border: 1px solid rgba(201, 122, 93, 0.28);
  border-radius: 999px;
}
.count-pill.zero { background: rgba(139, 157, 126, 0.12); color: #6f8265; border-color: rgba(139, 157, 126, 0.3); }

.user-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 11px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  text-align: center;
  min-width: 96px;
  white-space: nowrap;
  line-height: 1.3;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}
.user-badge--sm { min-width: 70px; padding: 4px 9px; font-size: 10.5px; }

.platform-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}
.platform-cell svg { flex-shrink: 0; }
.platform-cell.platform-ios svg { color: #1a1a2e; }
.platform-cell.platform-android svg { color: #3DDC84; }
.platform-cell.platform-test svg { color: #999; }

.country-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.country-flag {
  display: inline-block;
  width: 20px;
  height: 15px;
  vertical-align: middle;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.users-help {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--slate);
  font-style: italic;
}

.users-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.users-filters input[type="search"],
.users-filters select {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.users-filters input[type="search"] {
  flex: 1;
  min-width: 220px;
}
.users-filters input[type="search"]:focus,
.users-filters select:focus {
  border-color: var(--terracotta);
}
.users-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  gap: 10px;
}
.users-pagination #users-page-info {
  color: var(--slate);
  font-size: 13px;
}
.users-pagination .pg-buttons { display: flex; gap: 6px; }
.users-pagination button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: background 120ms;
}
.users-pagination button:hover:not(:disabled) { background: rgba(184, 151, 126, 0.08); }
.users-pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

.tableblock.collapsed .table-wrap { display: none; }
.tableblock.collapsed::after {
  content: 'Aucune erreur observée — section masquée.';
  display: block;
  margin-top: 10px;
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 13.5px;
  color: var(--slate);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead th {
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--slate);
  text-align: left;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 248, 245, 0.5);
}
tbody td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-soft);
  vertical-align: middle;
  font-feature-settings: "tnum";
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(184, 151, 126, 0.05); }
tbody td:first-child {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--slate);
  white-space: nowrap;
}
.empty-row td { text-align: center; padding: 36px; font-family: 'DM Serif Display', serif; font-style: italic; color: var(--slate); font-size: 14px; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.tag.lang { background: rgba(94, 155, 149, 0.1); color: var(--teal); border: 1px solid rgba(94, 155, 149, 0.28); }
.tag.islamic { background: rgba(156, 123, 170, 0.1); color: var(--plum); border: 1px solid rgba(156, 123, 170, 0.28); }
.tag.psychological { background: rgba(94, 155, 149, 0.1); color: var(--teal); border: 1px solid rgba(94, 155, 149, 0.28); }

.excerpt {
  display: block;
  max-width: 540px;
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.45;
  cursor: help;
}

tbody td a {
  font-family: 'DM Sans', sans-serif;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--taupe-dark);
  border-bottom: 1px solid rgba(184, 151, 126, 0.4);
  padding-bottom: 1px;
  letter-spacing: 0.02em;
}

.error-msg {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--ink-soft);
  cursor: help;
}

/* ============================================================
   FOOTER
   ============================================================ */

footer.app {
  padding: 30px 56px 50px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 12.5px;
  color: var(--slate);
}
footer.app p { margin: 0; }
footer.app .meta {
  font-family: 'DM Sans', sans-serif;
  font-style: normal;
  font-size: 11.5px;
  letter-spacing: 0.02em;
}
.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--sage);
}
.live-dot.pulse { animation: pulse 1.1s ease-out; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(139, 157, 126, 0.6); transform: scale(1); }
  50%  { transform: scale(1.5); }
  100% { box-shadow: 0 0 0 14px rgba(139, 157, 126, 0); transform: scale(1); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1100px) {
  .cards { grid-template-columns: 1fr; }
  .card.wide { grid-column: span 1; }
  .cards.three { grid-template-columns: 1fr; }
  .cards.three .card.wide { grid-column: span 1; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi:nth-child(2) { border-right: none; }
  .kpi:nth-child(1), .kpi:nth-child(2) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 720px) {
  header.app, .kpis, section.block, section.tableblock, footer.app {
    padding-left: 22px; padding-right: 22px;
  }
  header.app { grid-template-columns: 1fr; gap: 14px; }
  .kpis { grid-template-columns: 1fr; }
  .kpi { border-right: none; border-bottom: 1px solid var(--line); }
  .kpi:last-child { border-bottom: none; }
  .heatmap { grid-template-columns: 28px repeat(24, 1fr); }
  .heatmap .cell, .heatmap .lbl { height: 16px; }
}

/* ============================================================
   VIEW TABS (sub-nav between Observatoire & TikTok)
   ============================================================ */
.view-tabs {
  display: inline-flex;
  gap: 4px;
  margin-top: 10px;
  padding: 3px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.view-tab {
  padding: 5px 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--slate);
  text-decoration: none;
  border-radius: 999px;
  transition: all 200ms;
}
.view-tab:hover {
  color: var(--ink);
  background: rgba(184, 151, 126, 0.08);
}
.view-tab.active {
  background: linear-gradient(135deg, var(--taupe-light) 0%, var(--taupe) 100%);
  color: var(--cream);
  box-shadow: 0 2px 6px rgba(184, 151, 126, 0.25);
}

/* ============================================================
   ACCOUNT MINI STATS (TikTok dashboard)
   ============================================================ */
.account-card { padding-bottom: 18px; }
.account-mini-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 24px;
  padding: 16px 22px 4px;
}
.acct-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.acct-stat-label {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--slate);
  text-transform: uppercase;
}
.acct-stat-value {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: 22px;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* ============================================================
   RANK PILL (top videos table)
   ============================================================ */
.rank-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 11.5px;
}

/* ============================================================
   BIG STAT (RevenueCat refund-rate, etc.)
   ============================================================ */
.big-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 220px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(184, 151, 126, 0.03);
  text-align: center;
}
.big-stat-value {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: clamp(40px, 4.5vw, 64px);
  line-height: 1;
  letter-spacing: -0.025em;
}
.big-stat-label {
  margin-top: 14px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--slate);
  text-transform: uppercase;
}
.big-stat-sub {
  margin-top: 10px;
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 13px;
  color: var(--slate);
  max-width: 240px;
}

/* ============================================================
   DIVERGING BARS (new MRR vs churned MRR)
   - Y axis goes from -niceMax (bottom) to +niceMax (top), zero centered
   ============================================================ */
.diverging-chart .bars { align-items: stretch; }
.bar-col.diverging {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  height: 100%;
  width: 100%;
}
.bar-col.diverging .bar-pos {
  align-self: stretch;
  margin-top: auto;
  border-radius: 3px 3px 0 0;
  min-height: 0;
}
.bar-col.diverging .bar-zero {
  height: 1px;
  background: rgba(26, 26, 46, 0.18);
  margin: 0;
}
.bar-col.diverging .bar-neg {
  align-self: stretch;
  margin-bottom: auto;
  border-radius: 0 0 3px 3px;
  min-height: 0;
}
.bar-col.diverging .bar-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  padding: 5px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}
.bar-col.diverging:hover .bar-tooltip { display: block; }

/* Diverging chart : center the zero line via grid override */
.diverging-chart .grid {
  /* same grid as standard, but with a center mark for zero */
}

/* ============================================================
   KPI ROW — variantes (5 KPI sur page TikTok)
   ============================================================ */
.kpis.kpis-5 {
  grid-template-columns: repeat(5, 1fr);
}
@media (max-width: 1100px) {
  .kpis.kpis-5 { grid-template-columns: repeat(2, 1fr); }
  .kpis.kpis-5 .kpi { border-right: 1px solid var(--line); }
  .kpis.kpis-5 .kpi:nth-child(2n) { border-right: none; }
  .kpis.kpis-5 .kpi { border-bottom: 1px solid var(--line); }
}

/* ============================================================
   MOBILE — Ultrathink phone-first optimization
   - Safe-area iOS notch
   - KPI swipe horizontal (snap)
   - Controls sticky on scroll
   - Tables sticky 1st column + scroll-shadow
   - Touch tooltips with .tip-pinned (mobile.js)
   - Modals 100dvh + safe-area
   ============================================================ */

/* Touch optimizations universal (no hover capability = phone/tablet) */
@media (hover: none) {
  /* No blue tap flash */
  * { -webkit-tap-highlight-color: transparent; }
  /* Faster click on interactive */
  a, button, .btn-mini, .view-tab, select.period, .btn-refresh, .btn-tables,
  .line-dot, .bar, .bar-stack, .sp-bar, .bucket {
    touch-action: manipulation;
  }
  /* Tooltip reveals via :active OR JS-pinned class */
  .line-dot:active::after,
  .line-dot.tip-pinned::after,
  .bar:active .bar-tooltip,
  .bar.tip-pinned .bar-tooltip,
  .bar-stack:active .bar-tooltip,
  .bar-stack.tip-pinned .bar-tooltip,
  .sp-bar:active .tip,
  .sp-bar.tip-pinned .tip,
  .bucket:active .tip,
  .bucket.tip-pinned .tip { opacity: 1; }
  /* Scale boost when pinned */
  .line-dot.tip-pinned { transform: translate(-50%, -50%) scale(1.55); z-index: 5; }
}

/* Safe-area pour notch iPhone (≤ 720px : tablet portrait + phone) */
@media (max-width: 720px) {
  body { padding-bottom: env(safe-area-inset-bottom, 0); }
  header.app {
    padding-top: max(env(safe-area-inset-top, 0), 22px);
    padding-left: max(env(safe-area-inset-left, 0), 22px);
    padding-right: max(env(safe-area-inset-right, 0), 22px);
  }
}

/* ── PHONE PORTRAIT (≤ 540px) ── */
@media (max-width: 540px) {
  body {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
  }

  /* Header — compact */
  header.app {
    padding: 16px 16px 12px;
    padding-top: max(env(safe-area-inset-top, 0), 16px);
    gap: 10px;
    max-width: 100%;
    box-sizing: border-box;
  }
  .brand { gap: 12px; align-items: flex-start; min-width: 0; max-width: 100%; }
  .brand > div { min-width: 0; flex: 1; max-width: 100%; }
  .brand-mark { width: 36px; height: 36px; flex-shrink: 0; }
  h1.brand-title { font-size: 22px; }
  .brand-sub { font-size: 11.5px; line-height: 1.4; }

  /* View tabs — style "tab" plat avec underline (pas pill) */
  .view-tabs {
    margin: 12px 0 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    gap: 0;
    scroll-snap-type: x proximity;
    box-sizing: border-box;
  }
  .view-tabs::-webkit-scrollbar { display: none; }
  .view-tab {
    flex-shrink: 0;
    padding: 10px 16px;
    font-size: 13px;
    scroll-snap-align: start;
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: var(--slate);
  }
  .view-tab.active {
    color: var(--ink);
    font-weight: 600;
    border-bottom-color: var(--taupe);
  }

  /* Subtitle hidden on phone (saves vertical space, info redundant) */
  .brand-sub { display: none; }
  /* Run-badge hidden on phone (freshness shown in footer) */
  .run-badge { display: none; }

  /* Controls — full-width touch-friendly, wrap fallback si pas de place */
  .controls {
    width: 100%;
    max-width: 100%;
    gap: 8px;
    justify-content: stretch;
    margin: 4px 0 0;
    flex-wrap: wrap;
    box-sizing: border-box;
  }
  .controls > * { box-sizing: border-box; max-width: 100%; }

  /* HEADER COLLAPSE quand body.is-scrolled — set par mobile.js après 80px */
  body.is-scrolled header.app {
    position: sticky;
    top: 0;
    z-index: 50;
    padding-top: max(env(safe-area-inset-top, 0), 8px);
    padding-bottom: 6px;
    background: rgba(250, 248, 245, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(26, 26, 46, 0.05);
    gap: 6px;
  }
  body.is-scrolled .brand > .brand-mark,
  body.is-scrolled h1.brand-title { display: none; }
  body.is-scrolled .brand { gap: 0; }
  body.is-scrolled .view-tabs { margin-top: 0; }
  body.is-scrolled .controls { margin-top: 6px; }
  .run-badge, .status {
    padding: 8px 11px;
    font-size: 10.5px;
    flex: 1;
    min-width: 0;
    justify-content: center;
  }
  .run-badge strong { font-size: 10.5px; }
  .btn-refresh { width: 40px; height: 40px; flex-shrink: 0; }
  select.period {
    flex: 1;
    min-width: 0;
    padding: 10px 30px 10px 14px;
    font-size: 12.5px;
  }
  /* DB Explorer button : icon only on mobile to save space */
  .btn-tables {
    width: 40px; height: 40px;
    padding: 0;
    flex-shrink: 0;
    justify-content: center;
  }
  .btn-tables { font-size: 0; }
  .btn-tables svg { font-size: initial; width: 16px; height: 16px; }

  /* KPIs : strip horizontal swipeable au lieu de stack vertical */
  .kpis, .kpis.kpis-5 {
    display: flex;
    grid-template-columns: none;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: 1px solid var(--line);
    padding: 0;
    scroll-padding-left: 16px;
  }
  .kpis::-webkit-scrollbar { display: none; }
  .kpi {
    flex: 0 0 80%;
    padding: 22px 18px;
    scroll-snap-align: start;
    border-right: 1px solid var(--line);
    border-bottom: none;
    gap: 14px;
  }
  .kpi:last-child { border-right: none; padding-right: 22px; }
  .kpis.kpis-5 .kpi { border-bottom: none; }
  .kpi:hover { background: transparent; } /* no hover on touch */
  .kpi-icon { width: 32px; height: 32px; margin-top: 4px; }
  .kpi-icon svg { width: 16px; height: 16px; }
  .kpi-value { font-size: 30px; }
  .kpi-label { font-size: 9.5px; margin-top: 6px; }
  .kpi-sub { font-size: 11.5px; }

  /* Sections / blocks */
  section.block, section.tableblock, footer.app {
    padding: 22px 16px 14px;
  }
  .block-title { font-size: 14px; margin-bottom: 14px; gap: 10px; }
  .block-title::before { width: 18px; }

  /* Cards */
  .cards, .cards.three { grid-template-columns: 1fr; gap: 12px; }
  .card.wide, .cards.three .card.wide { grid-column: span 1; }
  .card::before, .card::after { display: none; } /* corner decorations enlevées (économise espace) */
  .card > header {
    padding: 12px 14px 8px;
    flex-wrap: wrap;
    gap: 4px;
  }
  .card > header h3 { font-size: 14.5px; }
  .card-sub { font-size: 11px; text-align: left; }

  /* Charts — compacts mais lisibles */
  .chart-body { padding: 10px 12px 12px; height: 220px; }
  .card.wide .chart-body { height: 240px; }
  .barchart { grid-template-columns: 28px 1fr; gap: 4px; }
  .barchart .yaxis { font-size: 9px; padding-bottom: 22px; }
  .barchart .xlabels { font-size: 9px; overflow: hidden; }
  .bars { gap: 2px; padding-bottom: 22px; }
  .grid { inset: 0 0 22px 0; }
  .bar-legend { font-size: 10.5px; gap: 8px; flex-wrap: wrap; padding-bottom: 6px; }
  .bar-tooltip { font-size: 10px; padding: 3px 8px; }

  /* Line dots : zone tap élargie via ::before invisible */
  .line-dot {
    width: 8px; height: 8px;
    border-width: 1.5px;
  }
  .line-dot::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: transparent;
  }
  .line-dot.tip-pinned::after {
    background: var(--ink);
    color: var(--cream);
    font-size: 11px;
    padding: 5px 10px;
    z-index: 100;
  }

  /* Doughnut : un peu plus petit */
  .doughnut { width: 140px; height: 140px; }
  .doughnut-legend { font-size: 11px; gap: 4px; }

  /* TABLES : horizontal scroll + sticky 1ère col + scroll-shadow */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  /* Scroll shadow droite — masquée par défaut, JS toggle has-scroll */
  .table-wrap::after {
    content: '';
    position: absolute; top: 0; right: 0; bottom: 0;
    width: 28px;
    background: linear-gradient(90deg, transparent, rgba(26, 26, 46, 0.12));
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms;
    z-index: 3;
  }
  .table-wrap.has-scroll::after { opacity: 1; }

  table { font-size: 12px; min-width: max-content; }
  thead th {
    padding: 9px 11px;
    font-size: 8.5px;
    background: var(--cream-deep);
  }
  thead th:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--cream-deep);
    box-shadow: 1px 0 0 var(--line);
  }
  tbody td { padding: 9px 11px; }
  tbody td:first-child {
    position: sticky; left: 0; z-index: 1;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(2px);
    box-shadow: 1px 0 0 var(--line-soft);
    font-size: 10.5px;
  }
  tbody tr:hover td:first-child { background: rgba(184, 151, 126, 0.05); }
  .empty-row td { padding: 24px 12px; font-size: 12.5px; }
  .empty-row td:first-child { position: static; box-shadow: none; }
  .excerpt { max-width: 220px; font-size: 12px; }
  tbody td a { font-size: 10.5px; }
  .error-msg { font-size: 10.5px; }

  /* Section heads */
  .section-head h2 { font-size: 18px; }
  .count-pill { font-size: 10.5px; padding: 2px 8px; }

  /* Tags compacts */
  .tag { padding: 2px 7px; font-size: 9px; }

  /* Footer */
  footer.app {
    padding-top: 22px;
    padding-bottom: max(env(safe-area-inset-bottom, 0), 24px);
  }
  footer.app .meta { font-size: 11px; line-height: 1.5; }

  /* Heatmap (Observatoire) */
  .heatmap { grid-template-columns: 22px repeat(24, 1fr); gap: 1px; }
  .heatmap .cell, .heatmap .lbl { height: 14px; font-size: 8px; }

  /* Revenue users-filters + pagination */
  .users-filters { flex-direction: column; align-items: stretch; gap: 8px; }
  .users-filters input[type="search"],
  .users-filters select { width: 100%; min-width: 0; padding: 10px 11px; font-size: 13.5px; }
  .users-help { font-size: 11.5px; margin-bottom: 10px; }
  .users-pagination {
    flex-direction: column; align-items: center; gap: 10px; padding-top: 14px;
  }
  .users-pagination #users-page-info { font-size: 12px; text-align: center; }
  .users-pagination button { padding: 10px 16px; font-size: 13px; min-width: 90px; }

  /* FAB scroll-to-top (visible uniquement si .visible) */
  .fab-top {
    position: fixed;
    right: 16px;
    bottom: max(env(safe-area-inset-bottom, 0), 18px);
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--paper);
    border: 1px solid var(--line-gold);
    box-shadow: 0 6px 18px rgba(26, 26, 46, 0.15);
    color: var(--taupe-dark);
    cursor: pointer;
    z-index: 90;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 200ms, transform 200ms;
  }
  body.is-mobile .fab-top { display: flex; }
  body.is-mobile .fab-top.visible { opacity: 1; transform: scale(1); }
  .fab-top:active { transform: scale(0.92); }
}

/* ── EXTRA-PETIT (iPhone SE / 320px) ── */
@media (max-width: 380px) {
  header.app, section.block, section.tableblock, footer.app {
    padding-left: 12px; padding-right: 12px;
  }
  h1.brand-title { font-size: 20px; }
  .kpi { flex-basis: 85%; padding: 18px 14px; }
  .kpi-value { font-size: 26px; }
  .controls { gap: 6px; }
  .run-badge, .status { font-size: 10px; padding: 7px 9px; }
  select.period { font-size: 12px; padding: 9px 28px 9px 12px; }
  .chart-body { height: 200px; padding: 8px 10px 10px; }
  .card.wide .chart-body { height: 220px; }
  .barchart { grid-template-columns: 22px 1fr; }
  thead th { padding: 8px 9px; font-size: 8px; }
  tbody td { padding: 8px 9px; font-size: 11px; }
  tbody td:first-child { font-size: 10px; }
  .excerpt { max-width: 180px; }
}

/* ── 100dvh modals (avec fallback 100vh) ── */
@supports (height: 100dvh) {
  @media (max-width: 540px) {
    .day-modal-card, .dbx-card { height: 100dvh; max-height: 100dvh; }
  }
}
