/* =============================================================================
   Tandy Chat Widget — Scoped Styles
   All selectors prefixed with .tandy- to avoid dashboard collisions.
   Works standalone when embedded cross-domain (getintandem.io homepage etc.)
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ---- Floating Bubble (avatar-based) ------------------------------------- */
.tandy-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.22);
  border: none;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: visible; /* allow badge + peek to escape */
}

.tandy-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.3);
}

.tandy-bubble:active {
  transform: scale(0.96);
}

/* Headshot circle */
.tandy-bubble-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #1a73e8;
  background: #e8f0fe; /* fallback while image loads */
}

.tandy-bubble-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

/* Small chat icon badge — pinned bottom-right of the circle */
.tandy-bubble-chat-icon {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  pointer-events: none;
}

.tandy-bubble-chat-icon svg {
  width: 11px;
  height: 11px;
  fill: #ffffff;
}

/* Unread count badge */
.tandy-bubble-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #e53935;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #fff;
  pointer-events: none;
}

/* ---- Proactive Peek Tooltip ---------------------------------------------- */
.tandy-peek {
  position: fixed;
  bottom: 36px;
  right: 98px; /* sits just left of the bubble */
  z-index: 99998;
  background: #ffffff;
  color: #1a1a2e;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
  padding: 10px 14px 10px 14px;
  border-radius: 18px 18px 4px 18px; /* speech bubble pointing right */
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.14),
    0 1px 4px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: all;
  /* Enter animation */
  animation: tandy-peek-enter 0.4s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
}

.tandy-peek.tandy-peek-out {
  animation: tandy-peek-exit 0.25s ease forwards;
}

.tandy-peek-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #9aa0a6;
  font-size: 16px;
  line-height: 1;
  padding: 0 0 0 4px;
  display: flex;
  align-items: center;
}

.tandy-peek-close:hover {
  color: #5f6368;
}

@keyframes tandy-peek-enter {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes tandy-peek-exit {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(8px); }
}

/* ---- Panel -------------------------------------------------------------- */
.tandy-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 99998;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 120px);
  border-radius: 20px;
  background: #ffffff;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.16),
    0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  transform-origin: bottom right;

  /* Hidden state */
  opacity: 0;
  transform: scale(0.88) translateY(16px);
  pointer-events: none;
  transition:
    opacity 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tandy-panel.tandy-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ---- Panel Header ------------------------------------------------------- */
.tandy-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
  flex-shrink: 0;
}

.tandy-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.tandy-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.tandy-header-text {
  flex: 1;
}

.tandy-header-name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.tandy-header-status {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.tandy-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #69f0ae;
  box-shadow: 0 0 0 2px rgba(105, 240, 174, 0.3);
  animation: tandy-pulse 2s ease-in-out infinite;
}

@keyframes tandy-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(105, 240, 174, 0.3); }
  50%       { box-shadow: 0 0 0 5px rgba(105, 240, 174, 0.0); }
}

.tandy-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s;
  flex-shrink: 0;
  outline: none;
}

.tandy-close-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ---- Message Thread ---------------------------------------------------- */
.tandy-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f9fc;
  scroll-behavior: smooth;
}

.tandy-messages::-webkit-scrollbar {
  width: 4px;
}

.tandy-messages::-webkit-scrollbar-thumb {
  background: #d0d4e0;
  border-radius: 4px;
}

/* ---- Message Bubbles ---------------------------------------------------- */
.tandy-msg {
  display: flex;
  gap: 8px;
  max-width: 86%;
  animation: tandy-msg-in 0.18s ease-out;
}

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

.tandy-msg.tandy-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.tandy-msg.tandy-msg-tandy {
  align-self: flex-start;
}

.tandy-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #1a73e8, #0d47a1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.tandy-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.tandy-msg-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tandy-bubble-text {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.tandy-msg-tandy .tandy-bubble-text {
  background: #fff;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.tandy-msg-user .tandy-bubble-text {
  background: linear-gradient(135deg, #1a73e8, #1557b0);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.tandy-msg-time {
  font-size: 10.5px;
  color: #9da3b2;
  padding: 0 2px;
}

.tandy-msg-tandy .tandy-msg-time { text-align: left; }
.tandy-msg-user .tandy-msg-time  { text-align: right; }

/* Hidden until typewriter completes */
.tandy-msg-time-hidden {
  opacity: 0;
}
.tandy-msg-time:not(.tandy-msg-time-hidden) {
  animation: tandy-fade-in 0.3s ease forwards;
}

@keyframes tandy-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Throttle subtext */
.tandy-throttle-subtext {
  font-size: 11px;
  color: #1a73e8;
  padding: 2px 2px 0;
  font-style: italic;
  cursor: pointer;
  text-decoration: underline dotted;
}

/* ---- Typing Indicator --------------------------------------------------- */
.tandy-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  animation: tandy-msg-in 0.18s ease-out;
}

.tandy-typing-dots {
  display: flex;
  gap: 4px;
  background: #fff;
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.tandy-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b0b7c8;
  animation: tandy-dot-bounce 1.2s ease-in-out infinite;
}

.tandy-typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.tandy-typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes tandy-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ---- Opportunity Cards -------------------------------------------------- */
.tandy-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  width: 100%;
}

.tandy-card {
  background: #fff;
  border: 1px solid #e3e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.tandy-card:hover {
  border-color: #1a73e8;
  box-shadow: 0 2px 10px rgba(26,115,232,0.12);
}

.tandy-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.tandy-card-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #1a1a2e;
  line-height: 1.35;
  flex: 1;
}

.tandy-card-score {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #1a73e8;
  border-radius: 6px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

.tandy-card-score.tandy-score-high   { background: #1a73e8; }
.tandy-card-score.tandy-score-medium { background: #fb8c00; }
.tandy-card-score.tandy-score-low    { background: #78909c; }
.tandy-card-score.tandy-score-none   { background: #90a4ae; }

.tandy-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.tandy-meta-tag {
  font-size: 10.5px;
  color: #5f6c7b;
  background: #f0f3f8;
  border-radius: 5px;
  padding: 2px 7px;
  white-space: nowrap;
}

.tandy-meta-tag.tandy-deadline-urgent {
  background: #fde8e8;
  color: #c62828;
  font-weight: 600;
}

.tandy-card-actions {
  display: flex;
  gap: 6px;
}

.tandy-btn-save {
  flex: 1;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #1a73e8, #1557b0);
  color: #fff;
  transition: opacity 0.15s, transform 0.1s;
  outline: none;
}

.tandy-btn-save:hover  { opacity: 0.9; }
.tandy-btn-save:active { transform: scale(0.97); }

.tandy-btn-save.tandy-saved {
  background: #e8f5e9;
  color: #2e7d32;
  cursor: default;
}

.tandy-btn-view {
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  border-radius: 8px;
  border: 1.5px solid #e3e8f0;
  cursor: pointer;
  background: transparent;
  color: #1a73e8;
  transition: background 0.15s, border-color 0.15s;
  outline: none;
}

.tandy-btn-view:hover {
  background: #f0f6ff;
  border-color: #1a73e8;
}

/* ---- Input Area --------------------------------------------------------- */
.tandy-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #eaecf2;
  flex-shrink: 0;
}

.tandy-input {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  padding: 9px 14px;
  border: 1.5px solid #dde1ed;
  border-radius: 20px;
  font-size: 13.5px;
  font-family: 'Inter', sans-serif;
  color: #1a1a2e;
  background: #f8f9fc;
  resize: none;
  outline: none;
  line-height: 1.45;
  transition: border-color 0.15s, background 0.15s;
  overflow-y: auto;
}

.tandy-input:focus {
  border-color: #1a73e8;
  background: #fff;
}

.tandy-input::placeholder {
  color: #b0b7c8;
}

.tandy-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #1a73e8, #1557b0);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  flex-shrink: 0;
  outline: none;
}

.tandy-send-btn:hover  { opacity: 0.88; }
.tandy-send-btn:active { transform: scale(0.93); }
.tandy-send-btn:disabled {
  background: #d0d4e0;
  cursor: not-allowed;
  transform: none;
  opacity: 1;
}

.tandy-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
  margin-left: 2px;
}

/* ---- Suggested Prompts (welcome state) ---------------------------------- */
.tandy-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 8px;
  gap: 12px;
  text-align: center;
}

.tandy-welcome-avatar {
  font-size: 40px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto;
}

.tandy-welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.tandy-welcome-title {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a2e;
}

.tandy-welcome-sub {
  font-size: 13px;
  color: #6b7280;
  max-width: 280px;
  line-height: 1.5;
}

.tandy-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}

.tandy-suggestion-btn {
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1.5px solid #e3e8f0;
  background: #fff;
  font-size: 12.5px;
  font-family: 'Inter', sans-serif;
  color: #374151;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  line-height: 1.4;
  outline: none;
}

.tandy-suggestion-btn:hover {
  border-color: #1a73e8;
  background: #f0f6ff;
  transform: translateX(2px);
}

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 440px) {
  .tandy-panel {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 88px;
    border-radius: 16px;
  }

  .tandy-bubble {
    bottom: 16px;
    right: 16px;
  }
}

/* ---- Contract opportunity links (tandy-opp:// scheme) ------------------- */
.tandy-opp-link {
  display: inline;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: #1a73e8;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
  text-align: left;
}

.tandy-opp-link:hover {
  color: #1558b0;
  text-decoration: underline;
}

/* -------------------------------------------------------------------------
   Research memo bubble (proactive Tandy intel)
   -------------------------------------------------------------------------*/
.tandy-memo-bubble {
  margin: 8px 0 12px 0;
  background: #fff8e7;
  border-left: 4px solid #f59e0b;
  border-radius: 12px;
  padding: 14px 16px 12px;
  position: relative;
  box-shadow: 0 1px 3px rgba(245,158,11,0.15);
}

.tandy-memo-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #b45309;
  margin-bottom: 8px;
}

.tandy-memo-content {
  font-size: 13px;
  line-height: 1.6;
  color: #1a1a2e;
  white-space: pre-wrap;
  word-break: break-word;
}

.tandy-memo-content.tandy-memo-collapsed {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tandy-memo-expand {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: #b45309;
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
}

.tandy-memo-dismiss {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}

.tandy-memo-dismiss:hover { color: #475569; }

.tandy-memo-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.tandy-memo-open-btn {
  display: inline-block;
  background: #f59e0b;
  color: #0f172a;
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border: none;
  font: inherit;
}

.tandy-memo-open-btn:hover { background: #d97706; }

/* Pulsing badge on launcher icon when an unsurfaced memo exists */
.tandy-bubble-memo-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  background: #f59e0b;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: tandy-pulse-amber 1.8s ease-in-out infinite;
}

@keyframes tandy-pulse-amber {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.4); opacity: 0.6; }
}

/* ---- Feedback Row (thumbs up/down on Tandy messages) -------------------- */
.tandy-feedback-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* Show on hover of the parent message, or always when rated */
.tandy-msg-tandy:hover .tandy-feedback-row,
.tandy-feedback-row.tandy-feedback-visible {
  opacity: 1;
}

.tandy-feedback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  color: #94a3b8;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.tandy-feedback-btn:hover {
  background: rgba(26, 115, 232, 0.1);
  color: #1a73e8;
  transform: scale(1.12);
}

.tandy-feedback-btn:active {
  transform: scale(0.92);
}

.tandy-feedback-btn.tandy-fb-selected {
  color: #1a73e8;
  background: rgba(26, 115, 232, 0.12);
  pointer-events: none;
}

.tandy-feedback-btn.tandy-fb-selected.tandy-fb-down {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.tandy-feedback-btn.tandy-fb-hidden {
  display: none;
}

.tandy-feedback-thanks {
  font-size: 11px;
  color: #64748b;
  margin-left: 4px;
  animation: tandy-fade-in 0.3s ease;
}

@keyframes tandy-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Correction Input (expands after thumbs-down) ----------------------- */
.tandy-correction-row {
  margin-top: 6px;
  animation: tandy-slide-down 0.25s ease;
}

@keyframes tandy-slide-down {
  from { opacity: 0; max-height: 0; transform: translateY(-4px); }
  to   { opacity: 1; max-height: 200px; transform: translateY(0); }
}

.tandy-correction-input {
  width: 100%;
  min-height: 44px;
  max-height: 80px;
  padding: 8px 10px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 8px;
  background: rgba(241, 245, 249, 0.6);
  color: #1e293b;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: border-color 0.15s ease;
}

.tandy-correction-input:focus {
  border-color: rgba(239, 68, 68, 0.4);
}

.tandy-correction-input::placeholder {
  color: #94a3b8;
}

.tandy-correction-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.tandy-correction-submit,
.tandy-correction-skip {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.tandy-correction-submit {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

.tandy-correction-submit:hover {
  background: rgba(239, 68, 68, 0.2);
  transform: scale(1.02);
}

.tandy-correction-skip {
  background: transparent;
  color: #94a3b8;
}

.tandy-correction-skip:hover {
  background: rgba(148, 163, 184, 0.1);
}
