/**
 * styles/rivet-chat.css
 * Rivet AI Intake Copilot Widget
 */

.rivet-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  isolation: isolate;
  min-width: 174px;
  height: 64px;
  padding: 0 25px;
  overflow: hidden;
  color: #f5efe4;
  border: 1px solid rgba(255, 255, 255, 0.23);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0.08) 24%, rgba(15, 15, 14, 0.98) 62%, rgba(5, 5, 5, 1) 100%);
  cursor: pointer !important;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, 0.42),
    inset 0 -14px 22px rgba(0, 0, 0, 0.82),
    0 4px 0 rgba(0, 0, 0, 0.9),
    0 18px 40px rgba(0, 0, 0, 0.62),
    0 0 30px rgba(189, 142, 73, 0.1);
  transform: translateY(0);
  transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1), border-color 280ms ease, box-shadow 280ms ease;
}

.rivet-fab::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 7px 12px auto;
  height: 23px;
  border-radius: 999px 999px 45% 45%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.31), rgba(255, 255, 255, 0.025));
  filter: blur(0.2px);
  pointer-events: none;
}

.rivet-fab::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: -60%;
  left: -55%;
  width: 45%;
  height: 220%;
  background: linear-gradient(90deg, transparent, rgba(231, 190, 121, 0.34), transparent);
  transform: rotate(18deg) translateX(0);
  transition: transform 650ms cubic-bezier(0.2, 0.75, 0.2, 1);
  pointer-events: none;
}

.rivet-fab:hover {
  transform: translateY(-3px) scale(1.018);
  border-color: rgba(222, 177, 103, 0.52);
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, 0.5),
    inset 0 -14px 22px rgba(0, 0, 0, 0.8),
    0 5px 0 rgba(0, 0, 0, 0.9),
    0 22px 46px rgba(0, 0, 0, 0.72),
    0 0 38px rgba(189, 142, 73, 0.2);
}

.rivet-fab:hover::after {
  transform: rotate(18deg) translateX(410px);
}

.rivet-fab:active {
  transform: translateY(2px) scale(0.99);
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.9),
    inset 0 -5px 12px rgba(255, 255, 255, 0.08),
    0 1px 0 rgba(0, 0, 0, 0.92),
    0 9px 24px rgba(0, 0, 0, 0.55);
}

.rivet-fab:focus-visible {
  outline: 2px solid #d2a04e;
  outline-offset: 4px;
}

.rivet-fab__content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.rivet-fab__label {
  color: #f5efe4;
  font: 650 14px/1 var(--font-body, system-ui, sans-serif);
  letter-spacing: 0.015em;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.rivet-fab svg {
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  fill: none;
  stroke: #d4a14d;
  filter: drop-shadow(0 0 6px rgba(212, 161, 77, 0.25));
}

.rivet-widget {
  --rivet-window-gap: 16px;
  position: fixed;
  bottom: 6rem;
  right: 2rem;
  width: min(400px, calc(100vw - (var(--rivet-window-gap) * 2)));
  height: min(600px, calc(100dvh - var(--header-height, 72px) - 7rem));
  min-width: min(300px, calc(100vw - (var(--rivet-window-gap) * 2)));
  min-height: min(400px, calc(100dvh - var(--header-height, 72px) - 7rem));
  max-width: calc(100vw - (var(--rivet-window-gap) * 2));
  max-height: calc(100dvh - (var(--rivet-window-gap) * 2));
  background: var(--color-bg-card, rgba(18, 19, 24, 0.72));
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  resize: none;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
  contain: layout paint;
}

.rivet-widget.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* iOS can include transformed fixed elements in the page's scrollable
   overflow. Closed touch widgets must not participate in layout at all. */
@media (hover: none), (pointer: coarse) {
  .rivet-widget:not(.is-open) {
    display: none;
    transform: none;
  }

  .rivet-widget.is-open {
    display: flex;
  }
}

/* Local Theme Toggles for Rivet */
.rivet-widget.theme-light {
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(0, 0, 0, 0.1);
  color: #121318;
}
.rivet-widget.theme-light .rivet-header {
  border-bottom-color: rgba(0, 0, 0, 0.1);
}
.rivet-widget.theme-light .rivet-message--user {
  background: #f0f0f0;
  color: #121318;
}
.rivet-widget.theme-light .rivet-input-area {
  border-top-color: rgba(0, 0, 0, 0.1);
}

/* Header & Dragging */
.rivet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  cursor: grab;
  user-select: none;
  touch-action: none;
  background: rgba(0, 0, 0, 0.2);
}

.rivet-header:active {
  cursor: grabbing;
}

.rivet-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-display, 'Jixellation', sans-serif);
  font-size: 1.2rem;
  color: var(--color-accent-emerald, #C2A476);
}

.rivet-header-actions {
  display: flex;
  gap: 0.5rem;
}
.rivet-close-label { display: none; }

.rivet-btn {
  background: transparent;
  border: none;
  color: var(--color-text-secondary, #8b949e);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.rivet-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-primary, #ffffff);
}

.rivet-widget.theme-light .rivet-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #000;
}

.rivet-resize-grip {
  position: absolute;
  right: 0;
  bottom: 0;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: end;
  padding: 0 8px 8px 0;
  border: 0;
  background: transparent;
  color: rgba(210, 160, 78, 0.78);
  cursor: nwse-resize;
  touch-action: none;
  z-index: 2;
}

.rivet-resize-grip svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.rivet-resize-grip:hover,
.rivet-resize-grip:focus-visible { color: #e7bc72; }
.rivet-resize-grip:focus-visible { outline: 2px solid #d2a04e; outline-offset: -6px; border-radius: 4px; }
.rivet-widget.is-resizing { user-select: none; }

/* Chat History Area */
.rivet-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scroll-behavior: smooth;
}

.rivet-message {
  max-width: 85%;
  line-height: 1.5;
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.95rem;
  animation: rivetFadeIn 0.3s ease forwards;
  white-space: pre-wrap;
}

.rivet-message__email {
  color: #e0b66d;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@keyframes rivetFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.rivet-message--assistant {
  align-self: flex-start;
  color: var(--color-text-primary, #ffffff);
}

.rivet-widget.theme-light .rivet-message--assistant {
  color: #121318;
}

.rivet-message--user {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.75rem 1rem;
  border-radius: 12px 12px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--color-text-primary, #ffffff);
}

/* Typing Indicator */
.rivet-typing {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0;
  align-self: flex-start;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.rivet-typing.is-visible {
  opacity: 1;
}

.rivet-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent-emerald, #C2A476);
  animation: rivetTypingBounce 1.4s infinite ease-in-out both;
}

.rivet-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.rivet-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes rivetTypingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Input Area */
.rivet-input-area {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.2);
}

.rivet-disclosure {
  margin: 0 0 0.65rem;
  color: var(--color-text-secondary, #8b949e);
  font: 500 0.7rem/1.4 var(--font-body, system-ui, sans-serif);
  letter-spacing: 0.02em;
}

.rivet-limit-note {
  margin: 0 0 0.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(210, 160, 78, 0.42);
  border-radius: 10px;
  color: #f3d49b;
  background: rgba(210, 160, 78, 0.1);
  font: 600 0.75rem/1.4 var(--font-body, system-ui, sans-serif);
}

.rivet-limit-note[hidden] { display: none; }

.rivet-email-action {
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  margin: 0 0 0.45rem;
  padding: 0.72rem 0.9rem;
  border: 1px solid rgba(210, 160, 78, 0.55);
  border-radius: 999px;
  color: #f5efe4;
  background: rgba(210, 160, 78, 0.14);
  font: 650 0.78rem/1.2 var(--font-body, system-ui, sans-serif);
  text-decoration: none;
}

.rivet-email-action:hover,
.rivet-email-action:focus-visible { background: rgba(210, 160, 78, 0.24); }
.rivet-email-action svg { flex:0 0 auto; width:.9rem; height:.9rem; margin-left:auto; fill:none; stroke:currentColor; stroke-width:1.65; stroke-linecap:round; stroke-linejoin:round; }
.rivet-email-action[hidden], .rivet-email-note[hidden] { display: none; }
.rivet-email-note {
  margin: 0 0 0.55rem;
  color: var(--color-text-secondary, #8b949e);
  font: 500 0.68rem/1.35 var(--font-body, system-ui, sans-serif);
  text-align: center;
}

.rivet-input-form {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  position: relative;
}

.rivet-input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 0.75rem 1rem;
  color: var(--color-text-primary, #ffffff);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
  min-height: 44px;
  max-height: 110px;
  resize: vertical;
  line-height: 1.35;
}

.rivet-input:disabled { opacity: 0.65; }

.rivet-widget.theme-light .rivet-input {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.1);
  color: #121318;
}

.rivet-input:focus {
  border-color: var(--color-accent-emerald, #C2A476);
}

.rivet-send-btn {
  background: var(--color-accent-emerald, #C2A476);
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #000;
  transition: all 0.2s ease;
}

.rivet-send-btn:hover {
  transform: scale(1.05);
}

.rivet-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Fullscreen Mobile View */
@media (max-width: 767px) {
  .rivet-fab {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    min-width: 52px;
    width: 52px;
    height: 52px;
    padding: 0;
  }

  .rivet-fab span { display: none !important; }

  .rivet-fab svg { width: 25px; height: 25px; }

  .rivet-widget {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    resize: none;
    z-index: 10050;
    transform: translateY(100%);
  }

  .rivet-widget.is-open {
    transform: translateY(0);
  }

  .rivet-resize-grip { display: none; }

  .rivet-header {
    gap: 0.45rem;
    padding: max(0.7rem, env(safe-area-inset-top)) 0.75rem 0.7rem;
    cursor: default;
  }

  .rivet-title {
    min-width: 0;
    gap: 0.45rem;
    font-size: 1rem;
    white-space: nowrap;
  }

  .rivet-title svg { width: 18px; height: 18px; flex: 0 0 auto; }

  .rivet-header-actions { gap: 0.1rem; }

  .rivet-btn { min-width:40px; min-height:40px; padding:.55rem; }
  .rivet-send-btn { flex:0 0 44px; width:44px; height:44px; }

  .rivet-messages {
    padding: 1.1rem 1rem;
    gap: 1rem;
  }

  .rivet-message {
    max-width: 92%;
    font-size: 0.92rem;
    line-height: 1.48;
  }

  .rivet-input-area {
    padding: 0.75rem 0.75rem max(0.75rem, env(safe-area-inset-bottom));
  }

  .rivet-disclosure {
    margin-bottom: 0.5rem;
    font-size: 0.67rem;
    line-height: 1.3;
  }

  .rivet-input-form { gap: 0.55rem; }

  .rivet-input {
    min-height: 44px;
    height: 44px;
    padding: 0.68rem 0.85rem;
    font-size: 0.9rem;
    line-height: 1.35;
    overflow-y: auto;
    resize: none;
  }
}

.rivet-widget.is-fullscreen {
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  resize: none;
}

@media (prefers-reduced-motion: reduce) {
  .rivet-fab,
  .rivet-widget,
  .rivet-message { animation: none; transition: none; }
}
