:root {
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #37394b;
  --text-2: #5b5f70;
  --text-3: #8a8e9c;
  --line: #e6e8ec;
  --accent: #14a89b;
  --accent-deep: #0b7a70;
  --accent-soft: #ddf5f2;
  --accent-grad: linear-gradient(135deg, #0b8a7f 0%, #1bb5a6 100%);
  --danger: #b3413f;
  --danger-soft: #fbeaea;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(30, 40, 60, 0.04), 0 6px 20px rgba(30, 40, 60, 0.05);
  --font: 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  display: grid;
  grid-template-columns: 236px 1fr;
  height: 100vh;
}

/* ---------- Menu à gauche ---------- */
.sidebar {
  background: #fbfbfc;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 0 14px 16px;
}

.brand {
  -webkit-app-region: drag;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 40px 10px 26px;
}

.brand .logo {
  width: 40px;
  height: 40px;
  flex: none;
  filter: drop-shadow(0 4px 10px rgba(11, 138, 127, 0.28));
}

.brand .name {
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: #eff1f4;
}

.nav-item[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.nav-item svg {
  width: 20px;
  height: 20px;
}

.status {
  margin-top: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--text-2);
}

.status .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-top: 5px;
  flex: none;
  background: var(--accent);
}

.status[data-state='recording'] .dot {
  background: #e5484d;
  animation: pulse 1s ease-in-out infinite;
}

.status[data-state='processing'] .dot {
  background: var(--accent-deep);
  animation: pulse 0.8s ease-in-out infinite;
}

.status[data-level='error'] {
  background: var(--danger-soft);
  border-color: #f0cccc;
  color: var(--danger);
}

.status[data-level='warn'] {
  background: #fbf7e6;
  border-color: #eadfae;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* ---------- Zone principale ---------- */
.main {
  position: relative;
  overflow-y: auto;
}

.drag {
  -webkit-app-region: drag;
  position: sticky;
  top: 0;
  height: 36px;
  z-index: 5;
}

.page {
  padding: 8px 36px 40px;
  max-width: 1120px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 6px 0 20px;
}

h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.page-inner > .card + .card {
  margin-top: 18px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.muted {
  color: var(--text-2);
}

.hint {
  color: var(--text-3);
  font-size: 12.5px;
}

.hint.tight {
  margin-top: 6px;
}

.hint.spaced {
  margin-top: 14px;
}

/* ---------- Bandeau d'accueil ---------- */
.hero {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 30px 34px;
  margin-bottom: 18px;
  border-radius: 22px;
  color: #fff;
  background: var(--accent-grad);
  box-shadow: 0 10px 30px rgba(11, 138, 127, 0.25);
}

.hero h1 {
  font-size: 32px;
}

.hero p {
  margin: 8px 0 0;
  font-size: 15px;
  max-width: 560px;
  color: rgba(255, 255, 255, 0.94);
}

kbd {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.4);
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
}

.wave {
  flex: none;
  width: 220px;
  height: 84px;
}

.wave rect {
  fill: rgba(255, 255, 255, 0.92);
  transform-box: fill-box;
  transform-origin: center;
  animation: wave 2.4s ease-in-out infinite;
}

@keyframes wave {
  50% {
    transform: scaleY(0.55);
  }
}

@media (prefers-reduced-motion: reduce) {
  .wave rect,
  .status .dot {
    animation: none !important;
  }
}

/* ---------- Cartes de chiffres ---------- */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.grid-eq {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.lead {
  margin: -6px 0 16px;
}

.btn.square {
  height: 42px;
  padding: 0 14px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
}

.stat-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.stat-icon svg {
  width: 22px;
  height: 22px;
}

.stat-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
}

.stat-value {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.stat > div:last-child {
  min-width: 0;
}

.stat-value {
  white-space: nowrap;
}

.stat-value small {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-3);
}

.stat-sub.up {
  color: var(--accent-deep);
  font-weight: 600;
}

/* ---------- Graphiques ---------- */
.chart {
  position: relative;
}

.streak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 13px;
}

.streak svg {
  width: 17px;
  height: 17px;
  color: var(--accent);
  fill: currentColor;
}

.bars {
  width: 100%;
  height: auto;
  display: block;
}

.bars .bar {
  fill: var(--accent);
  transition: fill 0.12s;
}

.bars .bar.empty {
  fill: #e3e8ea;
}

.bars .bar:hover {
  fill: var(--accent-deep);
}

.bars text {
  font-size: 11px;
  fill: var(--text-3);
  font-family: var(--font);
}

.tooltip {
  position: absolute;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  opacity: 0;
  transition: opacity 0.1s;
}

.tooltip.show {
  opacity: 1;
}

.hbar {
  display: grid;
  grid-template-columns: 96px 1fr 44px;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
}

.hbar .label {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hbar .track {
  height: 10px;
  border-radius: 999px;
  background: #eef0f2;
  overflow: hidden;
}

.hbar .fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.hbar .pct {
  text-align: right;
  font-weight: 700;
  font-size: 13px;
}

/* ---------- Dictées ---------- */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.row-entry {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.row-entry .top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.row-entry:first-child {
  border-top: 0;
  padding-top: 0;
}

.row-entry .time {
  font-weight: 700;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  padding-top: 1px;
}

.row-entry .words {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.clamp2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  transition: background 0.12s, color 0.12s;
}

.icon-btn:hover {
  background: #eef0f2;
  color: var(--text);
}

.icon-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.empty-state {
  text-align: center;
  padding: 34px 12px;
  color: var(--text-2);
}

.empty-state .stat-icon {
  margin: 0 auto 12px;
  width: 56px;
  height: 56px;
}

/* ---------- Historique ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.search {
  position: relative;
  flex: 1 1 260px;
}

.search svg {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--text-3);
}

.input,
.select {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.search .input {
  padding-left: 40px;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.select {
  width: auto;
  min-width: 170px;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 12px;
  background: #e9ebee;
}

.segmented button {
  padding: 7px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 600;
  color: var(--text-2);
}

.segmented button[aria-pressed='true'] {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(30, 40, 60, 0.12);
}

.day-title {
  margin: 26px 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.entry {
  padding: 18px 20px;
}

.entry + .entry {
  margin-top: 12px;
}

.entry header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.entry .time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.entry .meta {
  color: var(--text-3);
  font-size: 12.5px;
}

.entry .spacer {
  flex: 1;
}

.entry .text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.entry details {
  margin-top: 10px;
}

.entry summary {
  cursor: pointer;
  color: var(--accent-deep);
  font-weight: 600;
  font-size: 13px;
}

.entry .raw {
  margin: 8px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f5f6f7;
  color: var(--text-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13.5px;
}

/* ---------- Boutons et champs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: filter 0.12s, background 0.12s;
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  filter: brightness(0.93);
}

.btn.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.btn.ghost:hover {
  background: #f3f4f6;
}

.btn.danger {
  background: #fff;
  border-color: #efcaca;
  color: var(--danger);
}

.btn.danger:hover {
  background: var(--danger-soft);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-row .input {
  flex: 1;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 6px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
}

.chip button {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}

.chip button:hover {
  background: rgba(11, 122, 112, 0.15);
}

.chip svg {
  width: 13px;
  height: 13px;
}

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

.table th {
  text-align: left;
  padding: 0 10px 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
}

.table td {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
}

.table .end {
  width: 64px;
  text-align: right;
}

.table .arrow {
  width: 40px;
  color: var(--text-3);
  text-align: center;
}

/* ---------- Réglages ---------- */
.setting {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.setting:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.setting .label {
  font-weight: 700;
}

.setting .control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.setting .input {
  width: 260px;
}

.setting .input.narrow {
  width: 96px;
}

.badge-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.engine {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  background: #f6f8f8;
}

.engine .stat-icon {
  width: 40px;
  height: 40px;
}

.engine .stat-icon svg {
  width: 19px;
  height: 19px;
}

.engine .k {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.engine .v {
  font-weight: 700;
  font-size: 13.5px;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

.badge.cloud {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.badge.local {
  background: var(--accent);
  color: #fff;
}

.badge.off {
  background: #e9ebee;
  color: var(--text-2);
}

.state {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.state.ok {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.state.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.state.wait {
  background: #fbf3d9;
  color: #7a6210;
}

.explain {
  margin: 16px 2px 0;
  color: var(--text-2);
}

.key-block + .key-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.key-block .top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.key-block .result {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
}

.key-block .result.ok {
  color: var(--accent-deep);
}

.key-block .result.bad {
  color: var(--danger);
}

.key-block a {
  color: var(--accent-deep);
}

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  flex: none;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cfd3d9;
  transition: background 0.15s;
}

.switch span::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.switch input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Notifications et fenêtre de confirmation ---------- */
.toasts {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(30, 40, 60, 0.25);
  animation: rise 0.2s ease-out;
}

.toast.error {
  background: var(--danger);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.modal-root:empty {
  display: none;
}

.modal-root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(30, 36, 50, 0.4);
  z-index: 60;
}

.modal {
  width: min(420px, calc(100vw - 48px));
  padding: 26px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(30, 40, 60, 0.3);
}

.modal h2 {
  margin-bottom: 8px;
  font-size: 18px;
}

.modal p {
  margin: 0 0 22px;
  color: var(--text-2);
}

.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1080px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2,
  .grid-eq {
    grid-template-columns: 1fr;
  }
  .badge-row {
    grid-template-columns: 1fr;
  }
}
