/* ============================================================
   KAIRO — WebSage floating local AI assistant
   Brand-matched: black glass + WebSage red (#ff2b2b)
   Isolated with `kairo-` prefix. No external dependencies.
   ============================================================ */
:root {
  --kairo-red: #ff2b2b;
  --kairo-red-dark: #d10000;
  --kairo-bg: rgba(10, 10, 12, 0.92);
  --kairo-card: rgba(255, 255, 255, 0.045);
  --kairo-border: rgba(255, 255, 255, 0.11);
  --kairo-text: #f5f5f7;
  --kairo-muted: #b4b4b8;
  --kairo-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --kairo-glow: 0 0 24px rgba(255, 43, 43, 0.45);
}

/* Hidden until kairo.js confirms it booted (no dead button if blocked) */
#kairo { display: none; }

/* Launcher — floats above Tawk.to bubble (bottom offset) */
#kairo-launcher {
  position: fixed;
  right: calc(22px + env(safe-area-inset-right, 0px));
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
  z-index: 99980;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 10px;
  border: 1px solid rgba(255, 43, 43, 0.4);
  border-radius: 999px;
  background: rgba(8, 8, 10, 0.9);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--kairo-text);
  font-family: 'Lato', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--kairo-shadow);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
#kairo-launcher:hover { transform: translateY(-2px); box-shadow: var(--kairo-shadow), var(--kairo-glow); }
#kairo-launcher:focus-visible { outline: 2px solid var(--kairo-red); outline-offset: 3px; }

.kairo-orb {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: radial-gradient(circle at 32% 30%, #ff7a7a 0%, var(--kairo-red) 42%, #7a0000 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', 'Lato', sans-serif;
  font-weight: 700;
  font-size: 19px;
  color: #fff;
}
.kairo-orb::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(255, 43, 43, 0.55);
  animation: kairo-ping 2.2s ease-out infinite;
}
@keyframes kairo-ping {
  0% { transform: scale(0.85); opacity: 1; }
  100% { transform: scale(1.25); opacity: 0; }
}
.kairo-orb img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* Pulse notification — launcher glows + gently nudges when Kairo has news */
#kairo-launcher.kairo-attention {
  border-color: var(--kairo-red);
  animation: kairo-nudge 1.6s ease-in-out infinite;
}
#kairo-launcher.kairo-attention .kairo-orb::after {
  animation-duration: 1.1s;
  border-color: var(--kairo-red);
}
#kairo-launcher.kairo-attention .kairo-badge.kairo-show {
  animation: kairo-badge-pop 1.1s ease-in-out infinite;
}
@keyframes kairo-nudge {
  0%, 100% { transform: translateY(0); box-shadow: var(--kairo-shadow); }
  50% { transform: translateY(-4px); box-shadow: var(--kairo-shadow), var(--kairo-glow); }
}
@keyframes kairo-badge-pop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}
#kairo-launcher.kairo-open .kairo-orb::after { animation: none; opacity: 0; }

.kairo-launcher-text { line-height: 1.15; text-align: left; }
.kairo-launcher-text small { display: block; font-size: 11px; font-weight: 400; color: var(--kairo-muted); }
.kairo-badge {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--kairo-red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
}
.kairo-badge.kairo-show { display: inline-flex; }

/* Panel */
#kairo-panel {
  position: fixed;
  right: calc(22px + env(safe-area-inset-right, 0px));
  bottom: calc(168px + env(safe-area-inset-bottom, 0px));
  z-index: 99981;
  width: min(384px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 200px));
  height: min(600px, calc(100dvh - 200px));
  min-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid var(--kairo-border);
  background: var(--kairo-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--kairo-shadow);
  font-family: 'Lato', system-ui, sans-serif;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}
#kairo-panel.kairo-open { opacity: 1; transform: none; pointer-events: auto; }

.kairo-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--kairo-border);
  background: linear-gradient(180deg, rgba(255, 43, 43, 0.12), transparent);
}
.kairo-header .kairo-orb { width: 42px; height: 42px; font-size: 21px; }
.kairo-header .kairo-orb::after { display: none; }
.kairo-who { flex: 1; min-width: 0; }
.kairo-who strong { display: block; font-family: 'Space Grotesk', 'Lato', sans-serif; font-size: 16px; color: #fff; }
.kairo-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #7ee2a8; }
.kairo-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.kairo-icon-btn {
  width: 32px; height: 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--kairo-muted);
  font-size: 17px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.kairo-icon-btn:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }

.kairo-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.kairo-msg { max-width: 86%; padding: 10px 13px; border-radius: 15px; font-size: 14px; line-height: 1.55; }
.kairo-msg p { margin: 0 0 8px; color: inherit; font-size: 14px; }
.kairo-msg p:last-child { margin-bottom: 0; }
.kairo-bot { align-self: flex-start; background: var(--kairo-card); border: 1px solid var(--kairo-border); color: var(--kairo-text); border-bottom-left-radius: 5px; }
.kairo-user { align-self: flex-end; background: linear-gradient(135deg, var(--kairo-red), var(--kairo-red-dark)); color: #fff; border-bottom-right-radius: 5px; }
.kairo-msg a { color: #ffb3b3; text-decoration: underline; text-underline-offset: 2px; }
.kairo-user a { color: #fff; }
.kairo-msg ul { margin: 6px 0 6px 18px; padding: 0; list-style: disc; }
.kairo-msg li { margin-bottom: 3px; }
.kairo-cta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.kairo-cta {
  display: inline-block;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid rgba(255, 43, 43, 0.5);
  color: #fff;
  background: rgba(255, 43, 43, 0.14);
  text-decoration: none !important;
}
.kairo-cta:hover { background: var(--kairo-red); }
.kairo-cta.ghost { border-color: var(--kairo-border); background: transparent; color: var(--kairo-text); }
.kairo-cta.ghost:hover { border-color: var(--kairo-red); color: #fff; }

/* Utmost-care policy footer: summary, never legal advice */
.kairo-msg p.kairo-policy-note {
  margin: 8px 0 0;
  padding: 8px 10px 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--kairo-muted);
  border-left: 2px solid var(--kairo-red);
  background: rgba(255, 43, 43, 0.06);
  border-radius: 0 10px 10px 0;
}
.kairo-msg p.kairo-policy-note strong { color: var(--kairo-text); }

.kairo-feedback { display: flex; gap: 4px; margin-top: 7px; opacity: 0.75; }
.kairo-feedback button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--kairo-muted);
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  padding: 2px 7px;
}
.kairo-feedback button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.kairo-feedback button.kairo-voted { color: var(--kairo-red); border-color: rgba(255, 43, 43, 0.4); }

.kairo-typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.kairo-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--kairo-muted); animation: kairo-blink 1.1s infinite; }
.kairo-typing span:nth-child(2) { animation-delay: 0.18s; }
.kairo-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes kairo-blink { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

.kairo-chips { display: flex; gap: 8px; padding: 10px 12px 4px; overflow-x: auto; scrollbar-width: none; }
.kairo-chips::-webkit-scrollbar { display: none; }
.kairo-chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--kairo-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--kairo-text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.kairo-chip:hover { border-color: var(--kairo-red); background: rgba(255, 43, 43, 0.12); }

.kairo-inputbar { display: flex; gap: 8px; padding: 10px 12px 6px; }
#kairo-input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border-radius: 13px;
  border: 1px solid var(--kairo-border);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
#kairo-input:focus { border-color: var(--kairo-red); box-shadow: 0 0 0 3px rgba(255, 43, 43, 0.18); }
#kairo-input::placeholder { color: #71717a; }
#kairo-send {
  width: 44px; height: 44px;
  flex: 0 0 auto;
  border-radius: 13px;
  border: none;
  background: linear-gradient(135deg, var(--kairo-red), var(--kairo-red-dark));
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 43, 43, 0.35);
}
#kairo-send:hover { filter: brightness(1.1); }
#kairo-send:disabled { opacity: 0.55; cursor: default; }
.kairo-foot { padding: 2px 14px 11px; font-size: 11px; color: #71717a; text-align: center; }

/* Tablets & small laptops */
@media (max-width: 1024px) {
  #kairo-panel { width: min(380px, calc(100vw - 32px)); }
}

/* Phones */
@media (max-width: 480px) {
  #kairo-launcher {
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    padding: 8px;
  }
  .kairo-launcher-text { display: none; }
  .kairo-orb { width: 48px; height: 48px; font-size: 20px; }
  #kairo-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: calc(148px + env(safe-area-inset-bottom, 0px));
    height: calc(100vh - 170px);
    height: calc(100dvh - 170px);
    min-height: 340px;
    border-radius: 18px;
  }
  #kairo-input { font-size: 16px; } /* stops iOS auto-zoom on focus */
  #kairo-send { width: 48px; height: 48px; }
  .kairo-msg { max-width: 88%; font-size: 14px; }
  .kairo-chip { padding: 10px 15px; min-height: 42px; }
  .kairo-chips { padding-bottom: 6px; }
}

/* Tiny phones */
@media (max-width: 360px) {
  .kairo-who strong { font-size: 14px; }
  .kairo-status { font-size: 11px; }
  .kairo-header { padding: 12px 10px 10px; gap: 9px; }
  .kairo-cta { font-size: 12px; padding: 7px 11px; }
}

/* Short landscape screens (phones held sideways, small laptops) */
@media (max-height: 560px) {
  #kairo-panel {
    bottom: 140px;
    height: calc(100vh - 150px);
    height: calc(100dvh - 150px);
    min-height: 260px;
  }
  .kairo-header { padding: 10px 12px 8px; }
  .kairo-messages { padding: 10px; gap: 8px; }
  .kairo-foot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #kairo-launcher, #kairo-panel, .kairo-orb::after,
  #kairo-launcher.kairo-attention, #kairo-launcher.kairo-attention .kairo-badge.kairo-show {
    animation: none !important; transition: none !important;
  }
}
