/* TERRA NOVA — Assistant fait maison, langage clair, « expliquer simplement », recherche tolérante (civic4.js). */

/* ---------- Bouton flottant ---------- */
.ai-fab { position: fixed; z-index: 85; inset: auto 1.2rem 1.2rem auto; width: 3.9rem; height: 3.9rem; padding: 0; border: 0; border-radius: 50%; cursor: pointer; display: grid; place-items: center;
   background: radial-gradient(circle at 30% 25%, #ff7ab0, var(--neon) 45%, #7a1fd1 100%); box-shadow: 0 10px 30px rgba(255, 45, 122, .45), 0 0 0 1px rgba(255, 255, 255, .18) inset; transition: transform .3s var(--e), box-shadow .3s }
.ai-fab:hover, .ai-fab:focus-visible { transform: translateY(-3px) scale(1.04); box-shadow: 0 16px 40px rgba(255, 45, 122, .6), 0 0 0 1px rgba(255, 255, 255, .25) inset }
.ai-fab::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid rgba(255, 45, 122, .45); animation: ai-ring 2.8s ease-out infinite }
.ai-fab.is-open { transform: scale(.92) }
.ai-fab.is-open::before { animation: none; opacity: 0 }
.ai-fab .ai-orb { width: 2.1rem; height: 2.1rem; background: none; box-shadow: none }
.ai-fab .ai-orb svg { fill: #fff; filter: drop-shadow(0 0 6px rgba(255, 255, 255, .7)) }
.ai-fab-tip { position: absolute; inset: auto calc(100% + .7rem) 50% auto; transform: translateY(50%); white-space: nowrap; padding: .45rem .8rem; font-size: .85rem; color: var(--ink); background: var(--panel2); box-shadow: inset 0 0 0 1px var(--line), 0 10px 24px rgba(0, 0, 0, .35); clip-path: var(--cut-s); opacity: 0; pointer-events: none; transition: opacity .3s }
.ai-fab--hello .ai-fab-tip, .ai-fab:hover .ai-fab-tip { opacity: 1 }
.ai-fab.is-open .ai-fab-tip { opacity: 0 }
[dir=rtl] .ai-fab { inset: auto auto 1.2rem 1.2rem }
[dir=rtl] .ai-fab-tip { inset: auto auto 50% calc(100% + .7rem) }
@keyframes ai-ring { 0% { transform: scale(.9); opacity: .9 } 70%, 100% { transform: scale(1.35); opacity: 0 } }

/* Les autres bandeaux flottants laissent la place au bouton */
.ld-bar { bottom: 5.8rem !important }

/* ---------- Panneau ---------- */
.ai-panel { position: fixed; z-index: 86; inset: auto 1.2rem 6rem auto; width: min(26rem, calc(100% - 2rem)); height: min(40rem, calc(100vh - 8rem)); display: flex; flex-direction: column;
   color: var(--ink); background: radial-gradient(120% 50% at 50% 0%, rgba(255, 45, 122, .12), transparent 60%), var(--panel2); box-shadow: inset 0 0 0 1px rgba(255, 45, 122, .4), 0 30px 70px rgba(0, 0, 0, .55); clip-path: var(--cut); animation: ai-in .35s var(--e) both; overflow: hidden }
.ai-panel[hidden] { display: none }
[dir=rtl] .ai-panel { inset: auto auto 6rem 1.2rem }
@keyframes ai-in { from { opacity: 0; transform: translateY(14px) scale(.98) } }
.ai-head { display: flex; align-items: center; gap: .6rem; padding: .8rem .9rem; border-bottom: 1px solid var(--line) }
.ai-id { flex: 1; min-width: 0; display: grid }
.ai-id b { font: 700 1rem var(--tech); text-transform: uppercase; letter-spacing: .03em }
.ai-id small { color: var(--mute); font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.ai-orb { flex: none; width: 2.2rem; height: 2.2rem; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 30% 25%, #ff7ab0, var(--neon) 50%, #7a1fd1); box-shadow: 0 0 14px rgba(255, 45, 122, .45) }
.ai-orb svg { width: 60%; height: 60%; fill: #fff }
.ai-ic { flex: none; width: 2.2rem; height: 2.2rem; border: 0; cursor: pointer; background: var(--mute); -webkit-mask: var(--m) center/1.15rem no-repeat; mask: var(--m) center/1.15rem no-repeat; transition: background .2s }
.ai-ic:hover, .ai-ic:focus-visible, .ai-ic[aria-expanded=true] { background: var(--ink) }
.ai-ic--hist { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5M12 7v5l3 2'/%3E%3C/svg%3E") }
.ai-ic--new { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E") }
.ai-ic--x { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E") }
.ai-ic--del { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3'/%3E%3C/svg%3E"); width: 1.9rem; height: 1.9rem }
.ai-ic--del:hover { background: var(--crit) }

/* Historique */
.ai-hist { position: absolute; z-index: 2; inset: 3.9rem 0 0 0; display: flex; flex-direction: column; background: var(--panel2); animation: ai-in .25s var(--e) both }
.ai-hist[hidden] { display: none }
.ai-hist-h { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .8rem .9rem; border-bottom: 1px solid var(--line) }
.ai-hist-list { list-style: none; margin: 0; padding: .4rem; overflow-y: auto; flex: 1 }
.ai-hist-list li { display: flex; align-items: center; gap: .3rem; padding: .15rem }
.ai-hist-list li.on { box-shadow: inset 3px 0 0 var(--neon) }
.ai-h-open { flex: 1; min-width: 0; display: grid; gap: .1rem; padding: .55rem .6rem; border: 0; cursor: pointer; text-align: start; color: var(--ink); background: none; font: inherit }
.ai-h-open:hover, .ai-h-open:focus-visible { background: rgba(255, 255, 255, .05) }
.ai-h-open b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.ai-h-open small { color: var(--mute); font-size: .76rem }

/* Messages */
.ai-msgs { flex: 1; overflow-y: auto; padding: 1rem .9rem; display: flex; flex-direction: column; gap: .8rem; scroll-behavior: smooth }
.ai-msg { display: flex; gap: .55rem; align-items: flex-end; max-width: 100% }
.ai-msg--me { justify-content: flex-end }
.ai-msg--me p { margin: 0; max-width: 85%; padding: .6rem .8rem; color: #fff; background: linear-gradient(135deg, var(--neon), #b1239b); border-radius: 14px 14px 4px 14px; overflow-wrap: anywhere }
.ai-msg--bot .ai-orb { width: 1.8rem; height: 1.8rem; margin-bottom: .2rem }
.ai-bub { flex: 1; min-width: 0; padding: .7rem .85rem; background: rgba(255, 255, 255, .05); box-shadow: inset 0 0 0 1px var(--line); border-radius: 14px 14px 14px 4px }
html[data-theme=light] .ai-bub { background: rgba(29, 27, 44, .04) }
.ai-txt p { margin: 0 0 .45rem; line-height: 1.5 } .ai-txt p:last-child { margin-bottom: 0 }
.ai-txt ul { margin: .2rem 0 .45rem; padding-inline-start: 1.1rem } .ai-txt li { margin: .15rem 0 }
.ai-msg--bot.is-typing { cursor: pointer }
.ai-caret { display: inline-block; width: .5em; height: 1em; margin-inline-start: 1px; vertical-align: -2px; background: var(--neon); animation: ai-blink .8s steps(1) infinite }
@keyframes ai-blink { 50% { opacity: 0 } }
.ai-dots { display: inline-flex; gap: .3rem; padding: .2rem 0 }
.ai-dots i { width: .5rem; height: .5rem; border-radius: 50%; background: var(--mute); animation: ai-dot 1.2s infinite }
.ai-dots i:nth-child(2) { animation-delay: .15s } .ai-dots i:nth-child(3) { animation-delay: .3s }
@keyframes ai-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .5 } 30% { transform: translateY(-5px); opacity: 1 } }
.ai-cards { display: grid; gap: .5rem; margin-top: .6rem }
.ai-cards:empty, .ai-sugg:empty { display: none }
.ai-card { display: grid; gap: .25rem; padding: .6rem .7rem; text-decoration: none; color: var(--ink); background: var(--panel2); box-shadow: inset 0 0 0 1px var(--line); animation: ai-in .35s var(--e) both }
.ai-card-t { color: var(--ink); text-decoration: none } .ai-card-t:hover b { color: var(--cyan) }
.ai-card span, .ai-card small { color: var(--mute); font-size: .85rem }
.ai-card--service { box-shadow: inset 3px 0 0 var(--neon), inset 0 0 0 1px var(--line) }
.ai-card--lieu { box-shadow: inset 3px 0 0 var(--cyan), inset 0 0 0 1px var(--line) }
.ai-card--call { box-shadow: inset 0 0 0 2px var(--crit); background: rgba(255, 59, 92, .1) } .ai-card--call b { color: var(--crit); font-size: 1.1rem }
.ai-card-a { margin-top: .2rem }
.ai-open { font-weight: 700; font-size: .78rem } .ai-open--on { color: var(--ok) !important } .ai-open--off { color: var(--mute) }
.ai-sugg { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem }
.ai-chip { padding: .35rem .65rem; border: 0; border-radius: 999px; cursor: pointer; font: inherit; font-size: .82rem; color: var(--ink); background: rgba(63, 214, 255, .1); box-shadow: inset 0 0 0 1px rgba(63, 214, 255, .45); transition: background .2s }
.ai-chip:hover, .ai-chip:focus-visible { background: rgba(63, 214, 255, .22) }

/* Saisie */
.ai-form { display: flex; gap: .5rem; align-items: flex-end; padding: .7rem .8rem; border-top: 1px solid var(--line) }
.ai-form textarea { flex: 1; min-height: 2.6rem; max-height: 7.5rem; resize: none; padding: .6rem .7rem; font: inherit; line-height: 1.4 }
.ai-send { flex: none; width: 2.6rem; height: 2.6rem; border: 0; border-radius: 50%; cursor: pointer; background: var(--neon); position: relative; transition: transform .2s }
.ai-send:hover { transform: scale(1.06) }
.ai-send::after { content: ""; position: absolute; inset: 0; background: #fff; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h13M13 6l6 6-6 6'/%3E%3C/svg%3E") center/1.2rem no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h13M13 6l6 6-6 6'/%3E%3C/svg%3E") center/1.2rem no-repeat }
[dir=rtl] .ai-send::after { transform: scaleX(-1) }
.ai-foot { margin: 0; padding: 0 .9rem .6rem; font-size: .72rem; color: var(--mute) }

@media (max-width: 560px) {
   .ai-panel, [dir=rtl] .ai-panel { inset: 0; width: 100%; height: 100%; clip-path: none }
   .ai-fab.is-open { opacity: 0; pointer-events: none }
   .ai-fab-tip { display: none }
}

/* ---------- F89 : langage clair ---------- */
.pl-tg { margin-top: .6rem }
.pl-tg[aria-pressed=true] { box-shadow: inset 0 0 0 2px var(--ok); color: var(--ok) }
.pl-box { margin: .6rem 0; padding: .7rem .9rem; background: rgba(77, 255, 176, .07); border-inline-start: 3px solid var(--ok); animation: ai-in .3s var(--e) both }
.pl-box ul { margin: .3rem 0 0; padding-inline-start: 1.1rem } .pl-box li { margin: .2rem 0 } .pl-box p { margin: .3rem 0 0 }
.pl-t { color: var(--ok); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em }
.pl-box details { margin-top: .4rem } .pl-box summary { cursor: pointer; color: var(--cyan); font-size: .85rem }
.pl-box dl { margin: .3rem 0 0 } .pl-box dt { font-weight: 700 } .pl-box dd { margin: 0 0 .3rem; color: var(--mute) }

/* ---------- F90 : expliquer simplement ---------- */
.ex-btn { position: absolute; z-index: 90; padding: .45rem .8rem; border: 0; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600; color: #fff; background: linear-gradient(135deg, var(--cyan), #2a7bd8); box-shadow: 0 8px 20px rgba(0, 0, 0, .35); clip-path: var(--cut-s); animation: ai-in .2s var(--e) both }
.ex-btn[hidden] { display: none }
.ex-pop { position: fixed; z-index: 91; inset: auto 50% 1.5rem auto; transform: translateX(50%); width: min(30rem, calc(100% - 2rem)); max-height: 70vh; overflow-y: auto; padding: 1rem 1.1rem; color: var(--ink); background: var(--panel2); box-shadow: inset 0 0 0 1px var(--cyan), 0 24px 60px rgba(0, 0, 0, .55); clip-path: var(--cut-s); animation: ai-in .3s var(--e) both }
.ex-h { display: flex; justify-content: space-between; align-items: center; gap: .5rem }
.ex-pop blockquote { margin: .5rem 0; padding: .5rem .7rem; font-size: .88rem; color: var(--mute); border-inline-start: 3px solid var(--line) }
.ex-body ul { padding-inline-start: 1.1rem } .ex-body li { margin: .25rem 0 }
.ex-words { margin: .6rem 0 } .ex-words dt { font-weight: 700 } .ex-words dd { margin: 0 0 .4rem; color: var(--mute) }

/* ---------- D10 : recherche ---------- */
.sr-form { display: flex; gap: .6rem; margin: 1rem 0 }
.sr-form input { flex: 1; font-size: 1.05rem }
.sr-fix { padding: .6rem .8rem; background: rgba(255, 177, 92, .1); border-inline-start: 3px solid var(--warn) }
.sr-list { list-style: none; display: grid; gap: .6rem; padding: 0; margin: .6rem 0 }
.sr-item p { margin: .3rem 0 0; color: var(--mute) }
.sr-item a b { color: var(--ink) } .sr-item a:hover b { color: var(--cyan) }
.sr-more { display: block; margin: .6rem 0 0; font-size: .9rem }

html.hc .ai-panel, html.hc .ex-pop, html.hc .ai-card { background: #000; box-shadow: inset 0 0 0 2px #fff }
html.rm .ai-fab::before, html.rm .ai-caret, html.rm .ai-dots i, html.lite .ai-fab::before { animation: none }
@media (prefers-reduced-motion: reduce) { .ai-fab::before, .ai-caret, .ai-dots i, .ai-panel, .ai-card { animation: none } }
@media print { .ai-fab, .ai-panel, .ex-btn, .ex-pop { display: none !important } }
