/* ─── AI Mode - Floating Intelligence Panel ───────────────────────────────── */
/* Self-contained styles for the AI Mode floating chat panel.
   Injected into every module page via <link> tag.
   Brand: navy #1B2E5A, emerald #22b378, no gradients. */

/* ─────────────────────────────────────────────────────────────────────────────
   1. CUSTOM PROPERTIES
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-panel,
.ai-mode-fab {
  --ai-navy: #1B2E5A;
  --ai-navy-light: #253d6e;
  --ai-navy-deep: #0e1c3a;
  --ai-emerald: #22b378;
  --ai-emerald-deep: #1a9660;
  --ai-red: #f7525a;
  --ai-amber: #dc9d28;
  --ai-text: #1B2E5A;
  --ai-text-secondary: #3a4d72;
  --ai-text-muted: #7b8fac;
  --ai-border: rgba(27,46,90,0.08);
  --ai-surface: #f7f8fa;
  --ai-panel: #ffffff;
  --ai-radius: 14px;
  --ai-radius-sm: 10px;
  --ai-font: "Open Sans", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
}

/* ─────────────────────────────────────────────────────────────────────────────
   2. ANIMATIONS
   ───────────────────────────────────────────────────────────────────────────── */

@keyframes ai-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes ai-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ai-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-4px); }
}

@keyframes ai-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes ai-card-approve {
  0%   { background-color: rgba(34,179,120,0.06); }
  50%  { background-color: rgba(34,179,120,0.14); }
  100% { background-color: rgba(34,179,120,0.06); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   3. FAB BUTTON
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  height: 40px;
  padding: 0 14px 0 12px;
  border-radius: 12px;
  border: none;
  background: var(--ai-navy);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 2px 12px rgba(27,46,90,0.25);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  outline: none;
  font-family: var(--ai-font);
}

.ai-mode-fab .ai-fab-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.85);
}

.ai-mode-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 18px rgba(27,46,90,0.35);
}

.ai-mode-fab:active {
  transform: translateY(0);
}

.ai-mode-fab.processing {
  animation: ai-pulse 1.4s infinite;
}

.ai-mode-fab .ai-fab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
  font-size: 1rem;
}

body.ai-mode-open .ai-mode-fab .ai-fab-icon {
  transform: rotate(45deg);
}

.ai-mode-fab .ai-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--ai-red);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #fff;
  line-height: 1;
}

.ai-mode-fab .ai-fab-badge.visible {
  display: flex;
}

/* ─────────────────────────────────────────────────────────────────────────────
   4. PANEL CONTAINER
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-panel {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 420px;
  max-height: min(600px, calc(100vh - 100px));
  border-radius: var(--ai-radius);
  background: var(--ai-panel);
  border: 1px solid var(--ai-border);
  box-shadow:
    0 24px 48px rgba(27,46,90,0.12),
    0 8px 24px rgba(27,46,90,0.06),
    0 0 0 1px rgba(27,46,90,0.04);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  font-family: var(--ai-font);
  font-size: 13px;
  color: var(--ai-text);
}

body.ai-mode-open .ai-mode-panel {
  display: flex;
  animation: ai-slide-up 0.25s ease forwards;
}

/* ─── EXPANDED / FULL-VIEW MODE ─── */
body.ai-mode-expanded .ai-mode-panel {
  position: fixed;
  top: 0;
  left: var(--sidebar-width, 150px);
  right: 0;
  bottom: 0;
  width: auto;
  max-height: none;
  border-radius: 0;
  border: none;
  box-shadow: none;
  z-index: 9998;
  animation: none;
}

body.ai-mode-expanded .ai-mode-fab {
  display: none;
}

/* Hide main content behind expanded panel */
body.ai-mode-expanded .main-content {
  visibility: hidden;
}

@media (max-width: 768px) {
  body.ai-mode-expanded .ai-mode-panel {
    left: 0;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   5. HEADER
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-header {
  background: var(--ai-navy);
  color: #fff;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ai-mode-header-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.ai-mode-header-info {
  flex: 1;
  min-width: 0;
}

.ai-mode-header-title {
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: -0.01em;
}

.ai-mode-tenant-name {
  font-weight: 400;
  font-size: 0.78rem;
  opacity: 0.7;
}

.ai-mode-header-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
}

.ai-mode-module-badge,
.ai-mode-provider-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
}

.ai-mode-provider-badge .ai-provider-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ai-emerald);
  flex-shrink: 0;
}

.ai-mode-provider-badge .ai-provider-dot.disconnected {
  background: var(--ai-red);
}

.ai-mode-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.ai-mode-daily-counter {
  font-size: 0.62rem;
  font-weight: 700;
  color: rgba(255,255,255,0.55);
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ai-mode-header-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
}

.ai-mode-header-btn:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

/* Quick Setup gear with a tiny "Quick Setup" superscript label.
   Wider than other header buttons to accommodate the sup; the sup itself
   sits top-right of the gear glyph and is styled smaller so it reads as
   a label rather than a control. */
.ai-mode-quick-setup-btn {
  position: relative;
  width: auto;
  min-width: 28px;
  padding: 0 10px 0 6px;
  gap: 2px;
}
.ai-mode-quick-setup-btn .ai-qs-gear {
  font-size: 0.95rem;
  line-height: 1;
}
.ai-mode-quick-setup-btn .ai-qs-sup {
  position: absolute;
  top: -2px;
  right: -3px;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  background: var(--brand-red, #D4273B);
  padding: 1px 5px;
  border-radius: 999px;
  line-height: 1.4;
  pointer-events: none;
}
.ai-mode-quick-setup-btn .quick-setup-pct {
  display: none; /* counts already shown in sidebar — keep this control compact */
}
@media (max-width: 480px) {
  /* On narrow phones drop the superscript label since header has limited
     width; keep the gear glyph with a tooltip for accessibility. */
  .ai-mode-quick-setup-btn .ai-qs-sup { display: none; }
  .ai-mode-quick-setup-btn { padding: 0; min-width: 28px; width: 28px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   6. MESSAGES AREA
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(27,46,90,0.08) transparent;
}

.ai-mode-messages::-webkit-scrollbar { width: 4px; }
.ai-mode-messages::-webkit-scrollbar-track { background: transparent; }
.ai-mode-messages::-webkit-scrollbar-thumb { background: rgba(27,46,90,0.1); border-radius: 4px; }
.ai-mode-messages::-webkit-scrollbar-thumb:hover { background: rgba(27,46,90,0.18); }

/* ─────────────────────────────────────────────────────────────────────────────
   7. MESSAGE BUBBLES
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: ai-fade-in 0.25s ease;
}

.ai-mode-msg.user {
  flex-direction: row-reverse;
}

.ai-mode-msg-body {
  min-width: 0;
  flex: 1;
  max-width: calc(100% - 36px);
}

.ai-mode-msg.user .ai-mode-msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.ai-mode-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.ai-mode-avatar.ai {
  background: var(--ai-navy);
  color: #fff;
  font-size: 0.8rem;
}

.ai-mode-avatar.user {
  background: var(--ai-emerald);
  color: #fff;
  font-size: 0.65rem;
}

.ai-mode-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 12px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
  font-size: 0.82rem;
  overflow-x: auto;
  overflow-y: hidden;
}

.ai-mode-bubble.ai {
  background: var(--ai-surface);
  color: var(--ai-text);
  border-top-left-radius: 3px;
}

.ai-mode-bubble.user {
  background: var(--ai-navy);
  color: #fff;
  border-top-right-radius: 3px;
}

.ai-mode-bubble strong { font-weight: 700; }
.ai-mode-bubble em { font-style: italic; }

.ai-mode-bubble code {
  background: rgba(27,46,90,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: ui-monospace,"SF Mono",Consolas,monospace;
}

.ai-mode-bubble.user code {
  background: rgba(255,255,255,0.12);
}

.ai-mode-bubble a {
  color: var(--ai-emerald);
  font-weight: 600;
  text-decoration: none;
}

.ai-mode-bubble a:hover {
  text-decoration: underline;
}

.ai-mode-bubble.user a {
  color: rgba(255,255,255,0.9);
}

.ai-mode-bubble ol,
.ai-mode-bubble ul {
  margin: 6px 0 2px 0;
  padding-left: 18px;
}

.ai-mode-bubble ol li,
.ai-mode-bubble ul li {
  margin-bottom: 2px;
}

.ai-mode-bubble table {
  border-collapse: collapse;
  margin: 6px 0 4px;
  font-size: 0.82em;
  width: max-content;
  min-width: 100%;
}

.ai-mode-bubble table th,
.ai-mode-bubble table td {
  padding: 3px 6px;
  text-align: left;
  border-bottom: 1px solid var(--ai-border);
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-mode-bubble table th {
  font-weight: 700;
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ai-text-muted);
  position: sticky;
  top: 0;
  background: inherit;
}

.ai-mode-time {
  font-size: 0.65rem;
  color: var(--ai-text-muted);
  margin-top: 2px;
  padding: 0 4px;
}

.ai-mode-msg.user .ai-mode-time {
  text-align: right;
}

/* Message attachments */
.ai-mode-bubble-image {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 6px;
  cursor: pointer;
}

/* ─────────────────────────────────────────────────────────────────────────────
   8. ACTION CONFIRMATION CARDS
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-action-card {
  background: var(--ai-panel);
  border: 1px solid rgba(217,119,6,0.15);
  border-left: 3px solid var(--ai-amber);
  border-radius: var(--ai-radius-sm);
  padding: 12px;
  margin: 4px 0;
  animation: ai-fade-in 0.3s ease;
  transition: border-color 0.3s, background 0.3s, opacity 0.3s;
  overflow-x: auto;
  overflow-y: hidden;
  word-break: break-word;
}

.ai-mode-action-card.approved {
  border-left-color: var(--ai-emerald);
  border-color: rgba(34,179,120,0.15);
  animation: ai-card-approve 0.5s ease;
}

.ai-mode-action-card.rejected {
  border-left-color: var(--ai-red);
  border-color: rgba(247,82,90,0.15);
  opacity: 0.6;
}

.ai-mode-action-card.executed {
  border-left-color: var(--ai-emerald);
  border-color: rgba(34,179,120,0.15);
  background: rgba(34,179,120,0.04);
}

.ai-mode-action-card.failed {
  border-left-color: var(--ai-red);
  border-color: rgba(247,82,90,0.2);
  background: rgba(247,82,90,0.06);
}

.ai-mode-action-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ai-amber);
}

.ai-mode-action-card.approved .ai-mode-action-title { color: var(--ai-emerald); }
.ai-mode-action-card.rejected .ai-mode-action-title { color: var(--ai-red); }
.ai-mode-action-card.executed .ai-mode-action-title { color: var(--ai-emerald); }
.ai-mode-action-card.failed .ai-mode-action-title { color: var(--ai-red); }

.ai-mode-action-status-icon {
  display: none;
  font-size: 0.85rem;
}

.ai-mode-action-card.approved .ai-mode-action-status-icon,
.ai-mode-action-card.rejected .ai-mode-action-status-icon,
.ai-mode-action-card.executed .ai-mode-action-status-icon,
.ai-mode-action-card.failed .ai-mode-action-status-icon {
  display: inline;
}

.ai-mode-action-body {
  font-size: 0.78rem;
  color: var(--ai-text-secondary);
  margin-bottom: 8px;
  line-height: 1.45;
}

.ai-mode-action-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.ai-mode-action-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.76rem;
  min-width: 0;
}

.ai-mode-action-row-label {
  color: var(--ai-text-muted);
  font-weight: 600;
  min-width: 60px;
  flex-shrink: 0;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
}

.ai-mode-action-row-value {
  color: var(--ai-text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.ai-mode-action-buttons {
  display: flex;
  gap: 6px;
}

.ai-mode-action-card.approved .ai-mode-action-buttons,
.ai-mode-action-card.rejected .ai-mode-action-buttons,
.ai-mode-action-card.executed .ai-mode-action-buttons,
.ai-mode-action-card.failed .ai-mode-action-buttons {
  display: none;
}

.ai-mode-btn-approve,
.ai-mode-btn-reject {
  flex: 1;
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s, transform 0.1s;
}

.ai-mode-btn-approve {
  background: var(--ai-emerald);
  color: #fff;
}

.ai-mode-btn-approve:hover {
  background: var(--ai-emerald-deep);
  transform: translateY(-1px);
}

.ai-mode-btn-reject {
  background: rgba(247,82,90,0.08);
  color: var(--ai-red);
}

.ai-mode-btn-reject:hover {
  background: rgba(247,82,90,0.15);
  transform: translateY(-1px);
}

/* Bulk approve/reject all */
.ai-mode-bulk-actions {
  display: flex;
  gap: 8px;
  margin: 6px 0 2px;
}

.ai-mode-btn-approve-all,
.ai-mode-btn-reject-all {
  flex: 1;
  padding: 8px 14px;
  border-radius: 8px;
  border: 2px solid transparent;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s, transform 0.1s;
}

.ai-mode-btn-approve-all {
  background: var(--ai-emerald);
  color: #fff;
  border-color: var(--ai-emerald-deep);
}

.ai-mode-btn-approve-all:hover {
  background: var(--ai-emerald-deep);
  transform: translateY(-1px);
}

.ai-mode-btn-reject-all {
  background: rgba(247,82,90,0.08);
  color: var(--ai-red);
  border-color: rgba(247,82,90,0.2);
}

.ai-mode-btn-reject-all:hover {
  background: rgba(247,82,90,0.15);
  transform: translateY(-1px);
}

/* ─── QUICK-REPLY BUTTONS (confirm/deny) ─── */
.ai-mode-quick-replies {
  display: flex;
  gap: 8px;
  margin: 8px 0 2px;
  animation: ai-fade-in 0.25s ease;
}

.ai-mode-quick-reply {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--ai-border);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  background: var(--ai-panel);
  color: var(--ai-text);
  font-family: var(--ai-font);
}

.ai-mode-quick-reply.confirm {
  border-color: rgba(34,179,120,0.3);
  color: var(--ai-emerald-deep);
}

.ai-mode-quick-reply.confirm:hover {
  background: rgba(34,179,120,0.1);
  border-color: var(--ai-emerald);
  transform: translateY(-1px);
}

.ai-mode-quick-reply.deny {
  border-color: rgba(247,82,90,0.2);
  color: var(--ai-red);
}

.ai-mode-quick-reply.deny:hover {
  background: rgba(247,82,90,0.08);
  border-color: var(--ai-red);
  transform: translateY(-1px);
}

/* ─────────────────────────────────────────────────────────────────────────────
   9. PRODUCT PREVIEW CARD
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-product-preview {
  background: var(--ai-panel);
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius-sm);
  overflow: hidden;
  margin: 4px 0;
  animation: ai-fade-in 0.3s ease;
}

.ai-mode-product-preview-header {
  background: var(--ai-emerald);
  color: #fff;
  padding: 7px 12px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-mode-product-preview-body {
  display: flex;
  gap: 12px;
  padding: 12px;
}

.ai-mode-product-thumb {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--ai-surface);
}

.ai-mode-product-info {
  flex: 1;
  min-width: 0;
}

.ai-mode-product-name {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 3px;
  color: var(--ai-text);
}

.ai-mode-product-desc {
  font-size: 0.74rem;
  color: var(--ai-text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-mode-product-price {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ai-emerald);
}

.ai-mode-product-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--ai-border);
}

.ai-mode-product-field {
  font-size: 0.72rem;
}

.ai-mode-product-field-label {
  color: var(--ai-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
}

.ai-mode-product-field-value {
  color: var(--ai-text);
  font-weight: 500;
}

.ai-mode-product-preview-footer {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--ai-border);
}

.ai-mode-btn-add-product {
  width: 100%;
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  background: var(--ai-emerald);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, transform 0.1s;
}

.ai-mode-btn-add-product:hover {
  background: var(--ai-emerald-deep);
  transform: translateY(-1px);
}

/* ─────────────────────────────────────────────────────────────────────────────
   10. FILE UPLOAD
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-upload-preview {
  display: none;
  padding: 6px 12px 4px;
  gap: 6px;
  flex-wrap: wrap;
  border-top: 1px solid var(--ai-border);
}

.ai-mode-upload-preview.has-files {
  display: flex;
}

.ai-mode-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: rgba(27,46,90,0.04);
  border: 1px solid var(--ai-border);
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ai-text-secondary);
  max-width: 160px;
  overflow: hidden;
}

.ai-mode-file-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-mode-file-chip-thumb {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  object-fit: cover;
  flex-shrink: 0;
}

.ai-mode-file-chip-remove {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: rgba(247,82,90,0.1);
  color: var(--ai-red);
  font-size: 0.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.ai-mode-file-chip-remove:hover {
  background: rgba(247,82,90,0.2);
}

/* Drag overlay */
.ai-mode-drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(34,179,120,0.08);
  border: 2px dashed var(--ai-emerald);
  border-radius: var(--ai-radius);
  z-index: 10;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--ai-emerald);
  font-size: 0.88rem;
  pointer-events: none;
  backdrop-filter: blur(2px);
}

.ai-mode-panel.drag-over .ai-mode-drop-overlay {
  display: flex;
}

/* ─────────────────────────────────────────────────────────────────────────────
   11. INPUT ROW
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--ai-border);
  background: var(--ai-panel);
  flex-shrink: 0;
}

.ai-mode-textarea {
  flex: 1;
  border: 1px solid rgba(27,46,90,0.1);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-family: inherit;
  line-height: 1.45;
  resize: none;
  overflow-y: hidden;
  min-height: 36px;
  max-height: 96px;
  background: var(--ai-surface);
  color: var(--ai-text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.ai-mode-textarea:focus {
  border-color: var(--ai-navy);
  box-shadow: 0 0 0 2px rgba(27,46,90,0.08);
}

.ai-mode-textarea::placeholder {
  color: #a0b0c8;
}

.ai-mode-input-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.ai-mode-btn-attach {
  background: transparent;
  color: var(--ai-text-muted);
}

.ai-mode-btn-attach:hover {
  background: var(--ai-surface);
  color: var(--ai-text-secondary);
}

.ai-mode-btn-voice {
  background: transparent;
  color: var(--ai-text-muted);
}

.ai-mode-btn-voice:hover {
  background: var(--ai-surface);
  color: var(--ai-text-secondary);
}

.ai-mode-btn-send {
  background: var(--ai-navy);
  color: #fff;
}

.ai-mode-btn-send:hover {
  background: var(--ai-navy-light);
  transform: translateY(-1px);
}

.ai-mode-btn-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.ai-mode-file-input {
  display: none;
}

/* ─────────────────────────────────────────────────────────────────────────────
   12. TYPING INDICATOR
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  animation: ai-fade-in 0.25s ease;
}

.ai-mode-typing-dots {
  display: flex;
  gap: 3px;
  padding: 10px 14px;
  background: var(--ai-surface);
  border-radius: 12px;
  border-top-left-radius: 3px;
}

.ai-mode-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai-text-muted);
  animation: ai-bounce 1.2s infinite;
}

.ai-mode-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-mode-typing-dot:nth-child(3) { animation-delay: 0.3s; }

.ai-mode-typing-text {
  font-size: 0.68rem;
  color: var(--ai-text-muted);
  font-style: italic;
}

/* ─────────────────────────────────────────────────────────────────────────────
   13. USAGE BAR
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-usage {
  padding: 6px 12px;
  border-top: 1px solid var(--ai-border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.65rem;
  color: var(--ai-text-muted);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s;
}

.ai-mode-usage:hover {
  background: rgba(27,46,90,0.02);
}

.ai-mode-usage-bar {
  flex: 1;
  height: 2px;
  border-radius: 2px;
  background: rgba(27,46,90,0.06);
  overflow: hidden;
}

.ai-mode-usage-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--ai-emerald);
  transition: width 0.4s ease;
}

.ai-mode-usage-text {
  white-space: nowrap;
}

.ai-mode-usage-detail {
  display: none;
  padding: 6px 12px;
  border-top: 1px solid var(--ai-border);
  font-size: 0.68rem;
  color: var(--ai-text-muted);
  flex-shrink: 0;
  gap: 10px;
}

.ai-mode-usage.expanded + .ai-mode-usage-detail {
  display: flex;
}

.ai-mode-usage-detail-item {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   14. EMPTY STATE
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px 16px;
  text-align: center;
}

.ai-mode-empty-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(27,46,90,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  margin-bottom: 12px;
}

.ai-mode-empty-title {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ai-text);
  margin-bottom: 4px;
}

.ai-mode-empty-desc {
  font-size: 0.78rem;
  color: var(--ai-text-muted);
  line-height: 1.5;
  margin-bottom: 14px;
  max-width: 280px;
}

.ai-mode-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  max-width: 360px;
}

.ai-mode-suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--ai-border);
  background: var(--ai-panel);
  color: var(--ai-text-secondary);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.ai-mode-suggestion-chip:hover {
  background: rgba(27,46,90,0.04);
  border-color: rgba(27,46,90,0.15);
  transform: translateY(-1px);
}

/* ─────────────────────────────────────────────────────────────────────────────
   15. WELCOME CARDS
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-welcome {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px 14px 14px;
}

.ai-mode-welcome-card {
  padding: 12px;
  border-radius: var(--ai-radius-sm);
  border: 1px solid var(--ai-border);
  background: var(--ai-panel);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.ai-mode-welcome-card:hover {
  border-color: rgba(27,46,90,0.15);
  background: rgba(27,46,90,0.02);
  transform: translateY(-1px);
}

.ai-mode-welcome-icon {
  font-size: 1.15rem;
  margin-bottom: 6px;
}

.ai-mode-welcome-title {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--ai-text);
  margin-bottom: 2px;
}

.ai-mode-welcome-desc {
  font-size: 0.68rem;
  color: var(--ai-text-muted);
  line-height: 1.4;
}

/* ─────────────────────────────────────────────────────────────────────────────
   16. ERROR / NO-AI STATES
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-error {
  background: rgba(247,82,90,0.06);
  border: 1px solid rgba(247,82,90,0.12);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: ai-fade-in 0.25s ease;
}

.ai-mode-error-icon {
  font-size: 1rem;
  flex-shrink: 0;
  line-height: 1;
}

.ai-mode-error-text {
  font-size: 0.78rem;
  color: var(--ai-red);
  line-height: 1.4;
}

.ai-mode-no-ai {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  flex: 1;
}

.ai-mode-no-ai-icon {
  font-size: 2rem;
  margin-bottom: 10px;
  opacity: 0.4;
}

.ai-mode-no-ai-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ai-text);
  margin-bottom: 4px;
}

.ai-mode-no-ai-desc {
  font-size: 0.78rem;
  color: var(--ai-text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.ai-mode-no-ai-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  border-radius: 6px;
  background: var(--ai-navy);
  color: #fff;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  transition: background 0.15s;
}

.ai-mode-no-ai-link:hover {
  background: var(--ai-navy-deep);
}

/* ─────────────────────────────────────────────────────────────────────────────
   17. LOADING SHIMMER
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-shimmer {
  background: linear-gradient(90deg,
    var(--ai-surface) 0%,
    rgba(27,46,90,0.04) 50%,
    var(--ai-surface) 100%);
  background-size: 400% 100%;
  animation: ai-shimmer 1.8s infinite;
  border-radius: 6px;
  height: 16px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   18. SETUP HINT
   ───────────────────────────────────────────────────────────────────────────── */

.ai-mode-setup-hint {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(220,157,40,0.06);
  border: 1px solid rgba(220,157,40,0.12);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--ai-text-secondary);
  line-height: 1.5;
}

.ai-mode-setup-hint a {
  color: var(--ai-emerald);
  font-weight: 600;
  text-decoration: none;
}

.ai-mode-setup-hint a:hover {
  text-decoration: underline;
}

/* ─────────────────────────────────────────────────────────────────────────────
   19. RESPONSIVE
   ───────────────────────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .ai-mode-fab {
    bottom: 16px;
    right: 16px;
  }

  body.ai-mode-open .ai-mode-panel {
    inset: 0;
    width: 100%;
    max-height: 100%;
    border-radius: 0;
    animation: ai-fade-in 0.2s ease;
  }

  .ai-mode-panel {
    bottom: 0;
    right: 0;
  }

  body.ai-mode-open .ai-mode-fab {
    display: none;
  }

  .ai-mode-welcome {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .ai-mode-bubble {
    max-width: 90%;
  }

  .ai-mode-product-preview-body {
    flex-direction: column;
  }

  .ai-mode-product-thumb {
    width: 100%;
    height: 100px;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   20. DARK THEME
   ───────────────────────────────────────────────────────────────────────────── */

html.dark .ai-mode-panel,
html.dark .ai-mode-fab {
  --ai-panel: #091222;
  --ai-surface: rgba(255,255,255,0.04);
  --ai-border: rgba(255,255,255,0.06);
  --ai-text: #e2e8f0;
  --ai-text-secondary: #94a3b8;
  --ai-text-muted: #64748b;
}

html.dark .ai-mode-panel {
  box-shadow:
    0 24px 48px rgba(0,0,0,0.35),
    0 8px 24px rgba(0,0,0,0.2);
}

html.dark .ai-mode-fab {
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}

html.dark .ai-mode-bubble.ai {
  background: rgba(255,255,255,0.05);
}

html.dark .ai-mode-bubble.user {
  background: var(--ai-navy-light);
}

html.dark .ai-mode-bubble code {
  background: rgba(255,255,255,0.08);
}

html.dark .ai-mode-bubble.user code {
  background: rgba(255,255,255,0.1);
}

html.dark .ai-mode-textarea {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.06);
  color: var(--ai-text);
}

html.dark .ai-mode-textarea:focus {
  border-color: rgba(255,255,255,0.15);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.04);
}

html.dark .ai-mode-textarea::placeholder {
  color: rgba(255,255,255,0.2);
}

html.dark .ai-mode-input-row {
  background: #091222;
}

html.dark .ai-mode-btn-attach,
html.dark .ai-mode-btn-voice {
  color: rgba(255,255,255,0.35);
}

html.dark .ai-mode-btn-attach:hover,
html.dark .ai-mode-btn-voice:hover {
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.6);
}

html.dark .ai-mode-action-card {
  background: rgba(255,255,255,0.03);
}

html.dark .ai-mode-product-preview {
  background: rgba(255,255,255,0.03);
}

html.dark .ai-mode-suggestion-chip {
  background: rgba(255,255,255,0.03);
}

html.dark .ai-mode-suggestion-chip:hover {
  background: rgba(255,255,255,0.06);
}

html.dark .ai-mode-welcome-card {
  background: rgba(255,255,255,0.03);
}

html.dark .ai-mode-welcome-card:hover {
  background: rgba(255,255,255,0.06);
}

html.dark .ai-mode-file-chip {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.08);
}

html.dark .ai-mode-typing-dots {
  background: rgba(255,255,255,0.05);
}

html.dark .ai-mode-typing-dot {
  background: rgba(255,255,255,0.25);
}

html.dark .ai-mode-empty-icon {
  background: rgba(255,255,255,0.06);
}

html.dark .ai-mode-error {
  background: rgba(247,82,90,0.08);
}

html.dark .ai-mode-drop-overlay {
  background: rgba(34,179,120,0.1);
}

/* ── Tool Result Display ──────────────────────────────────────────────── */

.ai-mode-tool-result {
  margin: 8px 0;
  padding: 8px 10px;
  background: rgba(34,179,120,0.06);
  border-radius: 6px;
  border: 1px solid rgba(34,179,120,0.12);
  font-size: 0.78rem;
}

.ai-mode-tool-result-text {
  color: var(--ai-text);
  line-height: 1.5;
  margin-bottom: 4px;
}

.ai-mode-tool-result-more {
  color: var(--ai-text-muted);
  font-size: 0.72rem;
  font-style: italic;
  padding-top: 4px;
}

.ai-mode-result-item {
  border-bottom: 1px solid rgba(0,0,0,0.06);
  padding: 4px 0;
  margin-bottom: 2px;
}

.ai-mode-result-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

html.dark .ai-mode-tool-result {
  background: rgba(34,179,120,0.08);
  border-color: rgba(34,179,120,0.15);
}

html.dark .ai-mode-result-item {
  border-bottom-color: rgba(255,255,255,0.06);
}

/* ── Download Links ───────────────────────────────────────────────────── */

.ai-mode-download-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 4px;
}

.ai-mode-download-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--ai-amber);
  color: #fff;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.ai-mode-download-link:hover {
  background: #b45309;
  transform: translateY(-1px);
}

.ai-mode-download-link:active {
  transform: translateY(0);
}

html.dark .ai-mode-setup-hint {
  background: rgba(220,157,40,0.08);
  border-color: rgba(220,157,40,0.15);
}

html.dark .ai-mode-quick-reply {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
}

html.dark .ai-mode-quick-reply.confirm {
  border-color: rgba(34,179,120,0.3);
  color: #22b378;
}

html.dark .ai-mode-quick-reply.deny {
  border-color: rgba(247,82,90,0.25);
  color: #f7525a;
}
