:root {
  --brand: #5B4BFF;
  --brand-dark: #3F2EE0;
  --brand-soft: #EEF0FF;
  --accent: #FF7A59;
  --ink: #14142B;
  --ink-2: #363A5B;
  --muted: #6B7089;
  --line: #E6E8F0;
  --bg: #F5F6FB;
  --card: #FFFFFF;
  --ok: #00B894;
  --warn: #E9A800;
  --danger: #E8434F;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 2px 10px rgba(20, 20, 43, .06);
  --shadow-lg: 0 12px 32px rgba(20, 20, 43, .12);
  --nav-h: 62px;
  --top-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; color: var(--ink); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
small { font-size: .82rem; }

.ic { flex: 0 0 auto; }

/* ------------------------------------------------------------- structure */

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), #8B5CF6);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(91, 75, 255, .35);
}
.brand-name { font-weight: 700; font-size: 1.08rem; letter-spacing: -.2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.avatar-link img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid var(--brand-soft); }

.content {
  padding: 16px 16px calc(var(--nav-h) + 34px + env(safe-area-inset-bottom, 0px));
}

.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  max-width: 760px;
  margin: 0 auto;
  background: rgba(255, 255, 255, .97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.navitem {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  height: var(--nav-h);
  color: var(--muted);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .1px;
}
.navitem.active { color: var(--brand); }
.navitem.active svg { transform: translateY(-1px); }

/* ------------------------------------------------------------- elements */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
  margin-bottom: 13px;
}
.card-flat { box-shadow: none; }
.card-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-title h2, .card-title h3 { margin: 0; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  margin: 18px 0 10px;
}
.section-head h2 { margin: 0; }
.section-head .link { font-size: .85rem; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: .92rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  transition: transform .12s ease, background .16s ease, opacity .16s ease;
  line-height: 1.2;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.btn-soft { background: var(--brand-soft); color: var(--brand-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: .84rem; }
.btn-xs { padding: 6px 11px; font-size: .78rem; border-radius: 999px; }
.btn-icon { padding: 9px; border-radius: 50%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-row {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .7rem; font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-ok { background: #E4F8F1; color: #067A5C; }
.badge-warn { background: #FDF3DC; color: #96690A; }
.badge-danger { background: #FDE8E9; color: #B3272F; }
.badge-muted { background: #EEF0F5; color: var(--muted); }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(0, 184, 148, .18);
}

.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.mt { margin-top: 14px; }
.mb0 { margin-bottom: 0; }

.avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.avatar-lg { width: 78px; height: 78px; border-radius: 50%; object-fit: cover; }

/* --------------------------------------------------------------- formulaires */

.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: .82rem;
  font-weight: 700;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(91, 75, 255, .14);
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.search-box { position: relative; }
.search-box .input { padding-left: 40px; }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.hint { font-size: .78rem; color: var(--muted); margin-top: 5px; }
.form-error { color: var(--danger); font-size: .86rem; font-weight: 600; margin-top: 8px; }

/* ------------------------------------------------------------------ listes */

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item h3 { margin: 0 0 3px; font-size: 1rem; }
.list-item a.title-link { color: var(--ink); }

.topic-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }

.hero {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  color: #fff;
  margin-bottom: 14px;
  min-height: 210px;
  display: flex;
  align-items: flex-end;
}
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero-overlay {
  position: relative;
  width: 100%;
  padding: 18px 16px;
  background: linear-gradient(180deg, rgba(20, 20, 43, .05) 0%, rgba(20, 20, 43, .78) 78%);
}
.hero h1 { color: #fff; font-size: 1.45rem; margin-bottom: 6px; }
.hero p { margin: 0 0 12px; color: rgba(255, 255, 255, .9); font-size: .9rem; }
.hero .btn-soft { background: rgba(255, 255, 255, .16); color: #fff; backdrop-filter: blur(6px); }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px;
  text-align: center;
}
.stat strong { display: block; font-size: 1.35rem; color: var(--brand); }
.stat span { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 700; }

.cat-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  color: var(--ink);
}
.cat-icon {
  width: 44px; height: 44px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; flex: 0 0 auto;
}
.cat-card h3 { margin: 0 0 2px; font-size: .98rem; }
.cat-card p { margin: 0; font-size: .8rem; color: var(--muted); }
.cat-count { font-size: .78rem; font-weight: 700; color: var(--brand); white-space: nowrap; }

.pill-cat {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .74rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark);
}

/* -------------------------------------------------------------------- chat */

.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--top-h) - var(--nav-h) - 40px - env(safe-area-inset-bottom, 0px)); }
.chat-messages { flex: 1 1 auto; overflow-y: auto; padding: 4px 0 10px; }
.msg { display: flex; gap: 9px; margin-bottom: 12px; }
.msg-avatar img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.msg-body { background: #fff; border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 9px 12px; max-width: 85%; }
.msg-head { display: flex; align-items: baseline; gap: 7px; margin-bottom: 2px; }
.msg-head strong { font-size: .84rem; }
.msg-head time { font-size: .7rem; color: var(--muted); }
.msg-body p { margin: 0; font-size: .92rem; word-break: break-word; }
.msg-mine { flex-direction: row-reverse; }
.msg-mine .msg-body { background: var(--brand); color: #fff; border-color: var(--brand); border-radius: 14px 4px 14px 14px; }
.msg-mine .msg-head strong { color: #fff; }
.msg-mine .msg-head time { color: rgba(255, 255, 255, .75); }
.chat-form {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 0 6px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.chat-form .input { border-radius: 999px; }
.chat-send {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto;
}

/* ------------------------------------------------------------------ profils */

.profil-head { display: flex; align-items: center; gap: 14px; }
.profil-head h1 { margin: 0 0 2px; font-size: 1.25rem; }

.progress {
  height: 8px; border-radius: 999px; background: #EEF0F5; overflow: hidden;
}
.progress span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}
.empty svg { color: #C7CBE0; margin-bottom: 8px; }

/* ------------------------------------------------------------------ admin */

.admin-title { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.admin-shell { display: flex; flex-direction: column; gap: 12px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.admin-table th, .admin-table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.admin-table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-nav {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px;
  scrollbar-width: none;
}
.admin-nav::-webkit-scrollbar { display: none; }
.switch { display: flex; align-items: center; gap: 10px; }
.switch input { width: 46px; height: 26px; appearance: none; background: #D8DBE8; border-radius: 999px; position: relative; transition: background .2s; cursor: pointer; }
.switch input:checked { background: var(--brand); }
.switch input::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s;
}
.switch input:checked::after { transform: translateX(20px); }

.chart-box { position: relative; height: 240px; }

/* --------------------------------------------------------------- overlays */

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 460px);
  pointer-events: none;
}
.toast {
  background: rgba(20, 20, 43, .94);
  color: #fff;
  padding: 11px 15px;
  border-radius: 12px;
  font-size: .88rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn .22s ease;
}
.toast-success { background: rgba(0, 148, 120, .96); }
.toast-error { background: rgba(200, 40, 50, .96); }
.toast-out { opacity: 0; transition: opacity .3s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 20, 43, .5);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fadeIn .16s ease;
}
.sheet {
  background: #fff;
  width: 100%;
  max-width: 760px;
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh;
  overflow-y: auto;
  animation: sheetUp .24s ease;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sheet-head h3 { margin: 0; }
.sheet-text { color: var(--ink-2); font-size: .93rem; }
.sheet-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 14px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(24px); } to { transform: none; } }

.install-steps { display: flex; flex-direction: column; gap: 14px; margin: 6px 0 2px; }
.install-step { display: flex; gap: 12px; align-items: flex-start; }
.install-step-icon {
  width: 44px; height: 44px; border-radius: 13px;
  background: var(--brand-soft); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.install-step p { margin: 2px 0 0; font-size: .87rem; color: var(--muted); }

.installbar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  margin-top: 18px;
  padding: 13px 16px;
  border-radius: var(--radius);
  border: 1px dashed var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 700;
  font-size: .9rem;
  font-family: inherit;
  cursor: pointer;
}
.install-ready { border-style: solid; background: var(--brand); color: #fff; border-color: var(--brand); }

/* ------------------------------------------------------------------ auth */

.auth { padding-top: 6px; }
.auth-visual {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 150px;
  margin-bottom: 14px;
  display: flex;
  align-items: flex-end;
}
.auth-visual img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.auth-visual .hero-overlay { padding: 14px; }
.auth-visual strong { color: #fff; font-size: 1.05rem; }
.auth-visual p { margin: 2px 0 0; color: rgba(255, 255, 255, .88); font-size: .82rem; }

/* ---------------------------------------------------------- plateformes */

.plateformes { display: grid; grid-template-columns: 1fr; gap: 10px; }
.plateforme {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fff;
}
.plateforme .install-step-icon { width: 40px; height: 40px; }
.plateforme strong { display: block; font-size: .9rem; }
.plateforme span { font-size: .78rem; color: var(--muted); }

/* ------------------------------------------------------------- responsive */

@media (min-width: 768px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .content { padding: 20px 20px calc(var(--nav-h) + 44px); }
  .hero { min-height: 260px; }
  .hero h1 { font-size: 1.8rem; }
  .plateformes { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; align-items: start; }
  .chat-wrap { height: calc(100vh - var(--top-h) - var(--nav-h) - 60px); }
}

@media (max-width: 767px) {
  .admin-table thead { display: none; }
  .admin-table tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .admin-table td { display: block; border: none; padding: 3px 0; }
  .admin-table td::before {
    content: attr(data-label) ' : ';
    font-weight: 700; color: var(--muted); font-size: .76rem;
  }
}
