/* DineWorld assistant — floating button and chat panel.
 * Uses the site tokens (styles.css) so day and night themes follow along.
 * Logical properties (inset-inline-end, padding-inline…) flip for RTL. */

#aiFab {
  position: fixed; inset-inline-end: 20px; bottom: 20px; z-index: 900;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 18px 12px 16px; border: 0; border-radius: 999px;
  background: linear-gradient(135deg, var(--deep-2, #123C7C), var(--deep, #081E46));
  color: #fff; font: 800 .92rem/1 var(--font-body); cursor: pointer;
  box-shadow: 0 10px 28px rgba(8, 30, 70, .32), inset 0 0 0 1.5px rgba(230, 183, 71, .55);
  transition: transform var(--speed, .18s), box-shadow var(--speed, .18s);
}
#aiFab svg { width: 22px; height: 22px; color: var(--brass, #D6A12D); flex: none; }
#aiFab:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(8, 30, 70, .4), inset 0 0 0 1.5px rgba(230, 183, 71, .8); }
#aiFab:focus-visible { outline: 3px solid var(--focus, #D6A12D); outline-offset: 3px; }
#aiFab[hidden] { display: none; }
body.aiOpen #aiFab { opacity: 0; pointer-events: none; }
body.menuMode #aiFab { display: none; }

#aiPanel {
  position: fixed; inset-inline-end: 20px; bottom: 20px; z-index: 950;
  width: min(410px, calc(100vw - 32px)); height: min(640px, calc(100vh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface, #fff); color: var(--text, #10294E);
  border: 1px solid var(--border, #C8D9EE); border-radius: 20px;
  box-shadow: 0 24px 60px rgba(8, 30, 70, .28);
  animation: aiIn .22s ease-out;
}
#aiPanel[hidden] { display: none; }
@keyframes aiIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #aiPanel { animation: none; } #aiFab { transition: none; } }

.aiHead {
  display: flex; align-items: center; gap: 10px; padding: 14px 14px 14px 16px;
  background: linear-gradient(135deg, var(--deep-2, #123C7C), var(--deep, #081E46)); color: #fff;
  border-bottom: 2px solid var(--brass, #D6A12D);
}
.aiLogo { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 255, 255, .1); flex: none; }
.aiLogo svg { width: 22px; height: 22px; color: var(--brass, #D6A12D); }
.aiHeadText { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.aiHeadText b { font-size: 1rem; }
.aiHeadText small { font-size: .78rem; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aiIcon { width: 34px; height: 34px; border: 0; border-radius: 10px; background: transparent; color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.aiIcon:hover { background: rgba(255, 255, 255, .12); }
.aiIcon:focus-visible { outline: 2px solid var(--brass, #D6A12D); }
.aiIcon svg { width: 20px; height: 20px; }

.aiLog { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 12px; background: var(--surface-2, #F2F6FC); overscroll-behavior: contain; }
.aiMsg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.aiMsg.me { justify-content: flex-end; }
.aiAvatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--deep, #081E46); flex: none; }
.aiAvatar svg { width: 16px; height: 16px; color: var(--brass, #D6A12D); }
.aiBubbleWrap { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: calc(100% - 36px); }
.aiBubble {
  padding: 10px 13px; border-radius: 16px; font-size: .93rem; line-height: 1.6;
  background: var(--surface, #fff); border: 1px solid var(--border, #C8D9EE);
  border-end-start-radius: 4px; overflow-wrap: anywhere; unicode-bidi: plaintext;
}
.aiBubble p { margin: 0 0 6px; } .aiBubble p:last-child { margin-bottom: 0; }
.aiBubble ul, .aiBubble ol { margin: 4px 0 6px; padding-inline-start: 20px; }
.aiBubble li { margin: 2px 0; }
.aiMsg.me .aiBubble { background: var(--deep-2, #123C7C); color: #fff; border-color: transparent; border-radius: 16px; border-end-end-radius: 4px; max-width: 82%; white-space: pre-wrap; }
.aiMsg.err .aiBubble { background: var(--warn-bg, #fbefd8); color: var(--warn, #9a6b17); border-color: transparent; margin-inline-start: 36px; }

.aiTyping { display: inline-flex; gap: 4px; padding: 13px 14px; }
.aiTyping i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3, #657C99); animation: aiDot 1.1s infinite ease-in-out; }
.aiTyping i:nth-child(2) { animation-delay: .15s; } .aiTyping i:nth-child(3) { animation-delay: .3s; }
@keyframes aiDot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.aiChips { display: flex; flex-wrap: wrap; gap: 8px; padding-inline-start: 36px; }
.aiChip {
  border: 1px solid var(--border-strong, #A4BCD8); background: var(--surface, #fff); color: var(--text, #10294E);
  border-radius: 999px; padding: 7px 12px; font: 700 .82rem/1.2 var(--font-body); cursor: pointer; text-align: start;
}
.aiChip:hover { border-color: var(--accent, #D6A12D); background: var(--accent-soft, #fff2d5); }

.aiCards { display: flex; flex-direction: column; gap: 8px; }
.aiCard {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; text-align: start;
  background: var(--surface, #fff); border: 1px solid var(--border, #C8D9EE); border-radius: 14px;
  color: inherit; font: inherit; cursor: pointer; transition: border-color var(--speed, .18s), box-shadow var(--speed, .18s);
}
.aiCard:hover { border-color: var(--accent, #D6A12D); box-shadow: 0 6px 18px rgba(8, 30, 70, .1); }
.aiCard img, .aiCardPh { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-3, #E2EDF9); }
.aiCardPh { display: grid; place-items: center; } .aiCardPh svg { width: 24px; height: 24px; color: var(--accent, #D6A12D); }
.aiCardBody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.aiCardBody b { font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aiCardBody small { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: .76rem; color: var(--text-2, #526985); }
.aiCardBody svg { width: 13px; height: 13px; vertical-align: -2px; }
.aiRate { color: var(--accent-ink, #A87516); font-weight: 800; display: inline-flex; align-items: center; gap: 2px; }
.aiRate svg { color: var(--accent, #D6A12D); }
.aiPlace { display: inline-flex; align-items: center; gap: 2px; min-width: 0; }
.aiCuis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block !important; }
.aiCardGo { flex: none; font-size: .76rem; font-weight: 800; color: var(--accent-ink, #A87516); padding: 6px 10px; border-radius: 999px; background: var(--accent-soft, #fff2d5); }

.aiForm { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border, #C8D9EE); background: var(--surface, #fff); }
.aiForm textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 120px; padding: 11px 14px;
  border: 1px solid var(--border-strong, #A4BCD8); border-radius: 14px; background: var(--surface-2, #F2F6FC);
  color: var(--text, #10294E); font: 500 .95rem/1.45 var(--font-body); unicode-bidi: plaintext;
}
.aiForm textarea:focus { outline: none; border-color: var(--accent, #D6A12D); box-shadow: 0 0 0 3px rgba(214, 161, 45, .2); }
.aiSend { width: 44px; height: 44px; border: 0; border-radius: 14px; background: var(--accent, #D6A12D); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.aiSend:disabled { opacity: .5; cursor: wait; }
.aiSend svg { width: 20px; height: 20px; }
[dir="rtl"] .aiSend svg { transform: scaleX(-1); }
.aiFoot { margin: 0; padding: 0 14px 10px; font-size: .7rem; color: var(--text-3, #657C99); background: var(--surface, #fff); text-align: center; }

:root[data-theme="dark"] .aiMsg.me .aiBubble { background: #2b5a92; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .aiMsg.me .aiBubble { background: #2b5a92; } }

/* phones: the panel becomes a full-height sheet and the button a round icon */
@media (max-width: 720px) {
  #aiFab { padding: 0; width: 56px; height: 56px; justify-content: center; inset-inline-end: 14px; bottom: 14px; }
  #aiFab span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #aiFab svg { width: 26px; height: 26px; }
  #aiPanel { inset: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; border: 0; }
  body.aiOpen { overflow: hidden; }
  .aiForm { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

/* the home page's smart strip now opens the chat: make that obvious */
body.aiReady #assistantForm .goldBtn::before { content: "✦ "; }

/* dashboards are work screens: no floating chat button there */
body:has(#adminView.active) #aiFab, body:has(#ownerView.active) #aiFab { display: none; }

/* ---- Admin -> AI assistant ------------------------------------------- */
.aiAdminHead { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.aiAdminHead .subtle { margin: 4px 0 0; }
.aiAdminStatus { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.aiCore summary { cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none; }
.aiCore summary::-webkit-details-marker { display: none; }
.aiCore summary::before { content: "▸"; color: var(--accent, #D6A12D); }
.aiCore[open] summary::before { content: "▾"; }
.aiCore pre { white-space: pre-wrap; font-size: .8rem; line-height: 1.6; background: var(--surface-2, #F2F6FC); border: 1px solid var(--border, #C8D9EE); border-radius: 12px; padding: 12px 14px; max-height: 360px; overflow: auto; text-align: left; margin-top: 10px; }
#aiAdminBody textarea { width: 100%; min-height: 90px; resize: vertical; font: inherit; line-height: 1.55; }
.aiMeter { margin: 12px 0; }
.aiMeter > div { display: flex; justify-content: space-between; gap: 12px; font-size: .86rem; margin-bottom: 6px; }
.aiMeter > div span { color: var(--text-2, #526985); }
.aiMeter i { display: block; height: 10px; border-radius: 999px; background: var(--surface-3, #E2EDF9); overflow: hidden; }
.aiMeter s { display: block; height: 100%; border-radius: inherit; background: var(--accent, #D6A12D); text-decoration: none; min-width: 2px; }
.aiMeter s.hot { background: var(--danger, #b3403a); }
.aiTranscript { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 14px; max-height: 520px; overflow: auto; }
.aiTr { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border, #C8D9EE); background: var(--surface, #fff); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; line-height: 1.6; }
.aiTr.me { background: var(--surface-2, #F2F6FC); }
.aiTr small { display: block; color: var(--text-3, #657C99); font-size: .72rem; margin-bottom: 4px; white-space: normal; }
.aiTestForm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.aiTestForm input { flex: 1 1 260px; }
.aiTestForm select { flex: 0 0 auto; max-width: 180px; }
.aiTokenBox { width: 100%; font-family: ui-monospace, Menlo, monospace; margin-top: 8px; }
