/* ---------- Sathi AI: floating launcher, pop-up panel, chat, full page ---------- */
.ai-fab { position: fixed; right: max(16px, var(--safe-r, 0px)); bottom: calc(88px + var(--safe-b, 0px)); z-index: 60; display: flex; align-items: center; gap: 8px; height: 56px; min-width: 56px; padding: 0 16px; border: 0; border-radius: 28px; cursor: pointer; color: #fff;
  background: radial-gradient(circle at 30% 25%, #ff6b88, var(--crimson) 45%, #3a1e6b 80%, var(--blue)); box-shadow: 0 10px 26px -8px rgba(58, 30, 107, .7), inset 0 1px 0 rgba(255,255,255,.35); transition: transform .18s, box-shadow .18s; }
.ai-fab:hover { transform: translateY(-2px) scale(1.03); }
.ai-fab:active { transform: scale(.96); }
.ai-fab .ai-fab-label { font-weight: 700; font-size: .9rem; white-space: nowrap; max-width: 0; overflow: hidden; transition: max-width .3s; }
.ai-fab.nudge .ai-fab-label, .ai-fab:hover .ai-fab-label, .ai-fab:focus-visible .ai-fab-label { max-width: 140px; }
.ai-fab.nudge { animation: aiPulse 1.6s ease-in-out 3; }
.ai-fab.active { opacity: 0; pointer-events: none; }
.ai-fab[hidden] { display: none; }
@keyframes aiPulse { 50% { box-shadow: 0 0 0 10px rgba(220, 20, 60, .18), 0 10px 26px -8px rgba(58, 30, 107, .7); } }
@media (min-width: 900px) { .ai-fab { bottom: 24px; right: 24px; } }
body.editor-mode .ai-fab, body.chat-mode .ai-fab { display: none; }

.ai-panel { position: fixed; z-index: 70; right: 16px; bottom: 16px; width: min(400px, calc(100vw - 24px)); height: min(640px, calc(100vh - 100px)); display: flex; flex-direction: column; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 24px 60px -20px rgba(15, 23, 42, .55); transform: translateY(20px) scale(.97); opacity: 0; pointer-events: none; transition: transform .2s, opacity .2s; overflow: hidden; }
.ai-panel.open { transform: none; opacity: 1; pointer-events: auto; }
@media (max-width: 640px) { .ai-panel { right: 0; left: 0; bottom: 0; width: 100%; height: calc(100dvh - 40px); border-radius: 22px 22px 0 0; } }
.ai-panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; color: #fff; background: linear-gradient(100deg, #b80f33, var(--crimson) 35%, #3a1e6b 75%, var(--blue)); }
.ai-panel-head .icon-btn { color: #fff; }
.ai-panel-body { flex: 1; min-height: 0; display: flex; }

.ai-orb { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; color: #fff; margin: 0 auto 8px; background: radial-gradient(circle at 30% 25%, #ff6b88, var(--crimson) 45%, #3a1e6b 80%, var(--blue)); box-shadow: 0 8px 20px -8px rgba(58, 30, 107, .7); }
.ai-orb.sm { width: 30px; height: 30px; margin: 0; flex: none; box-shadow: none; border: 1.5px solid rgba(255,255,255,.6); }

.aichat { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; }
.ai-log { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px 6px; overscroll-behavior: contain; }
.ai-hello { text-align: center; padding: 16px 6px; }
.ai-hello h3 { margin: 4px 0; }
.ai-hello .lead { margin: 2px 0 6px; font-weight: 600; }
.ai-hello .chips { justify-content: center; margin: 12px 0; }
.ai-hello .chips button { white-space: normal; text-align: left; font-weight: 500; }
.ai-msg { display: flex; gap: 8px; margin: 10px 0; }
.ai-msg.me { justify-content: flex-end; flex-wrap: wrap; }
.ai-msg.me .bubble { max-width: 85%; background: linear-gradient(160deg, var(--crimson), #b80f33); color: #fff; padding: 9px 13px; border-radius: 18px 18px 4px 18px; white-space: normal; word-wrap: break-word; }
.ai-msg.me .ai-img { max-width: 60%; max-height: 220px; border-radius: 14px; flex-basis: 100%; object-fit: cover; margin-left: auto; display: block; width: auto; }
.ai-file { flex-basis: 100%; text-align: right; font-size: .8rem; color: var(--muted); }
.ai-avatar { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: linear-gradient(140deg, var(--crimson), var(--blue)); margin-top: 2px; }
.ai-msg.bot .bubble { background: var(--surface2); padding: 10px 14px; border-radius: 4px 18px 18px 18px; line-height: 1.55; overflow-wrap: anywhere; }
.bubble.md p { margin: 0 0 8px; } .bubble.md p:last-child { margin-bottom: 0; }
.bubble.md ul, .bubble.md ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble.md li { margin: 2px 0; }
.bubble.md h3, .bubble.md h4, .bubble.md h5 { margin: 8px 0 4px; font-size: 1rem; }
.bubble.md code { background: color-mix(in srgb, var(--text) 8%, transparent); padding: 1px 5px; border-radius: 5px; font-size: .88em; }
.bubble.md pre { background: #0f172a; color: #e2e8f0; padding: 10px; border-radius: 10px; overflow-x: auto; font-size: .82rem; }
.bubble.md pre code { background: none; padding: 0; }
.bubble.md blockquote { border-left: 3px solid var(--crimson); margin: 6px 0; padding-left: 10px; color: var(--muted); }
.bubble.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md-table { overflow-x: auto; margin: 6px 0; }
.md-table table { border-collapse: collapse; font-size: .86rem; width: 100%; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.md-table th { background: color-mix(in srgb, var(--blue) 8%, transparent); }
a.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; margin: 0 1px; border-radius: 9px; background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); font-size: .68rem; font-weight: 700; text-decoration: none; vertical-align: super; }
:root[data-theme="dark"] a.cite { color: #8fb1ff; }
.ai-route { display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .02em; color: var(--crimson); margin-bottom: 4px; text-transform: uppercase; }
.ai-tool { font-size: .8rem; color: var(--muted); margin: 0 0 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ai-tool.done { color: #15803d; } .ai-tool.error { color: #b91c1c; }
.ai-tool .spin { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: aispin .8s linear infinite; }
@keyframes aispin { to { transform: rotate(360deg); } }
.ai-confirm { border: 1.5px solid var(--crimson); background: color-mix(in srgb, var(--crimson) 6%, var(--surface)); border-radius: 14px; padding: 10px 12px; margin: 0 0 8px 36px; font-size: .9rem; }
.ai-err { color: #b91c1c; font-size: .86rem; margin-top: 6px; }
.ai-sources { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.ai-src { font-size: .78rem; color: var(--text); text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-src b { color: var(--blue); margin-right: 4px; }
.ai-actions { display: flex; gap: 2px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.ai-actions .icon-btn { width: 32px; height: 32px; min-height: 32px; font-size: .9rem; }
.ai-actions .icon-btn.on { background: color-mix(in srgb, var(--crimson) 12%, transparent); }
.ai-actions small { margin-left: 6px; font-size: .7rem; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: aiDot 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aiDot { 50% { transform: translateY(-4px); opacity: .5; } }
.ai-pending { padding: 4px 12px; }
.ai-pending .chip button { border: 0; background: none; font-size: 1rem; cursor: pointer; color: inherit; }
.ai-input { display: flex; gap: 6px; align-items: flex-end; padding: 8px 10px calc(10px + var(--safe-b, 0px)); border-top: 1px solid var(--line); background: var(--surface); }
.ai-input textarea { flex: 1; resize: none; min-height: 44px; max-height: 160px; border-radius: 22px; padding: 11px 14px; line-height: 1.35; }
.ai-input .ai-send { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; flex: none; }
.ai-input #mic.rec { color: #fff; background: var(--crimson); animation: aiPulse 1.2s infinite; }

/* full page */
.ai-page { display: flex; height: calc(100dvh - var(--datebar-h) - 84px - var(--safe-b, 0px)); min-height: 420px; max-width: 1100px; margin: 0 auto; }
@media (min-width: 900px) { .ai-page { height: calc(100dvh - var(--datebar-h) - 16px); padding: 8px; gap: 12px; } }
.ai-side { width: 270px; flex: none; display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--surface); border-radius: 18px; border: 1px solid var(--line); }
.ai-threads { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.ai-thread { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 10px; border-radius: 12px; cursor: pointer; }
.ai-thread b { display: block; font-size: .86rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.ai-thread small { font-size: .72rem; }
.ai-thread:hover { background: var(--surface2); } .ai-thread.on { background: color-mix(in srgb, var(--crimson) 10%, var(--surface)); }
.ai-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); border-radius: 18px; border: 1px solid var(--line); overflow: hidden; }
.ai-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.ai-head h2 { font-size: 1.1rem; margin: 0; }
.ai-head .pill { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface2); color: var(--muted); }
.ai-chat-host { flex: 1; min-height: 0; display: flex; }
.ai-hist-btn { display: none; }
@media (max-width: 899px) {
  .ai-page { padding: 0; }
  .ai-main { border-radius: 0; border: 0; }
  .ai-hist-btn { display: inline-grid; }
  .ai-side { position: fixed; z-index: 65; left: 0; top: 0; bottom: 0; width: min(300px, 85vw); border-radius: 0 18px 18px 0; transform: translateX(-105%); transition: transform .2s; box-shadow: 0 10px 40px rgba(0,0,0,.3); padding-top: calc(12px + var(--safe-t, 0px)); }
  .ai-side.open { transform: none; }
}
/* in-context "Ask Sathi AI" buttons */
.ask-ai { display: inline-flex; align-items: center; gap: 6px; border: 1px solid color-mix(in srgb, var(--crimson) 40%, var(--line)); color: var(--crimson); background: color-mix(in srgb, var(--crimson) 6%, var(--surface)); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer; }
.ask-ai:hover { background: color-mix(in srgb, var(--crimson) 12%, var(--surface)); }
.ai-fab.raised { bottom: calc(160px + var(--safe-b, 0px)); }
.ai-fab.tucked { bottom: 42%; right: 0; height: 44px; min-width: 40px; padding: 0 8px 0 12px; border-radius: 22px 0 0 22px; opacity: .92; }
.ai-fab.tucked svg { width: 20px; height: 20px; }
@media (min-width: 900px) { .ai-fab.raised { bottom: 104px; } .ai-fab.tucked { right: 24px; bottom: 96px; border-radius: 22px; } }

/* ---- Store product cards, POS rows, per-destination results, confirmation thumbnails, tier chip, panels */
.ai-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin: 6px 0 8px; }
.ai-pcard { display: flex; flex-direction: column; gap: 3px; padding: 8px; border: 1px solid var(--line, #e3e6ee); border-radius: 12px; background: var(--surface); color: inherit; text-decoration: none; font-size: .82rem; }
.ai-pcard:hover { border-color: var(--crimson); }
.ai-pcard img, .ai-pcard .ai-pimg { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: color-mix(in srgb, var(--navy, #0b1f4d) 8%, var(--surface)); }
.ai-pcard b { line-height: 1.2; overflow-wrap: anywhere; }
.ai-price { font-weight: 700; color: var(--crimson); }
.ai-price s { color: var(--muted, #6b7280); font-weight: 400; font-size: .75rem; }
.ai-price em { font-style: normal; font-size: .7rem; background: color-mix(in srgb, var(--crimson) 12%, transparent); padding: 1px 5px; border-radius: 99px; }
.ai-pcard .ok, .ai-row .ok { color: var(--ok, #15803d); }
.ai-pcard .out, .ai-row .out { color: var(--err, #b91c1c); }
.ai-rows { display: grid; gap: 4px; margin: 6px 0 8px; font-size: .85rem; }
.ai-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: baseline; padding: 6px 8px; border: 1px solid var(--line, #e3e6ee); border-radius: 10px; background: var(--surface); }
.ai-thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.ai-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.ai-tier { display: inline-block; font-size: .7rem; color: var(--muted, #6b7280); background: color-mix(in srgb, var(--navy, #0b1f4d) 7%, transparent); padding: 1px 8px; border-radius: 99px; margin-right: 4px; }
.ai-next { margin-top: 6px; }
.ai-panel .mem-row, .ai-panel .act-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line, #e3e6ee); font-size: .9rem; }
.ai-panel .act-row .st { font-size: .72rem; padding: 1px 8px; border-radius: 99px; background: color-mix(in srgb, var(--ok, #15803d) 14%, transparent); color: var(--ok, #15803d); }
.ai-panel .act-row .st.failed { background: color-mix(in srgb, var(--err, #b91c1c) 14%, transparent); color: var(--err, #b91c1c); }
.ai-panel .act-row .st.cancelled { background: color-mix(in srgb, var(--muted, #6b7280) 16%, transparent); color: var(--muted, #6b7280); }
.ai-meter { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--navy, #0b1f4d) 10%, transparent); overflow: hidden; margin: 3px 0 6px; }
.ai-meter i { display: block; height: 100%; background: var(--crimson); }

/* the floating assistant button is the "Ask Saathi AI" badge picture: a round friendly helper, no text pill */
.ai-fab { width: 72px; height: 72px; min-width: 72px; padding: 0; border-radius: 50%; background: #fff; box-shadow: 0 8px 22px rgb(11 31 77 / .35); overflow: visible; }
.ai-fab .ai-fab-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.ai-fab.nudge { animation: aiPulse 1.6s ease-in-out 3; }
@media (min-width: 760px) { .ai-fab { width: 88px; height: 88px; min-width: 88px; bottom: 24px; } }

/* ---- role-aware assistant: "Acting as" chooser, charts, tables, risk labels */
.ai-ws { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line, rgba(128,128,128,.25)); font-size: .85rem; }
.ai-ws select { width: auto; min-width: 0; max-width: 70%; padding: 4px 8px; }
.ai-chart { margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line, rgba(128,128,128,.25)); border-radius: 10px; --ai-chart: var(--accent, #c2410c); }
.ai-chart figcaption { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: .85rem; margin-bottom: 4px; }
.ai-table-wrap { overflow-x: auto; margin: 8px 0; }
.ai-table { border-collapse: collapse; width: 100%; font-size: .82rem; font-variant-numeric: tabular-nums; }
.ai-table th, .ai-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line, rgba(128,128,128,.25)); white-space: nowrap; }
.ai-table th { font-weight: 600; opacity: .8; }
.ai-risk { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; vertical-align: middle; }
.ai-risk.destructive { background: rgba(220, 38, 38, .15); color: #b91c1c; }
.ai-risk.financial { background: rgba(217, 119, 6, .18); color: #92400e; }
:root[data-theme="dark"] .ai-risk.destructive { color: #fca5a5; }
:root[data-theme="dark"] .ai-risk.financial { color: #fcd34d; }
.ai-codes textarea { width: 100%; font-family: ui-monospace, monospace; font-size: .8rem; }

/* Sathi AI picture instead of the red square / sparkle icon */
.ai-orb-img { display: block; width: 96px; height: 96px; margin: 0 auto 8px; border-radius: 50%; object-fit: cover; box-shadow: 0 10px 24px -10px rgba(11, 31, 77, .5); background: #fff; }
.ai-avatar-img { flex: none; width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #fff; box-shadow: 0 2px 6px rgba(11, 31, 77, .25); }
.ai-avatar-img.sm { width: 36px; height: 36px; }

/* ---- voice: language chip, hands-free, status line, settings (web/js/ai/voice.js, docs/SAATHI-AI-VOICE.md) */
.ai-vbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 10px 0; }
.ai-vbar .chip-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line, #d7dbe6); background: var(--surface, #fff); color: inherit; font: inherit; font-size: .85rem; cursor: pointer; }
.ai-vbar .chip-btn.on { background: var(--crimson); color: #fff; border-color: var(--crimson); }
.ai-vbar .chip-btn:focus-visible, .ai-vbar .icon-btn:focus-visible { outline: 3px solid var(--blue-l, #3b82f6); outline-offset: 2px; }
.ai-vstat { flex: 1 1 120px; min-width: 0; font-size: .85rem; color: var(--muted, #5b6478); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aichat.listening .ai-input { box-shadow: 0 0 0 2px var(--crimson); border-radius: 14px; }
.aichat.speaking .ai-vstat { color: var(--crimson); font-weight: 600; }
.vs { display: grid; gap: 12px; }
.vs-row { display: grid; gap: 4px; font-weight: 600; }
.vs-row .input, .vs-row input[type=range] { width: 100%; font-weight: 400; }
@media (prefers-reduced-motion: reduce) { .ai-input #mic.rec { animation: none; } }
