/* ==========================================================================
   Design tokens
   Palette et typographie pensées pour le sujet : cryptographie à réseaux
   euclidiens (ML-KEM = "lattice-based"), matériel NAS (LED cyan/ambre des
   baies réseau). Fond indigo-ardoise sombre façon salle serveur, deux
   accents porteurs de sens (cyan = session active, ambre = renégociation),
   motif de points en grille = le "lattice" rendu visible.
   ========================================================================== */
:root {
  --bg: #12141f;
  --surface: #1b1f2e;
  --surface-alt: #232840;
  --border: #2b3149;
  --accent: #5fe0c4;
  --accent-dim: #2e7f6c;
  --warn: #f0a84e;
  --danger: #e2637a;
  --text: #edeef3;
  --text-muted: #8890a6;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, "Inter", system-ui, sans-serif;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow: hidden;
}

#app {
  height: 100dvh;
  height: 100vh;
  position: relative;
}

.view {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.view.hidden { display: none; }

button {
  font-family: var(--sans);
  cursor: pointer;
  border: none;
  border-radius: 10px;
}
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="text"] {
  font-family: var(--sans);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px; /* évite le zoom automatique iOS */
  width: 100%;
}
input[type="text"]::placeholder { color: var(--text-muted); }

/* ==========================================================================
   Écran de configuration (première ouverture)
   ========================================================================== */
#view-setup {
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.lattice-bg {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--accent-dim) 1.4px, transparent 1.4px);
  background-size: 34px 34px;
  opacity: 0.22;
  mask-image: radial-gradient(ellipse at center, black 0%, transparent 72%);
  pointer-events: none;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin: 0 0 10px;
  text-transform: uppercase;
}

.setup-card h1 {
  font-size: 22px;
  margin: 0 0 8px;
  font-weight: 650;
}

.lede {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 22px;
}

label {
  display: block;
  margin-bottom: 14px;
}
label span {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #0a1512;
  font-weight: 650;
  font-size: 15px;
  padding: 13px;
  margin-top: 4px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 9px 14px;
  font-size: 13px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent-dim); }

.setup-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  min-height: 18px;
  margin: 14px 0 0;
}
.setup-status.error { color: var(--danger); }

.selftest-toggle {
  width: 100%;
  margin-top: 16px;
  font-size: 12px;
}
.selftest-results {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  color: var(--accent);
  max-height: 160px;
  overflow-y: auto;
}
.selftest-results.error { color: var(--danger); }
.selftest-results p { margin: 0; }

/* ===== Écrans (liste de conversations / conversation individuelle) ===== */
#screen-list, #screen-chat {
  height: 100%;
  display: flex;
  flex-direction: column;
}
#screen-list.hidden, #screen-chat.hidden { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: block;
}
.brand-name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--text);
}

.identity-sub {
  padding: 2px 16px 10px;
  margin: 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.list-tabs { margin: 12px 16px 0; }

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}
.convo-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border-radius: 10px;
  padding: 10px 8px;
  text-align: left;
  color: var(--text);
}
.convo-item:hover { background: var(--surface-alt); }
.convo-avatar {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--bg);
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.convo-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.convo-name { font-size: 14px; font-weight: 600; }
.convo-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-time {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
}

.chat-peer-name { font-size: 14px; font-weight: 600; }

.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0 12px;
}

.call-banner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.call-banner.hidden { display: none; }
.call-banner p {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.call-banner-actions {
  display: flex;
  gap: 10px;
}
.call-banner-actions button { flex: 1; }
.call-banner-actions.hidden,
.call-banner-actions button.hidden { display: none; }

/* ==========================================================================
   Écran principal
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.identity-name {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-muted);
}
.identity-name b { color: var(--text); }

/* Le "cipher strip" : signature du produit — rend visible, en continu,
   la pile cryptographique réellement utilisée pour la session en cours. */
.cipher-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.cipher-strip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.4s ease, box-shadow 0.4s ease;
}
.cipher-strip .dot.live {
  background: var(--accent);
  box-shadow: 0 0 6px 1px var(--accent-dim);
}
.cipher-strip .dot.handshake {
  background: var(--warn);
  box-shadow: 0 0 6px 1px var(--warn);
  animation: pulse 0.9s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .cipher-strip .dot.handshake { animation: none; }
}

.convo-panel {
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.convo-panel.hidden { display: none; }
.convo-panel-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.convo-panel-actions .btn-primary,
.convo-panel-actions .btn-ghost { flex: 1; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  margin: auto;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  max-width: 260px;
}

.bubble {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
}
.bubble.mine {
  align-self: flex-end;
  background: var(--accent-dim);
  color: var(--text);
  border-bottom-right-radius: 4px;
}
.bubble.theirs {
  align-self: flex-start;
  background: var(--surface-alt);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.bubble .meta {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  opacity: 0.8;
}
.bubble.mine .meta { text-align: right; }

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.composer input { flex: 1; }
.composer button {
  background: var(--accent);
  color: #0a1512;
  font-weight: 650;
  padding: 0 18px;
}
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

.mic-btn {
  background: var(--surface-alt) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  font-size: 17px;
  width: 42px !important;
  height: 42px !important;
  flex-shrink: 0;
}
.mic-btn.recording {
  background: var(--danger) !important;
  color: white !important;
  border-color: var(--danger);
  animation: pulse 1s ease-in-out infinite;
}

.bubble audio {
  display: block;
  max-width: 220px;
  height: 34px;
}

.tab-switch {
  display: flex;
  gap: 6px;
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.tab-btn {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  padding: 9px 8px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--accent);
}

.icon-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent-dim); }

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.info-panel {
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}
.info-panel.hidden { display: none; }
.info-panel h3 {
  color: var(--text);
  font-size: 13px;
  margin: 0 0 8px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.info-panel ul { margin: 0 0 12px; padding-left: 18px; }
.info-panel .warn-box {
  background: rgba(240, 168, 78, 0.1);
  border: 1px solid var(--warn);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 12px;
}
