/*
 * Meme parti pris qu'Arthas : noir, blanc, rien d'autre. Pas de verre, pas de
 * degrade, pas de flou, pas de couleur d'accent. Du skill `apple-design` on ne
 * garde que la typographie (tracking et interligne dependants de la taille),
 * l'accessibilite et les regles de mouvement — jamais la decoration.
 */

:root {
  --bg: #000000;
  --border: #4d4d4d;
  --border-hi: #808080;
  --text: #ffffff;
  --text-dim: #999999;
  --text-faint: #666666;
  --hover: #1a1a1a;
  --active: #262626;
  --danger: #ff5c5c;

  --radius: 12px;
  --radius-pill: 999px;

  --font-ui: 'Lora', Georgia, 'Times New Roman', serif;
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;

  --topbar-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

::selection { background: #fff; color: #000; }

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* Tracking negatif quand le texte grandit, interligne serre : regle
   typographique du skill, la seule chose qu'on lui emprunte ici. */
.display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 13px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------------- login ---------------- */

.screen { height: 100dvh; display: flex; }
.login-card {
  margin: auto; padding: 24px; width: min(360px, 86vw);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card h1 { font-size: 40px; margin: 0 0 4px; }

input, textarea, button { font-family: var(--font-ui); font-size: 16px; color: var(--text); }

input[type=password], input[type=text], input[type=number], textarea {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--border-hi); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }

.field { position: relative; display: flex; }
.field input { padding-right: 48px; }
.field .eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; display: grid; place-items: center;
  background: transparent; border: none; color: var(--text-faint); padding: 0;
}
.field .eye.on { color: var(--text); }

.login-card button, .btn {
  background: var(--text); color: #000; border: none;
  border-radius: var(--radius); padding: 12px 16px; font-weight: 600;
  transition: transform 100ms ease-out;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.login-card button:active, .btn:active { transform: scale(0.97); }

/* ---------------- shell ---------------- */

#shell { height: 100dvh; display: flex; flex-direction: column; }

#topbar {
  flex: none;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0;
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--border);
}
#topbar-title {
  flex: 1; text-align: center; font-family: var(--font-display);
  font-size: 17px; font-weight: 600; letter-spacing: -0.01em;
}

.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  background: transparent; border: none; border-radius: var(--radius);
  color: var(--text); padding: 0;
  transition: background 120ms ease-out;
}
.icon-btn:active { background: var(--active); }
.icon-btn:empty { visibility: hidden; }

#content { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; display: block; }
.pad { padding: 18px 16px calc(28px + var(--safe-bottom)); }

/* ---------------- drawer ---------------- */

#scrim {
  position: fixed; inset: 0; background: #000; opacity: 0;
  pointer-events: none; z-index: 40;
}
#scrim.on { pointer-events: auto; }

#drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(280px, 82vw);
  background: var(--bg); border-right: 1px solid var(--border);
  z-index: 50; transform: translateX(-100%);
  display: flex; flex-direction: column;
  /* pan-y : on laisse le scroll vertical au navigateur et on garde le
     geste horizontal pour nous, sinon Safari s'approprie le glissement
     avant notre seuil de 10px et le preventDefault arrive trop tard. */
  touch-action: pan-y;
  padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
}
#drawer-inner { padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; }
#drawer-head { padding: 6px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
#drawer-head .display { font-size: 28px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; border-radius: var(--radius);
  padding: 12px 10px; width: 100%; text-align: left;
  color: var(--text-dim); font-size: 15px;
  transition: background 120ms ease-out, color 120ms ease-out;
}
.nav-item svg { flex: none; }
.nav-item:active { background: var(--active); }
.nav-item.active { color: var(--text); background: var(--hover); }

/* ---------------- chat ---------------- */

#messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px; display: flex; flex-direction: column; gap: 12px;
}
/* Les messages se collent au bas comme dans une vraie messagerie. En
   margin-top plutot qu'en justify-content: flex-end, qui rogne le haut du
   contenu une fois la zone remplie. */
#messages > .msg:first-child { margin-top: auto; }

.msg {
  max-width: 84%; padding: 10px 14px; border-radius: 16px;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55;
}
.msg.user { align-self: flex-end; background: var(--text); color: #000; border-bottom-right-radius: 5px; }
.msg.coach { align-self: flex-start; border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.pending { color: var(--text-faint); border-style: dashed; }
.msg.failed { border-color: var(--danger); color: var(--danger); }

.msg .tag {
  display: inline-block; margin-top: 9px; padding: 3px 10px;
  border: 1px solid var(--border-hi); border-radius: var(--radius-pill);
  font-size: 12px; font-family: var(--font-mono); color: var(--text-dim);
}
.msg.user .tag { border-color: rgba(0,0,0,.35); color: rgba(0,0,0,.65); }

#composer {
  flex: none; display: flex; gap: 8px; align-items: flex-end;
  /* Zone sure d'iOS reduite a 40 % : la pleine valeur faisait flotter la barre
     trop haut au-dessus du bord. Il reste de quoi ne pas coller le bouton
     d'envoi a l'indicateur d'accueil. */
  padding: 10px 12px calc(4px + var(--safe-bottom) * 0.4);
  border-top: 1px solid var(--border);
}
#input { flex: 1; resize: none; max-height: 130px; border-radius: 20px; line-height: 1.4; }
#send, #mic, #photo {
  width: 44px; height: 44px; flex: none; border-radius: var(--radius-pill);
  display: grid; place-items: center; transition: transform 100ms ease-out;
}
#send { background: var(--text); color: #000; border: none; }
#mic, #photo { background: transparent; color: var(--text); border: 1px solid var(--border); }
#send:active, #mic:active, #photo:active { transform: scale(0.94); }
#send:disabled, #mic:disabled, #photo:disabled { opacity: .35; }

/* Vignette d'une photo envoyee dans le fil */
/* Plafond de hauteur : une photo prise en portrait remplirait sinon tout
   l'ecran dans le fil. */
.msg .shot {
  display: block; width: 100%; max-width: 230px; max-height: 260px;
  object-fit: cover; border-radius: 11px;
  margin-bottom: 8px; background: var(--hover); min-height: 90px;
}

#composer { position: relative; }

/* ---- barre d'enregistrement vocal ---- */

#recbar {
  flex: 1; display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 6px 0 14px;
  border: 1px solid var(--border); border-radius: 23px;
}
#wave { flex: 1; height: 26px; min-width: 0; display: block; }
#rec-time { font-size: 12px; color: var(--text-dim); flex: none; }

#rec-cancel, #rec-send {
  width: 34px; height: 34px; flex: none; border-radius: var(--radius-pill);
  display: grid; place-items: center; border: none;
  transition: transform 100ms ease-out;
}
#rec-cancel { background: var(--active); color: var(--text); }
#rec-send { background: var(--text); color: #000; }
#rec-cancel:active, #rec-send:active { transform: scale(0.92); }

/* Attente de transcription : on garde la barre, la forme d'onde passe en
   animation et la fleche devient un indicateur de chargement. */
/* Le bouton d'annulation disparait : sans ca la barre deborde et pousse le
   bouton d'envoi hors de l'ecran. */
#recbar.busy #rec-cancel { display: none; }
#recbar.busy #rec-send { pointer-events: none; }
#recbar.busy #rec-send svg { display: none; }
#recbar.busy #rec-send::after {
  content: ''; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, .25); border-top-color: #000;
  animation: spin .7s linear infinite;
}
#recbar.busy #rec-time { letter-spacing: .02em; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  #recbar.busy #rec-send::after { animation-duration: 2s; }
}


@media (prefers-reduced-motion: reduce) {
  }

/* ---------------- cartes / stats ---------------- */

.card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card h2 {
  margin: 0 0 12px; font-size: 12px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--font-ui);
}

.hero { text-align: center; padding: 22px 16px; }
.hero .big {
  font-family: var(--font-mono); font-size: 52px; font-weight: 500;
  letter-spacing: -0.03em; line-height: 1; display: block;
}
.hero .unit { font-size: 13px; color: var(--text-dim); margin-top: 8px; display: block; }

.meter { height: 3px; background: var(--hover); border-radius: 2px; overflow: hidden; margin-top: 12px; }
.meter > i { display: block; height: 100%; background: var(--text); }
.meter.over > i { background: var(--danger); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 14px; }
.stat .v { font-family: var(--font-mono); font-size: 21px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .k { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; }
.row + .row { border-top: 1px solid var(--hover); }
.row .k { color: var(--text-dim); font-size: 14px; }
.row .v { font-family: var(--font-mono); font-size: 14px; }

/* barres : blanc plein = ok, contour seul = sous l'objectif */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 82px; }
.bars > i {
  flex: 1; min-height: 2px; background: var(--text); border-radius: 2px 2px 0 0;
  display: block;
}
.bars > i.low { background: var(--text-faint); }
.bars > i.none { background: var(--hover); }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-faint); margin-top: 8px; font-family: var(--font-mono); }

.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; }
.item + .item { border-top: 1px solid var(--hover); }
.item .body { flex: 1; min-width: 0; }
.item .t { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 12px; color: var(--text-faint); font-family: var(--font-mono); }
.item .del {
  background: transparent; border: none; color: var(--text-faint);
  width: 34px; height: 34px; flex: none; border-radius: var(--radius);
}
.item .del:active { background: var(--active); color: var(--danger); }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.inline-form .btn { flex: none; }

/* ---------------- toast ---------------- */

#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translate(-50%, 14px); opacity: 0; pointer-events: none; z-index: 60;
  background: var(--text); color: #000; padding: 9px 16px;
  border-radius: var(--radius-pill); font-size: 13px; font-weight: 600;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- accessibilite ---------------- */

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; }
}

@media (prefers-contrast: more) {
  :root { --border: #8a8a8a; --text-dim: #cfcfcf; --text-faint: #a6a6a6; }
}
