/* =====================================================================
   base.css — Variables, réinitialisation et composants communes
   (boutons, champs, onglets, badges, toasts) aux deux pages.
   ===================================================================== */

/* ---------- Variables de thème (clair par défaut) ---------- */
:root {
  --color-bg: #f4f6fa;
  --color-surface: #ffffff;
  --color-surface-2: #eef1f6;
  --color-border: #dde2ea;
  --color-text: #1b1f24;
  --color-muted: #667085;
  --color-primary: #4f7cff;
  --color-primary-hover: #3b66e6;
  --color-primary-text: #ffffff;
  --color-danger: #d1242f;
  --color-success: #1a7f37;
  --color-online: #2da44e;
  --color-bubble-mine: #4f7cff;
  --color-bubble-mine-text: #ffffff;
  --color-bubble-theirs: #ffffff;
  --color-read: #7ee2ff;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 12px rgb(16 24 40 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --transition: 150ms ease;

  color-scheme: light dark;
}

/* ---------- Thème sombre automatique (préférence du système) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f1216;
    --color-surface: #171b21;
    --color-surface-2: #212730;
    --color-border: #2c333d;
    --color-text: #e6e9ee;
    --color-muted: #98a2b3;
    --color-bubble-theirs: #212730;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 12px rgb(0 0 0 / 25%);
  }
}

/* ---------- Réinitialisation ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.muted { color: var(--color-muted); }
.text-online { color: var(--color-online); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background var(--transition), opacity var(--transition);
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--color-primary); color: var(--color-primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn-ghost { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-ghost:hover { background: var(--color-surface-2); }
.btn-danger { background: transparent; color: var(--color-danger); border-color: var(--color-danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--color-danger) 10%, transparent); }

/* Petit indicateur de chargement dans un bouton */
.btn.is-loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--color-surface-2); }
.icon-btn-small { width: 30px; height: 30px; font-size: 13px; color: var(--color-muted); }

/* ---------- Champs de formulaire ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 14px;
  padding: 0;
  border: none;
}
.field > span, .field > legend { font-size: 14px; font-weight: 600; padding: 0; }

input[type="text"], input[type="email"], input[type="password"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

/* ---------- Onglets ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--color-surface-2);
}
.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  font-weight: 600;
}
.tab.is-active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow); }

/* ---------- Badge (compteur de non-lus) ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Avatar et pastille de statut ---------- */
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  user-select: none;
}
.status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-surface);
  border-radius: 50%;
  background: var(--color-muted);
}
.status-dot.is-online { background: var(--color-online); }

/* ---------- Messages éphémères (toasts) ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--color-text);
  color: var(--color-bg);
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: slide-up 200ms ease;
}
.toast-error { background: var(--color-danger); color: #fff; }
.toast-success { background: var(--color-success); color: #fff; }
.toast.is-clickable { cursor: pointer; }

/* ---------- Alertes ---------- */
.alert { padding: 12px; margin-bottom: 16px; border-radius: var(--radius-sm); font-size: 14px; }
.alert-error {
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
  color: var(--color-danger);
}

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide-up { from { opacity: 0; transform: translateY(8px); } }

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