/* ============================================================================
   Flutter chat widget — styles
   Loaded on every page via base.njk. Behavior in /js/components/chat.js.
   Tokens (--green, --teal, --dark, --shadow*, --r) come from main.css :root.
   ============================================================================ */

.flutter-chat {
  font-family: 'Nunito', sans-serif;
  color: var(--dark);
  --fc-grey-1: var(--bg2);
  --fc-grey-2: var(--border);
  --fc-grey-3: #c8d0d8;
  --fc-grey-4: var(--muted);
  --fc-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --fc-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --fc-shadow-soft: 0 8px 28px rgba(26, 35, 50, 0.10);
  --fc-shadow-float: 0 20px 60px rgba(26, 35, 50, 0.18), 0 4px 12px rgba(26, 35, 50, 0.06);
  --fc-shadow-bubble: 0 2px 8px rgba(26, 35, 50, 0.06);
}

/* ----- Launcher ---------------------------------------------------------- */

.flutter-chat__launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.9),
    0 0 0 4px rgba(121, 201, 204, 0.35),
    0 12px 32px rgba(26, 35, 50, 0.18),
    0 4px 12px rgba(121, 201, 204, 0.18);
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s var(--fc-ease-out), box-shadow 0.25s var(--fc-ease-out);
  padding: 0;
  overflow: visible;
  animation: fc-launcher-in 0.5s var(--fc-ease-out) 0.3s both;
}
.flutter-chat__launcher::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--green));
  opacity: 0;
  z-index: -1;
  animation: fc-launcher-pulse 2.8s ease-in-out infinite;
}
.flutter-chat__launcher::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #fff;
  z-index: 0;
}
.flutter-chat__launcher:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.9),
    0 0 0 4px rgba(121, 201, 204, 0.5),
    0 18px 40px rgba(26, 35, 50, 0.22),
    0 6px 16px rgba(121, 201, 204, 0.28);
}
.flutter-chat__launcher:active {
  transform: translateY(-1px) scale(1.0);
}
.flutter-chat__launcher object,
.flutter-chat__launcher img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  position: relative;
  z-index: 1;
  border-radius: 50%;
  overflow: hidden;
}
@keyframes fc-launcher-in {
  0%   { transform: scale(0) rotate(-45deg); opacity: 0; }
  60%  { transform: scale(1.12) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes fc-launcher-pulse {
  0%, 100% { transform: scale(1); opacity: 0; }
  50%      { transform: scale(1.15); opacity: 0.55; }
}

/* ----- Proactive bubble -------------------------------------------------- */

.flutter-chat__bubble {
  position: fixed;
  bottom: 110px;
  right: 24px;
  background: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 14px 16px 14px 18px;
  box-shadow: var(--fc-shadow-float);
  z-index: 9998;
  max-width: 280px;
  font-size: 14px;
  color: var(--dark);
  font-weight: 600;
  line-height: 1.45;
  border: 1px solid rgba(232, 237, 242, 0.7);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  animation:
    fc-bubble-in 0.45s var(--fc-ease-out) both,
    fc-bubble-float 4s ease-in-out 0.6s infinite;
  transition: transform 0.2s var(--fc-ease-out), box-shadow 0.2s var(--fc-ease-out);
}
.flutter-chat__bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 24px 64px rgba(26, 35, 50, 0.22), 0 6px 16px rgba(26, 35, 50, 0.08);
}
.flutter-chat__bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 26px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 1px solid rgba(232, 237, 242, 0.7);
  border-bottom: 1px solid rgba(232, 237, 242, 0.7);
  transform: rotate(45deg);
  border-radius: 0 0 4px 0;
}
.flutter-chat__bubble > div:first-child {
  flex: 1;
}
.flutter-chat__bubble-dismiss {
  background: var(--fc-grey-1);
  border: none;
  color: var(--fc-grey-4);
  cursor: pointer;
  font-size: 16px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.flutter-chat__bubble-dismiss:hover {
  background: var(--border);
  color: var(--dark);
}
@keyframes fc-bubble-in {
  from { transform: translateY(12px) scale(0.92); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes fc-bubble-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

/* ----- Panel ------------------------------------------------------------- */

.flutter-chat__panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 384px;
  height: 620px;
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 24px;
  box-shadow: var(--fc-shadow-float);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(232, 237, 242, 0.6);
  animation: fc-panel-in 0.35s var(--fc-ease-out) both;
  transform-origin: bottom right;
}
@keyframes fc-panel-in {
  from { transform: scale(0.88) translateY(16px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

/* ----- Header ----------------------------------------------------------- */

.flutter-chat__header {
  padding: 18px 16px 18px 18px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--green) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.flutter-chat__header::before {
  content: '';
  position: absolute;
  top: -40%;
  right: -20%;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.18) 0%, transparent 65%);
  pointer-events: none;
}
.flutter-chat__header::after {
  content: '';
  position: absolute;
  bottom: -80%;
  left: -10%;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.10) 0%, transparent 60%);
  pointer-events: none;
}
.flutter-chat__avatar {
  width: 46px;
  height: 46px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.35),
    0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1;
}
.flutter-chat__avatar > object,
.flutter-chat__avatar > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: opacity 0.2s ease;
}
.flutter-chat__titles {
  flex: 1;
  line-height: 1.2;
  z-index: 1;
}
.flutter-chat__titles-name {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.flutter-chat__titles-sub {
  font-size: 12px;
  opacity: 0.88;
  margin-top: 2px;
  font-weight: 600;
}
.flutter-chat__status {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 5px 11px;
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  letter-spacing: 0.01em;
  z-index: 1;
}
.flutter-chat__status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #b5f2a4;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(181, 242, 164, 0.4);
  animation: fc-status-pulse 2.2s ease-in-out infinite;
}
.flutter-chat__status--closed::before {
  background: #f0a8a8;
  box-shadow: 0 0 0 2px rgba(240, 168, 168, 0.4);
  animation: none;
}
@keyframes fc-status-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(181, 242, 164, 0.4); }
  50%      { box-shadow: 0 0 0 4px rgba(181, 242, 164, 0.15); }
}
.flutter-chat__close {
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 1;
  transition: background 0.15s, transform 0.15s;
}
.flutter-chat__close:hover {
  background: rgba(255, 255, 255, 0.32);
  transform: rotate(90deg);
}

/* ----- Messages --------------------------------------------------------- */

.flutter-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 16px;
  background:
    linear-gradient(180deg, var(--fc-grey-1) 0%, #fff 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.flutter-chat__messages::-webkit-scrollbar {
  width: 6px;
}
.flutter-chat__messages::-webkit-scrollbar-track {
  background: transparent;
}
.flutter-chat__messages::-webkit-scrollbar-thumb {
  background: var(--fc-grey-2);
  border-radius: 100px;
}
.flutter-chat__messages::-webkit-scrollbar-thumb:hover {
  background: var(--fc-grey-3);
}
.flutter-chat__msg {
  display: flex;
  gap: 10px;
  max-width: 92%;
  animation: fc-msg-in 0.35s var(--fc-ease-out) both;
}
@keyframes fc-msg-in {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.flutter-chat__msg--bot  { align-self: flex-start; }
.flutter-chat__msg--user { align-self: flex-end; flex-direction: row-reverse; }
.flutter-chat__msg-avatar {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--green) 100%);
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(121, 201, 204, 0.3);
  align-self: flex-end;
}
.flutter-chat__msg-avatar > object,
.flutter-chat__msg-avatar > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.flutter-chat__msg--user .flutter-chat__msg-avatar { display: none; }
.flutter-chat__msg-bubble {
  background: #fff;
  border: 1px solid var(--fc-grey-2);
  border-radius: 16px;
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--dark);
  box-shadow: var(--fc-shadow-bubble);
}
.flutter-chat__msg--bot  .flutter-chat__msg-bubble { border-top-left-radius: 4px; }
.flutter-chat__msg--user .flutter-chat__msg-bubble {
  background: linear-gradient(135deg, var(--dark) 0%, var(--mid) 100%);
  color: #fff;
  border-color: transparent;
  border-top-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(26, 35, 50, 0.18);
}
.flutter-chat__msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.flutter-chat__msg--bot:hover .flutter-chat__msg-actions,
.flutter-chat__msg-actions:focus-within { opacity: 1; }
.flutter-chat__msg-actions button {
  background: transparent;
  border: none;
  color: var(--fc-grey-3);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1;
  transition: color 0.15s, background 0.15s, transform 0.15s;
}
.flutter-chat__msg-actions button:hover {
  color: var(--td);
  background: var(--fc-grey-2);
  transform: scale(1.1);
}
.flutter-chat__msg-actions button.is-active {
  color: var(--gd);
  opacity: 1;
}

/* ----- Inline CTAs (tool-use buttons) ----------------------------------- */

.flutter-chat__msg-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.flutter-chat__msg-cta {
  display: inline-block;
  padding: 9px 16px;
  background: linear-gradient(135deg, var(--green) 0%, var(--gd) 100%);
  color: var(--dark);
  border: none;
  border-radius: 100px;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s var(--fc-ease-out), box-shadow 0.15s, filter 0.15s;
  box-shadow: 0 2px 8px rgba(126, 217, 87, 0.3);
}
.flutter-chat__msg-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(126, 217, 87, 0.4);
  filter: brightness(1.05);
  color: var(--dark);
}
.flutter-chat__msg-cta--outline {
  background: #fff;
  color: var(--td);
  border: 1.5px solid var(--teal);
  box-shadow: var(--fc-shadow-bubble);
}
.flutter-chat__msg-cta--outline:hover {
  background: var(--tp);
  color: var(--td);
  box-shadow: 0 4px 12px rgba(121, 201, 204, 0.25);
}

/* ----- Typing indicator ------------------------------------------------- */

.flutter-chat__typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
  align-items: center;
}
.flutter-chat__typing span {
  width: 7px;
  height: 7px;
  background: var(--teal);
  border-radius: 50%;
  animation: fc-typing 1.3s infinite;
  opacity: 0.5;
}
.flutter-chat__typing span:nth-child(2) { animation-delay: 0.18s; }
.flutter-chat__typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes fc-typing {
  0%, 60%, 100% { transform: translateY(0) scale(0.85); opacity: 0.4; }
  30%           { transform: translateY(-5px) scale(1); opacity: 1; }
}

/* ----- Error state ------------------------------------------------------ */

.flutter-chat__error {
  margin: 8px 16px;
  padding: 10px 12px;
  background: #fef0f0;
  border: 1px solid #f0a8a8;
  border-radius: 12px;
  font-size: 12px;
  color: #8a3a3a;
  line-height: 1.4;
  animation: fc-msg-in 0.3s var(--fc-ease-out) both;
}

/* ----- Input ------------------------------------------------------------ */

.flutter-chat__input {
  flex-shrink: 0;
  border-top: 1px solid var(--fc-grey-2);
  padding: 12px 14px;
  background: #fff;
  display: flex;
  gap: 10px;
  align-items: center;
}
.flutter-chat__input input {
  flex: 1;
  border: 1.5px solid var(--fc-grey-2);
  background: var(--fc-grey-1);
  padding: 11px 16px;
  border-radius: 100px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  color: var(--dark);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.flutter-chat__input input::placeholder {
  color: var(--fc-grey-4);
}
.flutter-chat__input input:focus {
  border-color: var(--teal);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(121, 201, 204, 0.15);
}
.flutter-chat__send {
  background: linear-gradient(135deg, var(--teal) 0%, var(--green) 100%);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s var(--fc-ease-out), box-shadow 0.15s, filter 0.15s;
  box-shadow: 0 4px 12px rgba(121, 201, 204, 0.35);
}
.flutter-chat__send:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 6px 16px rgba(121, 201, 204, 0.45);
  filter: brightness(1.05);
}
.flutter-chat__send:active:not(:disabled) {
  transform: translateY(0) scale(1);
}
.flutter-chat__send:disabled {
  background: var(--fc-grey-3);
  cursor: not-allowed;
  box-shadow: none;
}
.flutter-chat__send svg {
  width: 18px;
  height: 18px;
  margin-left: -2px;
}

/* ----- Footer ----------------------------------------------------------- */

.flutter-chat__footer {
  text-align: center;
  padding: 9px 12px;
  background: var(--fc-grey-1);
  font-size: 10.5px;
  color: var(--fc-grey-4);
  letter-spacing: 0.4px;
  border-top: 1px solid var(--fc-grey-2);
  font-weight: 600;
}

/* ----- Hidden ----------------------------------------------------------- */

.flutter-chat [hidden] { display: none !important; }

/* ----- Mobile: full-bottom-sheet panel ---------------------------------- */

@media (max-width: 540px) {
  .flutter-chat__panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    width: auto;
    height: 92vh;
    max-height: 92vh;
    border-radius: 24px 24px 0 0;
  }
  .flutter-chat__launcher {
    width: 60px;
    height: 60px;
    bottom: 20px;
    right: 20px;
  }
  .flutter-chat__bubble {
    bottom: 96px;
    right: 20px;
    max-width: 240px;
  }
}

/* ----- Reduced motion --------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .flutter-chat__launcher,
  .flutter-chat__launcher::before,
  .flutter-chat__bubble,
  .flutter-chat__panel,
  .flutter-chat__msg,
  .flutter-chat__status::before,
  .flutter-chat__avatar > object,
  .flutter-chat__avatar > img,
  .flutter-chat__typing span,
  .flutter-chat__error {
    animation: none !important;
    transition: none !important;
  }
}
