/* ════════════════════════════════════════════════════════════
   style.css — E2EE Chat · Design : "Terminal Sécurisé"
   Esthétique : sombre, typographie monospace, accents verts
   Inspiration : terminaux Unix + Signal + Keybase
   ════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;600;700&family=Inter:wght@300;400;500;600&display=swap');

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --bg-base:      #0a0c0f;
  --bg-surface:   #111418;
  --bg-elevated:  #181c22;
  --bg-input:     #1e232b;

  --border:       #252b35;
  --border-glow:  rgba(0, 255, 136, 0.3);

  --text-primary:   #e8edf5;
  --text-secondary: #7a8699;
  --text-muted:     #3d4654;

  --accent:         #00ff88;   /* vert terminal */
  --accent-dim:     #00cc6a;
  --accent-bg:      rgba(0, 255, 136, 0.08);

  --danger:         #ff4757;
  --danger-dim:     rgba(255, 71, 87, 0.15);

  --sent-bg:      #00ff8818;
  --received-bg:  #1e232b;

  --radius-sm:    6px;
  --radius:       12px;
  --radius-lg:    18px;

  --font-mono:  'JetBrains Mono', monospace;
  --font-ui:    'Inter', sans-serif;

  --shadow-glow: 0 0 20px rgba(0, 255, 136, 0.15);
  --transition:  0.18s ease;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout principal ────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ════════════════════════════════════════════════════════════
   ÉCRAN D'AUTH (login / register)
   ════════════════════════════════════════════════════════════ */
#auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 60% 40% at 50% -10%, rgba(0,255,136,0.12) 0%, transparent 70%),
    var(--bg-base);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 40px 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  color: var(--bg-base);
  flex-shrink: 0;
}

.auth-logo-text {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 18px;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.auth-logo-text span {
  color: var(--accent);
}

.auth-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 28px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.auth-tab.active {
  background: var(--bg-elevated);
  color: var(--accent);
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.12);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.remember-row input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--accent);
}

.remember-row label {
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--bg-base);
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: opacity var(--transition), transform var(--transition);
}

.btn-primary:hover    { opacity: 0.9; }
.btn-primary:active   { transform: scale(0.98); }
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.auth-notice {
  margin-top: 20px;
  padding: 10px 14px;
  background: var(--accent-bg);
  border: 1px solid rgba(0, 255, 136, 0.2);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--accent-dim);
  line-height: 1.5;
}

.auth-notice::before {
  content: '🔐 ';
}

#auth-error {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--danger-dim);
  border: 1px solid rgba(255, 71, 87, 0.3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--danger);
  display: none;
}

/* ════════════════════════════════════════════════════════════
   INTERFACE CHAT
   ════════════════════════════════════════════════════════════ */
#chat-screen {
  display: none;
  width: 100%;
  height: 100%;
}

#chat-screen.visible {
  display: flex;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
#sidebar {
  width: 280px;
  flex-shrink: 0;
  height: 100%;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.current-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--bg-base);
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 5px;
  animation: pulse 2s infinite;
}

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

.sidebar-users {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-section-label {
  padding: 10px 18px 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition);
  position: relative;
}

.user-item:hover {
  background: var(--bg-elevated);
}

.user-item.active {
  background: var(--accent-bg);
  border-left: 2px solid var(--accent);
}

.user-item .user-avatar {
  width: 36px; height: 36px;
  font-size: 14px;
}

.user-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.user-item-hint {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.btn-logout {
  width: 100%;
  padding: 9px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: var(--transition);
}

.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ── Zone de conversation ────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg-base);
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-info h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-header-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid rgba(0,255,136,0.2);
  border-radius: 20px;
  padding: 2px 8px;
  margin-top: 2px;
  display: inline-block;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 13px;
  gap: 12px;
}

.chat-empty-icon {
  font-size: 36px;
  opacity: 0.3;
}

/* ── Messages ────────────────────────────────────────────────── */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

#messages-container::-webkit-scrollbar { width: 4px; }
#messages-container::-webkit-scrollbar-track { background: transparent; }
#messages-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 68%;
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-wrapper.sent {
  align-self: flex-end;
  align-items: flex-end;
}

.message-wrapper.received {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.55;
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity var(--transition);
  overflow: hidden;
}

.message-wrapper.sent .message-bubble {
  background: var(--sent-bg);
  border: 1px solid rgba(0, 255, 136, 0.2);
  border-bottom-right-radius: 4px;
}

.message-wrapper.received .message-bubble {
  background: var(--received-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* État chiffré (par défaut) */
.message-bubble .msg-content {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

/* État déchiffré */
.message-bubble.revealed .msg-content {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-primary);
}

.message-bubble .msg-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.message-bubble.decrypt-error {
  animation: shake 0.4s ease;
  border-color: var(--danger) !important;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-5px); }
  75%       { transform: translateX(5px); }
}

.message-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

/* ── Barre de progression appui long ────────────────────────── */
.decrypt-progress {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: rgba(255,255,255,0.06);
  display: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.decrypt-progress.active {
  display: block;
}

.decrypt-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent);
}

/* ── Zone de saisie ─────────────────────────────────────────── */
#input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: none;
}

#input-area.visible {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#msg-input {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  resize: none;
  transition: border-color var(--transition);
  overflow-y: auto;
}

#msg-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.1);
}

#msg-input::placeholder {
  color: var(--text-muted);
}

#send-btn {
  width: 42px; height: 42px;
  flex-shrink: 0;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition), transform var(--transition);
}

#send-btn:hover  { opacity: 0.85; }
#send-btn:active { transform: scale(0.94); }

#send-btn svg {
  width: 18px; height: 18px;
  fill: var(--bg-base);
}

/* ── Loader ──────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ── Toast notifications ─────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  animation: toastIn 0.25s ease, toastOut 0.25s ease 3.5s forwards;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast.success { border-color: rgba(0,255,136,0.4); color: var(--accent); }
.toast.error   { border-color: rgba(255,71,87,0.4); color: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}

/* ── Generating key overlay ──────────────────────────────────── */
#keygen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 15, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1000;
}

.keygen-text {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 1px;
}

.keygen-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Responsive mobile ───────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 100;
  }
  #sidebar.open { display: flex; }
  #main { width: 100%; }
}
