/*
 * Memes jetons que la console SAV (C:\dev\sav-oe/public/style.css) : meme fond,
 * meme accent, memes bulles. Ce qui change est la mise en page — l'app client
 * est pensee pour un telephone, donc barre d'onglets en bas et vues plein ecran
 * au lieu de la grille deux colonnes de la console.
 */
:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1d222b;
  --line: #262c37;
  --text: #e6e9ef;
  --muted: #8a93a3;
  --accent: #4f8cff;
  --agent: #23405f;
  --ok: #38b26b;
  --warn: #d7a44f;
  --danger: #e2685f;
  --shell: 480px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Le `display` du navigateur pour [hidden] perd contre n'importe quelle classe
   qui en declare un (.btn, .app, .view…). L'app pilote tout par l'attribut
   hidden : sans cette regle, les ecrans caches restent visibles. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior-y: none;
}

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------- Communs ------------------------------- */
.btn {
  padding: 11px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font: inherit; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn--block { width: 100%; }
.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn--icon { padding: 0; width: 42px; height: 42px; flex: 0 0 42px; border-radius: 50%; }
.btn--icon svg { fill: currentColor; stroke: none; width: 20px; height: 20px; }

.btn--bio {
  width: 100%; background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent);
  padding: 14px; margin-bottom: 4px;
}
.btn--bio svg { width: 24px; height: 24px; }

input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
textarea { resize: vertical; }

label { display: grid; gap: 6px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
label.check { grid-template-columns: auto 1fr; align-items: start; gap: 10px; line-height: 1.4; }
label.check input { width: 18px; height: 18px; margin-top: 1px; }

fieldset { border: 0; border-top: 1px solid var(--line); margin: 0 0 4px; padding: 14px 0 0; }
fieldset:first-of-type { border-top: 0; padding-top: 0; }
legend { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 0 6px; }
.legend-note { text-transform: none; letter-spacing: 0; opacity: .7; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.hint--inline { margin: 0 0 0 auto; }
.error {
  font-size: 13px; color: var(--danger); margin: 0 0 12px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: 8px; padding: 8px 10px;
}
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }

.badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted);
}
.badge--mobile { color: #9d8bff; border-color: #453a7a; }
.badge--ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge--muted { color: var(--muted); }

.unread {
  background: var(--accent); color: #fff; font-size: 11px; font-style: normal;
  min-width: 18px; text-align: center; border-radius: 999px; padding: 0 5px;
}

.status { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: auto; }
.status--on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

/* -------------------------- Marque / connexion -------------------------- */
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .02em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.brand__mark {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 700; letter-spacing: .04em;
  background: linear-gradient(140deg, var(--accent), #7d5bff); color: #fff;
}
.brand__mark--sm { width: 28px; height: 28px; flex-basis: 28px; border-radius: 8px; font-size: 11px; }

.auth { min-height: 100%; display: flex; justify-content: center; padding: max(32px, env(safe-area-inset-top)) 16px 32px; }
.auth__inner { width: 100%; max-width: var(--shell); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.segmented__btn { padding: 9px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; cursor: pointer; }
.segmented__btn[aria-selected="true"] { background: var(--panel-2); color: var(--text); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }

/* ------------------------------ Coquille app ---------------------------- */
.app { height: 100%; max-width: var(--shell); margin: 0 auto; display: flex; flex-direction: column; border-inline: 1px solid var(--line); }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar h1 { font-size: 15px; margin: 0; letter-spacing: .03em; }

.stage { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }
.view--scroll { overflow-y: auto; padding: 16px 16px 24px; display: block; }
.view__head { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.view__count { margin: 0; font-size: 13px; color: var(--muted); }
.view__head .btn { margin-left: auto; }

.tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line); background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  position: relative; background: transparent; border: 0; color: var(--muted);
  font: inherit; font-size: 11px; cursor: pointer;
  display: grid; justify-items: center; gap: 3px; padding: 9px 2px 8px;
}
.tab[aria-selected="true"] { color: var(--accent); }
.tab .unread { position: absolute; top: 4px; right: 50%; transform: translateX(22px); }

/* ------------------------------ Messagerie ------------------------------ */
.thread__head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 80%; padding: 9px 13px; border-radius: 14px; background: var(--panel-2); }
.msg--me { align-self: flex-end; background: var(--agent); }
.msg__meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg__body { white-space: pre-wrap; word-break: break-word; }
.day { align-self: center; font-size: 11px; color: var(--muted); padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; }

.composer {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.composer__row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { max-height: 120px; }

/* -------------------------------- Fiches -------------------------------- */
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.tile__title { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font-size: 16px; }
.tile__sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

.specs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0; }
.specs div { min-width: 0; }
.specs dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.specs dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.tile__actions { display: flex; gap: 8px; margin-top: 16px; }
.tile__actions .btn { flex: 1; white-space: nowrap; }
.tile__actions input { min-width: 0; }

/* Carnet : une frise verticale, la plus recente en haut. */
.timeline { list-style: none; margin: 0; padding: 0 0 0 22px; position: relative; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.entry { position: relative; padding: 0 0 18px; }
.entry::before {
  content: ""; position: absolute; left: -21px; top: 6px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--bg); border: 2px solid var(--accent);
}
.entry--client::before { border-color: var(--muted); }
.entry__top { display: flex; align-items: center; gap: 8px; }
.entry__title { font-weight: 600; }
.entry__date { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.entry__meta { font-size: 13px; color: var(--muted); }
.entry__notes { font-size: 13px; margin-top: 4px; }

.row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row__main { min-width: 0; flex: 1; }
.row__side { display: grid; gap: 8px; justify-items: end; }
.row__title { font-weight: 600; }
.row__sub { font-size: 13px; color: var(--muted); }

/* ------------------------------- Dialogues ------------------------------ */
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  padding: 20px; width: min(440px, 92vw); max-height: 86vh;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 16px; font-size: 16px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; margin: 14px 0 0; padding: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; font-size: 13px; z-index: 10; max-width: 90vw;
}
.toast--error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }

@media (min-width: 520px) {
  .app { border-inline: 1px solid var(--line); }
}
