:root {
  --bg: #eef2f8;
  --bg-soft: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  font-size: 14px;
}

#app { min-height: 100vh; }
.hidden { display: none !important; }

/* ── Auth minimal ── */
#auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.auth-card.auth-minimal {
  width: min(320px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-error {
  margin: 10px 0 0;
  min-height: 1em;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* ── Password field with eye ── */
.pw-field {
  position: relative;
  display: flex;
  align-items: center;
}

.pw-field input {
  padding-right: 40px;
}

.pw-toggle {
  position: absolute;
  right: 4px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.pw-toggle:hover { background: var(--surface-2); color: var(--text); }
.pw-toggle.active { color: var(--accent); }

/* ── App shell ── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  padding: 6px 10px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.sidebar-brand strong { display: block; font-size: 14px; }
.sidebar-brand span { color: var(--muted); font-size: 11px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-icon { width: 1rem; text-align: center; font-size: 12px; }
.sidebar-logout { margin-top: 8px; font-size: 12px; }

.main-content { padding: 20px 24px 36px; max-width: 1100px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}

.status-dot.live {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.status-dot.error { background: var(--danger); }

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { color: var(--muted); background: transparent; border: 1px solid var(--border); width: 100%; }
.btn-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  padding: 4px 10px;
  font-size: 11px;
}
.btn-block { width: 100%; }

/* ── Fields ── */
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

input, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
}

input::placeholder { color: #94a3b8; }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input.input-sm, select.input-sm { padding: 6px 8px; font-size: 12px; }

/* ── Sections ── */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.section-card.narrow { max-width: 420px; }
.section-card.account-card { max-width: 960px; }
.account-user-field { max-width: 480px; margin-bottom: 14px; }
.account-pw-row {
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr) auto;
}
.account-pw-row .account-pw-field input {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  min-height: 38px;
}
.account-pw-row .pw-field { width: 100%; }
.account-pw-row .btn { align-self: end; min-height: 38px; }
.section-head { margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.section-head.compact { margin-bottom: 12px; padding-bottom: 8px; }
.section-head.compact p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}
.section-head h2 { margin: 0; font-size: 14px; font-weight: 700; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.form-grid.single-col { grid-template-columns: 1fr; }

/* ── Toast ── */
.toast {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 100;
  min-width: 240px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
}
.toast.ok { background: var(--ok-soft); border: 1px solid #bbf7d0; color: #166534; }
.toast.err { background: var(--danger-soft); border: 1px solid #fecaca; color: #991b1b; }

/* ── Cards stats ── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card .value { font-size: 1.5rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.card .value.small { font-size: 0.95rem; color: var(--text); font-weight: 700; }
.card .label { margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }

/* ── Table ── */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }
td:first-child { font-family: ui-monospace, monospace; font-size: 12px; color: var(--accent); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
}

.listen-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.stream-player-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.stream-player-wrap.hidden { display: none; }

.stream-player-wrap audio {
  flex: 1;
  min-width: 200px;
  height: 36px;
}

.stream-player-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Statistiques auditeurs ── */
.stats-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 8px;
}

.stats-filter {
  min-width: 160px;
  margin: 0;
}

.stats-filter span {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}

.stats-filter select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 13px;
}

.stats-chart {
  min-height: 180px;
  padding: 8px 4px 4px;
}

.stats-bars-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 12px 8px 8px;
}

.stats-bars-plot {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 200px;
  overflow-x: auto;
  padding: 0 4px;
}

.stats-bar-col {
  flex: 0 0 40px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.stats-bar-value {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stats-bar-track {
  width: 28px;
  flex: 1 1 auto;
  min-height: 40px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 4px 4px 2px 2px;
  border: 1px solid var(--border);
}

.stats-bar-fill {
  width: 100%;
  background: linear-gradient(180deg, #60a5fa, var(--accent));
  border-radius: 3px 3px 1px 1px;
  min-height: 2px;
}

.stats-bars-dates {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin-top: 8px;
  padding: 0 4px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.stats-bar-date {
  flex: 0 0 40px;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-country-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stats-country-row {
  display: grid;
  grid-template-columns: 120px 1fr 40px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.stats-country-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-country-bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.stats-country-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.stats-country-count {
  text-align: right;
  font-weight: 700;
  color: var(--accent);
  font-size: 12px;
}

.stats-live-mount {
  margin-bottom: 14px;
}

.stats-live-mount:last-child {
  margin-bottom: 0;
}

.stats-live-mount-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.ua-cell {
  font-size: 11px;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audience-map-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: hidden;
}

.audience-map-stage {
  position: relative;
  width: 100%;
  line-height: 0;
}

.audience-map-bg {
  display: block;
  width: 100%;
  height: auto;
}

.audience-map-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.audience-map-overlay .map-point {
  pointer-events: auto;
}

.map-ocean {
  fill: transparent;
}

.map-grid,
.map-land {
  display: none;
}

.map-point {
  cursor: default;
}

.map-pulse {
  fill: rgba(239, 68, 68, 0.35);
  animation: map-pulse 2s ease-out infinite;
}

.map-dot {
  fill: #ef4444;
  stroke: #fff;
  stroke-width: 2;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}

.map-dot-label {
  fill: #fff;
  font-size: 10px;
  font-weight: 800;
  text-anchor: middle;
  pointer-events: none;
}

@keyframes map-pulse {
  0% { opacity: 0.6; }
  70% { opacity: 0; }
  100% { opacity: 0; }
}

.audience-map-legend {
  margin: 0;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}

.stats-hour-table-wrap {
  max-height: 320px;
}

.stats-line-chart-wrap {
  margin-bottom: 12px;
}

.stats-line-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.stats-line-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stats-legend-swatch {
  display: inline-block;
  width: 14px;
  height: 4px;
  border-radius: 2px;
}

.stats-legend-max { background: #2563eb; }
.stats-legend-avg { background: #16a34a; }

.stats-line-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.stats-line-svg {
  display: block;
  min-width: 100%;
  height: auto;
}

.stats-grid-line {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.stats-axis {
  stroke: var(--border);
  stroke-width: 1.5;
}

.stats-axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--sans, Inter, system-ui, sans-serif);
}

.stats-x-label {
  font-size: 10px;
}

.stats-area-max {
  fill: rgba(37, 99, 235, 0.12);
}

.stats-line-max {
  fill: none;
  stroke: #2563eb;
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.stats-line-avg {
  fill: none;
  stroke: #16a34a;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 6 4;
}

.stats-dot {
  cursor: default;
}

.stats-dot-max {
  fill: #2563eb;
  stroke: #fff;
  stroke-width: 1;
}

.stats-dot-avg {
  fill: #16a34a;
  stroke: #fff;
  stroke-width: 1;
}

.stats-hour-details {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.stats-hour-details summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 8px;
  user-select: none;
}

/* ── Mounts compact ── */
.mount-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-user-field { max-width: 320px; margin-bottom: 14px; }

.toolbar-hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
}

.pw-change-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.pw-change-row .pw-current {
  background: #fff;
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

.pw-change-row .btn { margin-bottom: 1px; white-space: nowrap; }

.mount-pw-block {
  grid-column: 1 / -1;
  margin-top: 4px;
}

@media (max-width: 720px) {
  .pw-change-row { grid-template-columns: 1fr; }
  .pw-change-row .btn { width: 100%; }
  .account-pw-row { grid-template-columns: 1fr; }
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.toggle-pill:has(input:checked) {
  border-color: #93c5fd;
  color: var(--accent);
  background: var(--accent-soft);
}

.toggle-pill input { width: 14px; height: 14px; accent-color: var(--accent); }

.mount-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.mount-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.mount-card h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  color: var(--accent);
}

.mount-row {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr 0.7fr 0.6fr 0.6fr;
  gap: 8px;
  align-items: end;
}

.mount-row label { gap: 3px; }
.mount-row .field span { font-size: 10px; }

.mount-advanced {
  margin-top: 8px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.mount-advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.mount-advanced summary::-webkit-details-marker { display: none; }
.mount-advanced summary::before { content: "▸"; font-size: 10px; }
.mount-advanced[open] summary::before { content: "▾"; }

.mount-advanced-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.empty-mounts {
  text-align: center;
  padding: 28px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.log-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.log-tabs { display: flex; gap: 6px; }

.log-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.log-auto {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.log-viewer {
  margin: 0;
  padding: 12px;
  min-height: 280px;
  max-height: 55vh;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-meta {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item { width: auto; }
  .mount-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .mount-row { grid-template-columns: 1fr; }
}

/* ── Page statistiques client ── */
#stats-app {
  min-height: 100vh;
}

.stats-client-card {
  width: min(360px, 100%);
}

.stats-client-title {
  margin: 0 0 4px;
  font-size: 1.25rem;
  text-align: center;
}

.stats-client-sub {
  margin: 0 0 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.stats-client-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto 20px;
  padding: 24px 20px 0;
}

.stats-client-header h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

#client-stats-screen {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.checkbox-field input {
  width: auto;
}
