:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #74808c;
  --blue: #2463eb;
  --blue-dark: #174bc0;
  --line: #e5e9ee;
  --surface: #fff;
  --page: #f4f6f8;
  --pink: #f7dce8;
  --received: #dceaff;
  --shadow: 0 5px 22px rgba(25, 39, 55, .055);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(36, 99, 235, .2); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.app-shell { min-height: 100vh; }

/* Connexion et inscription */
.auth-view {
  width: min(420px, calc(100% - 32px));
  margin: 0 auto;
  padding: 58px 0 32px;
  text-align: center;
}
.brand-mark, .wake-logo, .brand-mini {
  display: grid;
  place-items: center;
  background: #172d4b;
  color: #fff;
  font-weight: 800;
}
.brand-mark, .wake-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  font-size: 29px;
}
.auth-view > h1 { margin: 0; font-size: 30px; letter-spacing: -.7px; }
.intro { margin: 7px 0 27px; }
.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.form-card { padding: 24px; text-align: left; }
.form-card h2 { margin: 0 0 20px; font-size: 20px; }
label { display: grid; gap: 7px; margin: 14px 0; font-size: 13px; font-weight: 650; }
input {
  width: 100%;
  min-width: 0;
  padding: 12px 13px;
  border: 1px solid #dce2e8;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(36, 99, 235, .09); }
.primary-btn, .secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 11px 16px;
  border: 0;
  border-radius: 9px;
  font-weight: 700;
  transition: background .15s ease, transform .15s ease;
}
.primary-btn { background: var(--blue); color: #fff; }
.primary-btn:hover { background: var(--blue-dark); }
.secondary-btn { background: #edf2f8; color: #24466e; }
.secondary-btn:hover { background: #e2eaf4; }
.form-card > .primary-btn { width: 100%; margin-top: 8px; }
.switch-line { margin: 18px 0 0; color: var(--muted); text-align: center; font-size: 13px; }
.text-btn { padding: 5px; border: 0; background: transparent; color: var(--blue); font-weight: 700; }
.text-btn:hover { text-decoration: underline; }
.notice { min-height: 18px; color: #bd3945; font-size: 13px; }
#auth-error { margin: 12px 0 0; }

/* Navigation et pages */
.topbar {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 max(20px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.97);
}
.brand-small { display: flex; align-items: center; gap: 9px; font-size: 18px; white-space: nowrap; }
.brand-mini { width: 31px; height: 31px; border-radius: 9px; }
.topbar nav { display: flex; align-items: center; gap: 5px; }
.nav-btn { padding: 10px 13px; border: 0; border-radius: 8px; background: transparent; color: #65717c; }
.nav-btn:hover, .nav-btn.active { background: #edf3ff; color: var(--blue); }
.nav-btn.active { font-weight: 700; }
.page { width: min(1120px, calc(100% - 32px)); margin: 32px auto; }
.page h2 { margin: 5px 0 21px; font-size: 25px; letter-spacing: -.4px; }
.eyebrow { margin: 0 0 7px; color: #82909c; font-size: 10px; font-weight: 800; letter-spacing: 1.5px; }

/* Profil */
.profile-card { margin-bottom: 18px; padding: 24px; }
.profile-main { display: flex; align-items: center; gap: 15px; }
.avatar-wrap {
  position: relative;
  display: grid;
  width: 66px;
  height: 66px;
  flex: 0 0 66px;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: #e7eef8;
  color: #315b91;
  font-size: 24px;
  font-weight: 750;
}
.avatar-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile-main h3 { margin: 0 0 5px; font-size: 20px; }
.profile-main p { margin: 0; font-size: 13px; }
.profile-stats { display: flex; flex-wrap: wrap; gap: 42px; margin: 22px 0; padding: 17px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.profile-stats div { display: grid; gap: 4px; }
.profile-stats strong { font-size: 17px; }
.profile-stats span { color: var(--muted); font-size: 12px; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.section-card { margin: 16px 0; padding: 21px; }
.section-card h3 { margin: 0 0 6px; font-size: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.count-pill { padding: 4px 9px; border-radius: 20px; background: #edf3ff; color: var(--blue); font-size: 12px; }
.stack-list { display: grid; gap: 9px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid #f0f2f4; }
.list-person { display: flex; min-width: 0; align-items: center; gap: 10px; }
.mini-avatar { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; overflow: hidden; border-radius: 50%; background: #e7eef8; color: #315b91; font-weight: 700; }
.mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.row-actions { display: flex; flex: 0 0 auto; gap: 6px; }
.row-actions button { padding: 8px 10px; border: 0; border-radius: 7px; background: #edf3ff; color: var(--blue); font-size: 12px; font-weight: 700; }
.row-actions .reject { background: #f6eeee; color: #a24b4b; }

/* Écran d'activation de la messagerie */
.wake-screen {
  display: grid;
  min-height: min(650px, calc(100vh - 125px));
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.wake-content { width: min(350px, calc(100% - 36px)); padding: 32px 24px; text-align: center; }
.wake-content h2 { margin: 0 0 10px; }
.wake-content p { line-height: 1.65; }
.wake-content > .primary-btn { width: 100%; margin-top: 12px; }
.wake-loading { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 22px; color: #586675; font-size: 13px; }
.spinner { width: 22px; height: 22px; flex: 0 0 22px; border: 3px solid #dce5f2; border-top-color: var(--blue); border-radius: 50%; animation: rotate .75s linear infinite; }
@keyframes rotate { to { transform: rotate(360deg); } }

/* Messagerie */
.messenger {
  display: grid;
  height: min(760px, calc(100vh - 125px));
  min-height: 480px;
  grid-template-columns: 275px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}
.contacts-panel { overflow-y: auto; padding: 18px; border-right: 1px solid var(--line); }
.contacts-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 18px; }
.contacts-heading h2 { margin: 0; font-size: 21px; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 8px; background: #f1f4f7; color: #536273; font-size: 20px; }
.network-choice { display: flex; width: 100%; align-items: center; gap: 11px; margin-bottom: 22px; padding: 12px; border: 1px solid #dfe8f6; border-radius: 9px; background: #f4f7fc; color: var(--ink); text-align: left; }
.network-choice.active { border-color: #cbdaf4; background: #edf3ff; }
.network-choice span:last-child { display: grid; gap: 4px; }
.network-choice small { color: var(--muted); font-size: 11px; }
.network-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #2aa66a; }
.contacts-label { margin-bottom: 10px; color: #8a949d; font-size: 10px; font-weight: 800; letter-spacing: 1.2px; }
.contacts-list { display: grid; gap: 4px; }
.contact-item { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; }
.contact-item:hover, .contact-item.active { background: #f1f5fa; }
.contact-item > span:last-child { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.empty-contacts { line-height: 1.6; }
.conversation-panel { display: flex; min-width: 0; flex-direction: column; }
.conversation-empty { margin: auto; padding: 25px; text-align: center; }
.empty-symbol { display: grid; width: 56px; height: 56px; place-items: center; margin: 0 auto 15px; border-radius: 16px; background: #eef3fa; color: #315b91; font-size: 27px; font-weight: 800; }
.conversation-empty h3 { margin: 0 0 7px; }
.conversation-header { display: flex; min-height: 68px; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.conversation-person { display: flex; min-width: 0; align-items: center; gap: 10px; }
.conversation-person > div { display: grid; min-width: 0; gap: 4px; }
.conversation-person small { color: var(--muted); font-size: 11px; }
.conversation-person strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-label { flex: 0 0 auto; color: #279766; font-size: 11px; }
.message-list { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 9px; overflow-y: auto; padding: 20px; }
.message { max-width: min(76%, 540px); padding: 10px 13px; border-radius: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.message.sent { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--pink); }
.message.received { align-self: flex-start; border-bottom-left-radius: 4px; background: var(--received); }
.message .sender { margin-bottom: 4px; color: #526579; font-size: 10px; font-weight: 800; }
.message time { display: block; margin-top: 5px; color: #6f7b86; font-size: 9px; text-align: right; }
.message-loading { padding: 8px; color: var(--muted); font-size: 12px; text-align: center; }
.message-form { display: flex; gap: 9px; padding: 14px; border-top: 1px solid var(--line); }
.message-form input { border-radius: 22px; padding: 12px 16px; }
.message-form button { width: 44px; flex: 0 0 44px; border: 0; border-radius: 50%; background: var(--blue); color: #fff; font-size: 18px; }
.message-form button:hover { background: var(--blue-dark); }

/* Paramètres, fenêtre modale et notifications */
.inline-form { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.inline-form input { max-width: 350px; }
.dialog { width: min(420px, calc(100% - 28px)); padding: 26px; border: 0; border-radius: 14px; box-shadow: 0 20px 70px rgba(23, 33, 43, .2); }
.dialog::backdrop { background: rgba(16, 24, 32, .42); }
.dialog form { position: relative; }
.dialog h2 { margin: 5px 0 8px; }
.dialog-close { position: absolute; top: 0; right: 0; width: 30px; height: 30px; border: 0; border-radius: 50%; background: #f1f3f5; font-size: 20px; }
.dialog .primary-btn { width: 100%; }
.toast { position: fixed; z-index: 20; bottom: 22px; left: 50%; max-width: calc(100% - 32px); padding: 11px 16px; transform: translate(-50%, 20px); border-radius: 9px; background: #17212b; color: #fff; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 720px) {
  .topbar { min-height: 62px; gap: 7px; padding: 0 10px; }
  .brand-small { gap: 6px; font-size: 15px; }
  .brand-mini { width: 28px; height: 28px; }
  .topbar nav { gap: 1px; }
  .nav-btn { padding: 9px 7px; font-size: 12px; }
  .topbar > .text-btn { font-size: 11px; white-space: nowrap; }
  .page { margin: 22px auto; }
  .messenger { height: calc(100dvh - 105px); min-height: 440px; grid-template-columns: 118px minmax(0, 1fr); }
  .contacts-panel { padding: 10px 7px; }
  .contacts-heading { margin-bottom: 13px; }
  .contacts-heading h2 { font-size: 16px; }
  .contacts-heading .eyebrow { font-size: 8px; }
  .contacts-heading .icon-btn { width: 30px; height: 30px; }
  .network-choice { gap: 6px; padding: 9px 6px; }
  .network-choice strong { font-size: 11px; }
  .network-choice small { font-size: 9px; }
  .contacts-label { font-size: 9px; letter-spacing: .6px; }
  .contact-item { gap: 6px; padding: 8px 5px; }
  .contact-item .mini-avatar { width: 28px; height: 28px; flex-basis: 28px; font-size: 11px; }
  .contact-item > span:last-child { font-size: 11px; }
  .conversation-header { min-height: 60px; padding: 0 10px; }
  .conversation-header .mini-avatar { width: 31px; height: 31px; flex-basis: 31px; }
  .conversation-person strong { max-width: 125px; font-size: 13px; }
  .online-label { font-size: 9px; }
  .message-list { padding: 12px 9px; }
  .message { max-width: 90%; padding: 9px 10px; font-size: 13px; }
  .message-form { gap: 6px; padding: 9px; }
  .message-form input { padding: 10px 12px; font-size: 13px; }
  .message-form button { width: 39px; flex-basis: 39px; }
}

@media (max-width: 420px) {
  .topbar { flex-wrap: wrap; justify-content: center; padding: 8px; }
  .topbar nav { order: 3; width: 100%; justify-content: center; }
  .topbar > .text-btn { margin-left: auto; }
  .profile-card, .section-card { padding: 17px; }
  .profile-stats { gap: 18px 26px; }
  .profile-actions > button { flex: 1 1 100%; }
  .list-row { align-items: flex-start; flex-direction: column; }
  .row-actions { align-self: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
