/* ============================================================
   DESIGN SYSTEM
   ============================================================ */
:root {
  --bg-base: #080b14;
  --bg-raise: #0e1322;
  --bg-float: #151b2e;

  --surface-1: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.09);

  --border-1: rgba(255, 255, 255, 0.07);
  --border-2: rgba(255, 255, 255, 0.12);
  --border-3: rgba(255, 255, 255, 0.2);

  --text-1: #f1f5ff;
  --text-2: #97a3c2;
  --text-3: #5f6b8a;
  --text-4: #3d4661;

  --accent-cyan: #22d3ee;
  --accent-violet: #8b5cf6;
  --accent-pink: #ec4899;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --grad-primary: linear-gradient(135deg, #22d3ee 0%, #8b5cf6 50%, #ec4899 100%);
  --grad-soft: linear-gradient(135deg, rgba(34, 211, 238, 0.15), rgba(139, 92, 246, 0.15));

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 32px rgba(139, 92, 246, 0.4);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

  --header-h: 64px;
  --input-h: 56px;
}

[data-theme="light"] {
  --bg-base: #f5f7fc;
  --bg-raise: #ffffff;
  --bg-float: #ffffff;

  --surface-1: rgba(15, 23, 42, 0.03);
  --surface-2: rgba(15, 23, 42, 0.05);
  --surface-3: rgba(15, 23, 42, 0.08);

  --border-1: rgba(15, 23, 42, 0.08);
  --border-2: rgba(15, 23, 42, 0.13);
  --border-3: rgba(15, 23, 42, 0.22);

  --text-1: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --text-4: #cbd5e1;

  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 0 32px rgba(139, 92, 246, 0.2);
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  margin: 0;
  padding: 0;
}

*::selection {
  background: rgba(139, 92, 246, 0.35);
  color: var(--text-1);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-1);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-overflow-scrolling: touch;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

button { cursor: pointer; }

svg {
  flex-shrink: 0;
  display: block;
}

/* ============================================================
   BACKGROUND
   ============================================================ */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  will-change: transform;
}

.bg-orb-1 {
  width: 480px;
  height: 480px;
  background: radial-gradient(circle, #22d3ee, transparent 70%);
  top: -180px;
  left: -160px;
  animation: orb-float 22s ease-in-out infinite;
}

.bg-orb-2 {
  width: 560px;
  height: 560px;
  background: radial-gradient(circle, #8b5cf6, transparent 70%);
  bottom: -240px;
  right: -180px;
  animation: orb-float 26s ease-in-out infinite reverse;
}

.bg-orb-3 {
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, #ec4899, transparent 70%);
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: orb-float 30s ease-in-out infinite;
  opacity: 0.3;
}

[data-theme="light"] .bg-orb { opacity: 0.22; }
[data-theme="light"] .bg-orb-3 { opacity: 0.15; }

@keyframes orb-float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -30px) scale(1.08); }
}

.bg-noise {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

[data-theme="light"] .bg-noise { opacity: 0.015; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.viewport {
  width: 100%;
  max-width: 640px;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ============================================================
   SCREENS
   ============================================================ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease);
}

.screen[hidden] {
  display: none;
}

.screen.entering {
  opacity: 0;
  transform: translateX(24px);
}

/* ============================================================
   SETUP SCREEN
   ============================================================ */
.screen-setup {
  justify-content: center;
  align-items: center;
  padding: 24px 20px;
  overflow-y: auto;
}

.setup-shell {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setup-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.setup-logo {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  background: var(--grad-primary);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-glow);
  animation: logo-pulse 4s ease-in-out infinite;
}

.setup-logo svg {
  width: 32px;
  height: 32px;
  stroke: #fff;
  stroke-width: 2.2;
}

@keyframes logo-pulse {
  0%, 100% { box-shadow: 0 0 28px rgba(139, 92, 246, 0.4); }
  50% { box-shadow: 0 0 44px rgba(139, 92, 246, 0.7); }
}

.setup-title {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.8px;
  line-height: 1.15;
}

.setup-title .grad {
  background: var(--grad-primary);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: grad-shift 6s ease infinite;
}

@keyframes grad-shift {
  0%, 100% { background-position: 0% center; }
  50% { background-position: 100% center; }
}

.setup-subtitle {
  color: var(--text-2);
  font-size: 0.92rem;
  line-height: 1.55;
  max-width: 340px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  padding: 22px;
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  box-shadow: var(--shadow-lg);
  position: relative;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 12%;
  right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  pointer-events: none;
}

/* ============================================================
   FORM FIELDS
   ============================================================ */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.field:last-child { margin-bottom: 0; }

.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-2);
}

.field-label svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  stroke-width: 2.2;
}

.field-hint {
  font-size: 0.72rem;
  color: var(--text-3);
  line-height: 1.5;
  padding-left: 2px;
}

.input, .textarea {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text-1);
  font-size: 0.95rem;
  line-height: 1.4;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

[data-theme="light"] .input,
[data-theme="light"] .textarea {
  background: rgba(255, 255, 255, 0.6);
}

.input::placeholder, .textarea::placeholder {
  color: var(--text-4);
}

.input:focus, .textarea:focus {
  border-color: rgba(139, 92, 246, 0.55);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12);
  background: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] .input:focus,
[data-theme="light"] .textarea:focus {
  background: rgba(255, 255, 255, 0.95);
}

.input-mono { font-family: 'JetBrains Mono', monospace; font-size: 0.88rem; }

.input-wrap { position: relative; }
.input-wrap .input { padding-right: 48px; }
.input-wrap .input.btn-pad { padding-right: 100px; }

.input-action {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.76rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s var(--ease);
}

.input-action:hover {
  background: var(--surface-3);
  color: var(--text-1);
}

.input-action svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  stroke-width: 2.4;
}

.input-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text-3);
  transition: all 0.2s var(--ease);
}

.input-icon:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

.input-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.1px;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
  min-height: 48px;
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2.4;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:active:not(:disabled) {
  transform: scale(0.975);
}

.btn-primary {
  color: #fff;
  background: var(--grad-primary);
  background-size: 200% auto;
  box-shadow: 0 8px 24px -8px rgba(139, 92, 246, 0.65);
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background-position: 100% center;
  box-shadow: 0 12px 32px -8px rgba(139, 92, 246, 0.85);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-1);
  border: 1px solid var(--border-1);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border-2);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.2);
}

.btn-sm {
  padding: 10px 16px;
  font-size: 0.82rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

/* ============================================================
   HOME HEADER
   ============================================================ */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(8, 11, 20, 0.7);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-bottom: 1px solid var(--border-1);
  flex-shrink: 0;
  z-index: 10;
}

[data-theme="light"] .header {
  background: rgba(255, 255, 255, 0.8);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.3px;
  flex-shrink: 0;
  transition: transform 0.15s var(--ease);
  position: relative;
}

.avatar-md {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  font-size: 1rem;
}

.avatar-lg {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 1.1rem;
}

.avatar-clickable { cursor: pointer; }
.avatar-clickable:active { transform: scale(0.94); }

.avatar-group::after {
  content: '👥';
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-raise);
  border: 2px solid var(--bg-base);
  display: grid;
  place-items: center;
  font-size: 9px;
}

.header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-sub {
  font-size: 0.72rem;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  color: var(--text-2);
  display: grid;
  place-items: center;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text-1);
  border-color: var(--border-2);
}

.icon-btn:active { transform: scale(0.94); }

.icon-btn svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2.2;
}

/* Sombre : soleil (pour passer en clair). Clair : lune (pour passer en sombre). */
.icon-btn .icon-moon { display: none; }
[data-theme="light"] .icon-btn .icon-moon { display: block; }
[data-theme="light"] .icon-btn .icon-sun { display: none; }

/* ============================================================
   HOME BODY
   ============================================================ */
.home-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px calc(140px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.home-body::-webkit-scrollbar { width: 4px; }
.home-body::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 100px;
}

.search-bar {
  position: relative;
  flex-shrink: 0;
}

.search-bar svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  stroke: var(--text-3);
  stroke-width: 2.2;
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  font-size: 0.9rem;
  transition: all 0.2s var(--ease);
}

.search-bar input::placeholder { color: var(--text-4); }

.search-bar input:focus {
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
}

.section-title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 8px 4px 4px;
}

/* ============================================================
   CONTACT CARDS
   ============================================================ */
.contact-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contact-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  min-height: 68px;
}

.contact-card:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
  transform: translateX(2px);
}

.contact-card:active {
  transform: scale(0.99);
}

.contact-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.contact-name {
  font-size: 0.96rem;
  font-weight: 700;
  letter-spacing: -0.1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-meta {
  font-size: 0.75rem;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.contact-actions button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text-3);
  transition: all 0.2s var(--ease);
}

.contact-actions button:hover {
  background: var(--surface-3);
  color: var(--text-1);
}

.contact-actions button.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.contact-actions button svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 2.2;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 24px;
  gap: 12px;
}

.empty-state-icon {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: var(--grad-soft);
  border: 1px solid var(--border-2);
  display: grid;
  place-items: center;
  margin-bottom: 4px;
}

.empty-state-icon svg {
  width: 32px;
  height: 32px;
  stroke: var(--accent-violet);
  stroke-width: 1.8;
}

.empty-state h3 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.empty-state p {
  font-size: 0.87rem;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 320px;
}

/* ============================================================
   FLOATING ADD BUTTON
   ============================================================ */
.floating-actions {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 20;
  pointer-events: none;
}

.floating-actions > * {
  pointer-events: auto;
}

.floating-actions .btn-primary {
  flex: 1;
  box-shadow: 0 12px 32px -8px rgba(139, 92, 246, 0.7), var(--shadow-md);
}

.floating-actions .btn-secondary {
  width: 56px;
  flex-shrink: 0;
  background: var(--bg-float);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-md);
}

/* ============================================================
   CHAT SCREEN
   ============================================================ */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(8, 11, 20, 0.75);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-bottom: 1px solid var(--border-1);
  flex-shrink: 0;
  z-index: 10;
}

[data-theme="light"] .chat-header {
  background: rgba(255, 255, 255, 0.85);
}

.chat-header .back-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.chat-header .back-btn:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

.chat-header .back-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.4;
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-3);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
  transition: all 0.3s var(--ease);
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot.connecting {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================================
   MESSAGES
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  position: relative;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 100px;
}

/* Waiting overlay */
.waiting {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  gap: 16px;
  text-align: center;
  background: rgba(8, 11, 20, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 5;
}

[data-theme="light"] .waiting {
  background: rgba(245, 247, 252, 0.8);
}

.waiting[hidden] { display: none; }

.waiting-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent-violet);
  animation: spin 0.9s linear infinite;
}

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

.waiting-title {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.waiting-text {
  font-size: 0.82rem;
  color: var(--text-2);
  line-height: 1.55;
  max-width: 280px;
}

/* Message bubbles */
.msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.92rem;
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere;
  animation: msg-in 0.28s var(--ease-bounce);
  position: relative;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-mine {
  align-self: flex-end;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 12px -4px rgba(139, 92, 246, 0.5);
}

.msg-theirs {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  color: var(--text-1);
  border-bottom-left-radius: 6px;
}

.msg-sender {
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.85;
  margin-bottom: 3px;
  letter-spacing: 0.2px;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.65rem;
  margin-top: 4px;
  opacity: 0.7;
}

.msg-mine .msg-meta { justify-content: flex-end; }
.msg-theirs .msg-meta { justify-content: flex-start; }

.msg-meta svg {
  width: 11px;
  height: 11px;
  stroke: currentColor;
  stroke-width: 2.5;
}

/* System messages */
.sys-msg {
  align-self: center;
  font-size: 0.75rem;
  color: var(--text-3);
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  text-align: center;
  max-width: 90%;
  animation: msg-in 0.3s var(--ease);
  line-height: 1.4;
}

.sys-msg.warn {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--warning);
}

.sys-msg.ok {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: var(--success);
}

.sys-msg.err {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

/* File message */
.msg-file {
  max-width: 82%;
  padding: 12px;
  border-radius: 18px;
  animation: msg-in 0.28s var(--ease-bounce);
}

.msg-file.msg-mine {
  align-self: flex-end;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg-file.msg-theirs {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-bottom-left-radius: 6px;
}

.msg-file .msg-sender {
  margin-bottom: 8px;
}

.msg-file img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 12px;
  display: block;
  margin-bottom: 8px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-icon-box {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.15);
}

.msg-theirs .file-icon-box {
  background: var(--surface-3);
}

.file-icon-box svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2.2;
}

.file-text {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 2px;
}

.file-open {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.72rem;
  font-weight: 700;
  transition: background 0.2s var(--ease);
  flex-shrink: 0;
}

.msg-theirs .file-open {
  background: var(--surface-3);
}

.file-open:hover {
  background: rgba(255, 255, 255, 0.28);
}

.msg-theirs .file-open:hover {
  background: rgba(255, 255, 255, 0.15);
}

.file-open svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 2.4;
}

/* Typing indicator */
.typing {
  align-self: flex-start;
  padding: 12px 16px;
  border-radius: 18px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  display: flex;
  gap: 4px;
  border-bottom-left-radius: 6px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: bounce 1.4s ease-in-out infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ============================================================
   CHAT INPUT BAR
   ============================================================ */
.chat-input-bar {
  flex-shrink: 0;
  background: rgba(8, 11, 20, 0.85);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-top: 1px solid var(--border-1);
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

[data-theme="light"] .chat-input-bar {
  background: rgba(255, 255, 255, 0.9);
}

/* File preview */
.file-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  animation: msg-in 0.2s var(--ease);
}

.file-preview[hidden] { display: none; }

.file-preview .file-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--accent-violet);
}

.file-preview-remove {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text-3);
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.file-preview-remove:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.file-preview-remove svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2.4;
}

/* Input row */
.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-row .attach-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  color: var(--text-2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.2s var(--ease);
}

.input-row .attach-btn:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

.input-row .attach-btn:active { transform: scale(0.94); }

.input-row .attach-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.2;
}

.chat-textarea {
  flex: 1;
  min-height: 46px;
  max-height: 120px;
  padding: 12px 16px;
  border-radius: 23px;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  font-size: 0.95rem;
  line-height: 1.4;
  resize: none;
  transition: all 0.2s var(--ease);
}

.chat-textarea::placeholder { color: var(--text-4); }

.chat-textarea:focus {
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
}

.chat-send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--grad-primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 6px 20px -6px rgba(139, 92, 246, 0.7);
  transition: all 0.2s var(--ease);
}

.chat-send:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: scale(1.04);
}

.chat-send:active:not(:disabled) {
  transform: scale(0.94);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.4;
}

.hidden-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  background: var(--bg-raise);
  border: 1px solid var(--border-2);
  border-radius: 26px 26px 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateY(30px);
  transition: transform 0.32s var(--ease-bounce);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

[data-theme="light"] .modal {
  background: #fff;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--border-1);
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text-2);
  display: grid;
  place-items: center;
  transition: all 0.2s var(--ease);
}

.modal-close:hover {
  background: var(--surface-3);
  color: var(--text-1);
}

.modal-close svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2.4;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 100px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 22px 20px;
  border-top: 1px solid var(--border-1);
  flex-shrink: 0;
}

.modal-footer .btn {
  flex: 1;
}

/* Hint box */
.hint {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.2);
  font-size: 0.79rem;
  line-height: 1.55;
  color: var(--text-2);
  margin-top: 14px;
}

.hint svg {
  width: 15px;
  height: 15px;
  stroke: var(--accent-violet);
  stroke-width: 2.2;
  flex-shrink: 0;
  margin-top: 1px;
}

.hint strong { color: var(--text-1); font-weight: 600; }

/* Identity display */
.info-block {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  margin-bottom: 12px;
}

.info-block:last-child { margin-bottom: 0; }

.info-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent-violet);
  margin-bottom: 6px;
}

.info-value {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  word-break: break-word;
}

.info-value.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  font-weight: 600;
}

.info-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.info-actions button {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.25);
  color: var(--accent-violet);
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s var(--ease);
}

.info-actions button:hover {
  background: rgba(139, 92, 246, 0.2);
}

.info-actions button svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  stroke-width: 2.4;
}

/* ============================================================
   TOASTS
   ============================================================ */
.toasts {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-float);
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-lg);
  font-size: 0.87rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.36s var(--ease-bounce);
  pointer-events: auto;
}

[data-theme="light"] .toast {
  background: rgba(255, 255, 255, 0.98);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast.out {
  animation: toast-out 0.25s var(--ease) forwards;
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(-10px) scale(0.96); }
}

.toast-icon {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.toast-icon svg {
  width: 13px;
  height: 13px;
  stroke-width: 2.5;
}

.toast.success .toast-icon { background: rgba(16, 185, 129, 0.18); }
.toast.success .toast-icon svg { stroke: var(--success); }
.toast.error .toast-icon { background: rgba(239, 68, 68, 0.18); }
.toast.error .toast-icon svg { stroke: var(--danger); }
.toast.info .toast-icon { background: rgba(34, 211, 238, 0.18); }
.toast.info .toast-icon svg { stroke: var(--accent-cyan); }

/* ============================================================
   IN-APP NOTIFICATION BANNER
   ============================================================ */
.notif-banner {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translate(-50%, -20px);
  z-index: 500;
  max-width: calc(100% - 32px);
  width: 420px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--grad-primary);
  color: #fff;
  font-size: 0.87rem;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(139, 92, 246, 0.5);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s var(--ease-bounce);
  cursor: pointer;
}

.notif-banner.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.notif-banner svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2.4;
  flex-shrink: 0;
}

.notif-banner span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   HIDDEN
   ============================================================ */
/* ============================================================
   APPELS VIDÉO
   ============================================================ */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: #05070d;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.call-local {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  width: 104px;
  height: 148px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid var(--border-2);
  background: #000;
  transform: scaleX(-1);
}

.call-controls {
  position: absolute;
  bottom: calc(26px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
}

.call-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-size: 1.3rem;
  display: grid;
  place-items: center;
}

.call-btn.off { background: rgba(239, 68, 68, 0.45); }

.call-btn.danger {
  background: #ef4444;
  width: 66px;
  height: 66px;
}

.call-status {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.install-steps {
  font-size: 0.82rem;
  color: var(--text-2);
  line-height: 1.6;
  margin-top: 10px;
}

[hidden] { display: none !important; }

/* ============================================================
   SAFE AREA
   ============================================================ */
@supports (padding: env(safe-area-inset-top)) {
  .header, .chat-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
}

/* ============================================================
   ANIMATIONS PREF
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 380px) {
  .header, .chat-header { padding-left: 12px; padding-right: 12px; }
  .home-body { padding-left: 12px; padding-right: 12px; }
  .floating-actions { left: 12px; right: 12px; }
  .card { padding: 18px; }
  .setup-title { font-size: 1.45rem; }
}


/* ---- Ajouts v6 : vocal, éphémères, PIN ---- */
.icon-btn.recording, .attach-btn.recording { color: var(--danger); animation: rec-pulse 1s infinite; }
@keyframes rec-pulse { 50% { opacity: 0.45; } }
.msg-file audio { width: 100%; max-width: 260px; margin-bottom: 6px; }
.ttl-help { font-size: 0.85rem; color: var(--text-2); line-height: 1.6; margin-bottom: 14px; }
.ttl-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ttl-option { padding: 12px; border-radius: var(--radius-md); border: 1px solid var(--border-2); background: var(--surface-1); color: var(--text-1); font: inherit; font-weight: 600; cursor: pointer; }
.ttl-option.selected { border-color: var(--accent-violet); background: var(--grad-soft); }
.lock-screen { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--bg-base); }
.lock-screen[hidden] { display: none !important; }
.lock-box { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.lock-title { font-size: 1.2rem; font-weight: 700; color: var(--text-1); }
.lock-text { font-size: 0.9rem; color: var(--text-2); }
.lock-input { text-align: center; font-size: 1.4rem; letter-spacing: 0.4em; }
.lock-error { color: var(--danger); font-size: 0.85rem; }
.lock-error[hidden] { display: none; }
.pin-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.pin-row .input { flex: 1; min-width: 120px; }

.ping-btn { margin-top: 8px; }
