/* ============================================================
   Hudhud Ethical Assistant — Frontend Popup Styles  v1.1.0
   Brand: orange (#f97316 / #ea580c)
   ============================================================ */

/* ── CSS Custom Properties ──────────────────────────────────── */
:root {
  --hd-primary:       #f97316;   /* Hudhud orange */
  --hd-accent:        #ea580c;   /* Hudhud dark orange */
  --hd-danger:        #ef4444;
  --hd-warning:       #f59e0b;
  --hd-unknown:       #6b7280;
  --hd-bg:            #ffffff;
  --hd-surface:       #fafafa;
  --hd-border:        #e5e7eb;
  --hd-text:          #111827;
  --hd-text-muted:    #6b7280;
  --hd-text-light:    #9ca3af;
  --hd-radius:        18px;
  --hd-radius-sm:     10px;
  --hd-shadow:        0 25px 60px rgba(0,0,0,0.18), 0 8px 24px rgba(0,0,0,0.1);
  --hd-shadow-sm:     0 4px 16px rgba(0,0,0,0.08);
  --hd-anim-fast:     160ms;
  --hd-anim-med:      300ms;
  --hd-anim-slow:     480ms;
  --hd-font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --hd-z-overlay:     99998;
  --hd-z-popup:       99999;
}

/* ── Overlay / Backdrop ─────────────────────────────────────── */
.hudhud-overlay {
  position:       fixed;
  inset:          0;
  background:     rgba(0,0,0,0);
  z-index:        var(--hd-z-overlay);
  display:        flex;
  align-items:    flex-end;
  justify-content: flex-end;
  padding:        20px;
  pointer-events: none;
  transition:     background var(--hd-anim-med) ease;
  font-family:    var(--hd-font);
}
.hudhud-overlay.is-open {
  background:     rgba(0,0,0,0.4);
  pointer-events: all;
  backdrop-filter: blur(3px);
}

/* ── Main Popup ─────────────────────────────────────────────── */
.hudhud-popup {
  position:        relative;
  width:           min(420px, calc(100vw - 40px));
  max-height:      min(640px, calc(100vh - 100px));
  background:      var(--hd-bg);
  border-radius:   var(--hd-radius);
  box-shadow:      var(--hd-shadow);
  display:         flex;
  flex-direction:  column;
  overflow:        hidden;
  transform:       translateY(40px) scale(0.96);
  opacity:         0;
  transition:      transform var(--hd-anim-slow) cubic-bezier(0.34,1.56,0.64,1),
                   opacity   var(--hd-anim-med)  ease;
  will-change:     transform, opacity;
  outline:         none; /* suppress focus ring on popup div itself */
}
.hudhud-overlay.is-open .hudhud-popup {
  transform: translateY(0) scale(1);
  opacity:   1;
}

/* ── Header ─────────────────────────────────────────────────── */
.hudhud-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         16px 20px;
  background:      linear-gradient(135deg, var(--hd-primary), var(--hd-accent));
  color:           #fff;
  flex-shrink:     0;
}
.hudhud-header__brand {
  display:     flex;
  align-items: center;
  gap:         12px;
}
.hudhud-mascot {
  width:           40px;
  height:          40px;
  background:      rgba(255,255,255,0.18);
  border-radius:   50%;
  display:         flex;
  align-items:     center;
  justify-content: center;
  flex-shrink:     0;
  overflow:        hidden;
}
.hudhud-mascot img {
  width:      28px;
  height:     28px;
  object-fit: contain;
}
.hudhud-header__text   { display: flex; flex-direction: column; }
.hudhud-name           { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.2; }
.hudhud-tagline        { font-size: 12px; opacity: 0.85; margin-top: 1px; }

.hudhud-close {
  background:    rgba(255,255,255,0.15);
  border:        none;
  cursor:        pointer;
  padding:       6px;
  border-radius: 50%;
  display:       flex;
  align-items:   center;
  justify-content: center;
  color:         white;
  transition:    background var(--hd-anim-fast), transform var(--hd-anim-fast);
  flex-shrink:   0;
}
.hudhud-close:hover { background: rgba(255,255,255,0.28); transform: scale(1.1); }
.hudhud-close svg   { width: 18px; height: 18px; }

/* ── Chat Body ──────────────────────────────────────────────── */
.hudhud-body {
  flex:       1;
  overflow-y: auto;
  padding:    16px 20px;
  scroll-behavior: smooth;
  background: var(--hd-bg);
  min-height: 120px;
}
.hudhud-body::-webkit-scrollbar        { width: 4px; }
.hudhud-body::-webkit-scrollbar-track  { background: transparent; }
.hudhud-body::-webkit-scrollbar-thumb  { background: var(--hd-border); border-radius: 2px; }

/* ── Loading ─────────────────────────────────────────────────── */
.hudhud-loading {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  padding:         32px 16px;
  color:           var(--hd-text-muted);
  font-size:       14px;
  gap:             12px;
}
.hudhud-loading.hidden { display: none; }

.hudhud-loading__dots { display: flex; gap: 6px; }
.hudhud-loading__dots span {
  width:         8px;
  height:        8px;
  background:    var(--hd-primary);
  border-radius: 50%;
  animation:     hudhud-bounce 1.2s ease-in-out infinite;
}
.hudhud-loading__dots span:nth-child(2) { animation-delay: 0.16s; }
.hudhud-loading__dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes hudhud-bounce {
  0%, 80%, 100% { transform: translateY(0);     opacity: 0.5; }
  40%           { transform: translateY(-10px);  opacity: 1;   }
}

/* ── Messages ─────────────────────────────────────────────────── */
.hudhud-messages { display: flex; flex-direction: column; gap: 12px; }

.hudhud-msg {
  display:   flex;
  gap:       10px;
  animation: hudhud-msg-in var(--hd-anim-med) ease both;
}
@keyframes hudhud-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}
.hudhud-msg.no-anim { animation: none; }

.hudhud-msg__avatar {
  width:           32px;
  height:          32px;
  background:      linear-gradient(135deg, var(--hd-primary), var(--hd-accent));
  border-radius:   50%;
  flex-shrink:     0;
  display:         flex;
  align-items:     center;
  justify-content: center;
  color:           white;
  font-size:       14px;
  margin-top:      2px;
}
.hudhud-msg__bubble {
  background:    var(--hd-surface);
  border-radius: var(--hd-radius-sm) var(--hd-radius-sm) var(--hd-radius-sm) 2px;
  padding:       10px 14px;
  font-size:     14px;
  line-height:   1.55;
  color:         var(--hd-text);
  max-width:     calc(100% - 50px);
  border:        1px solid var(--hd-border);
}
.hudhud-msg__bubble a   { color: var(--hd-primary); text-decoration: none; }
.hudhud-msg__bubble a:hover { text-decoration: underline; }

.hudhud-msg--user               { flex-direction: row-reverse; }
.hudhud-msg--user .hudhud-msg__bubble {
  background:    linear-gradient(135deg, var(--hd-primary), var(--hd-accent));
  color:         white;
  border-radius: var(--hd-radius-sm) var(--hd-radius-sm) 2px var(--hd-radius-sm);
  border:        none;
}
.hudhud-msg--user .hudhud-msg__bubble a { color: rgba(255,255,255,0.85); }

/* ── Status Card ─────────────────────────────────────────────── */
.hudhud-status-card {
  border:        2px solid var(--hd-border);
  border-radius: var(--hd-radius-sm);
  padding:       14px 16px;
  margin-bottom: 2px;
}
.hudhud-status-card.status-approved { border-color: #22c55e; background: #f0fdf4; }
.hudhud-status-card.status-avoid    { border-color: #ef4444; background: #fef2f2; }
.hudhud-status-card.status-review   { border-color: #f59e0b; background: #fffbeb; }
.hudhud-status-card.status-unknown  { border-color: #d1d5db; background: #f9fafb; }

.hudhud-status-card__header {
  display:     flex;
  align-items: center;
  gap:         10px;
  margin-bottom: 8px;
}
.hudhud-status-icon  { font-size: 22px; line-height: 1; flex-shrink: 0; }
.hudhud-status-label { font-size: 15px; font-weight: 700; color: var(--hd-text); flex: 1; }

.status-approved .hudhud-status-label { color: #15803d; }
.status-avoid    .hudhud-status-label { color: #dc2626; }
.status-review   .hudhud-status-label { color: #d97706; }
.status-unknown  .hudhud-status-label { color: var(--hd-unknown); }

.hudhud-confidence {
  font-size:     11px;
  font-weight:   600;
  padding:       3px 8px;
  border-radius: 100px;
  background:    rgba(0,0,0,0.06);
  color:         var(--hd-text-muted);
  white-space:   nowrap;
}
.hudhud-status-reason {
  font-size:   13px;
  color:       var(--hd-text-muted);
  line-height: 1.5;
  margin:      0;
}
.hudhud-brand-tag {
  display:       inline-flex;
  align-items:   center;
  gap:           4px;
  font-size:     11px;
  font-weight:   600;
  color:         var(--hd-text-muted);
  background:    var(--hd-border);
  padding:       2px 8px;
  border-radius: 100px;
  margin-top:    8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Quick Prompts ───────────────────────────────────────────── */
.hudhud-quick-prompts {
  display:     flex;
  flex-wrap:   wrap;
  gap:         6px;
  padding:     10px 20px 12px;
  border-top:  1px solid var(--hd-border);
  background:  var(--hd-bg);
  flex-shrink: 0;
}
.hudhud-prompt-btn {
  font-size:     12px;
  font-weight:   500;
  color:         var(--hd-primary);
  background:    rgba(249,115,22,0.08);
  border:        1px solid rgba(249,115,22,0.25);
  border-radius: 100px;
  padding:       5px 12px;
  cursor:        pointer;
  transition:    all var(--hd-anim-fast);
  white-space:   nowrap;
  font-family:   var(--hd-font);
}
.hudhud-prompt-btn:hover  { background: rgba(249,115,22,0.15); border-color: var(--hd-primary); transform: translateY(-1px); }
.hudhud-prompt-btn:active { transform: translateY(0); }
.hudhud-prompt-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Input Area ──────────────────────────────────────────────── */
.hudhud-input-area {
  display:     flex;
  align-items: center;
  gap:         8px;
  padding:     10px 16px 12px;
  border-top:  1px solid var(--hd-border);
  background:  var(--hd-bg);
  flex-shrink: 0;
}
#hudhud-input {
  flex:          1;
  font-size:     14px;
  font-family:   var(--hd-font);
  color:         var(--hd-text);
  background:    var(--hd-surface);
  border:        1.5px solid var(--hd-border);
  border-radius: 100px;
  padding:       9px 16px;
  outline:       none;
  transition:    border-color var(--hd-anim-fast), box-shadow var(--hd-anim-fast);
}
#hudhud-input:focus {
  border-color: var(--hd-primary);
  box-shadow:   0 0 0 3px rgba(249,115,22,0.12);
}
#hudhud-input::placeholder { color: var(--hd-text-light); }
#hudhud-input:disabled     { opacity: 0.5; cursor: not-allowed; }

#hudhud-send {
  width:         38px;
  height:        38px;
  background:    linear-gradient(135deg, var(--hd-primary), var(--hd-accent));
  color:         white;
  border:        none;
  border-radius: 50%;
  display:       flex;
  align-items:   center;
  justify-content: center;
  cursor:        pointer;
  flex-shrink:   0;
  transition:    transform var(--hd-anim-fast), box-shadow var(--hd-anim-fast);
  box-shadow:    0 2px 8px rgba(249,115,22,0.35);
}
#hudhud-send:hover    { transform: scale(1.08); box-shadow: 0 4px 14px rgba(249,115,22,0.5); }
#hudhud-send:active   { transform: scale(0.96); }
#hudhud-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
#hudhud-send svg      { width: 16px; height: 16px; }

/* ── Footer ──────────────────────────────────────────────────── */
.hudhud-footer {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         7px 20px;
  background:      var(--hd-surface);
  border-top:      1px solid var(--hd-border);
  font-size:       11px;
  color:           var(--hd-text-light);
  flex-shrink:     0;
}
.hudhud-report-link {
  background:      none;
  border:          none;
  font-size:       11px;
  color:           var(--hd-text-light);
  cursor:          pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding:         0;
  font-family:     var(--hd-font);
  transition:      color var(--hd-anim-fast);
}
.hudhud-report-link:hover { color: var(--hd-danger); }

/* ── Notification Indicator ──────────────────────────────────── */
/* Hidden by default — JS adds .hudhud-indicator--visible after 300ms */
.hudhud-indicator {
  display:        inline-flex;
  align-items:    center;
  gap:            10px;
  margin-top:     14px;
  cursor:         pointer;
  padding:        8px 14px 8px 10px;
  background:     var(--hd-bg);
  border:         1.5px solid rgba(249,115,22,0.3);
  border-radius:  100px;
  box-shadow:     var(--hd-shadow-sm);
  user-select:    none;
  width:          fit-content;
  /* Start invisible, animate in */
  opacity:        0;
  transform:      translateY(6px);
  transition:     opacity var(--hd-anim-med) ease,
                  transform var(--hd-anim-med) ease,
                  border-color var(--hd-anim-fast),
                  box-shadow var(--hd-anim-fast);
}
/* JS adds this class to trigger entrance */
.hudhud-indicator.hudhud-indicator--visible {
  opacity:   1;
  transform: translateY(0);
}
.hudhud-indicator:hover {
  border-color: var(--hd-primary);
  box-shadow:   0 4px 20px rgba(249,115,22,0.22);
  transform:    translateY(-1px);
}
.hudhud-indicator:active { transform: translateY(0); }

.hudhud-indicator__icon {
  width:           28px;
  height:          28px;
  background:      linear-gradient(135deg, var(--hd-primary), var(--hd-accent));
  border-radius:   50%;
  display:         flex;
  align-items:     center;
  justify-content: center;
  flex-shrink:     0;
  color:           white;
}
.hudhud-indicator__icon svg { width: 18px; height: 18px; }

.hudhud-indicator__badge {
  display:     flex;
  align-items: center;
  gap:         7px;
}

/* Pulse dot — JS updates background colour when status is known */
.hudhud-indicator__pulse {
  position:      relative;
  display:       inline-block;
  width:         8px;
  height:        8px;
  background:    var(--hd-primary);
  border-radius: 50%;
  flex-shrink:   0;
  transition:    background 400ms ease;
}
.hudhud-indicator__pulse::before {
  content:       '';
  position:      absolute;
  inset:         -4px;
  background:    inherit;
  border-radius: 50%;
  opacity:       0.4;
  animation:     hudhud-pulse 2s cubic-bezier(0.4,0,0.6,1) infinite;
}
@keyframes hudhud-pulse {
  0%, 100% { transform: scale(1);   opacity: 0.4; }
  50%       { transform: scale(2.2); opacity: 0;   }
}

.hudhud-indicator__text {
  font-size:     13px;
  font-weight:   600;
  color:         var(--hd-text);
  font-family:   var(--hd-font);
  letter-spacing: -0.2px;
}

/* ── Typing indicator ────────────────────────────────────────── */
.hudhud-typing { display: flex; align-items: center; gap: 5px; padding: 8px 4px; }
.hudhud-typing span {
  width:         6px;
  height:        6px;
  background:    var(--hd-text-light);
  border-radius: 50%;
  animation:     hudhud-typing 1.4s ease-in-out infinite;
}
.hudhud-typing span:nth-child(2) { animation-delay: 0.2s; }
.hudhud-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes hudhud-typing {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── Report Modal ────────────────────────────────────────────── */
.hudhud-report-modal {
  position:        fixed;
  inset:           0;
  background:      rgba(0,0,0,0.5);
  z-index:         calc(var(--hd-z-popup) + 10);
  display:         flex;
  align-items:     center;
  justify-content: center;
  padding:         20px;
  opacity:         0;
  pointer-events:  none;
  transition:      opacity var(--hd-anim-med);
}
.hudhud-report-modal.is-open { opacity: 1; pointer-events: all; }

.hudhud-report-modal__inner {
  background:    var(--hd-bg);
  border-radius: var(--hd-radius);
  padding:       28px;
  width:         min(380px, 100%);
  box-shadow:    var(--hd-shadow);
}
.hudhud-report-modal__inner h3  { margin: 0 0 6px; font-size: 18px; color: var(--hd-text); }
.hudhud-report-modal__inner p   { margin: 0 0 16px; font-size: 14px; color: var(--hd-text-muted); }
.hudhud-report-modal__inner textarea {
  width:         100%;
  font-size:     14px;
  font-family:   var(--hd-font);
  border:        1.5px solid var(--hd-border);
  border-radius: var(--hd-radius-sm);
  padding:       10px 14px;
  resize:        vertical;
  outline:       none;
  transition:    border-color var(--hd-anim-fast);
  box-sizing:    border-box;
}
.hudhud-report-modal__inner textarea:focus { border-color: var(--hd-primary); }
.hudhud-report-modal__actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }

#hudhud-report-submit {
  background:    linear-gradient(135deg, var(--hd-primary), var(--hd-accent));
  color:         white;
  border:        none;
  border-radius: var(--hd-radius-sm);
  padding:       9px 20px;
  font-size:     14px;
  font-weight:   600;
  cursor:        pointer;
  font-family:   var(--hd-font);
  transition:    transform var(--hd-anim-fast), box-shadow var(--hd-anim-fast);
}
#hudhud-report-submit:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(249,115,22,0.4); }

#hudhud-report-cancel {
  background:    transparent;
  color:         var(--hd-text-muted);
  border:        1.5px solid var(--hd-border);
  border-radius: var(--hd-radius-sm);
  padding:       9px 16px;
  font-size:     14px;
  cursor:        pointer;
  font-family:   var(--hd-font);
  transition:    border-color var(--hd-anim-fast);
}
#hudhud-report-cancel:hover { border-color: var(--hd-primary); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  .hudhud-overlay { padding: 10px; align-items: flex-end; }
  .hudhud-popup   { width: 100%; max-height: calc(100vh - 80px);
                    border-radius: var(--hd-radius) var(--hd-radius) 0 0; }
  .hudhud-indicator { margin-top: 10px; }
}

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .hudhud-overlay, .hudhud-popup, .hudhud-msg,
  .hudhud-indicator, .hudhud-prompt-btn,
  #hudhud-send { transition: none !important; }
  .hudhud-loading__dots span,
  .hudhud-indicator__pulse::before,
  .hudhud-typing span { animation: none !important; }
}
