/* ============================================================
   LexiCore Copilot Widget - Styles
   Floating AI assistant chat widget for the legal platform
   ============================================================ */

/* --- Design Tokens --- */
:root {
  --copilot-primary: #1e40af;
  --copilot-primary-light: #2563eb;
  --copilot-gold: #d97706;
  --copilot-gold-light: #fef3c7;
  --copilot-navy: #1e293b;
  --copilot-navy-light: #334155;
  --copilot-white: #ffffff;
  --copilot-gray: #6b7280;
  --copilot-gray-light: #e2e8f0;
  --copilot-gray-bg: #f1f5f9;
  --copilot-success: #059669;
  --copilot-red: #dc2626;
  --copilot-shadow: rgba(0, 0, 0, 0.15);
  --copilot-fab-shadow: rgba(30, 64, 175, 0.4);
  --copilot-radius-lg: 16px;
  --copilot-radius-pill: 24px;
  --copilot-panel-width: 440px;
  --copilot-panel-max-height: 700px;
  --copilot-z-panel: 9998;
  --copilot-z-fab: 9999;
  --copilot-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   Floating Action Button (FAB)
   ============================================================ */

#copilot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--copilot-primary), var(--copilot-primary-light));
  color: var(--copilot-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  cursor: pointer;
  z-index: var(--copilot-z-fab);
  box-shadow: 0 4px 12px var(--copilot-fab-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  border: none;
  outline: none;
}

#copilot-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(30, 64, 175, 0.55);
}

#copilot-fab:active {
  transform: scale(1.0);
}

#copilot-fab.active {
  background: linear-gradient(135deg, var(--copilot-navy), var(--copilot-navy-light));
}

#copilot-fab.active i.fa-bolt::before {
  content: "\f00d"; /* fa-times when panel is open */
  font-family: "Font Awesome 5 Free", "Font Awesome 6 Free";
  font-weight: 900;
}

/* Pulse animation on load - 3 pulses then stops */
@keyframes copilot-pulse {
  0% {
    box-shadow: 0 4px 12px var(--copilot-fab-shadow), 0 0 0 0 rgba(30, 64, 175, 0.5);
  }
  50% {
    box-shadow: 0 4px 12px var(--copilot-fab-shadow), 0 0 0 14px rgba(30, 64, 175, 0);
  }
  100% {
    box-shadow: 0 4px 12px var(--copilot-fab-shadow), 0 0 0 0 rgba(30, 64, 175, 0);
  }
}

#copilot-fab.copilot-pulse {
  animation: copilot-pulse 1.2s ease-out 3;
}

/* Unread badge */
#copilot-fab .copilot-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--copilot-red);
  border: 2px solid var(--copilot-white);
  display: none;
}

#copilot-fab .copilot-badge.visible {
  display: block;
}

/* ============================================================
   Chat Panel
   ============================================================ */

#copilot-panel {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: var(--copilot-panel-width);
  max-height: var(--copilot-panel-max-height);
  border-radius: var(--copilot-radius-lg);
  background: var(--copilot-white);
  box-shadow: 0 8px 32px var(--copilot-shadow);
  z-index: var(--copilot-z-panel);
  display: none;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: opacity var(--copilot-transition), transform var(--copilot-transition);
}

#copilot-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ============================================================
   Panel Header
   ============================================================ */

#copilot-header {
  background: linear-gradient(135deg, var(--copilot-navy), var(--copilot-navy-light));
  padding: 16px;
  border-radius: var(--copilot-radius-lg) var(--copilot-radius-lg) 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.copilot-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.copilot-header-icon {
  color: var(--copilot-gold);
  font-size: 18px;
}

.copilot-title {
  color: var(--copilot-white);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.copilot-subtitle {
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.3;
}

.copilot-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.copilot-header-actions button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  transition: color 0.15s ease, background 0.15s ease;
  line-height: 1;
}

.copilot-header-actions button:hover {
  color: var(--copilot-white);
  background: rgba(255, 255, 255, 0.1);
}

/* ============================================================
   Quick Action Chips
   ============================================================ */

#copilot-chips {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 1px solid var(--copilot-gray-light);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#copilot-chips::-webkit-scrollbar {
  display: none;
}

.copilot-chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border: 1px solid var(--copilot-gray-light);
  border-radius: 100px;
  background: var(--copilot-white);
  color: var(--copilot-navy);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  line-height: 1.4;
  font-family: inherit;
}

.copilot-chip:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--copilot-primary);
}

.copilot-chip:active {
  background: #dbeafe;
}

/* ============================================================
   Messages Area
   ============================================================ */

#copilot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  max-height: calc(var(--copilot-panel-max-height) - 68px - 46px - 82px);
  scroll-behavior: smooth;
}

/* Custom scrollbar for messages */
#copilot-messages::-webkit-scrollbar {
  width: 4px;
}

#copilot-messages::-webkit-scrollbar-track {
  background: transparent;
}

#copilot-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

#copilot-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* --- Message Bubbles --- */

.copilot-msg {
  max-width: 80%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 8px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: copilot-msg-appear 0.2s ease-out;
}

@keyframes copilot-msg-appear {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User Messages */
.copilot-msg-user {
  align-self: flex-end;
  background: var(--copilot-primary);
  color: var(--copilot-white);
  border-radius: 16px 16px 4px 16px;
}

/* AI / Assistant Messages */
.copilot-msg-assistant {
  align-self: flex-start;
  background: var(--copilot-gray-bg);
  color: var(--copilot-navy);
  border-radius: 16px 16px 16px 4px;
  max-width: 85%;
}

.copilot-msg-assistant strong {
  font-weight: 600;
}

.copilot-msg-assistant a {
  color: var(--copilot-primary);
  text-decoration: underline;
}

.copilot-msg-assistant a:hover {
  color: var(--copilot-primary-light);
}

/* ============================================================
   Action Cards
   ============================================================ */

.copilot-action-card {
  background: var(--copilot-gold-light);
  border-left: 3px solid var(--copilot-gold);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: copilot-msg-appear 0.2s ease-out;
  line-height: 1.4;
  color: var(--copilot-navy);
}

.copilot-action-icon {
  color: var(--copilot-gold);
  font-size: 14px;
  flex-shrink: 0;
}

.copilot-action-card span {
  flex: 1;
}

.copilot-action-link {
  color: var(--copilot-primary);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  font-size: 12px;
}

.copilot-action-link:hover {
  text-decoration: underline;
  color: var(--copilot-primary-light);
}

/* ============================================================
   Typing Indicator
   ============================================================ */

.copilot-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.copilot-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
  animation: copilot-bounce 1.2s infinite ease-in-out;
}

.copilot-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.copilot-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes copilot-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ============================================================
   Input Area
   ============================================================ */

#copilot-input-area {
  border-top: 1px solid var(--copilot-gray-light);
  padding: 12px 16px;
  flex-shrink: 0;
  background: var(--copilot-white);
  border-radius: 0 0 var(--copilot-radius-lg) var(--copilot-radius-lg);
}

.copilot-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#copilot-input {
  flex: 1;
  border: 1px solid var(--copilot-gray-light);
  border-radius: var(--copilot-radius-pill);
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  color: var(--copilot-navy);
  background: var(--copilot-white);
  font-family: inherit;
  line-height: 1.4;
}

#copilot-input::placeholder {
  color: #9ca3af;
}

#copilot-input:focus {
  border-color: var(--copilot-primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

#copilot-input:disabled {
  background: #f9fafb;
  color: #9ca3af;
  cursor: not-allowed;
}

#copilot-send {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--copilot-primary);
  color: var(--copilot-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

#copilot-send:hover {
  background: #1d3a9f;
}

#copilot-send:active {
  transform: scale(0.93);
}

#copilot-send:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
}

/* Context badge */
#copilot-context-badge {
  font-size: 11px;
  color: var(--copilot-gray);
  margin-top: 6px;
  padding-left: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

#copilot-context-badge::before {
  content: "\f3c5"; /* fa-map-marker-alt */
  font-family: "Font Awesome 5 Free", "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 9px;
  opacity: 0.6;
}

/* ============================================================
   Empty State
   ============================================================ */

.copilot-empty-state {
  text-align: center;
  padding: 32px 24px;
  color: var(--copilot-gray);
}

.copilot-empty-state i {
  font-size: 36px;
  color: #cbd5e1;
  margin-bottom: 12px;
  display: block;
}

.copilot-empty-state p {
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}

/* ============================================================
   Feedback Buttons & Source Tag
   ============================================================ */

.copilot-feedback-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding-top: 4px;
}

.copilot-feedback-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  color: #94a3b8;
  font-size: 12px;
  transition: color 0.15s ease, background 0.15s ease;
  line-height: 1;
}

.copilot-feedback-btn:hover {
  color: var(--copilot-navy);
  background: rgba(0, 0, 0, 0.06);
}

.copilot-feedback-btn.active[data-rating="up"] {
  color: var(--copilot-success);
}

.copilot-feedback-btn.active[data-rating="down"] {
  color: var(--copilot-red);
}

.copilot-source-tag {
  margin-left: auto;
  font-size: 10px;
  color: #94a3b8;
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  line-height: 1.5;
  font-weight: 500;
}

/* ============================================================
   Responsive - Below 500px
   ============================================================ */

@media (max-width: 500px) {
  #copilot-panel {
    width: 100%;
    right: 0;
    bottom: 0;
    border-radius: var(--copilot-radius-lg) var(--copilot-radius-lg) 0 0;
    max-height: 70vh;
  }

  #copilot-panel.open {
    transform: translateY(0) scale(1);
  }

  #copilot-input-area {
    border-radius: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  #copilot-messages {
    max-height: calc(70vh - 68px - 46px - 82px);
  }

  #copilot-fab {
    bottom: 16px;
    right: 16px;
  }
}

/* ============================================================
   Reduced Motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  #copilot-fab,
  #copilot-panel,
  .copilot-msg,
  .copilot-action-card,
  .copilot-typing-dots span {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  #copilot-fab.copilot-pulse {
    animation: none !important;
  }
}

/* ============================================================
   Print - Hide widget
   ============================================================ */

@media print {
  #copilot-fab,
  #copilot-panel {
    display: none !important;
  }
}
