/* PLANCK - mise en page commune à tous les décors. Espacements en multiples de 5. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
/* Fond en planche de verre : deux lueurs douces, pas de blanc pur */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1200px 700px at 15% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, var(--bg-glow-2), transparent 60%),
    var(--bg);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: var(--r-s); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Verre : uniquement sur ce qui flotte */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(var(--blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
  box-shadow: var(--shadow);
}

.icon { width: 24px; height: 24px; flex: none; }
.icon-l { width: 40px; height: 40px; }

/* ---------- Boutons : toujours une icône ET un mot ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 50px; padding: 0 20px;
  border-radius: var(--r-m);
  border: 1px solid var(--line-strong);
  background: transparent;
  font-weight: 600; font-size: 16px;
  transition: transform .15s var(--ease), background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-main { background: var(--accent); color: var(--on-accent); border-color: transparent; width: 100%; }
.btn-ghost { border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-small { min-height: 40px; padding: 0 15px; font-size: 14px; border-radius: var(--r-s); }

/* Bouton-icône avec son mot dessous (barres d'outils) */
.tool {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 60px; padding: 5px 10px;
  border: 0; background: transparent; border-radius: var(--r-s);
  font-size: 12px; font-weight: 500; color: var(--text-2);
}
.tool:hover, .tool[aria-pressed="true"] { color: var(--text); background: var(--line); }

/* ---------- Champs ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.input-wrap { position: relative; display: flex; }
.input {
  width: 100%; min-height: 50px; padding: 0 15px;
  border-radius: var(--r-m);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 16px; /* 16 px : iPhone ne zoome pas */
}
.input:focus { outline: none; border-color: var(--focus); }
.input-wrap .input { padding-right: 90px; }
.peek {
  position: absolute; right: 5px; top: 5px; bottom: 5px;
  display: inline-flex; align-items: center; gap: 5px; padding: 0 10px;
  border: 0; border-radius: var(--r-s); background: var(--surface-2);
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.peek .icon { width: 18px; height: 18px; }
.hint { font-size: 13px; color: var(--text-2); }
.msg { min-height: 20px; font-size: 14px; font-weight: 500; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* Segment (choix à 2 ou 3 boutons) */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 5px; gap: 5px;
  border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line);
}
.seg button {
  min-height: 40px; border: 0; border-radius: var(--r-s);
  background: transparent; font-weight: 600; font-size: 15px; color: var(--text-2);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* ---------- Écran de connexion ---------- */
.auth {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 40px 15px calc(40px + env(safe-area-inset-bottom));
}
.auth-card {
  width: 100%; max-width: 420px;
  padding: 30px 25px;
  border-radius: var(--r-xl);
  display: flex; flex-direction: column; gap: 20px;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center; }
.brand canvas { width: 200px; height: 150px; margin-bottom: -10px; }
.brand h1 { margin: 0; font-size: 30px; letter-spacing: .3em; padding-left: .3em; font-weight: 700; color: var(--title); }
.brand p { margin: 0; color: var(--text-2); font-size: 15px; }
.auth form, .auth-body { display: flex; flex-direction: column; gap: 15px; }
.auth-body p { margin: 0; }
.auth-foot { display: flex; justify-content: center; flex-wrap: wrap; gap: 5px; }
.devlink {
  padding: 15px; border-radius: var(--r-m); border: 1px dashed var(--line-strong);
  font-size: 14px; word-break: break-all;
}
.devlink a { color: var(--link); font-weight: 600; }

/* ---------- Accueil ---------- */
.home { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  margin: 10px 10px 0; padding: 5px 10px;
  border-radius: var(--r-l);
  display: flex; align-items: center; gap: 10px;
  padding-top: max(5px, env(safe-area-inset-top));
}
.wordmark { font-weight: 700; letter-spacing: .25em; font-size: 15px; color: var(--title); padding: 0 5px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 0 15px; border-radius: var(--r-m);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-2);
}
.search input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; font-size: 16px; }
.search .icon { width: 20px; height: 20px; }
.topbar .tools { display: flex; gap: 5px; }

.banner {
  margin: 10px 10px 0; padding: 10px 15px; border-radius: var(--r-m);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 14px;
}
.banner span { flex: 1; min-width: 200px; }

.tiles {
  flex: 1;
  display: grid; gap: 20px;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: minmax(260px, 1.4fr) minmax(160px, 1fr);
  padding: 20px; max-width: 1280px; width: 100%; margin: 0 auto;
}
.tile {
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 25px; text-align: center;
  border-radius: var(--r-l);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), background .2s;
}
.tile:hover { transform: translateY(-3px) scale(1.01); box-shadow: var(--shadow); background: var(--tile-hover); }
.tile:hover { background: var(--surface); }
.tile:active { transform: scale(.98); }
.tile .icon { width: 40px; height: 40px; color: var(--title); }
.tile b { font-size: 24px; font-weight: 600; }
.tile small { color: var(--text-2); font-size: 14px; }
.tile-lab { grid-column: 1 / -1; }
/* Le tableau vu de loin, derrière le verre de la tuile */
.tile-preview {
  position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%;
  filter: blur(1.5px); opacity: .55; transform: scale(1.03);
  transition: opacity .3s, filter .3s, transform .5s var(--ease);
}
.tile::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(ellipse at center, var(--surface) 0%, color-mix(in srgb, var(--surface) 55%, transparent) 45%, transparent 85%);
}
.tile:hover .tile-preview { opacity: .75; filter: blur(.5px); transform: scale(1); }
html[data-glass="off"] .tile-preview { filter: none; opacity: .3; }
.tile-lab b { font-size: 38px; }
.tile-lab .icon { width: 56px; height: 56px; }
.tile .soon {
  position: absolute; top: 20px; right: 20px;
  font-size: 12px; font-weight: 600; letter-spacing: .05em;
  padding: 5px 10px; border-radius: 50px; border: 1px solid var(--line-strong); color: var(--text-2);
}

/* ---------- Feuille de réglages ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); animation: fade .2s; }
.sheet {
  position: fixed; z-index: 41; top: 10px; right: 10px; bottom: 10px;
  width: min(420px, calc(100% - 20px));
  border-radius: var(--r-xl);
  padding: 25px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 25px;
  animation: slide .3s var(--ease);
}
.sheet header { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font-size: 24px; color: var(--title); }
.sheet section { display: flex; flex-direction: column; gap: 10px; }
.sheet h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.switch {
  position: relative; width: 50px; height: 30px; flex: none;
  border-radius: 30px; border: 0; background: var(--line-strong);
  transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .2s var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.account-box { padding: 15px; border-radius: var(--r-m); background: var(--surface); border: 1px solid var(--line); font-size: 14px; display: flex; flex-direction: column; gap: 5px; }
.account-box b { font-size: 16px; word-break: break-all; }

/* ---------- Fenêtre de confirmation ---------- */
.dialog {
  position: fixed; z-index: 51; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(400px, calc(100% - 30px));
  padding: 25px; border-radius: var(--r-xl);
  display: flex; flex-direction: column; gap: 15px;
}
.dialog h2 { margin: 0; font-size: 20px; }
.dialog p { margin: 0; color: var(--text-2); }
.dialog .actions { display: flex; gap: 10px; }
.dialog .actions .btn { flex: 1; }

/* ---------- Bulles d'info (avec Annuler) ---------- */
.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  width: min(480px, calc(100% - 30px));
}
.toast {
  display: flex; align-items: center; gap: 15px;
  padding: 10px 10px 10px 20px; border-radius: var(--r-l);
  font-size: 15px; animation: rise .3s var(--ease);
}
.toast span { flex: 1; }

.busy { display: inline-flex; gap: 5px; }
.busy i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: dot 1s infinite; }
.busy i:nth-child(2) { animation-delay: .15s; }
.busy i:nth-child(3) { animation-delay: .3s; }

@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
@keyframes rise { from { transform: translateY(15px); opacity: 0; } }
@keyframes dot { 0%, 100% { transform: translateY(0); opacity: .4; } 50% { transform: translateY(-5px); opacity: 1; } }

/* ---------- Téléphone ---------- */
@media (max-width: 720px) {
  .tiles { grid-template-columns: 1fr 1fr; grid-template-rows: auto; padding: 15px; gap: 15px; }
  .tile-lab { min-height: 200px; }
  .tile { min-height: 150px; padding: 40px 15px 20px; }
  .tile .soon { top: 10px; right: 10px; font-size: 11px; padding: 3px 8px; }
  .tile b { font-size: 20px; }
  .tile-lab b { font-size: 30px; }
  .tile-lab, .tile[data-room="dossiers"] { grid-column: 1 / -1; }
  .tile[data-room="dossiers"] { min-height: 120px; }
  .topbar { flex-wrap: wrap; row-gap: 5px; padding-bottom: 10px; }
  .wordmark { flex: 1; }
  .topbar .tools .tool { min-width: 50px; padding: 5px; }
  .search { order: 3; flex-basis: 100%; }
  .banner { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Voyant de synchro (en bas à gauche) */
.sync-pill {
  position: fixed; z-index: 35; left: 20px; bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 6px; padding: 5px 12px 5px 9px; border-radius: 50px;
  font-size: 12px; font-weight: 600; color: var(--text-2); pointer-events: auto;
}
.sync-pill .icon { width: 17px; height: 17px; }
.sync-pill[data-state="busy"] .icon { animation: dot 1s infinite; }
.sync-pill[data-state="offline"], .sync-pill[data-state="error"] { color: var(--danger); }
