:root {
  --bg: #050505;
  --surface: #151515;
  --surface-2: #1d1d1d;
  --border: #2a2a2a;
  --text: #f5f5f5;
  --muted: #8b8b8b;
  --green: #5bea5b;
  --green-2: #2fbf3a;
  --green-glow: rgba(91, 234, 91, 0.35);
  --radius: 22px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --logo-font: "Nunito", var(--font);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; color: var(--text); font-family: var(--font); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; }

.app {
  position: relative; max-width: 430px; height: 100dvh; margin: 0 auto; overflow: hidden;
  background: var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
/* Tablette et ordinateur : une colonne centrée plus large, sans cadre de téléphone */
@media (min-width: 760px) {
  body { background: #0b0b0b; }
  .app { max-width: 860px; border-left: 1px solid #161616; border-right: 1px solid #161616; }
  .screen { padding: 18px 32px 24px; }
  .results { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .msg { max-width: 72%; }
  .hero h1 { font-size: 32px; }
  .logo .logo-mark { max-width: 300px; }
  .drawer { width: 320px; }
  .sheet { left: 50%; right: auto; width: 560px; transform: translate(-50%, 105%); }
  .sheet.show { transform: translate(-50%, 0); }
  .chip-rows .chips { flex-wrap: wrap; justify-content: center; }
}

.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: 14px 18px 18px; }
.screen.active { display: flex; }

/* En-tête */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface-2); border: 1px solid var(--border); color: #ddd;
}
.icon-btn:active { transform: scale(.96); }
.icon-btn.on { color: var(--green); border-color: var(--green-2); }
.icon-btn svg { width: 20px; height: 20px; }

.segmented { display: flex; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.segmented button { padding: 9px 22px; border-radius: 999px; color: #cfcfcf; font-weight: 600; }
.segmented button.on { background: var(--green); color: #061006; }

/* Logo */
.logo { display: flex; flex-direction: column; align-items: center; margin: 10px 0 4px; }
.logo .logo-mark { display: block; width: 78%; max-width: 280px; aspect-ratio: 690 / 240; background-color: var(--logo-color, #27fe6b);
  -webkit-mask: url("../img/logo.png") center / contain no-repeat; mask: url("../img/logo.png") center / contain no-repeat; }
.logo .word { font-family: var(--logo-font); font-weight: 900; font-size: 30px; color: var(--green); letter-spacing: .5px; margin-top: 2px; }
.logo.small .logo-mark { max-width: 190px; }
.logo.small .word { font-size: 24px; }

/* Écran recherche */
.scroll { flex: 1; overflow-y: auto; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }
.card-btn {
  width: 100%; margin-top: 16px; padding: 30px 16px; border-radius: var(--radius); text-align: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.card-btn svg { width: 40px; height: 40px; color: #cfcfcf; }
.card-btn .label { display: block; margin-top: 12px; font-size: 16px; }
.card-btn .value { display: block; margin-top: 6px; color: var(--green); font-weight: 600; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; padding: 10px 16px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); color: #e6e6e6; font-size: 14px; white-space: nowrap;
}
.chip.on { background: rgba(91,234,91,.12); border-color: var(--green); color: var(--green); }
.field {
  width: 100%; margin-top: 14px; min-height: 92px; padding: 14px 16px; border-radius: 18px; resize: none;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); outline: none;
}
.field:focus { border-color: var(--green-2); }
.field::placeholder { color: #6f6f6f; }
.primary {
  width: 100%; margin-top: 16px; padding: 15px; border-radius: 16px; font-weight: 600; font-size: 15px;
  background: var(--green); color: #061006;
}
.primary:active { filter: brightness(.92); }

/* Écran assistant */
.hero { text-align: center; padding: 6px 4px 0; }
.hero p { color: #b5b5b5; margin: 18px 0 6px; }
.hero h1 { font-size: 27px; font-weight: 500; line-height: 1.25; margin: 0; }
.chat { display: flex; flex-direction: column; gap: 12px; padding: 8px 0 12px; }
.msg { max-width: 88%; padding: 11px 14px; border-radius: 18px; line-height: 1.4; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--green); color: #061006; border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.typing span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: #888; animation: blink 1s infinite; }
.msg.typing span:nth-child(2) { animation-delay: .15s; } .msg.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .2; } }
.chip-rows { display: grid; gap: 8px; padding-top: 8px; }
.chip-rows .chips { padding: 0; }
.composer {
  display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 6px 6px 6px 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.composer input { flex: 1; min-width: 0; background: none; border: 0; outline: none; padding: 10px 4px; }
.composer input::placeholder { color: #6f6f6f; }
.composer .ghost { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #bdbdbd; }
.composer .ghost svg { width: 20px; height: 20px; }
.mic-btn {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: radial-gradient(circle at 35% 30%, #9bff86, var(--green-2)); color: #052005;
  box-shadow: 0 0 22px var(--green-glow);
}
.mic-btn svg { width: 22px; height: 22px; }

/* Résultats */
.results { display: grid; gap: 12px; margin-top: 4px; }
.listing { border-radius: 18px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); }
.listing .media { height: 130px; position: relative; display: grid; place-items: center;
  background: radial-gradient(120% 120% at 20% 0%, #1f3a1f, #0e140e 60%, #0a0a0a); color: #3d8a3d; }
.listing .media img { width: 100%; height: 100%; object-fit: cover; }
.listing .media svg { width: 44px; height: 44px; }
.listing .tag { position: absolute; top: 10px; left: 10px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: rgba(0,0,0,.6); border: 1px solid var(--border); }
.listing .tag.sale { color: #ffd166; } .listing .tag.rent { color: var(--green); }
.listing .body { padding: 12px 14px 14px; }
.listing h3 { margin: 0; font-size: 15px; font-weight: 600; }
.listing .loc { color: var(--muted); font-size: 13px; margin-top: 3px; }
.listing .price { color: var(--green); font-weight: 700; margin-top: 8px; }
.listing .facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.listing .facts span { font-size: 12px; padding: 4px 8px; border-radius: 8px; background: var(--surface-2); color: #cfcfcf; }
.listing .actions { display: flex; gap: 8px; margin-top: 12px; }
.listing .actions a, .listing .actions span {
  flex: 1; text-align: center; padding: 10px; border-radius: 12px; font-size: 13px; font-weight: 600; text-decoration: none;
  background: var(--surface-2); border: 1px solid var(--border);
}
.listing .actions .wa { background: var(--green); color: #061006; border: 0; }
.listing .actions .off { color: var(--muted); }
.listing .contact { font-size: 12px; color: var(--muted); margin-top: 8px; }
.note { font-size: 12px; color: var(--muted); text-align: center; margin: 8px 0; }

/* Écran vocal */
.voice { justify-content: flex-start; background: radial-gradient(120% 70% at 50% 108%, #1f7a2a 0%, #0b2a0f 38%, var(--bg) 70%); }
.voice .hint { text-align: center; color: #9a9a9a; margin: 14px 24px 0; line-height: 1.45; }
.voice .transcript { text-align: center; font-size: 22px; min-height: 64px; margin: 26px 12px 0; line-height: 1.35; }
.voice .status { text-align: center; color: var(--green); font-size: 13px; min-height: 18px; margin-top: 8px; }
.voice .stage { margin-top: auto; position: relative; height: 200px; display: grid; place-items: center; }
.voice canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.voice .big-mic {
  position: relative; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #9bff86, var(--green-2)); color: #052005;
  box-shadow: 0 0 0 10px rgba(91,234,91,.12), 0 0 50px var(--green-glow);
}
.voice .big-mic svg { width: 32px; height: 32px; }
.voice .big-mic.listening { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 18px rgba(91,234,91,.08), 0 0 70px var(--green-glow); } }
.voice .bottom { display: flex; justify-content: space-between; align-items: center; }
.voice .fallback { display: none; margin-top: 14px; }
.voice .fallback.show { display: block; }

/* Feuilles (lieu, menu) */
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: none; z-index: 20; }
.overlay.show { display: block; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 82%; display: flex; flex-direction: column;
  background: #101010; border-top: 1px solid var(--border); border-radius: 26px 26px 0 0; padding: 10px 18px 18px;
  transform: translateY(105%); transition: transform .25s ease, visibility .25s; z-index: 30; visibility: hidden;
}
.sheet.show { transform: none; visibility: visible; }
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: #333; margin: 2px auto 12px; }
.sheet h2 { font-size: 18px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.sheet .back { color: var(--green); font-size: 14px; }
.sheet input.search { width: 100%; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); outline: none; }
.sheet ul { list-style: none; margin: 10px 0 0; padding: 0; overflow-y: auto; }
.sheet li button { width: 100%; text-align: left; padding: 14px 6px; border-bottom: 1px solid #1f1f1f; display: flex; justify-content: space-between; }
.sheet li button small { color: var(--muted); }
.sheet li button.all { color: var(--green); font-weight: 600; }

.drawer {
  position: absolute; top: 0; bottom: 0; left: 0; width: 78%; background: #0f0f0f; border-right: 1px solid var(--border);
  padding: 24px 18px; transform: translateX(-102%); transition: transform .25s ease, visibility .25s; visibility: hidden; z-index: 30; display: flex; flex-direction: column; gap: 6px;
}
.drawer.show { transform: none; visibility: visible; }
.drawer a { text-decoration: none; padding: 14px 10px; border-radius: 12px; display: flex; gap: 12px; align-items: center; }
.drawer a:hover, .drawer a.current { background: var(--surface-2); color: var(--green); }
.drawer .meta { margin-top: auto; font-size: 12px; color: var(--muted); line-height: 1.5; }
.drawer svg { width: 20px; height: 20px; }
.hidden { display: none !important; }

/* Ajouts : chat IA, installation */
.listing .media > svg { position: absolute; }
.listing .media img { position: absolute; inset: 0; }
.listing .tag.demo { left: auto; right: 10px; color: #ffb4a8; }
.listing .cond { font-size: 12px; color: #b5b5b5; margin-top: 8px; }
.listing .contact a { color: inherit; }
.msg.error { border-color: #5a2a2a; }
.msg .retry { display: inline-block; margin-left: 6px; padding: 4px 12px; border-radius: 999px; background: var(--green); color: #061006; font-weight: 600; font-size: 13px; }
.secondary {
  width: 100%; margin: 14px 0 6px; padding: 13px; border-radius: 16px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--green);
}
#search-results .msg { max-width: 100%; margin: 16px 0 12px; }
.primary:disabled { opacity: .7; cursor: progress; }
.composer.busy .mic-btn { opacity: .6; }
.chip:disabled { opacity: .5; }
.install-btn { padding: 14px 10px; border-radius: 12px; display: flex; gap: 12px; align-items: center; color: var(--green); text-align: left; }
.install-btn:hover { background: var(--surface-2); }
.steps { margin: 4px 0 6px; padding-left: 20px; line-height: 1.7; color: #dcdcdc; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* Écran d'ouverture : vert vif + logo blanc, puis blanc + logo vert, puis fondu vers l'appli */
#splash {
  --s-green: #009a44; --s-bright: #00ff00; --s-white: #ffffff;
  position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center;
  justify-content: center; background: var(--s-bright); color: var(--s-white);
  animation: splash-bg 4.5s ease-in-out forwards;
}
#splash .splash-logo {
  width: min(82vw, 560px); aspect-ratio: 690 / 240; background-color: currentColor;
  -webkit-mask: url("../img/logo.png") center / contain no-repeat; mask: url("../img/logo.png") center / contain no-repeat;
  animation: splash-logo-in .9s ease-out both;
}
#splash .splash-tag {
  margin: clamp(28px, 7vh, 64px) 0 0; font-family: "Montserrat", var(--font); font-weight: 400;
  font-size: clamp(17px, 4.6vw, 24px); letter-spacing: .3px; color: currentColor;
  animation: splash-text-in .8s .35s ease-out both;
}
#splash .splash-spin {
  position: absolute; bottom: max(7vh, calc(24px + env(safe-area-inset-bottom))); width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid transparent; border-top-color: currentColor; border-right-color: currentColor; border-bottom-color: currentColor;
  animation: splash-spin .9s linear infinite;
}
#splash.done { display: none; }
@keyframes splash-bg {
  0%, 38%  { background: var(--s-bright); color: var(--s-white); opacity: 1; visibility: visible; }
  50%, 84% { background: var(--s-white); color: var(--s-green); opacity: 1; visibility: visible; }
  100%     { background: var(--s-white); color: var(--s-green); opacity: 0; visibility: hidden; }
}
@keyframes splash-logo-in { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes splash-text-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes splash-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #splash .splash-logo, #splash .splash-tag { animation: none; }
}

/* Thème clair (bouton « Mode clair » dans le menu) */
:root[data-theme="light"] {
  --logo-color: #009a44;
  --bg: #ffffff; --surface: #f4f6f4; --surface-2: #eceff0; --border: #dde3de;
  --text: #121212; --muted: #6a6f6b; --green: #009a44; --green-2: #00863b; --green-glow: rgba(0,154,68,.25);
}
:root[data-theme="light"] { background: #f2f4f2; }
:root[data-theme="light"] body { background: #f2f4f2; }
@media (min-width: 760px) { :root[data-theme="light"] .app { border-color: #e3e7e3; } }
:root[data-theme="light"] .icon-btn { color: #333; }
:root[data-theme="light"] .segmented button { color: #444; }
:root[data-theme="light"] .segmented button.on,
:root[data-theme="light"] .primary,
:root[data-theme="light"] .msg.user,
:root[data-theme="light"] .listing .actions .wa,
:root[data-theme="light"] .msg .retry { color: #fff; }
:root[data-theme="light"] .card-btn svg { color: #555; }
:root[data-theme="light"] .chip { color: #222; }
:root[data-theme="light"] .chip.on { background: rgba(0,154,68,.10); }
:root[data-theme="light"] .field::placeholder, :root[data-theme="light"] .composer input::placeholder { color: #8a8f8b; }
:root[data-theme="light"] .hero p, :root[data-theme="light"] .listing .cond { color: #555; }
:root[data-theme="light"] .composer .ghost { color: #555; }
:root[data-theme="light"] .mic-btn, :root[data-theme="light"] .voice .big-mic { background: radial-gradient(circle at 35% 30%, #3fd46f, #009a44); color: #fff; }
:root[data-theme="light"] .listing .media { background: radial-gradient(120% 120% at 20% 0%, #dff3e4, #eef6f0 60%, #f6f8f6); color: #3e9a5a; }
:root[data-theme="light"] .listing .tag { background: rgba(255,255,255,.85); }
:root[data-theme="light"] .listing .tag.sale { color: #a86b00; }
:root[data-theme="light"] .listing .tag.demo { color: #b4402e; }
:root[data-theme="light"] .listing .facts span { color: #333; }
:root[data-theme="light"] .voice { background: radial-gradient(120% 70% at 50% 108%, #9fe3b4 0%, #e4f6e9 38%, var(--bg) 70%); }
:root[data-theme="light"] .voice .hint { color: #666; }
:root[data-theme="light"] .overlay { background: rgba(0,0,0,.35); }
:root[data-theme="light"] .sheet, :root[data-theme="light"] .drawer { background: #ffffff; }
:root[data-theme="light"] .sheet .grab { background: #ccc; }
:root[data-theme="light"] .sheet li button { border-bottom-color: #eceeec; }
:root[data-theme="light"] .msg.typing span { background: #999; }
:root[data-theme="light"] .msg.error { border-color: #e7b9b2; }
:root[data-theme="light"] .steps { color: #333; }
.theme-btn { padding: 14px 10px; border-radius: 12px; display: flex; gap: 12px; align-items: center; text-align: left; }
.theme-btn:hover { background: var(--surface-2); color: var(--green); }

/* Compte utilisateur */
.account-box { margin: 4px 0 6px; padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); display: grid; gap: 8px; }
.account-box .who { font-weight: 600; }
.account-box .who small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }
.account-box .primary { margin: 0; padding: 11px; font-size: 14px; }
.account-box .link { color: var(--muted); font-size: 13px; text-align: left; padding: 0; }
.account-sheet { max-height: 92%; overflow-y: auto; }
.account-sheet .tabs { margin: 0 auto 12px; width: fit-content; }
.auth-form { display: grid; gap: 12px; }
.auth-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-form input, .auth-form select {
  width: 100%; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); outline: none; font-size: 16px;
}
.auth-form input:focus, .auth-form select:focus { border-color: var(--green-2); }
.auth-form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auth-form .primary { margin-top: 4px; }
.auth-form .primary:disabled { opacity: .7; }
.auth-form .link { color: var(--green); font-size: 14px; padding: 4px; }
.auth-msg { margin: 0; font-size: 13px; color: #ff8a7a; min-height: 0; }
.auth-msg.ok { color: var(--green); }
.auth-msg:empty { display: none; }
:root[data-theme="light"] .auth-msg { color: #c0392b; }
:root[data-theme="light"] .auth-msg.ok { color: var(--green); }

/* Petit message de confirmation (haut-parleur, etc.) */
#toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px);
  padding: 10px 16px; border-radius: 999px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 900; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.msg .err-detail { display: block; margin-top: 8px; font-size: 11px; color: var(--muted); word-break: break-word; }

/* Liste des conversations du compte (menu) */
.drawer { overflow-y: auto; }
.conv-box { margin: 2px 0 8px; }
.conv-head { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 6px 10px; }
.conv-box ul { list-style: none; margin: 0; padding: 0; max-height: 38vh; overflow-y: auto; }
.conv-box li { display: flex; align-items: center; border-radius: 12px; }
.conv-box li.current { background: var(--surface-2); }
.conv-box li:hover { background: var(--surface-2); }
.conv-open { flex: 1; min-width: 0; text-align: left; padding: 10px; display: grid; gap: 2px; }
.conv-open .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-box li.current .conv-open .t { color: var(--green); }
.conv-open small { color: var(--muted); font-size: 11px; }
.conv-del { width: 34px; height: 34px; flex: none; display: grid; place-items: center; color: var(--muted); border-radius: 10px; }
.conv-del:hover { color: #ff8a7a; }
.conv-del svg { width: 16px; height: 16px; }
.conv-empty { color: var(--muted); font-size: 13px; padding: 8px 10px; }
