:root {
  --ai-primary: #0b3b77;
  --ai-accent: #f28a23;
  --ai-border: #e3e8ef;
  --ai-muted: #758195;
  --ai-shadow: 0 18px 48px rgba(16, 35, 62, .18);
}
.ai-history-toolbar { display:flex; flex-wrap:wrap; gap:6px; padding:10px; border-bottom:1px solid #e3e8ef; }
.ai-history-toolbar button { border:1px solid #dce4ee; background:#f7f9fc; border-radius:7px; padding:7px 10px; color:#0b3b77; font-size:12px; }
.ai-history-toolbar input { width:100%; padding:7px; border:1px solid #dce4ee; border-radius:7px; font:inherit; font-size:12px; }
.ai-history-notice { padding:8px 12px; font-size:11px; color:#657188; }
.ai-history-list { flex:1; min-height:0; overflow:auto; padding:12px; }
.ai-history-list button { display:block; width:100%; text-align:right; padding:12px; margin-bottom:8px; border:1px solid #dce4ee; border-radius:9px; background:#f7f9fc; color:#344054; line-height:1.8; font-size:12px; overflow-wrap:anywhere; }
.ai-assistant-panel [hidden] { display:none!important; }
.ai-assistant-settings label + label { margin-top:10px; }

.ai-assistant-launcher {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 1040;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: var(--ai-primary);
  box-shadow: 0 10px 28px rgba(11, 59, 119, .3);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.ai-assistant-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(11, 59, 119, .38); }
.ai-assistant-launcher svg { width: 26px; height: 26px; }
.ai-assistant-launcher[aria-expanded="true"] { opacity: 0; pointer-events: none; transform: scale(.9); }

.ai-assistant-panel {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 1041;
  width: min(390px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  transform: translateY(18px) scale(.98);
  border: 1px solid var(--ai-border);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--ai-shadow);
  direction: rtl;
  transition: opacity 180ms ease, transform 180ms ease, visibility 0s linear 180ms;
}

.ai-assistant-panel.open {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition-delay: 0s;
}

.ai-assistant-header {
  min-height: 68px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  background: linear-gradient(135deg, #0b3b77, #062b5b);
}

.ai-assistant-mark { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 12px; background: rgba(255,255,255,.13); }
.ai-assistant-mark svg { width: 22px; height: 22px; }
.ai-assistant-title { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.ai-assistant-title strong { font-size: 13px; }
.ai-assistant-title small { margin-top: 3px; color: rgba(255,255,255,.7); font-size: 10px; }
.ai-assistant-header-actions { display: flex; direction: ltr; gap: 2px; }
.ai-assistant-icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 9px; color: inherit; background: transparent; cursor: pointer; }
.ai-assistant-icon-btn:hover { background: rgba(255,255,255,.12); }
.ai-assistant-icon-btn svg { width: 18px; height: 18px; }

.ai-assistant-settings {
  padding: 10px 14px;
  display: none;
  border-bottom: 1px solid var(--ai-border);
  color: #4c586b;
  background: #f8fafc;
  font-size: 11px;
}
.ai-assistant-settings.open { display: block; }
.ai-assistant-settings label { margin: 0; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ai-assistant-settings input { accent-color: var(--ai-primary); }
.ai-assistant-settings-hint { margin: 6px 24px 0 0; color: #8994a5; font-size: 9.5px; }

.ai-assistant-messages { flex: 1; padding: 16px 14px; overflow-y: auto; background: #f7f9fc; scroll-behavior: smooth; }
.ai-message { margin-bottom: 12px; display: flex; flex-direction: column; align-items: flex-start; }
.ai-message.user { align-items: flex-end; }
.ai-message-bubble { max-width: 88%; padding: 10px 12px; border: 1px solid var(--ai-border); border-radius: 13px 13px 13px 4px; color: #344054; background: #fff; font-size: 12px; line-height: 1.9; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-message.user .ai-message-bubble { border-color: var(--ai-primary); border-radius: 13px 13px 4px 13px; color: #fff; background: var(--ai-primary); }
.ai-message.error .ai-message-bubble { border-color: #f4c7c7; color: #9f2424; background: #fff4f4; }
.ai-message-time { margin-top: 4px; padding: 0 4px; color: #9aa3b1; font-size: 8.5px; direction: ltr; }
.ai-message-citations { width: 88%; margin-top: 6px; border: 1px solid #dce4ee; border-radius: 10px; color: #556174; background: #fff; font-size: 10px; }
.ai-message-citations summary { padding: 8px 10px; color: var(--ai-primary); font-weight: 700; cursor: pointer; list-style-position: inside; }
.ai-citation-list { padding: 0 9px 9px; display: grid; gap: 7px; }
.ai-citation-item { padding: 8px; border-radius: 8px; background: #f6f8fb; }
.ai-citation-item strong { display: block; color: #3c485b; font-size: 9.5px; line-height: 1.6; }
.ai-citation-item p { max-height: 105px; margin: 5px 0 0; overflow-y: auto; color: #707b8d; font-size: 9px; line-height: 1.8; white-space: pre-wrap; }
.ai-message-loading .ai-message-bubble { display: flex; gap: 4px; align-items: center; min-height: 38px; }
.ai-message-loading i { width: 6px; height: 6px; border-radius: 50%; background: #8d98aa; animation: aiTyping 1.1s infinite ease-in-out; }
.ai-message-loading i:nth-child(2) { animation-delay: .15s; }
.ai-message-loading i:nth-child(3) { animation-delay: .3s; }
@keyframes aiTyping { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

.ai-assistant-composer { padding: 10px; display: flex; align-items: flex-end; gap: 7px; border-top: 1px solid var(--ai-border); background: #fff; }
.ai-assistant-input { min-height: 42px; max-height: 112px; flex: 1; resize: none; overflow-y: auto; padding: 10px 12px; border: 1px solid #dce2ea; border-radius: 12px; outline: 0; color: #2d3748; background: #fff; font: 11.5px/1.8 inherit; }
.ai-assistant-input:focus { border-color: #8eacd0; box-shadow: 0 0 0 3px rgba(11,59,119,.08); }
.ai-assistant-input:disabled { background: #f2f4f7; }
.ai-assistant-action { width: 40px; height: 40px; flex: 0 0 auto; display: grid; place-items: center; border: 0; border-radius: 11px; cursor: pointer; }
.ai-assistant-action svg { width: 19px; height: 19px; }
.ai-assistant-send { color: #fff; background: var(--ai-primary); }
.ai-assistant-send:disabled { opacity: .45; cursor: not-allowed; }
.ai-assistant-voice { color: #657188; background: #eef2f7; }
.ai-assistant-voice:disabled { opacity: .45; cursor: not-allowed; }
.ai-assistant-voice.recording { color: #fff; background: #c93636; animation: aiPulse 1.3s infinite; }
@keyframes aiPulse { 50% { box-shadow: 0 0 0 7px rgba(201,54,54,.14); } }
.ai-assistant-note { padding: 0 14px 9px; color: #98a1af; background: #fff; font-size: 8.5px; text-align: center; }

@media (max-width: 575px) {
  .ai-assistant-launcher { left: 16px; bottom: 16px; }
  .ai-assistant-panel { inset: 0; width: 100%; height: 100%; max-width: none; border: 0; border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-assistant-panel, .ai-assistant-launcher { transition: none; }
  .ai-message-loading i, .ai-assistant-voice.recording { animation: none; }
}
