/* === AI Assistant Chat Panel === */

.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 999;
  box-shadow:
    0 6px 18px rgba(6, 182, 212, 0.35),
    0 2px 6px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.18s, opacity 0.18s;
}
.ai-fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    0 10px 24px rgba(6, 182, 212, 0.45),
    0 3px 8px rgba(0, 0, 0, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.ai-fab:active { transform: translateY(0) scale(0.98); }

/* Hide FAB when panel is open — close button in header handles dismissal */
.ai-fab.panel-open {
  opacity: 0;
  transform: scale(0.6) translateY(20px);
  pointer-events: none;
}

.ai-fab-icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.18s, transform 0.18s;
}
.ai-fab-icon.hide { opacity: 0; transform: scale(0.6) rotate(-30deg); }

.ai-fab.thinking::before,
.ai-fab.thinking::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: aiPulse 1.6s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  pointer-events: none;
}
.ai-fab.thinking::after { animation-delay: 0.8s; }
@keyframes aiPulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.6); opacity: 0; }
}

.ai-fab-unread {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg);
  animation: badgePop 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}
@keyframes badgePop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* === Backdrop (modal mode only) === */
.ai-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 997;
  animation: aiFadeIn 0.18s ease-out;
}
[data-theme="dark"] .ai-backdrop { background: rgba(0, 0, 0, 0.6); }
@keyframes aiFadeIn { from { opacity: 0; } to { opacity: 1; } }
.ai-backdrop.closing { animation: aiFadeOut 0.16s ease-in forwards; }
@keyframes aiFadeOut { to { opacity: 0; } }

/* === Panel (shared) === */
.ai-panel {
  background: var(--bg-elevated);
  z-index: 998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Modal mode */
.ai-panel.modal {
  position: fixed;
  width: 720px;
  height: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow:
    0 32px 64px rgba(0, 0, 0, 0.20),
    0 8px 20px rgba(0, 0, 0, 0.10);
  animation: aiModalIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
[data-theme="dark"] .ai-panel.modal {
  box-shadow:
    0 32px 64px rgba(0, 0, 0, 0.55),
    0 8px 20px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.03);
}
@keyframes aiModalIn {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.ai-panel.modal.closing {
  animation: aiModalOut 0.16s cubic-bezier(0.4, 0, 1, 1) forwards;
}
@keyframes aiModalOut {
  to { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
}

/* Sidebar mode */
.ai-panel.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 100vw;
  height: 100vh;
  border-left: 1px solid var(--border);
  border-radius: 0;
  animation: aiSidebarIn 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes aiSidebarIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.ai-panel.sidebar.closing {
  animation: aiSidebarOut 0.18s cubic-bezier(0.4, 0, 1, 1) forwards;
}
@keyframes aiSidebarOut {
  to { transform: translateX(100%); }
}

/* === Header === */
.ai-header {
  height: 52px;
  padding: 0 10px 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #14b8a6);
  display: grid;
  place-items: center;
  color: white;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 6px rgba(6, 182, 212, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.ai-avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.35), transparent 55%);
}
.ai-avatar svg { position: relative; z-index: 1; }

.ai-title-row {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.ai-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
}
.ai-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  position: relative;
}
.ai-status-dot::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--success);
  animation: aiDotRing 2s ease-out infinite;
  opacity: 0;
}
.ai-status-dot.thinking { background: var(--accent); }
.ai-status-dot.thinking::before {
  background: var(--accent);
  animation: aiDotRing 1.2s ease-out infinite;
  opacity: 1;
}
@keyframes aiDotRing {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(2.5); opacity: 0; }
}

.ai-title-tag {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: uppercase;
}

/* Layout toggle */
.ai-layout-toggle {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  gap: 1px;
}
.ai-layout-toggle button {
  width: 26px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 5px;
  color: var(--text-subtle);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.12s;
}
.ai-layout-toggle button:hover { color: var(--text); }
.ai-layout-toggle button.active {
  background: var(--bg-elevated);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .ai-layout-toggle button.active {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.ai-header-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text-subtle);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.ai-header-btn:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

/* === Messages === */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}
.ai-panel.modal .ai-messages { padding: 20px 24px 8px; }
.ai-messages::-webkit-scrollbar { width: 6px; }
.ai-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.ai-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: msgIn 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-width: 100%;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-msg.user {
  flex-direction: row-reverse;
  align-self: flex-end;
  max-width: 75%;
}
.ai-msg.ai {
  align-self: flex-start;
  max-width: 85%;
}

.ai-msg-avatar {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 600;
  margin-top: 2px;
}
.ai-msg-avatar.ai {
  background: linear-gradient(135deg, var(--accent), #14b8a6);
  color: white;
}
.ai-msg-avatar.user {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.ai-msg-wrap { min-width: 0; max-width: 100%; }

.ai-msg-bubble {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  position: relative;
}
.ai-msg.user .ai-msg-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}
.ai-msg.ai .ai-msg-bubble {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.ai-msg-bubble strong { font-weight: 600; }
.ai-msg-bubble ul {
  margin: 6px 0 2px;
  padding-left: 4px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-msg-bubble ul li {
  position: relative;
  padding-left: 14px;
}
.ai-msg-bubble ul li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}
.ai-msg.user .ai-msg-bubble ul li::before { background: rgba(255, 255, 255, 0.7); }

.ai-msg-meta {
  font-size: 10.5px;
  color: var(--text-subtle);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.15s;
}
.ai-msg:hover .ai-msg-meta { opacity: 1; }
.ai-msg.user .ai-msg-meta { text-align: right; }

/* Data chip */
.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  font-weight: 500;
  margin: 0 1px;
}
.ai-chip.danger { background: var(--danger-soft); color: var(--danger); }
.ai-chip.success { background: var(--success-soft); color: var(--success); }
.ai-chip.warning { background: var(--warning-soft); color: var(--warning); }

/* Typing */
.ai-typing {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  height: 14px;
  padding: 0 2px;
}
.ai-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-subtle);
  animation: aiTyping 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes aiTyping {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Quick prompts */
.ai-suggested {
  flex-shrink: 0;
  padding: 8px 14px 6px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg-elevated);
  mask-image: linear-gradient(to right, black, black calc(100% - 24px), transparent);
  animation: promptsIn 0.2s ease-out;
}
.ai-panel.modal .ai-suggested { padding: 8px 24px 6px; }
@keyframes promptsIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.ai-suggested.hide {
  animation: promptsOut 0.2s ease-in forwards;
  pointer-events: none;
}
@keyframes promptsOut {
  to { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }
}
.ai-suggested::-webkit-scrollbar { display: none; }
.ai-suggested-pill {
  flex-shrink: 0;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.ai-suggested-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.ai-suggested-pill svg { color: var(--text-subtle); }
.ai-suggested-pill:hover svg { color: var(--accent); }

/* Input */
.ai-input-row {
  flex-shrink: 0;
  height: 56px;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.ai-panel.modal .ai-input-row { padding: 10px 20px; }

.ai-input {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.ai-input:focus {
  border-color: var(--accent);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.ai-input::placeholder { color: var(--text-subtle); }

.ai-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.12s, transform 0.12s, opacity 0.12s;
  box-shadow: 0 1px 2px rgba(6, 182, 212, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  flex-shrink: 0;
}
.ai-send:hover:not(:disabled) { background: var(--accent-hover); }
.ai-send:active:not(:disabled) { transform: scale(0.94); }
.ai-send:disabled {
  background: var(--bg-hover);
  color: var(--text-subtle);
  cursor: not-allowed;
  box-shadow: none;
}
