/**
 * External Note Criteria Extraction Styles
 */

.external-note-wrapper {
  position: relative;
  z-index: 1; /* Create stacking context for popover to display above following elements */
}

/* ============================================
   SMART INPUT CONTAINER - Unified component
   ============================================ */

.smart-input-container {
  border: 1px solid var(--sp-color-border, #e5e7eb);
  border-radius: var(--sp-radius-md, 8px);
  background: var(--sp-color-surface, #fff);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.smart-input-container:focus-within {
  border-color: var(--sp-primary, #3b82f6);
  box-shadow: 0 0 0 3px var(--sp-primary-light, rgba(59, 130, 246, 0.1));
}

/* Textarea inside container - remove its own border */
.smart-input-textarea.sp-textarea {
  border: none;
  border-radius: 0;
  resize: vertical;
  min-height: 100px;
  width: 100%;
  display: block;
}

.smart-input-textarea.sp-textarea:focus {
  box-shadow: none;
  outline: none;
}

/* Toolbar - boutons + badge */
.smart-input-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--sp-gray-50, #f9fafb);
  border-top: 1px solid var(--sp-color-border-light, #f3f4f6);
}

.smart-input-toolbar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.smart-input-toolbar__status {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 1;
  min-width: 0;
}

/* Mobile: toolbar wraps properly */
@media (max-width: 480px) {
  .smart-input-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .smart-input-toolbar__actions {
    width: 100%;
  }

  .smart-input-toolbar__status {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Boutons dans la toolbar */
.smart-input-btn {
  display: none; /* Hidden until enough text, JS shows */
}

/* Results zone (suggestions chips) */
.smart-input-results {
  padding: 0.5rem 0.75rem;
  background: var(--sp-gray-50, #f9fafb);
  border-top: 1px solid var(--sp-color-border-light, #f3f4f6);
}

.smart-input-results--hidden {
  display: none;
}

/* ============================================
   LEGACY: Keep old classes for compatibility
   (can be removed after full migration)
   ============================================ */

/* Textarea container for floating button positioning */
.external-note-textarea-container {
  position: relative;
  display: flex;
}

/* Make textarea fill the container */
.external-note-textarea-container .sp-textarea {
  flex: 1;
  width: 100%;
}

/* ============================================
   LOADING STATES - Shimmer style (Notion AI/Linear)
   ============================================ */

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes shimmerSlide {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Base loading state for smart-input buttons */
.smart-input-btn--loading {
  cursor: wait;
  pointer-events: none;
  position: relative;
  overflow: hidden;
}

/* Replace icon with spinner */
.smart-input-btn--loading i::before {
  content: '\f110'; /* fa-spinner */
  animation: spin 1s linear infinite;
  display: inline-block;
}

/* Replace text content */
.smart-input-btn--loading span {
  visibility: hidden;
  position: relative;
}

.smart-input-btn--loading span::after {
  content: 'Analyse...';
  visibility: visible;
  position: absolute;
  left: 0;
  white-space: nowrap;
}

/* Shimmer effect overlay */
.smart-input-btn--loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.5) 50%,
    transparent 100%
  );
  animation: shimmerSlide 1.2s linear infinite;
  z-index: 1;
}

/* Modified state - text changed after previous analysis */
.smart-input-btn--modified {
  background: var(--sp-color-warning-background, #fffbeb) !important;
  border-color: var(--sp-color-warning, #f59e0b) !important;
  color: var(--sp-color-warning-dark, #b45309) !important;
}

/* Hint badge - dans la toolbar status */
.smart-input-toolbar__status:empty {
  display: none;
}

.external-note-hint-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--sp-radius-md, 8px);
  background-color: var(--sp-gray-100, #f3f4f6);
  color: var(--sp-gray-600, #4b5563);
  font-weight: 500;
  font-size: 0.75rem;
  white-space: nowrap;
}

.external-note-hint-badge i {
  font-size: 0.625rem;
  color: var(--sp-success, #10b981);
}

/* Quality states for hint badge */
.external-note-hint-badge--insufficient {
  background-color: var(--sp-color-warning-background, #fffbeb);
  color: var(--sp-color-warning-dark, #b45309);
}

.external-note-hint-badge--insufficient i {
  color: var(--sp-color-warning, #f59e0b);
}

/* Clickable criteria button - base styles */
.external-note-hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--sp-radius-md, 8px);
  font-weight: 500;
  font-size: 0.8125rem;
  white-space: nowrap;
  border: 1px solid;
  cursor: pointer;
  transition: all 0.15s ease;
}

.external-note-hint-btn i {
  transition: color 0.15s ease;
}

/* Warning variant (insufficient criteria) */
.external-note-hint-btn--warning {
  border-color: var(--sp-color-warning, #f59e0b);
  background-color: var(--sp-color-warning-background, #fffbeb);
  color: var(--sp-color-warning-dark, #b45309);
}

.external-note-hint-btn--warning i {
  color: var(--sp-color-warning, #f59e0b);
}

.external-note-hint-btn--warning:hover {
  background-color: var(--sp-color-warning, #f59e0b);
  color: white;
}

.external-note-hint-btn--warning:hover i {
  color: white;
}

/* Success variant (good/excellent criteria) */
.external-note-hint-btn--success {
  border-color: var(--sp-success, #10b981);
  background-color: var(--sp-color-success-background, #ecfdf5);
  color: var(--sp-color-success-dark, #065f46);
}

.external-note-hint-btn--success i {
  color: var(--sp-success, #10b981);
}

.external-note-hint-btn--success:hover {
  background-color: var(--sp-success, #10b981);
  color: white;
}

.external-note-hint-btn--success:hover i {
  color: white;
}

/* Dot indicator for exclusionary criteria */
.external-note-hint-btn__dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-left: 0.5rem;
  flex-shrink: 0;
}

.external-note-hint-btn__dot--danger {
  background-color: var(--sp-color-danger, #ef4444);
}

/* Keep dot visible on hover */
.external-note-hint-btn--success:hover .external-note-hint-btn__dot--danger {
  background-color: white;
  opacity: 0.9;
}

.external-note-hint-badge--good {
  background-color: var(--sp-color-success-background, #ecfdf5);
  color: var(--sp-color-success-dark, #065f46);
}

.external-note-hint-badge--good i {
  color: var(--sp-success, #10b981);
}

.external-note-hint-badge--excellent {
  background-color: var(--sp-color-success-background, #ecfdf5);
  color: var(--sp-color-success-dark, #065f46);
}

.external-note-hint-badge--excellent i {
  color: var(--sp-color-warning, #f59e0b); /* Gold star */
}

.external-note-hint-link {
  color: var(--sp-gray-500, #6b7280);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color 0.15s ease;
}

.external-note-hint-link:hover {
  color: var(--sp-primary, #3b82f6);
}

/* Popover */
.external-note-popover {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 8px;
  background: var(--sp-color-surface, #fff);
  border: 1px solid var(--sp-color-border, #e5e7eb);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 500; /* Above most content, below modals (1000+) and side-panel backdrop (900) */
  max-width: 400px;
}

.external-note-popover__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--sp-color-border, #e5e7eb);
  font-weight: 600;
}

.external-note-popover__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sp-color-text-muted, #6b7280);
  padding: 4px;
  line-height: 1;
}

.external-note-popover__close:hover {
  color: var(--sp-color-text, #111827);
}

.external-note-popover__content {
  padding: 12px 16px;
  max-height: 300px;
  overflow-y: auto;
}

.external-note-popover__footer {
  padding: 8px 16px;
  border-top: 1px solid var(--sp-color-border, #e5e7eb);
  color: var(--sp-color-text-muted, #6b7280);
  font-size: 0.75rem;
}

/* Criteria list */
.external-note-criteria-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.external-note-criteria-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--sp-color-border-light, #f3f4f6);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.external-note-criteria-item:last-child {
  border-bottom: none;
}

.external-note-criteria-text {
  flex: 1;
  min-width: 0;
}

/* Weight badges */
.external-note-criteria-weight {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: var(--sp-radius-full, 9999px);
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
  background-color: var(--sp-gray-100, #f3f4f6);
  color: var(--sp-gray-500, #6b7280);
}

.external-note-criteria-weight--important {
  background-color: var(--sp-gray-200, #e5e7eb);
  color: var(--sp-gray-700, #374151);
}

.external-note-criteria-weight--exclusionary {
  background-color: #fef2f2;
  color: #991b1b;
}

/* Dot indicator for exclusionary criteria in list */
.external-note-criteria-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 0.5rem;
}

.external-note-criteria-dot--exclusionary {
  background-color: var(--sp-color-danger, #ef4444);
}

.external-note-criteria-hint {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 12px 0 0;
  padding: 8px 10px;
  font-size: 11px;
  color: #991b1b;
  line-height: 1.4;
  background: #fef2f2;
  border-radius: var(--sp-radius-sm, 6px);
}

.external-note-criteria-hint i {
  color: var(--sp-color-danger, #ef4444);
  flex-shrink: 0;
  font-size: 12px;
}

/* Fullscreen class for mobile - applied by JS with scroll lock */
.external-note-popover.external-note-popover--fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  max-width: none;
  border-radius: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
}

.external-note-popover.external-note-popover--fullscreen .external-note-popover__header {
  padding: 16px;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.external-note-popover.external-note-popover--fullscreen .external-note-popover__close {
  padding: 8px;
  font-size: 1.25rem;
}

.external-note-popover.external-note-popover--fullscreen .external-note-popover__content {
  flex: 1;
  max-height: none;
  overflow-y: auto;
}

/* Animations */
.external-note-popover {
  animation: fadeInUp 0.2s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   SUGGESTIONS BUTTON - Loading state
   ============================================ */

.smart-input-btn--suggestions-loading i::before {
  content: '\f110'; /* fa-spinner */
  animation: spin 1s linear infinite;
  display: inline-block;
}

/* ============================================
   SUGGESTIONS STYLES
   Uses DS chip component (.sp-chip)
   ============================================ */

/* List uses DS chip-group style */
.suggestions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Chip being removed after click - animation only */
.suggestion-chip--used {
  pointer-events: none;
}
