/* ========================================
   CHAT WIDGET PANEL (Idia Slide-over)
   Persistent AI chat accessible from any page
   ======================================== */

.chat-widget-panel {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: 420px;
  z-index: 45;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-default);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-widget-panel.open {
  transform: translateX(0);
}

/* Mobile: full width */
@media (max-width: 768px) {
  .chat-widget-panel {
    width: 100vw;
  }
}

/* Header */
.chat-widget-header {
  height: 52px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border-default);
  gap: 8px;
}

.chat-widget-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.chat-widget-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chat-widget-session-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.chat-widget-header-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.chat-widget-header-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* Messages area */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-widget-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 12px;
}

.chat-widget-empty-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-10, rgba(var(--accent-h), var(--accent-s), var(--accent-l), 0.1));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.chat-widget-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-widget-empty-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Message bubbles */
.chat-widget-msg {
  max-width: 90%;
  word-break: break-word;
  overflow-wrap: break-word;
}

.chat-widget-msg-user {
  align-self: flex-end;
  background: var(--accent-10, rgba(0, 0, 0, 0.05));
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-widget-msg-assistant {
  align-self: flex-start;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
}

/* Markdown prose inside assistant messages */
.chat-widget-msg-assistant .prose {
  font-size: 14px;
  line-height: 1.7;
}

.chat-widget-msg-assistant .prose p {
  margin: 0.5em 0;
}

.chat-widget-msg-assistant .prose p:first-child {
  margin-top: 0;
}

.chat-widget-msg-assistant .prose p:last-child {
  margin-bottom: 0;
}

.chat-widget-msg-assistant .prose ul,
.chat-widget-msg-assistant .prose ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.chat-widget-msg-assistant .prose code {
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--bg-surface-hover);
}

.chat-widget-msg-assistant .prose pre {
  margin: 0.5em 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-surface-hover);
  overflow-x: auto;
  font-size: 12px;
}

/* Tool step indicators */
.chat-widget-tool-step {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.chat-widget-tool-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: chat-widget-spin 0.8s linear infinite;
  flex-shrink: 0;
}

.chat-widget-tool-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-widget-tool-done {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

@keyframes chat-widget-spin {
  to { transform: rotate(360deg); }
}

/* Thinking indicator */
.chat-widget-thinking {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.chat-widget-thinking-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: chat-widget-spin 0.8s linear infinite;
  flex-shrink: 0;
}

.chat-widget-thinking-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Input area */
.chat-widget-input {
  border-top: 1px solid var(--border-default);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-surface);
}

.chat-widget-input-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.chat-widget-cost-hint {
  font-size: 11px;
  color: var(--accent, #38B2AC);
  font-weight: 500;
  display: none;
  margin-right: auto;
  padding-left: 2px;
}

.chat-widget-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-default);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-surface);
  outline: none;
  max-height: 120px;
  min-height: 42px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.chat-widget-textarea:focus {
  border-color: var(--accent);
}

.chat-widget-textarea::placeholder {
  color: var(--text-tertiary);
}

.chat-widget-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}

.chat-widget-send-btn:hover {
  opacity: 0.9;
}

.chat-widget-send-btn:active {
  transform: scale(0.95);
}

.chat-widget-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Icon Tab Bar (Quick Info / Idia / Websearch) */
.chat-widget-tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

.chat-widget-icon-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.15s;
}

.chat-widget-icon-tab:hover:not(.active) {
  color: var(--text-secondary);
  background: var(--bg-surface-hover);
}

.chat-widget-icon-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.chat-widget-tab-label {
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
}

/* Tab content panels */
.chat-widget-tab-content {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-widget-tab-content.active {
  display: flex;
}

/* Idia tab sub-header (session switcher + new session) */
.chat-widget-idia-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

.chat-widget-session-switch-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.chat-widget-session-switch-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.chat-widget-idia-session-label {
  font-weight: 500;
}

/* Session switcher tabs (Conversations / Agents inside dropdown) */
.chat-widget-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-default);
  padding: 0 0.75rem;
}

.chat-widget-tab {
  flex: 1;
  padding: 0.5rem 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
  text-align: center;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.chat-widget-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.chat-widget-tab:hover:not(.active) {
  color: var(--text-secondary);
}

/* Agent items */
.chat-widget-agent-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 0.5rem;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.chat-widget-agent-item:hover {
  background: var(--bg-surface-hover);
}

.chat-widget-agent-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

/* Session switcher dropdown */
.chat-widget-sessions-dropdown {
  position: absolute;
  top: 52px;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 10;
  max-height: 320px;
  overflow-y: auto;
  display: none;
}

.chat-widget-sessions-dropdown.open {
  display: block;
}

.chat-widget-session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.1s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.chat-widget-session-item:hover {
  background: var(--bg-surface-hover);
}

.chat-widget-session-item.active {
  background: var(--accent-10, rgba(0, 0, 0, 0.05));
}

.chat-widget-session-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-widget-session-item-preview {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* Confirmation card (compact) */
.chat-widget-confirmation {
  align-self: flex-start;
  width: 100%;
  background: var(--bg-surface-hover);
  border-radius: 12px;
  padding: 14px;
}

.chat-widget-confirmation-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.chat-widget-confirmation-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.chat-widget-confirmation-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.chat-widget-confirmation-label {
  font-size: 12px;
  color: var(--text-primary);
  flex: 1;
}

.chat-widget-confirmation-cost {
  font-size: 11px;
  color: var(--text-tertiary);
}

.chat-widget-confirmation-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-default);
}

/* Unread indicator on header icon */
.chat-widget-unread-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
  display: none;
}

.chat-widget-unread-dot.visible {
  display: block;
}
