/* ============================================================
   TerraSense AI — floating chat button + panel
   Injected on every page by terrasense.js. Memory-only history.
   ============================================================ */

/* ---------- Floating action button ---------- */
.ts-fab {
  position: fixed;
  right: 1.4rem;
  bottom: 1.4rem;
  z-index: 940;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--grad);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 14px 32px rgba(13, 148, 136, 0.42);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.28s ease, border-radius 0.28s ease;
}

.ts-fab:hover,
.ts-fab:focus-visible {
  transform: translateY(-4px) scale(1.05);
  border-radius: 26px;
  box-shadow: 0 20px 40px rgba(13, 148, 136, 0.5);
}

.ts-fab:focus-visible {
  outline: 3px solid rgba(13, 148, 136, 0.45);
  outline-offset: 3px;
}

/* soft sonar pulse behind the button */
.ts-fab::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--grad);
  opacity: 0.35;
  z-index: -1;
  animation: tsPulse 2.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}

@keyframes tsPulse {
  0% { transform: scale(1); opacity: 0.35; }
  70%, 100% { transform: scale(1.45); opacity: 0; }
}

/* the little sparkle that makes the bot feel alive */
.ts-fab::after {
  content: "✦";
  position: absolute;
  top: -7px;
  right: -6px;
  font-size: 0.85rem;
  color: #0d9488;
  background: #eafff6;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 3px 8px rgba(11, 31, 22, 0.18);
}

.ts-fab.active::before {
  animation: none;
  opacity: 0;
}

/* hover label (desktop) */
.ts-fab-label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  padding: 0.48rem 0.85rem;
  border-radius: 11px;
  background: #06281d;
  color: #d7fbe9;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: 0 10px 22px rgba(11, 31, 22, 0.28);
}

.ts-fab-label::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: #06281d;
}

.ts-fab:hover .ts-fab-label,
.ts-fab:focus-visible .ts-fab-label {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

@media (hover: none) {
  .ts-fab-label { display: none; }
}

/* ---------- Panel ---------- */
.ts-panel {
  position: fixed;
  right: 1.35rem;
  bottom: calc(1.4rem + 76px);
  z-index: 945;
  display: flex;
  flex-direction: column;
  width: min(386px, calc(100vw - 2rem));
  height: min(600px, calc(100vh - 8.5rem));
  overflow: hidden;
  background: #fbfdfc;
  border: 1px solid rgba(13, 148, 136, 0.22);
  border-radius: 24px;
  box-shadow: 0 30px 70px rgba(6, 40, 29, 0.3);
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transform-origin: 100% 100%;
  transition: opacity 0.24s ease, transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.ts-panel.open {
  opacity: 1;
  transform: none;
}

/* CRITICAL: .ts-panel { display:flex } would defeat the [hidden] attribute
   (author rules beat the UA's [hidden]{display:none}), leaving an invisible
   opacity-0 panel permanently rendered at z-index 945 — it silently swallowed
   every tap that landed on it (hamburger menu items, page content). */
.ts-panel[hidden] {
  display: none !important;
}

/* Belt & braces: a closed (or fading-out) panel can never intercept clicks. */
.ts-panel:not(.open) {
  pointer-events: none;
}

/* ---------- Header ---------- */
.ts-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 0.95rem 0.85rem 1rem;
  background: linear-gradient(130deg, #065f46 0%, #0b7a5e 55%, #0d9488 100%);
  color: #eafff6;
}

.ts-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  animation: tsAvatarBob 3.6s ease-in-out infinite;
}

@keyframes tsAvatarBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.ts-id {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}

.ts-name {
  font-family: "Sora", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.01em;
}

.ts-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.74rem;
  color: #a7f3d0;
}

.ts-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6);
  animation: tsDotPing 2s ease-out infinite;
}

@keyframes tsDotPing {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55); }
  70%, 100% { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); }
}

.ts-head-actions {
  margin-left: auto;
  display: flex;
  gap: 0.3rem;
}

.ts-icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.12);
  color: #eafff6;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.ts-icon-btn:hover {
  background: rgba(255, 255, 255, 0.26);
  transform: translateY(-1px);
}

/* ---------- Log ---------- */
.ts-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.9rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background:
    radial-gradient(circle at 85% -10%, rgba(13, 148, 136, 0.08), transparent 42%),
    linear-gradient(180deg, #f4faf7 0%, #fbfdfc 100%);
  scrollbar-width: thin;
  scrollbar-color: rgba(13, 148, 136, 0.35) transparent;
}

.ts-msg {
  display: flex;
}

.ts-msg.bot { justify-content: flex-start; }
.ts-msg.user { justify-content: flex-end; }

.ts-bubble {
  max-width: 86%;
  padding: 0.66rem 0.9rem;
  font-size: 0.92rem;
  line-height: 1.52;
  border-radius: 16px;
  animation: tsBubbleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes tsBubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.ts-msg.bot .ts-bubble {
  background: #ffffff;
  border: 1px solid rgba(13, 148, 136, 0.16);
  border-left: 3px solid var(--brand);
  border-bottom-left-radius: 6px;
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(11, 31, 22, 0.06);
}

.ts-msg.user .ts-bubble {
  background: var(--grad);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.3);
}

.ts-bubble a {
  color: #0b7a5e;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ts-msg.user .ts-bubble a { color: #eafff6; }

.ts-bubble strong { font-weight: 700; }

/* word-by-word reveal helper */
.ts-bubble.ts-typing:not(:empty) {
  animation: none;
}

/* ---------- Typing dots ---------- */
.ts-bubble-typing {
  border-left: 3px solid var(--brand);
  background: #fff;
  border: 1px solid rgba(13, 148, 136, 0.16);
  border-left: 3px solid var(--brand);
  border-bottom-left-radius: 6px;
}

.ts-dots {
  display: inline-flex;
  gap: 5px;
  padding: 0.2rem 0.1rem;
}

.ts-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #0d9488;
  opacity: 0.5;
  animation: tsBounce 1.1s ease-in-out infinite;
}

.ts-dots i:nth-child(2) { animation-delay: 0.15s; }
.ts-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes tsBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Suggestion chips ---------- */
.ts-chips {
  display: flex;
  gap: 0.45rem;
  padding: 0.55rem 0.9rem;
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid rgba(13, 148, 136, 0.12);
  background: #fbfdfc;
}

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

.ts-chip {
  flex: none;
  padding: 0.42rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #0b7a5e;
  background: rgba(13, 148, 136, 0.08);
  border: 1px solid rgba(13, 148, 136, 0.22);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.ts-chip:hover {
  background: var(--grad);
  color: #fff;
  transform: translateY(-1px);
}

/* ---------- Form ---------- */
.ts-form {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem 0.55rem;
  background: #fbfdfc;
}

.ts-form input {
  flex: 1;
  min-width: 0;
  padding: 0.72rem 1.05rem;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: #fff;
  border: 1.6px solid rgba(13, 148, 136, 0.25);
  border-radius: 999px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ts-form input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(14, 159, 110, 0.14);
}

.ts-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(13, 148, 136, 0.35);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s ease;
}

.ts-send:hover { transform: translateY(-2px) scale(1.06); }
.ts-send:active { transform: scale(0.94); }

/* ---------- Footer note ---------- */
.ts-foot {
  margin: 0;
  padding: 0.35rem 1rem 0.7rem;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: #7d9a8c;
  text-align: center;
  background: #fbfdfc;
}

/* ---------- Keep back-to-top out of the chat's way ---------- */
body.ts-panel-open .to-top {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .ts-fab {
    right: 1rem;
    bottom: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 18px;
  }

  .ts-panel {
    right: 0.6rem;
    left: 0.6rem;
    bottom: calc(1rem + 68px);
    width: auto;
    height: min(66vh, 540px);
    border-radius: 20px;
  }
}

/* ============================================================
   Homepage — the long TerraSense AI banner (#innovations)
   ============================================================ */
.ts-banner {
  position: relative;
  overflow: hidden;
  padding: clamp(2.4rem, 5.5vw, 4rem) clamp(1.6rem, 5vw, 4rem);
  border-radius: 30px;
  background:
    radial-gradient(560px circle at 88% -20%, rgba(45, 212, 191, 0.22), transparent 60%),
    radial-gradient(420px circle at -6% 110%, rgba(16, 185, 129, 0.18), transparent 55%),
    linear-gradient(130deg, #04251a 0%, #065f46 48%, #0d9488 100%);
  color: #e8fff6;
  box-shadow: var(--shadow-lg);
}

/* faint circuit grid */
.ts-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(167, 243, 208, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(167, 243, 208, 0.055) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at 70% 40%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 70% 40%, #000 0%, transparent 78%);
  pointer-events: none;
}

.ts-banner-grid {
  position: relative;
  display: grid;
  grid-template-columns: 1.12fr 0.88fr;
  gap: clamp(1.6rem, 4vw, 3rem);
  align-items: center;
}

.ts-banner .eyebrow {
  color: #99f6e4;
}

.ts-banner h2 {
  color: #fff;
  font-size: clamp(1.7rem, 3.2vw, 2.5rem);
  margin-bottom: 0.55em;
}

.ts-grad {
  background: linear-gradient(92deg, #6ee7b7 10%, #5eead4 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.ts-banner-lead {
  max-width: 36rem;
  color: #cdf5e5;
  font-size: 1.03rem;
}

.ts-points {
  list-style: none;
  margin: 1.3rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 1.4rem;
  max-width: 34rem;
}

.ts-points li {
  position: relative;
  padding-left: 1.7rem;
  font-size: 0.92rem;
  font-weight: 500;
  color: #e8fff6;
}

.ts-points li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0.05em;
  display: grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 800;
  color: #04251a;
  background: #5eead4;
}

.ts-banner-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.7rem;
}

.ts-banner-hint {
  font-size: 0.82rem;
  color: #99f6e4;
}

/* ---------- Banner visual: AI core + rings + demo chat ---------- */
.ts-banner-visual {
  position: relative;
  min-height: 340px;
  display: grid;
  place-items: center;
}

.tsb-ring {
  position: absolute;
  left: 50%;
  top: 44%;
  border: 1.6px dashed rgba(167, 243, 208, 0.35);
  border-radius: 50%;
  pointer-events: none;
}

.tsb-ring.r1 {
  width: 300px;
  height: 300px;
  transform: translate(-50%, -50%);
  animation: tsbSpin 26s linear infinite;
}

.tsb-ring.r2 {
  width: 210px;
  height: 210px;
  transform: translate(-50%, -50%);
  border-color: rgba(167, 243, 208, 0.22);
  animation: tsbSpin 18s linear infinite reverse;
}

@keyframes tsbSpin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* nodes riding the outer ring */
.tsb-ring.r1::before,
.tsb-ring.r1::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #5eead4;
  box-shadow: 0 0 12px rgba(94, 234, 212, 0.9);
}

.tsb-ring.r1::before { top: -4.5px; left: calc(50% - 4.5px); }
.tsb-ring.r1::after { bottom: -4.5px; left: calc(50% - 4.5px); background: #f5b940; box-shadow: 0 0 12px rgba(245, 185, 64, 0.9); }

.tsb-core {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 30px;
  color: #eafff6;
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(6px);
  box-shadow: 0 0 0 0 rgba(94, 234, 212, 0.5), 0 18px 44px rgba(4, 37, 26, 0.55);
  animation: tsbCorePulse 3.4s ease-in-out infinite;
}

@keyframes tsbCorePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(94, 234, 212, 0.45), 0 18px 44px rgba(4, 37, 26, 0.55);
    transform: translateY(0);
  }
  50% {
    box-shadow: 0 0 0 16px rgba(94, 234, 212, 0), 0 18px 44px rgba(4, 37, 26, 0.55);
    transform: translateY(-5px);
  }
}

.tsb-spark {
  position: absolute;
  color: #a7f3d0;
  animation: tsbTwinkle 2.6s ease-in-out infinite;
  pointer-events: none;
}

.tsb-spark.s1 { top: 12%; right: 14%; font-size: 1.05rem; }
.tsb-spark.s2 { top: 26%; left: 10%; font-size: 0.8rem; color: #f5b940; animation-delay: 0.9s; }
.tsb-spark.s3 { bottom: 30%; right: 6%; font-size: 0.9rem; animation-delay: 1.6s; }

@keyframes tsbTwinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.8) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.15) rotate(18deg); }
}

/* the little self-playing conversation */
.ts-demo {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.ts-demo-row {
  display: flex;
}

.ts-demo-row.q { justify-content: flex-end; }
.ts-demo-row.a { justify-content: flex-start; }

.ts-demo-bubble {
  max-width: 88%;
  padding: 0.5rem 0.8rem;
  font-size: 0.78rem;
  line-height: 1.45;
  border-radius: 13px;
  min-height: 1.2em;
}

.ts-demo-row.q .ts-demo-bubble {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #e8fff6;
  border-bottom-right-radius: 4px;
}

.ts-demo-row.a .ts-demo-bubble {
  background: #eafff6;
  color: #04251a;
  font-weight: 500;
  border-bottom-left-radius: 4px;
  box-shadow: 0 8px 20px rgba(4, 37, 26, 0.35);
}

.ts-demo-row.typing .ts-demo-bubble::after {
  content: "▌";
  margin-left: 1px;
  color: #0d9488;
  animation: tsbCaret 0.8s steps(2) infinite;
}

@keyframes tsbCaret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ---------- Banner responsive ---------- */
@media (max-width: 940px) {
  .ts-banner-grid {
    grid-template-columns: 1fr;
  }

  .ts-banner-visual {
    min-height: 300px;
    margin-top: 0.6rem;
  }

  .ts-points {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .ts-banner {
    border-radius: 24px;
  }

  .ts-banner-visual {
    min-height: 250px;
  }

  .tsb-ring.r1 { width: 230px; height: 230px; }
  .tsb-ring.r2 { width: 160px; height: 160px; }
  .tsb-core { width: 76px; height: 76px; border-radius: 24px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .ts-fab,
  .ts-fab:hover,
  .ts-fab:focus-visible {
    transform: none;
    transition: none;
  }

  .ts-fab::before,
  .ts-dot,
  .ts-avatar,
  .ts-dots i,
  .tsb-ring,
  .tsb-core,
  .tsb-spark,
  .ts-demo-row.typing .ts-demo-bubble::after {
    animation: none;
  }

  .ts-panel,
  .ts-bubble {
    transition: none;
    animation: none;
  }
}
