/**
 * Footprint AI Assistant Sidebar Styles
 * Mirrors ai-assistant.css with fp-ai- prefixes + image gallery cards
 */

/* =========================================================================
   Toggle Button in Toolbar
   ========================================================================= */

.btn-fp-ai-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white;
  border: none;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.8rem;
}

.btn-fp-ai-toggle:hover {
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.btn-fp-ai-toggle.active {
  background: linear-gradient(135deg, #0284c7, #4f46e5);
}

.fp-ai-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
}

/* =========================================================================
   Sidebar Container
   ========================================================================= */

.fp-ai-sidebar {
  display: flex;
  flex-direction: row;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
  height: 100%;
  width: 360px;
  min-width: 360px;
  flex-shrink: 0;
}

.fp-ai-sidebar.collapsed {
  width: 0;
  min-width: 0;
  border: none;
  opacity: 0;
  pointer-events: none;
}

/* =========================================================================
   Sidebar Content
   ========================================================================= */

.fp-ai-sidebar-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
}

/* Header */
.fp-ai-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white;
  flex-shrink: 0;
}

.fp-ai-sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.fp-ai-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
}

.fp-ai-sidebar-actions {
  display: flex;
  gap: 4px;
}

.fp-ai-header-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.fp-ai-header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Status Bar */
.fp-ai-sidebar-status {
  padding: 8px 12px;
  background: rgba(245, 158, 11, 0.1);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  flex-shrink: 0;
}

.fp-ai-status-warning {
  color: #f59e0b;
}

.fp-ai-status-link {
  background: none;
  border: none;
  color: var(--accent-color);
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
  padding: 0;
  margin-left: 4px;
}

/* Messages Area */
.fp-ai-sidebar-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

/* Input Area */
.fp-ai-sidebar-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-light);
  flex-shrink: 0;
}

.fp-ai-input-field {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  resize: none;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: inherit;
  max-height: 100px;
  min-height: 38px;
}

.fp-ai-input-field:focus {
  outline: none;
  border-color: #0ea5e9;
}

.fp-ai-send-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

.fp-ai-send-btn:hover {
  transform: scale(1.05);
}

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

/* =========================================================================
   Message Styles
   ========================================================================= */

.fp-ai-message {
  display: flex;
  flex-direction: column;
  max-width: 95%;
}

.fp-ai-message-user {
  align-self: flex-end;
}

.fp-ai-message-assistant {
  align-self: flex-start;
}

.fp-ai-message-content {
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
}

.fp-ai-message-content p {
  margin: 0 0 6px 0;
}

.fp-ai-message-content p:last-child {
  margin-bottom: 0;
}

.fp-ai-message-user .fp-ai-message-content {
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white;
  border-bottom-right-radius: 4px;
}

.fp-ai-message-assistant .fp-ai-message-content {
  background: var(--bg-light);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.fp-ai-message-content code {
  background: rgba(0, 0, 0, 0.15);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 12px;
}

.fp-ai-message-content pre {
  background: rgba(0, 0, 0, 0.15);
  padding: 8px;
  border-radius: 5px;
  overflow-x: auto;
  margin: 6px 0;
}

.fp-ai-message-content ul {
  margin: 6px 0;
  padding-left: 18px;
}

.fp-ai-message-content li {
  margin: 3px 0;
  font-size: 12px;
}

/* =========================================================================
   Streaming Styles
   ========================================================================= */

.fp-ai-message-streaming {
  position: relative;
}

.fp-ai-streaming-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(99, 102, 241, 0.1));
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  animation: fpAiPulse 2s ease-in-out infinite;
}

@keyframes fpAiPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.fp-ai-status-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(14, 165, 233, 0.3);
  border-top-color: #0ea5e9;
  border-radius: 50%;
  animation: fpAiSpin 1s linear infinite;
}

@keyframes fpAiSpin {
  to { transform: rotate(360deg); }
}

.fp-ai-status-text {
  flex: 1;
}

.fp-ai-message-streaming .fp-ai-message-content {
  opacity: 0.9;
}

/* =========================================================================
   Image Gallery
   ========================================================================= */

.fp-ai-image-gallery {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
  margin-top: 8px;
}

.fp-ai-image-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.fp-ai-image-card:hover {
  border-color: #0ea5e9;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.15);
}

.fp-ai-image-thumb {
  width: 100%;
  height: 140px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fp-ai-image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fp-ai-image-broken {
  color: var(--text-secondary);
  font-size: 11px;
  padding: 10px;
  text-align: center;
}

.fp-ai-image-info {
  padding: 8px 10px;
}

.fp-ai-image-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.fp-ai-image-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-secondary);
}

.fp-ai-image-source {
  display: inline-block;
  margin-top: 3px;
  font-size: 10px;
  color: var(--accent-color);
  text-decoration: none;
}

.fp-ai-image-source:hover {
  text-decoration: underline;
}

.fp-ai-image-actions {
  padding: 6px 10px 10px;
  display: flex;
  gap: 6px;
}

.fp-ai-use-btn {
  flex: 1;
  font-size: 12px !important;
  padding: 6px 10px !important;
}

/* =========================================================================
   Layout Integration
   ========================================================================= */

/* The sidebar sits beside the split pane in the extractor container */
.fp-extractor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.fp-extractor-body {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}

/* =========================================================================
   Light Theme
   ========================================================================= */

[data-theme="light"] .fp-ai-sidebar {
  background: #ffffff;
}

[data-theme="light"] .fp-ai-message-assistant .fp-ai-message-content {
  background: #f3f4f6;
}

[data-theme="light"] .fp-ai-input-field {
  background: #ffffff;
}

[data-theme="light"] .fp-ai-sidebar-input {
  background: #f9fafb;
}

[data-theme="light"] .fp-ai-image-card {
  background: #ffffff;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 1200px) {
  .fp-ai-sidebar:not(.collapsed) {
    width: 300px;
    min-width: 300px;
  }
}

@media (max-width: 900px) {
  .fp-ai-sidebar:not(.collapsed) {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
  }
}
