/* =========================================================
   Atelier Chat — tokens
   Encre profonde + laiton, esprit "carnet d'atelier".
   ========================================================= */
:root {
  --ink: #1f2a24;
  --ink-soft: #2b362f;
  --brass: #b8863b;
  --brass-light: #d9ae6e;
  --paper: #f3efe8;
  --paper-dim: #e8e2d6;
  --text: #26231d;
  --muted: #8b8378;
  --line: #d8d0c0;
  --danger: #b3452f;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --font-display: "Newsreader", "Iowan Old Style", Georgia, serif;
  --font-body: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

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

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea {
  font-family: inherit;
}

::selection { background: var(--brass-light); color: var(--ink); }

/* ---------- Écran de chargement ---------- */
.splash {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.02em;
}

/* ---------- Authentification ---------- */
.auth-screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px calc(32px + var(--safe-bottom));
  background: var(--ink);
  color: var(--paper);
}

.auth-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--paper);
  color: var(--brass);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.15;
  margin: 0 0 8px;
}

.auth-sub {
  color: #c9c2b3;
  font-size: 15px;
  line-height: 1.5;
  margin: 0 0 32px;
  max-width: 34ch;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brass-light);
}

.field input {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--paper);
  outline: none;
}
.field input::placeholder { color: #7f8b81; }
.field input:focus { border-color: var(--brass); }

.field input[data-code] {
  letter-spacing: 0.5em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.btn-primary {
  background: var(--brass);
  color: var(--ink);
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 600;
  width: 100%;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; }

.btn-link {
  background: none;
  border: none;
  color: var(--brass-light);
  font-size: 14px;
  padding: 12px 4px;
  text-align: left;
}

.auth-msg {
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}
.auth-msg.error { color: #e8886c; }
.auth-msg.ok { color: #9fd6ae; }

/* ---------- En-tête ---------- */
.topbar {
  padding: calc(14px + var(--safe-top)) 18px 14px;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.topbar .back {
  display: none;
  background: none;
  border: none;
  color: var(--brass-light);
  font-size: 20px;
  padding: 4px 8px 4px 0;
}
.topbar.with-back .back { display: block; }
.topbar-titles { flex: 1; min-width: 0; }
.topbar-title {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub {
  font-size: 12px;
  color: #a9b3ab;
  margin: 2px 0 0;
}
.topbar .signout {
  background: none;
  border: none;
  color: #a9b3ab;
  font-size: 13px;
}

/* ---------- Liste des clients (vue atelier) ---------- */
.thread-list {
  flex: 1;
  overflow-y: auto;
  background: var(--paper);
}

.thread-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: none;
  border-left: none; border-right: none; border-top: none;
  width: 100%;
  text-align: left;
}
.thread-row:active { background: var(--paper-dim); }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink-soft);
  color: var(--brass-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 17px;
  flex-shrink: 0;
}

.thread-row-body { flex: 1; min-width: 0; }
.thread-row-top { display: flex; justify-content: space-between; gap: 8px; }
.thread-name { font-weight: 600; font-size: 15px; }
.thread-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.thread-preview {
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.badge {
  background: var(--brass);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

.empty-state {
  padding: 60px 32px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}
.empty-state .tag {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

/* ---------- Fil de discussion ---------- */
.thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day-tag {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 14px;
  margin: 14px 0 10px;
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
}

.bubble-row { display: flex; margin: 2px 0; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row.in { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.4;
  border-radius: var(--radius-md);
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble-row.in .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.bubble-row.out .bubble {
  background: var(--ink);
  color: var(--paper);
  border-bottom-right-radius: 4px;
}
.bubble-time {
  font-size: 10.5px;
  opacity: 0.6;
  margin-top: 4px;
  display: block;
  text-align: right;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
}
.composer textarea:focus { border-color: var(--brass); }

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--brass);
  color: var(--ink);
  border: none;
  font-size: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.4; }

.thread-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  padding: 32px;
  text-align: center;
}

/* ---------- Layout mobile (un seul panneau à la fois) ---------- */
.app-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.thread-list-pane, .thread-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.app-shell:not(.mobile-thread-open) .thread-pane { display: none; }
.app-shell.mobile-thread-open .thread-list-pane { display: none; }

/* ---------- Layout desktop (panneau double) ---------- */
@media (min-width: 760px) {
  .app-shell { flex-direction: row; }
  .app-shell:not(.mobile-thread-open) .thread-pane { display: flex; }
  .app-shell.mobile-thread-open .thread-list-pane { display: flex; }
  .thread-list-pane {
    width: 340px;
    border-right: 1px solid var(--line);
    flex-shrink: 0;
    display: flex;
  }
  .thread-pane { flex: 1; display: flex; }
  .topbar.with-back .back { display: none; }
}

.hidden { display: none !important; }
