/* ─── Neby AI Assistant — FAB + Chat Panel ─────────────────────────────────── */

/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --neby-fab-size: 56px;
  --neby-panel-w: 370px;
  --neby-panel-h: 530px;
  --neby-radius: 24px;
  --neby-bubble-user: var(--md-primary);
  --neby-bubble-user-text: var(--md-on-primary);
  --neby-bubble-ai-bg: var(--md-surface-container);
  --neby-bubble-ai-text: var(--md-on-surface);
  --neby-glass: rgba(var(--md-surface-rgb, 255, 255, 255), 0.82);
  --neby-border: var(--md-outline-variant);
  --neby-shadow: var(--md-elevation-3);
}
[data-theme="dark"] {
  --neby-glass: rgba(28, 30, 40, 0.88);
  --neby-border: var(--md-outline-variant);
  --neby-shadow: var(--md-elevation-3);
}

/* ── FAB ─────────────────────────────────────────────────────────────────────── */
#neby-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1100;
  width: var(--neby-fab-size);
  height: var(--neby-fab-size);
  border-radius: var(--md-radius-full);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  box-shadow: none;
  transition: transform 0.22s cubic-bezier(.34, 1.56, .64, 1);
  outline: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#neby-fab:hover {
  transform: scale(1.08);
}
#neby-fab:active { transform: scale(0.94); }
#neby-fab.panel-open { display: none; }

#neby-fab .material-symbols-outlined {
  font-size: 26px;
  transition: transform 0.22s ease;
  font-variation-settings: 'FILL' 1, 'wght' 500;
}

.neby-fab-avatar-badge {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.neby-fab-avatar-badge .neby-avatar-mini {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* ── Panel ───────────────────────────────────────────────────────────────────── */
#neby-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1099;
  width: min(var(--neby-panel-w), calc(100vw - 24px));
  height: min(var(--neby-panel-h), calc(100dvh - 88px));
  border-radius: var(--neby-radius);
  background: var(--neby-glass);
  border: 1.5px solid var(--neby-border);
  box-shadow: var(--neby-shadow);
  backdrop-filter: blur(18px) saturate(1.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.6) translateY(30px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(.34, 1.4, .64, 1), opacity 0.22s ease;
}
#neby-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Panel Header ────────────────────────────────────────────────────────────── */
.neby-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  flex-shrink: 0;
  border-radius: var(--neby-radius) var(--neby-radius) 0 0;
}
.neby-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.neby-header-avatar .neby-avatar-mini {
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}
.neby-header-avatar .material-symbols-outlined {
  font-size: 20px;
  font-variation-settings: 'FILL' 1;
  color: var(--md-on-primary);
}
.neby-header-info { flex: 1; min-width: 0; }
.neby-header-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
}
.neby-header-status {
  font-size: 11px;
  opacity: 0.78;
  display: flex;
  align-items: center;
  gap: 4px;
}
.neby-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 5px #4ade80;
}
.neby-panel-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--md-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.neby-panel-close:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}
.neby-panel-close .material-symbols-outlined { font-size: 20px; }

/* ── Chat Area ───────────────────────────────────────────────────────────────── */
.neby-chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.neby-chat-area::-webkit-scrollbar { width: 4px; }
.neby-chat-area::-webkit-scrollbar-track { background: transparent; }
.neby-chat-area::-webkit-scrollbar-thumb { background: rgba(0, 75, 212, 0.2); border-radius: 4px; }

/* ── Messages ────────────────────────────────────────────────────────────────── */
.neby-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
  animation: neby-msg-in 0.22s cubic-bezier(.34, 1.3, .64, 1) both;
}
@keyframes neby-msg-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.neby-msg.user { justify-content: flex-end; }

/* AI message column: bubble + optional tool results beneath it */
.neby-msg.ai { width: 100%; }
.neby-msg.user .neby-bubble { max-width: 84%; }

.neby-bubble {
  width: fit-content;
  max-width: 100%;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.5;
  overflow-wrap: break-word;
  word-break: break-word;
}
.neby-msg.ai .neby-bubble {
  background: none;
  color: var(--neby-bubble-ai-text);
  width: 100%;
  max-width: 100%;
  padding: 0;
  border-radius: 0;
}
.neby-msg.user .neby-bubble {
  background: var(--neby-bubble-user);
  color: var(--neby-bubble-user-text);
  border-bottom-right-radius: 5px;
}

/* ── Tool Result Cards ───────────────────────────────────────────────────────── */
.neby-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-width: 0;
}
.neby-result-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--md-radius-md);
  background: var(--md-surface-container-low);
  border: 1px solid var(--neby-border);
  text-decoration: none;
  color: var(--md-on-surface);
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
  cursor: pointer;
  min-width: 0;
  width: 100%;
}
.neby-result-card:hover {
  background: var(--md-surface-container);
  border-color: var(--md-primary);
  transform: translateY(-1px);
  color: var(--md-on-surface);
  text-decoration: none;
}
.neby-result-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--md-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.neby-result-icon .material-symbols-outlined {
  font-size: 16px;
  color: var(--md-on-primary-container);
  font-variation-settings: 'FILL' 1;
}
.neby-result-body {
  flex: 1 1 auto;
  min-width: 0;
}
.neby-result-title {
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.neby-result-meta {
  font-size: 11px;
  color: var(--md-on-surface-variant);
  opacity: 0.8;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.neby-result-meta .material-symbols-outlined {
  font-size: 12px;
  vertical-align: -2px;
}
.neby-result-arrow {
  flex-shrink: 0;
  opacity: 0.4;
  display: flex;
}
.neby-result-arrow .material-symbols-outlined { font-size: 16px; }

/* navigate card */
.neby-nav-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--md-radius-md);
  background: var(--md-primary-container);
  border: 1px solid var(--md-primary);
  text-decoration: none;
  color: var(--md-on-primary-container);
  font-size: 13px;
  font-weight: 500;
  width: fit-content;
  max-width: 100%;
  transition: background 0.15s, transform 0.12s;
}
.neby-nav-card:hover {
  background: var(--md-surface-container);
  transform: translateY(-1px);
  color: var(--md-on-primary-container);
  text-decoration: none;
}
.neby-nav-card .material-symbols-outlined {
  font-size: 18px;
  font-variation-settings: 'FILL' 1;
}
.neby-nav-card .neby-result-arrow { margin-left: auto; }

/* subject chips */
.neby-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.neby-chip {
  padding: 5px 12px;
  border-radius: var(--md-radius-full);
  background: var(--md-secondary-container);
  border: 1px solid var(--md-outline-variant);
  font-size: 11.5px;
  color: var(--md-on-secondary-container);
  font-weight: 500;
  white-space: nowrap;
}

/* ── Suggestions ─────────────────────────────────────────────────────────────── */
.neby-suggestions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0 14px 8px;
  flex-shrink: 0;
}
.neby-suggestion-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: var(--md-radius-md);
  background: var(--md-surface-container-low);
  border: 1px solid var(--neby-border);
  color: var(--md-on-surface);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.14s;
  min-width: 0;
}
.neby-suggestion-btn:hover { background: var(--md-surface-container); }
.neby-suggestion-btn .material-symbols-outlined {
  font-size: 15px;
  color: var(--md-primary);
  font-variation-settings: 'FILL' 1;
  flex-shrink: 0;
}
.neby-suggestions-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--md-on-surface-variant, #777);
  font-weight: 600;
  padding: 0 1px 3px;
}

/* ── Input Row ───────────────────────────────────────────────────────────────── */
.neby-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--neby-border);
  flex-shrink: 0;
}
.neby-input-row textarea {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--md-outline-variant);
  border-radius: var(--md-radius-full);
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  background: var(--md-surface-container-low);
  color: var(--md-on-surface);
  outline: none;
  line-height: 1.4;
  max-height: 80px;
  transition: border-color 0.15s;
}
.neby-input-row textarea:focus {
  border-color: var(--md-primary);
  background: var(--md-surface-container);
}
.neby-input-row textarea::placeholder { opacity: 0.55; }
.neby-send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--md-radius-full);
  border: none;
  background: var(--md-primary);
  color: var(--md-on-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.12s;
}
.neby-send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.neby-send-btn:not(:disabled):hover { transform: scale(1.08); }
.neby-send-btn .material-symbols-outlined {
  font-size: 18px;
  font-variation-settings: 'FILL' 1;
}

/* ── Empty State ─────────────────────────────────────────────────────────────── */
.neby-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  padding: 20px;
  text-align: center;
  color: var(--md-on-surface-variant, #777);
}
.neby-empty-icon {
  width: 72px;
  height: 72px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.neby-empty-icon .material-symbols-outlined {
  font-size: 26px;
  color: var(--md-on-primary-container);
  font-variation-settings: 'FILL' 1;
}
.neby-empty-state p {
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 220px;
}

/* ── Count badges ────────────────────────────────────────────────────────────── */
.neby-count-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--md-radius-full);
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  margin-left: 6px;
  vertical-align: 1px;
  display: inline-block;
}

/* ── Powered by ──────────────────────────────────────────────────────────────── */
.neby-powered {
  font-size: 10px;
  opacity: 0.38;
  text-align: center;
  padding-bottom: 4px;
  flex-shrink: 0;
}

/* ── Mobile ──────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #neby-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 92vh;
    height: 92svh;
    border-radius: var(--neby-radius) var(--neby-radius) 0 0;
    transform-origin: bottom center;
  }
  #neby-fab {
    bottom: 16px;
    right: 16px;
  }
  .neby-msg.user .neby-bubble { max-width: 88%; }
  .neby-bubble { font-size: 13px; }
}
