/**
 * GRACE Companion — floating chat panel (desktop) + bottom sheet (mobile/card).
 * Pairs with grace-companion.js and grace-orb.css.
 */

/* ── Root containers ── */
.gcp-root--float {
  position: fixed;
  right: 24px;
  bottom: 24px;
  pointer-events: none;
}

.gcp-root--float .gcp-panel {
  width: 384px;
  max-width: calc(100vw - 48px);
  height: min(580px, calc(100vh - 80px));
  border-radius: 20px;
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.22s ease, visibility 0.22s;
}

.gcp-root--float.open .gcp-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.gcp-root--sheet {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 12, 24, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.gcp-root--sheet.open {
  opacity: 1;
  visibility: visible;
}

.gcp-root--sheet .gcp-panel {
  width: 100%;
  height: 78%;
  max-height: 640px;
  border-radius: 22px 22px 0 0;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.9, 0.35, 1);
}

.gcp-root--sheet.open .gcp-panel {
  transform: translateY(0);
}

/* ── Panel ── */
.gcp-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #fdfdff 0%, #f7f7fc 100%);
  border: 1px solid rgba(124, 92, 237, 0.18);
  box-shadow:
    0 24px 64px rgba(27, 42, 74, 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.6) inset,
    0 0 36px rgba(99, 102, 241, 0.12);
  font-family: inherit;
}

/* ── Header ── */
.gcp-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px;
  background:
    radial-gradient(circle at 12% 0%, rgba(96, 165, 250, 0.16) 0%, transparent 55%),
    radial-gradient(circle at 90% 120%, rgba(217, 70, 239, 0.12) 0%, transparent 55%),
    linear-gradient(135deg, #131a30 0%, #1b2a4a 60%, #2b2150 100%);
  border-bottom: 1px solid rgba(124, 92, 237, 0.25);
}

.gcp-head-orb { flex-shrink: 0; }

.gcp-head-text { flex: 1; min-width: 0; }

.gcp-title {
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.gcp-tag {
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(191, 219, 254, 0.85);
  background: rgba(96, 165, 250, 0.14);
  border: 1px solid rgba(96, 165, 250, 0.3);
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
}

.gcp-sub {
  font-size: 10.5px;
  color: rgba(226, 232, 240, 0.7);
  margin-top: 3px;
}

.gcp-icon-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.75);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease;
}

.gcp-icon-btn:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

.gcp-icon-btn.gcp-voice-on {
  background: rgba(96, 165, 250, 0.28);
  border-color: rgba(96, 165, 250, 0.55);
  color: #dbeafe;
}

.gcp-close { font-size: 17px; line-height: 1; }

/* ── Thread ── */
.gcp-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gcp-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 92%;
}

.gcp-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.gcp-msg--grace { align-self: flex-start; }

.gcp-msg-orb {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(147, 197, 253, 0.95) 0%, #3b82f6 35%, #7c3aed 70%, #d946ef 100%);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.45);
}

.gcp-bubble {
  padding: 10px 13px;
  border-radius: 15px;
  font-size: 12.5px;
  line-height: 1.55;
  word-wrap: break-word;
}

.gcp-msg--grace .gcp-bubble {
  background: #fff;
  border: 1px solid rgba(124, 92, 237, 0.16);
  border-bottom-left-radius: 5px;
  color: #2a2a35;
  box-shadow: 0 2px 8px rgba(27, 42, 74, 0.06);
}

.gcp-msg--user .gcp-bubble {
  background: linear-gradient(135deg, #1b2a4a, #2b2150);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.gcp-action {
  display: block;
  margin-top: 9px;
  padding: 7px 13px;
  border: none;
  border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6, #7c3aed);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.gcp-action:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(99, 102, 241, 0.45); }

/* Typing dots */
.gcp-typing { display: inline-flex; gap: 4px; align-items: center; min-height: 18px; }

.gcp-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7c8db5;
  animation: gcpTypingBlink 1.2s ease-in-out infinite;
}

.gcp-typing span:nth-child(2) { animation-delay: 0.18s; }
.gcp-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes gcpTypingBlink {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ── Chips ── */
.gcp-chips {
  display: flex;
  gap: 6px;
  padding: 4px 14px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.gcp-chips::-webkit-scrollbar { display: none; }

.gcp-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(124, 92, 237, 0.25);
  background: #fff;
  color: #4c3f8f;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.gcp-chip:hover { background: linear-gradient(135deg, #3b82f6, #7c3aed); color: #fff; }

/* ── Input row ── */
.gcp-inputrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid rgba(124, 92, 237, 0.14);
  background: #fff;
}

.gcp-inputrow .gcp-icon-btn {
  border-color: rgba(124, 92, 237, 0.3);
  background: #f4f2fc;
  color: #6552c5;
}

.gcp-inputrow .gcp-icon-btn:hover { background: #e9e5fa; color: #4c3f8f; }

.gcp-mic.listening {
  background: #fde8e9 !important;
  border-color: #ee2b37 !important;
  color: #ee2b37 !important;
  animation: gcpMicPulse 1.1s ease-in-out infinite;
}

@keyframes gcpMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(238, 43, 55, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(238, 43, 55, 0); }
}

.gcp-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(124, 92, 237, 0.22);
  border-radius: 11px;
  padding: 9px 12px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  background: #fbfaff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.gcp-input:focus {
  border-color: #7c5ced;
  box-shadow: 0 0 0 3px rgba(124, 92, 237, 0.12);
}

.gcp-send {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #3b82f6, #7c3aed);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.4);
  transition: transform 0.12s ease;
}

.gcp-send:hover { transform: scale(1.07); }

/* ── Footer ── */
.gcp-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 9px;
  background: #fff;
}

.gcp-foot-note {
  flex: 1;
  font-size: 8.5px;
  color: #9a96ab;
  line-height: 1.4;
}

.gcp-clear {
  flex-shrink: 0;
  border: none;
  background: none;
  font-size: 9px;
  font-weight: 700;
  color: #7c5ced;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  padding: 2px;
}

/* ── Bound orbs: invite interaction, intensify while GRACE speaks ── */
.gcp-orb-bound { cursor: pointer; }

.gcp-orb-bound:hover .grace-orb,
.gcp-orb-bound.grace-orb:hover {
  filter: drop-shadow(0 0 18px rgba(59, 130, 246, 0.65)) drop-shadow(0 0 34px rgba(168, 85, 247, 0.4));
}

.gcp-orb-bound:focus-visible { outline: 2px solid #7c5ced; outline-offset: 3px; border-radius: 50%; }

.grace-orb.is-speaking .grace-orb__wave span { animation-duration: 0.38s; }

.grace-orb.is-speaking .grace-orb__halo { animation-duration: 0.9s; border-color: rgba(147, 197, 253, 0.85); }

.grace-orb.is-speaking {
  filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.7)) drop-shadow(0 0 40px rgba(168, 85, 247, 0.45));
}

/* Compact tweaks inside sheet on small screens */
@media (max-width: 430px) {
  .gcp-tag { display: none; }
  .gcp-root--sheet .gcp-panel { height: 84%; }
}
