/* ==========================================================================
   SIVET Floating Chat Bubble & Responsive Mobile/Desktop Widget
   Applied UX Laws: Jakob's Law (#4), Hick's Law (#1), Miller's Law (#2),
   Fitts's Law (#3), Progressive Disclosure (#11), Aesthetic-Usability (#1).
   ========================================================================== */

#sivet-cw-root {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  z-index: 2147483000;
  box-sizing: border-box;
  line-height: 1.45;
  color: #0f172a;
  -webkit-font-smoothing: antialiased;
}

#sivet-cw-root *,
#sivet-cw-root *::before,
#sivet-cw-root *::after {
  box-sizing: border-box;
}

/* Proactive Teaser Bubble (Von Restorff Effect #13 + Fitts's Law #3) */
.sivet-cw-teaser {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 276px;
  background: #ffffff;
  color: #0f172a;
  border-radius: 16px 16px 4px 16px;
  padding: 12px 32px 12px 14px;
  box-shadow: 0 12px 30px -6px rgba(15, 23, 42, 0.2), 0 0 0 1px rgba(15, 118, 110, 0.14);
  cursor: pointer;
  transform-origin: bottom right;
  animation: sivetCwPopIn 0.32s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sivet-cw-teaser:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px -6px rgba(15, 23, 42, 0.26), 0 0 0 1px rgba(15, 118, 110, 0.28);
}

.sivet-cw-hidden {
  display: none !important;
}

.sivet-cw-teaser-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 700;
  color: #0f766e;
  margin-bottom: 4px;
}

.sivet-cw-teaser-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.22);
}

.sivet-cw-teaser-text {
  font-size: 12.5px;
  font-weight: 500;
  color: #1e293b;
  margin: 0;
  line-height: 1.4;
}

.sivet-cw-teaser-text strong {
  color: #0f766e;
  font-weight: 700;
}

.sivet-cw-teaser-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: #64748b;
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.sivet-cw-teaser-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Floating Launcher Button (Fitts's Law #3: 60x60px target) */
.sivet-cw-launcher {
  width: 60px;
  height: 60px;
  border-radius: 999px;
  border: 2px solid #ffffff;
  background: #0f766e;
  color: #ffffff;
  box-shadow: 0 10px 26px -4px rgba(15, 118, 110, 0.55), 0 4px 10px rgba(15, 23, 42, 0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
  outline: none;
}

.sivet-cw-launcher:hover {
  background: #0d9488;
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 14px 32px -4px rgba(13, 148, 136, 0.65), 0 6px 14px rgba(15, 23, 42, 0.22);
}

.sivet-cw-launcher:active {
  transform: scale(0.96);
}

.sivet-cw-launcher-pulse {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #22c55e;
  border: 2.5px solid #ffffff;
  z-index: 2;
}

/* Chat Window Panel */
.sivet-cw-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100dvh - 110px));
  background: #efeae2;
  border-radius: 18px;
  box-shadow: 0 22px 54px -12px rgba(15, 23, 42, 0.32), 0 0 0 1px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.sivet-cw-panel.sivet-cw-closed {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.94) translateY(12px);
}

.sivet-cw-panel.sivet-cw-open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

/* Header — Warm Clinical SIVET Reception (Jakob's Law #4 + Aesthetic-Usability #1) */
.sivet-cw-header {
  background: #0f766e;
  color: #ffffff;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  z-index: 2;
}

.sivet-cw-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.sivet-cw-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.16);
}

.sivet-cw-avatar-img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  display: block;
}

.sivet-cw-avatar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #0f766e;
}

.sivet-cw-header-info {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.sivet-cw-header-title {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sivet-cw-header-subtitle {
  font-size: 12px;
  font-weight: 500;
  color: #ccfbf1;
  margin: 2px 0 0 0;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sivet-cw-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.sivet-cw-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sivet-cw-icon-btn:hover,
.sivet-cw-icon-btn-active {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.32);
  color: #ffffff;
}

/* Progressive Disclosure (#11): Collapsible Patient Selector Drawer */
.sivet-cw-context-bar {
  background: #f0fdfa;
  border-bottom: 1px solid #ccfbf1;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  font-size: 11.5px;
}

.sivet-cw-context-label {
  font-weight: 600;
  color: #0f766e;
  white-space: nowrap;
}

.sivet-cw-context-select {
  flex: 1;
  min-width: 0;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #99f6e4;
  background: #ffffff;
  color: #0f172a;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 0 8px;
  outline: none;
  cursor: pointer;
}

/* Messages Stream (Jakob's Law #4: Warm WhatsApp-like canvas) */
.sivet-cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: #efeae2;
  background-image: radial-gradient(rgba(15, 23, 42, 0.06) 0.75px, transparent 0.75px);
  background-size: 16px 16px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sivet-cw-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: sivetCwFadeUp 0.18s ease forwards;
}

.sivet-cw-msg-row.sivet-cw-msg-bot {
  align-self: flex-start;
}

.sivet-cw-msg-row.sivet-cw-msg-user {
  align-self: flex-end;
}

.sivet-cw-bubble {
  position: relative;
  padding: 8px 11px 6px 11px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1);
}

.sivet-cw-msg-bot .sivet-cw-bubble {
  background: #ffffff;
  color: #111b21;
  border-top-left-radius: 3px;
}

.sivet-cw-msg-user .sivet-cw-bubble {
  background: #d9fdd3;
  color: #111b21;
  border-top-right-radius: 3px;
}

.sivet-cw-bubble-content p {
  margin: 0 0 5px 0;
}

.sivet-cw-bubble-content p:last-child {
  margin-bottom: 0;
}

.sivet-cw-bubble-content ul {
  margin: 4px 0 5px 0;
  padding-left: 18px;
}

.sivet-cw-bubble-content li {
  margin-bottom: 2px;
}

.sivet-cw-bubble-content strong {
  font-weight: 700;
}

.sivet-cw-bubble-time {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: #667781;
  text-align: right;
  margin-top: 2px;
  line-height: 1;
  user-select: none;
}

.sivet-cw-read-checks {
  color: #0d9488;
  font-weight: 700;
  letter-spacing: -2px;
  margin-left: 2px;
}

.sivet-cw-escalation-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  margin-bottom: 2px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 11px;
  font-weight: 600;
}

/* Typing indicator */
.sivet-cw-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 9px 13px;
  background: #ffffff;
  border-radius: 12px 12px 12px 3px;
  align-self: flex-start;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1);
}

.sivet-cw-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #64748b;
  animation: sivetCwBounce 1.3s infinite ease-in-out;
}

.sivet-cw-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.sivet-cw-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

.sivet-cw-typing-label {
  font-size: 11.5px;
  font-weight: 500;
  color: #64748b;
  margin-left: 4px;
}

/* Quick Chips Row (Hick's Law #1: <= 4 options) */
.sivet-cw-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: #f0f2f5;
  border-top: 1px solid rgba(15, 23, 42, 0.06);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sivet-cw-chips::-webkit-scrollbar {
  display: none;
}

.sivet-cw-chip {
  flex-shrink: 0;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #0f766e;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sivet-cw-chip:hover {
  background: #f0fdfa;
  border-color: #0f766e;
}

.sivet-cw-chip:active {
  transform: scale(0.97);
}

/* Attachment Preview Bar & Composer Controls */
.sivet-cw-attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #f0fdfa;
  border-top: 1px solid #99f6e4;
  flex-shrink: 0;
}

.sivet-cw-attach-preview.sivet-cw-hidden {
  display: none !important;
}

.sivet-cw-attach-thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #14b8a6;
  flex-shrink: 0;
  background: #ffffff;
}

.sivet-cw-attach-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.sivet-cw-attach-name {
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sivet-cw-attach-hint {
  font-size: 10.5px;
  color: #0f766e;
  font-weight: 600;
}

.sivet-cw-attach-remove {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.08);
  color: #334155;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sivet-cw-attach-remove:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.sivet-cw-bubble-media {
  display: block;
  max-width: 100%;
  max-height: 210px;
  border-radius: 8px;
  margin-bottom: 6px;
  object-fit: contain;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.sivet-cw-attach-btn {
  width: 38px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #54656f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.sivet-cw-attach-btn:hover {
  color: #0f766e;
  background: rgba(15, 118, 110, 0.08);
}

/* Composer / Input Footer (Jakob's Law #4 + Fitts's Law #3) */
.sivet-cw-composer {
  background: #f0f2f5;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.sivet-cw-input {
  flex: 1;
  min-height: 40px;
  max-height: 96px;
  border-radius: 20px;
  border: 1px solid #ffffff;
  background: #ffffff;
  color: #111b21;
  font-family: inherit;
  /* 16px prevents iOS Safari from zooming on focus */
  font-size: 16px;
  line-height: 1.35;
  padding: 8px 14px;
  resize: none;
  outline: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.sivet-cw-input:focus {
  border-color: #0d9488;
}

.sivet-cw-input::placeholder {
  color: #8696a0;
}

.sivet-cw-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #0f766e;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}

.sivet-cw-send-btn:hover:not(:disabled) {
  background: #0d9488;
  transform: scale(1.04);
}

.sivet-cw-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Navbar Portal Link button injected cleanly into SIVET header */
.sivet-portal-nav-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  font-family: 'Montserrat', sans-serif;
  font-size: 13px !important;
  font-weight: 700 !important;
  color: #0f766e !important;
  background: #f0fdfa !important;
  border: 1.5px solid #0d9488 !important;
  border-radius: 999px !important;
  padding: 7px 15px !important;
  margin-left: 10px;
  text-decoration: none !important;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.sivet-portal-nav-btn:hover {
  background: #0d9488 !important;
  color: #ffffff !important;
}

/* Mobile Responsive Full-Screen / Sheet Overrides (<= 640px) */
@media (max-width: 640px) {
  #sivet-cw-root {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }

  .sivet-cw-teaser {
    width: min(265px, calc(100vw - 36px));
    bottom: 68px;
  }

  .sivet-cw-launcher {
    width: 56px;
    height: 56px;
  }

  .sivet-cw-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    z-index: 2147483001;
  }

  .sivet-cw-header {
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px 12px;
  }

  .sivet-cw-icon-btn {
    width: 38px;
    height: 38px;
  }

  .sivet-cw-chip {
    padding: 6px 12px;
    font-size: 12px;
  }

  .sivet-portal-nav-btn {
    margin-left: 0;
    margin-top: 8px;
    justify-content: center;
  }
}

@keyframes sivetCwPopIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

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

@keyframes sivetCwBounce {
  0%, 80%, 100% {
    transform: scale(0.65);
    opacity: 0.45;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}
