/* ============================================================
 * Golova Widget — refined business style
 * Warm ivory canvas, deep ink, restrained typography.
 * ============================================================ */

:root {
  /* Surfaces — clean white canvas to match avatar's studio backdrop */
  --bg:           #FFFFFF;          /* primary canvas */
  --bg-stage:     #EEF1FF;          /* surrounding stage (around phone) */
  --surface:      #FFFFFF;          /* hero/cards */
  --surface-2:    #F8F9FF;          /* secondary surface (sheets) */
  --surface-3:    #F0F2FF;          /* hovered surface */

  /* Type */
  --ink:          #161A2D;          /* primary text */
  --ink-soft:     #262B40;          /* hovers / strong body */
  --ink-mute:     #6D7391;          /* secondary text */
  --ink-dim:      #98A0BE;          /* tertiary text */

  /* Accent */
  --accent:       #1F2937;          /* deep graphite — primary action */
  --accent-2:     #0E1116;          /* hover */
  --accent-warm:  #B7855A;          /* warm clay — subtle highlights only */

  /* States */
  --positive:     #2E7D5B;
  --negative:     #B53D2E;

  /* Hairlines */
  --rule:         rgba(20, 22, 29, 0.08);
  --rule-strong:  rgba(20, 22, 29, 0.16);

  /* Legacy compat (consumed elsewhere) */
  --screen-bg:    var(--bg);
  --sheet-bg:     var(--surface-2);
  --chip-bg:      var(--accent);
  --chip-border-color: var(--accent);
  --chip-voice-border-color: var(--rule-strong);
  --chip-chat-border-color: var(--accent);
  --chip-text:    #FFFFFF;
  --input-border: var(--rule-strong);
  --accent-secondary: var(--accent-warm);

  /* Tenant branding — set by widget JS from /api/widget/config
     (config.branding.primaryColor). Fallback matches the historical
     hard-coded purple that was scattered across mode-tab styles. */
  --brand-primary:       #6B47FF;
  --brand-primary-hover: #5a3dd4;
  --brand-primary-rgb:   107, 71, 255;

  /* Widget-card background — the color of the rounded rectangle behind
     the avatar video + mode tabs. Defaults to pure white; per-tenant
     override comes from config.branding.cardBackgroundColor and is
     applied via document.documentElement.style.setProperty. */
  --card-bg: #ffffff;

  /* Vertical whitespace above the avatar video in the home screen.
     The widget-head (title + close/minimize controls) is absolute-
     positioned at top:0, so this padding is what "pushes" the video
     down below it. Was 78px — reduce to shrink the white band and
     bring the avatar/controls closer to the top edge. */
  --widget-head-space: 0px;

  /* Overall height of the widget card (the white rounded box). Used
     in the base widget (was 548), compact refresh (was 540) and
     admin-preview (was 590). Reduce this to pull the bottom tab bar
     UP towards the video and shrink the trailing whitespace. */
  --widget-card-height: 548px;

  /* Typography */
  --font-display: "Fraunces", "Georgia", "Times New Roman", serif;
  --font-body:    "Instrument Sans", -apple-system, "SF Pro Text", system-ui, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  /* Radius — keep restrained */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button {
  cursor: pointer;
  font-family: inherit;
  transition: transform 200ms cubic-bezier(.2,.8,.2,1),
              background 180ms ease,
              color 180ms ease,
              border-color 180ms ease,
              box-shadow 180ms ease;
}

button:active { transform: translateY(1px); }

/* ===== Loading State ===== */

.loading-state {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
}

.loading-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--rule-strong);
  border-top-color: var(--ink);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Error State ===== */

.error-state {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
  padding: 28px;
}

.error-state-content {
  text-align: center;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 28px 24px 30px;
  box-shadow: 0 1px 2px rgba(20, 22, 29, 0.04), 0 8px 24px rgba(20, 22, 29, 0.04);
}

.error-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(181, 61, 46, 0.10);
  color: var(--negative);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  margin-bottom: 14px;
}

.error-state-content p {
  font-size: 14.5px;
  color: var(--ink-mute);
  line-height: 1.55;
  margin: 0;
}

/* ===== Stage & Phone ===== */

.stage {
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  padding: 24px 0;
  background: var(--bg-stage);
}

.phone {
  position: relative;
  width: 312px;
  height: var(--widget-card-height);
  background: #fff;
  border-radius: 24px;
  overflow: hidden;
  border: none;
  margin: 0 auto;
  box-shadow: 0 24px 70px rgba(27, 34, 76, 0.22);
  display: flex;
  flex-direction: column;
}

.phone.iframe-mode {
  width: 100vw;
  height: 100dvh;
  transform: none !important;
  border: none;
  margin: 0;
  max-width: none;
  max-height: none;
}

.phone.iframe-mode .stage { background: var(--bg); }

.screen { position: absolute; inset: 0; }
.screen.is-active { background: transparent; }

#screen-home.is-active {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: var(--widget-head-space) 0 0;
  gap: 0;
}

.phone:not(.iframe-mode) #screen-home.is-active { padding-bottom: 14px; }

#screen-home.is-active .hero {
  flex: 0 0 auto;
  height: 280px;
  min-height: 280px;
  width: 100%;
  max-width: 100%;
}

/* ===== Shared Widget Header ===== */

.widget-head {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 10px;
  background: linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(255,255,255,0.92) 72%, rgba(255,255,255,0) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.widget-head-row {
  position: relative;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.widget-head-row h1 {
  margin: 0;
  font-family: var(--font-display);
  font-variation-settings: "opsz" 96;
  font-weight: 460;
  font-size: 22px;
  letter-spacing: -0.012em;
  color: var(--ink);
  text-align: center;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-switcher {
  display: flex;
  gap: 6px;
  padding: 0 12px 14px;
  justify-content: flex-start;
  align-items: stretch;
  flex-wrap: nowrap;
}

.mode-tab {
  min-height: 44px;
  padding: 0 10px;
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  border-radius: 999px;
  /* Base border falls back to --brand-primary; individual tabs
     override with their own tenant-driven color below. */
  border: 2px solid var(--brand-primary);
  background: #fff;
  color: #1F2937;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-tab:hover:not(:disabled) {
  background: rgba(var(--brand-primary-rgb), 0.08);
}

/* Inactive tabs — outlined only. Each tab reads its own tenant
   border color; text matches border color for a consistent read.
   Fills happen ONLY on .is-active (see below). */
.mode-tab.mode-tab-voice {
  border-color: var(--chip-voice-border-color, var(--brand-primary));
  color: var(--chip-voice-border-color, var(--brand-primary));
}
.mode-tab.mode-tab-chat {
  border-color: var(--chip-chat-border-color, var(--brand-primary));
  color: var(--chip-chat-border-color, var(--brand-primary));
}
.mode-tab.mode-tab-manager {
  border-color: var(--chip-support-color, var(--brand-primary));
  color: var(--chip-support-color, var(--brand-primary));
}

/* Active tab — fill with its own color, white text. Overrides the
   generic .mode-tab.is-active rule further down the file thanks to
   equal specificity + later cascade position. */
.mode-tab.mode-tab-voice.is-active {
  background: var(--chip-voice-border-color, var(--brand-primary));
  border-color: var(--chip-voice-border-color, var(--brand-primary));
  color: #fff;
}
.mode-tab.mode-tab-chat.is-active {
  background: var(--chip-chat-border-color, var(--brand-primary));
  border-color: var(--chip-chat-border-color, var(--brand-primary));
  color: #fff;
}
.mode-tab.mode-tab-manager.is-active {
  background: var(--chip-support-color, var(--brand-primary));
  border-color: var(--chip-support-color, var(--brand-primary));
  color: #fff;
}

/* Hover-tint each tab towards its own colour instead of a shared
   fade — same rgba(brand-rgb) but keeps the border color intact. */
.mode-tab.mode-tab-voice:hover:not(:disabled):not(.is-active) {
  background: rgba(var(--brand-primary-rgb), 0.08);
}
.mode-tab.mode-tab-chat:hover:not(:disabled):not(.is-active) {
  background: rgba(var(--brand-primary-rgb), 0.08);
}
.mode-tab.mode-tab-manager:hover:not(:disabled):not(.is-active) {
  background: rgba(var(--brand-primary-rgb), 0.08);
}

.mode-tab.is-active {
  background: linear-gradient(180deg, #1F2532 0%, #14161D 100%);
  color: #fff;
  border-color: #0D0F14;
  box-shadow: 0 8px 18px rgba(20,22,29,0.16);
}

.mode-tab.is-live {
  background: linear-gradient(180deg, #C8493A 0%, #A33223 100%);
  border-color: #8A2A1D;
  color: #fff;
}

.mode-tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.mode-tab-icon svg { display: block; }

/* ===== Legacy Top Header ===== */

.top {
  position: relative;
  width: 100%;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}

.top h1 {
  margin: 0;
  font-family: var(--font-display);
  font-variation-settings: "opsz" 96;
  font-weight: 460;
  font-size: 24px;
  letter-spacing: -0.012em;
  color: var(--ink);
  text-align: center;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-chat {
  height: 64px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--rule);
}

.top-chat h2 {
  margin: 0;
  font-family: var(--font-display);
  font-variation-settings: "opsz" 72;
  font-weight: 460;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: var(--ink);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back {
  position: absolute;
  left: 12px;
  top: 50%;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  padding: 0;
  transform: translateY(-50%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-mute);
}

.back:hover { background: var(--surface-3); color: var(--ink); }

.back span {
  display: block;
  width: 9px;
  height: 9px;
  border-left: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg);
  margin: 0 0 0 4px;
}

.top-chat .back { left: 12px; }

/* ===== Hero / Avatar ===== */

.hero {
  position: relative;
  width: 100%;
  height: 280px;
  margin: 0 auto;
  background: transparent;
  flex-shrink: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--r-lg);
  isolation: isolate;
}


.avatar-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center top;
  position: absolute;
  inset: 0;
  background: transparent;
  visibility: hidden;
  z-index: 1;
  border-radius: var(--r-lg);
}

.avatar-video.ready { visibility: visible; }
.avatar-video.hidden { opacity: 0; pointer-events: none; }

/* Custom right-click menu on avatar videos — replaces the browser's
 * default "Save video as / Copy video address" with our own minimal
 * one. Positioned absolutely at the click coordinates. */
.avatar-video-menu {
  position: fixed;
  z-index: 9999;
  min-width: 180px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, .18);
  padding: 4px;
  font-family: inherit;
}
.avatar-video-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
  color: #1f2937;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.avatar-video-menu__item:hover {
  background: #f1f5f9;
}
.avatar-video-menu__item svg {
  flex-shrink: 0;
  color: #64748b;
}

/* ===== Action Buttons ===== */

.switcher {
  display: none !important;
}

.mic-level-bar {
  width: 100%;
  height: 3px;
  background: var(--rule);
  border-radius: 999px;
  margin-top: 10px;
  flex-shrink: 0;
  overflow: hidden;
}

.mic-level-fill {
  height: 100%;
  width: 0%;
  background: var(--ink);
  border-radius: 999px;
  transition: width 50ms linear, background 200ms ease;
}

.chip {
  position: relative;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 550;
  letter-spacing: -0.003em;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  isolation: isolate;
  transition:
    transform 240ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 240ms cubic-bezier(0.16, 1, 0.3, 1),
    background 200ms ease,
    border-color 200ms ease,
    color 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.chip:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.chip:disabled,
.chip.chip-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.chip-content {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: currentColor;
  transition: transform 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

.chip-icon svg { display: block; width: 100%; height: 100%; }
.chip-icon-voice { width: 14px; height: 18px; }
.chip-icon-chat  { width: 17px; height: 16px; }

/* ==== Voice = secondary (refined ghost) ==== */
.chip-voice {
  background: var(--surface);
  color: var(--ink);
  border-color: rgba(20, 22, 29, 0.14);
  box-shadow:
    0 1px 1px rgba(20, 22, 29, 0.025),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.chip-voice:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: rgba(20, 22, 29, 0.28);
  transform: translateY(-1px);
  box-shadow:
    0 4px 12px -4px rgba(20, 22, 29, 0.10),
    0 1px 2px rgba(20, 22, 29, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.chip-voice:hover:not(:disabled) .chip-icon {
  transform: scale(1.06);
}

.chip-voice:active:not(:disabled) {
  transform: translateY(0);
  box-shadow:
    0 1px 1px rgba(20, 22, 29, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

/* ==== Chat = primary (filled, with dimensional depth) ==== */
.chip-chat {
  background: linear-gradient(180deg, #1F2532 0%, #14161D 100%);
  color: #FFFFFF;
  border-color: #0D0F14;
  box-shadow:
    0 1px 2px rgba(20, 22, 29, 0.18),
    0 4px 10px -2px rgba(20, 22, 29, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.20);
}

.chip-chat::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 50%);
  opacity: 0;
  transition: opacity 240ms ease;
  pointer-events: none;
  z-index: 0;
}

.chip-chat .chip-content { position: relative; z-index: 1; }

.chip-chat:hover:not(:disabled) {
  background: linear-gradient(180deg, #262C3A 0%, #181B24 100%);
  transform: translateY(-1px);
  box-shadow:
    0 2px 4px rgba(20, 22, 29, 0.22),
    0 8px 20px -4px rgba(20, 22, 29, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -1px 0 rgba(0, 0, 0, 0.20);
}

.chip-chat:hover:not(:disabled)::before { opacity: 1; }
.chip-chat:hover:not(:disabled) .chip-icon { transform: scale(1.06); }

.chip-chat:active:not(:disabled) {
  transform: translateY(0);
  box-shadow:
    0 1px 1px rgba(20, 22, 29, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    inset 0 -1px 0 rgba(0, 0, 0, 0.20);
}

/* ==== Live state (active voice call) ==== */
.chip-live {
  background: linear-gradient(180deg, #C8493A 0%, #A33223 100%) !important;
  border-color: #8A2A1D !important;
  color: #FFFFFF !important;
  box-shadow:
    0 1px 2px rgba(165, 50, 35, 0.30),
    0 4px 14px -2px rgba(165, 50, 35, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -1px 0 rgba(0, 0, 0, 0.18) !important;
}

.chip-live .chip-icon-voice {
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%      { transform: scale(1.15); opacity: 0.85; }
}

.chip-soon {
  font-size: 11px;
  margin-left: 6px;
  opacity: 0.55;
  letter-spacing: 0.02em;
}

/* ===== Composer ===== */

.composer {
  position: absolute;
  left: 20px;
  width: calc(100% - 40px);
  height: 48px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  display: flex;
  align-items: center;
  padding: 4px 4px 4px 6px;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(20, 22, 29, 0.03);
}

.composer:focus-within { border-color: var(--ink); }

.composer-home { top: 506px; display: none; }
.composer-chat { bottom: 18px; }

.phone.iframe-mode .composer {
  left: 16px;
  width: calc(100% - 32px);
}

.composer input {
  border: 0;
  outline: none;
  flex: 1;
  padding: 0 12px;
  font-family: var(--font-body);
  font-size: 15px;
  background: transparent;
  color: var(--ink);
}

.composer input::placeholder { color: var(--ink-dim); }

.mini {
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  font-size: 15px;
  color: var(--ink-mute);
}

.send {
  width: 44px;
  height: 38px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #FFFFFF;
  font-size: 16px;
  display: grid;
  place-items: center;
}

.send:hover:not(:disabled) { background: var(--accent-2); }
.send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Bottom Sheet / Suggestions ===== */

.bottom-sheet {
  position: relative;
  width: 100%;
  flex: 0 0 auto;
  background: var(--surface-2);
  border-top: 1px solid var(--rule);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 12px 14px 14px;
  overflow-y: auto;
  margin-top: 8px;
}

.phone.iframe-mode .bottom-sheet {
  width: 100%;
  padding: 14px 16px 14px;
}

.grabber {
  width: 36px;
  height: 3px;
  border-radius: 999px;
  background: var(--rule-strong);
  margin: 0 auto 14px;
}

.suggestion {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  min-height: 36px;
  margin: 0 auto 8px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 13.5px;
  letter-spacing: 0.005em;
  padding: 8px 14px;
  text-align: left;
  position: relative;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.suggestion:hover {
  background: var(--surface-3);
  border-color: var(--rule-strong);
  color: var(--ink);
}

/* ===== Chat Canvas ===== */

.chat-canvas {
  position: absolute;
  inset: 102px 16px 82px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}

.chat-canvas::-webkit-scrollbar { width: 6px; }
.chat-canvas::-webkit-scrollbar-thumb {
  background: var(--rule-strong);
  border-radius: 999px;
}

/* ===== Message Bubbles ===== */

.message-wrapper { margin-bottom: 12px; }

.message-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-assistant {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.bubble {
  border-radius: var(--r-lg);
  padding: 11px 14px;
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  max-inline-size: min(82%, 44ch);
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  text-wrap: pretty;
  hyphens: auto;
  letter-spacing: 0.003em;
}

.message-user .bubble-out {
  max-inline-size: min(78%, 38ch);
  background: var(--accent);
  color: #FFFFFF;
}

.message-assistant .bubble-in {
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-size: 14.5px;
  letter-spacing: 0.005em;
  max-inline-size: min(84%, 46ch);
  white-space: normal;
}

.assistant-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.assistant-paragraph { margin: 0; }

.assistant-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

.assistant-list li { margin: 0; }

.bubble-out { background: var(--accent); color: #FFFFFF; }
.bubble-in  { background: var(--surface); color: var(--ink); }

/* ===== Source Citation ===== */

.source-citation {
  display: block;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--ink-dim);
  line-height: 1.4;
  padding-left: 4px;
  letter-spacing: 0.005em;
}

/* ===== Typing Indicator ===== */

.typing-indicator {
  position: absolute;
  left: 18px;
  bottom: 76px;
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  width: fit-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-dim);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* New in-flow typing bubble — replaces the legacy absolute-positioned
 * indicator. Lives as a real message bubble inside chat-canvas so it
 * always appears right after the last user message. */
.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
}
.typing-bubble .typing-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-dim);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-bubble .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble .typing-dot:nth-child(3) { animation-delay: 0.4s; }
.typing-label {
  margin-left: 4px;
  color: var(--ink-dim);
  font-size: 12px;
  font-style: italic;
}

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ===== Rule-classifier debug panel =====
   Floating HUD pinned to the TOP-RIGHT corner of the viewport. Top-right
   avoids the iframe-mode widget's composer (bottom-anchored) AND the
   preview-admin-portrait stage's phone mockup (centered). Both layouts
   stay completely untouched. Activated via ?debug=rules; visitors never
   see this. */
.rule-debug-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 280px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.18);
  padding: 10px 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 12px;
  color: #0f172a;
  z-index: 9999;
  animation: rule-debug-in 0.18s ease-out;
}

/* On narrow viewports (iframe-mode is exactly that) the absolute 280px
   panel can still overlap the chat scroll. Cap to 60% width and stay
   slim there. */
@media (max-width: 480px) {
  .rule-debug-panel {
    width: calc(60vw - 16px);
    min-width: 200px;
    font-size: 11px;
  }
}
@keyframes rule-debug-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.rule-debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.rule-debug-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6440ef;
}
.rule-debug-close {
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
}
.rule-debug-close:hover { color: #475569; background: #f1f5f9; }
.rule-debug-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rule-debug-empty {
  color: #94a3b8;
  font-style: italic;
  padding: 6px 2px;
}
.rule-debug-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.rule-debug-row.is-match .rule-debug-row-name { color: #6440ef; font-weight: 700; }
.rule-debug-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.rule-debug-row-name {
  flex: 1 1 auto;
  font-weight: 500;
  color: #1f2937;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule-debug-row-pct {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #475569;
  font-size: 11px;
}
.rule-debug-row.is-match .rule-debug-row-pct { color: #6440ef; }
.rule-debug-bar {
  height: 4px;
  background: #eef2ff;
  border-radius: 2px;
  overflow: hidden;
}
.rule-debug-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #a5b4fc 0%, #818cf8 100%);
  border-radius: inherit;
  transition: width 0.25s ease;
}
.rule-debug-row.is-match .rule-debug-bar span {
  background: linear-gradient(90deg, #818cf8 0%, #6440ef 100%);
}
.rule-debug-reason {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed #e5e7eb;
  font-size: 10px;
  color: #64748b;
  font-style: italic;
}

/* ===== Feedback Buttons ===== */

.feedback-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding-left: 4px;
}

.feedback-btn {
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: var(--font-body);
  font-size: 12.5px;
  color: var(--ink-mute);
  cursor: pointer;
  line-height: 1;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.feedback-btn:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--ink-mute);
  color: var(--ink);
}

.feedback-btn.feedback-active {
  border-color: var(--accent);
  background: rgba(31, 41, 55, 0.06);
  color: var(--ink);
}

.feedback-btn.feedback-disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* ===== Feedback Comment Form ===== */

.feedback-comment-form {
  width: 100%;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feedback-textarea {
  width: 100%;
  max-width: 280px;
  padding: 9px 11px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  font-family: var(--font-body);
  font-size: 13.5px;
  background: var(--surface);
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: border-color 180ms ease;
}

.feedback-textarea:focus { border-color: var(--ink); }

.feedback-error {
  font-size: 11.5px;
  color: var(--negative);
  min-height: 14px;
}

.feedback-submit-btn {
  align-self: flex-start;
  padding: 7px 16px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #FFFFFF;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.feedback-submit-btn:hover { background: var(--accent-2); }

.feedback-confirm {
  font-size: 12px;
  color: var(--positive);
  margin-left: 6px;
}

/* ===== Debug Panel ===== */

.debug-panel { display: none; }
.debug-panel.active {
  display: block;
  background: rgba(31, 41, 55, 0.06);
  border-top: 1px solid var(--rule);
  padding: 6px 12px;
}
.debug-panel p {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  line-height: 1.3;
  text-align: center;
  color: var(--ink-mute);
}

.crm-sync-indicator {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 12;
  max-width: calc(100% - 36px);
  padding: 8px 12px;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
  backdrop-filter: blur(10px);
}

.crm-sync-indicator[data-tone="success"] {
  background: rgba(22, 163, 74, 0.92);
}

.crm-sync-indicator[data-tone="warning"] {
  background: rgba(217, 119, 6, 0.92);
}

.crm-sync-indicator[data-tone="error"] {
  background: rgba(220, 38, 38, 0.92);
}

/* ===== Iframe / Embed Mode ===== */

.phone.iframe-mode .debug-panel { display: none !important; }

.phone.iframe-mode #screen-home {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow-y: auto;
  background: var(--card-bg);
  padding: 92px 16px 12px;
}

.phone.iframe-mode .top { display: none; }

.phone.iframe-mode .hero {
  width: 100%;
  max-width: 100%;
  height: auto;
  flex: 0 0 auto;
  min-height: 160px;
  margin: 0;
}

.phone.iframe-mode .switcher { display: none !important; }

.phone.iframe-mode .composer-home { display: none !important; }

.phone.iframe-mode .bottom-sheet {
  width: 100%;
  min-height: 40px;
  flex: 0 0 auto;
  padding: 12px 14px;
}

.phone.iframe-mode .suggestion {
  width: 100%;
  max-width: 100%;
  font-size: 13px;
  min-height: 32px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 7px 14px;
}

.phone.iframe-mode .chat-canvas {
  position: absolute;
  inset: 102px 16px 70px;
}

.phone.iframe-mode .composer-chat {
  bottom: 14px;
  width: calc(100% - 32px);
}

/* Mobile avatar scale */
@media (max-width: 768px) {
  .hero {
    transform: scale(var(--mobile-avatar-scale, 1));
    transform-origin: center top;
  }

  .message-assistant .bubble-in {
    max-inline-size: min(92%, 40ch);
    font-size: 14.5px;
  }
}

.phone.iframe-mode .back { display: none; }

.phone.iframe-mode .widget-head {
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.05s !important;
  }
}
.locale-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  min-width: 66px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  box-shadow: 0 8px 18px rgba(20, 22, 29, 0.06);
}

.locale-toggle:hover {
  background: #fff;
  color: var(--ink);
}

.manager-canvas {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.manager-canvas.is-empty {
  /* When no messages yet, center the welcome card vertically AND
     horizontally inside the canvas. The card itself caps at ~260px
     width so it doesn't stretch awkwardly. */
  justify-content: center;
  align-items: center;
}

.manager-chips {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.manager-chip {
  padding: 10px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.manager-chip:hover {
  background: var(--surface-3);
  border-color: var(--ink);
}

.composer-manager .composer-extra {
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--ink-mute);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.composer-manager .composer-extra:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--ink);
}

.composer-manager .composer-extra:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Pending-attachment strip: chips shown ABOVE the composer for files
   the visitor has picked but not yet sent. Empty-state hides itself
   via `:empty`. Each chip carries a mini-icon, the filename and a ×
   button to drop it. Uploading chips get a spinner overlay. */
.manager-pending-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 12px 0;
}
.manager-pending-attachments:empty { display: none; }

.manager-pending-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 180px;
  padding: 4px 8px;
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink);
  transition: opacity 0.15s;
}
.manager-pending-chip.is-uploading { opacity: 0.55; }
.manager-pending-chip.is-error {
  border-color: #e05252;
  color: #e05252;
}
.manager-pending-chip__thumb {
  width: 20px; height: 20px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--surface-3);
  flex: 0 0 auto;
}
.manager-pending-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.manager-pending-chip__remove {
  border: 0; background: transparent; color: currentColor;
  cursor: pointer; padding: 0; margin-left: 2px;
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 14px; line-height: 1;
}
.manager-pending-chip__remove:hover { background: var(--surface-3); }

/* Drop overlay: covers the whole manager panel while a file is
   dragged over the widget. Uses backdrop-filter for a soft "dim +
   invite" effect so drop target is unmistakable. */
.manager-drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--primary-rgb, 100, 64, 239), 0.08);
  backdrop-filter: blur(2px);
  pointer-events: none;
  border: 2px dashed var(--primary, #6440ef);
  border-radius: inherit;
  color: var(--primary, #6440ef);
  font-weight: 600;
  font-size: 13px;
}
.manager-drop-overlay__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 16px;
}

/* Emoji picker panel: small grid of frequently-used emojis, no
   search, no skin tones. Toggled from the 😀 button. */
.manager-emoji-panel {
  position: relative;
  margin: 0 12px 6px;
  padding: 8px;
  background: var(--surface-1);
  border: 1px solid var(--surface-3);
  border-radius: 10px;
  max-height: 180px;
  overflow-y: auto;
}
.manager-emoji-panel__cats {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--surface-3);
}
.manager-emoji-panel__cat {
  flex: 1 1 0;
  border: 0;
  background: transparent;
  padding: 4px 0;
  cursor: pointer;
  font-size: 16px;
  border-radius: 6px;
  transition: background 0.15s;
}
.manager-emoji-panel__cat:hover,
.manager-emoji-panel__cat.is-active {
  background: var(--surface-2);
}
.manager-emoji-panel__grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.manager-emoji-panel__btn {
  border: 0;
  background: transparent;
  padding: 4px 0;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
}
.manager-emoji-panel__btn:hover { background: var(--surface-2); }

/* Attachment cards INSIDE a message bubble — for staff replies that
   include a file (or the visitor's own outgoing after send). Two
   variants: an image thumbnail (clicks through to Drive) or a
   file-card with icon + name + size + open link. */
.bubble-attachments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.bubble-attach-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: auto;
  height: auto;
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface-2);
}
.bubble-attach-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.04);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  font-size: 13px;
  max-width: 240px;
}
.bubble-out .bubble-attach-file { background: rgba(255,255,255,0.15); }
.bubble-attach-file:hover { filter: brightness(0.97); }
.bubble-attach-file__icon {
  font-size: 22px;
  flex: 0 0 auto;
}
.bubble-attach-file__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.bubble-attach-file__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.bubble-attach-file__size {
  font-size: 11px;
  opacity: 0.75;
}

.bubble-author {
  font-size: 11px;
  color: var(--ink-mute);
  margin-bottom: 4px;
  margin-left: 4px;
  font-weight: 500;
}

.message-system {
  text-align: center;
  margin: 8px 0;
}

.message-system .bubble-system {
  display: inline-block;
  padding: 4px 12px;
  font-size: 11px;
  color: var(--ink-mute);
  background: var(--surface-2);
  border-radius: 999px;
}

.manager-empty-state {
  width: 100%;
  max-width: 260px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: rgba(255,255,255,0.92);
  padding: 22px 18px;
  text-align: center;
}

.manager-empty-title {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--ink);
  margin-bottom: 8px;
}

.manager-empty-copy {
  font-size: 13px;
  color: var(--ink-mute);
  line-height: 1.5;
}

.composer-disabled {
  opacity: 0.72;
}

/* ===== Compact 2026 Widget Refresh ===== */

:root {
  --bg-stage: #EEF1FF;
  --surface-2: #F8F9FF;
  --surface-3: #F0F2FF;
  --ink: #161A2D;
  --ink-soft: #262B40;
  --ink-mute: #6D7391;
  --ink-dim: #98A0BE;
  /* Wire the widget's «accent» family to the tenant brand so send
     button, user chat bubbles and any other var(--accent) consumers
     follow the admin-configured primary color. Was hard-coded to
     #5A49F8 which meant tenants would see purple everywhere no
     matter what they set in Branding. */
  --accent: var(--brand-primary);
  --accent-2: var(--brand-primary-hover);
  --accent-warm: var(--brand-primary);
  --positive: #29B36B;
  --negative: #D45252;
  --rule: rgba(69, 79, 126, 0.12);
  --rule-strong: rgba(69, 79, 126, 0.22);
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
}

.phone {
  width: 390px;
  height: var(--widget-card-height);
  border-radius: 28px;
  box-shadow: 0 24px 70px rgba(58, 66, 126, 0.16);
}

#screen-home.is-active {
  padding: var(--widget-head-space) 12px 6px;
}

.phone:not(.iframe-mode) #screen-home.is-active {
  padding-bottom: 6px;
}

.widget-head {
  gap: 10px;
  padding: 10px 12px 8px;
  /* Was a hard-coded 3-stop purple gradient — replaced with a
     brand-driven 2-stop so the widget header follows the tenant's
     configured primary color instead of being locked to purple. */
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-hover) 100%);
  box-shadow: 0 10px 34px rgba(var(--brand-primary-rgb), 0.26);
}

.widget-head-row h1 {
  color: #FFFFFF;
  font-size: 16px;
  letter-spacing: -0.01em;
  max-width: 200px;
}

.widget-controls {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.widget-control {
  position: relative;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.widget-control:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.28);
}

.widget-control.is-active {
  background: rgba(255, 255, 255, 0.28);
}

.widget-control-compact {
  display: none !important;
}

.widget-control span {
  position: absolute;
  inset: 0;
  display: block;
}

.widget-control span::before,
.widget-control span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: currentColor;
}

.widget-control span::before {
  width: 10px;
  height: 1.7px;
  border-radius: 999px;
}

.widget-control-compact span::before {
  width: 11px;
  height: 8px;
  background: transparent;
  border: 1.6px solid currentColor;
  border-radius: 3px;
}

.widget-control-close span::before,
.widget-control-close span::after {
  width: 11px;
  height: 1.7px;
  border-radius: 999px;
}

.widget-control-close span::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.widget-control-close span::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.mode-switcher {
  gap: 8px;
}

.mode-tab {
  min-height: 38px;
  border-radius: 14px;
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.88);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.mode-tab:hover:not(:disabled) {
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.22);
}

.mode-tab.is-active {
  background: #FFFFFF;
  color: #3156F7;
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 24px rgba(35, 22, 111, 0.16);
}

.mode-tab.is-live {
  background: linear-gradient(180deg, #FF7D6A 0%, #FF5B76 100%);
  border-color: rgba(255, 255, 255, 0.32);
}

.hero {
  height: 400px;
}

.composer {
  left: 14px;
  width: calc(100% - 28px);
  height: 52px;
  border-radius: 18px;
  padding: 5px 5px 5px 8px;
  gap: 8px;
  box-shadow: 0 10px 28px rgba(52, 60, 103, 0.08);
}

.composer-home {
  top: 446px;
}

.composer-chat {
  bottom: 14px;
}

.send {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
}

.send:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-hover) 100%);
}

.bottom-sheet {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(118, 125, 177, 0.16);
  border-radius: 18px;
  padding: 10px 10px 12px;
  margin-top: 2px;
  box-shadow: 0 -2px 0 rgba(255, 255, 255, 0.22), 0 12px 32px rgba(52, 60, 103, 0.08);
}

.grabber {
  width: 34px;
  height: 4px;
  margin: 0 auto 10px;
}

.suggestion {
  max-width: none;
  min-height: 42px;
  border-radius: 14px;
  font-size: 13px;
  letter-spacing: 0;
  padding: 10px 14px;
}

.chat-canvas {
  inset: 108px 14px 76px;
}

.bubble {
  padding: 10px 13px;
  font-size: 14px;
  line-height: 1.5;
}

.typing-indicator {
  left: 14px;
  bottom: 72px;
}

.phone.iframe-mode #screen-home {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 0;
}

.phone.iframe-mode .hero {
  position: absolute;
  left: 0;
  right: 0;
  top: 118px;
  bottom: 0;
  width: auto;
  max-width: none;
  height: auto;
  min-height: 0;
  margin: 0;
}

.phone.iframe-mode .avatar-video {
  object-position: 50% top;
  transform: none;
}

.phone.iframe-mode .bottom-sheet {
  padding: 10px;
}

.phone.iframe-mode .chat-canvas {
  inset: 108px 14px 74px;
}

.phone.iframe-mode .composer-chat {
  width: calc(100% - 28px);
}

.phone.iframe-mode .widget-head {
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}

.locale-toggle {
  display: none !important;
}

.manager-canvas {
  padding: 18px;
}

.manager-empty-state {
  max-width: 250px;
  border-radius: 18px;
}

.manager-empty-title {
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.manager-empty-copy {
  font-size: 13px;
}

.phone.widget-compact {
  height: 470px;
}

.phone.widget-compact #screen-home.is-active {
  padding: var(--widget-head-space) 10px 4px;
}

.phone.widget-compact #screen-home.is-active .hero,
.phone.widget-compact .hero,
.phone.widget-compact.phone.iframe-mode .hero {
  height: 286px;
  min-height: 286px;
}

.phone.widget-compact .widget-head {
  padding: 8px 10px 6px;
}

.phone.widget-compact .widget-head-row h1 {
  font-size: 14px;
}

.phone.widget-compact .mode-tab {
  min-height: 34px;
  font-size: 10.5px;
}

.phone.widget-compact.phone.iframe-mode #screen-home {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 0;
}

.phone.widget-compact.phone.iframe-mode .hero {
  position: absolute;
  left: 0;
  right: 0;
  top: 102px;
  bottom: 4px;
  width: auto;
  max-width: none;
  height: auto;
  min-height: 0;
  margin: 0;
}

/* «Свернуть» теперь ПОЛНОСТЬЮ прячет виджет (было — полоса
   с табами 104px). В embed-режиме embed.js независимо закрывает
   overlay и показывает лаунчер; в standalone режиме показывается
   плавающая restore-кнопка (см. .widget-restore-btn ниже). */
.phone.widget-minimized {
  display: none !important;
}

/* Restore-кнопка — плавающий круг снизу-справа, видна только когда
   виджет свёрнут в standalone-контексте (в embed-режиме iframe
   скрыт вместе со всем этим контентом, кнопку никто не увидит). */
.widget-restore-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  /* Launcher color drives both the border and the tinted glow.
     Falls back to --brand-primary so unconfigured tenants still
     get purple. */
  border: 3px solid var(--launcher-color, var(--brand-primary));
  background: #fff url('/golova-btn.svg') center/70% no-repeat;
  cursor: pointer;
  padding: 0;
  z-index: 2147483646;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28),
              0 0 0 2px rgba(var(--brand-primary-rgb), 0.2);
  transition: transform 0.2s, box-shadow 0.2s;
}
.widget-restore-btn:hover {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.34),
              0 0 0 3px rgba(var(--brand-primary-rgb), 0.4);
}
.widget-restore-btn:hover {
  transform: scale(1.08);
}
.widget-restore-btn[hidden] {
  display: none !important;
}

/* ===== Admin Portrait Preview ===== */

.phone.preview-admin-portrait {
  width: 388px;
  height: var(--widget-card-height);
  border-radius: 28px;
  background: var(--card-bg);
  box-shadow: 0 24px 64px rgba(27, 34, 76, 0.14);
}

.phone.preview-admin-portrait .widget-head {
  gap: 0;
  padding: 14px 16px 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.phone.preview-admin-portrait .widget-head-row {
  min-height: 32px;
  justify-content: flex-end;
}

.phone.preview-admin-portrait .widget-head-row h1 {
  display: none;
}

.phone.preview-admin-portrait .widget-controls {
  position: static;
  gap: 8px;
}

.phone.preview-admin-portrait .widget-control {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #151515;
  box-shadow: none;
}

.phone.preview-admin-portrait .widget-control:hover,
.phone.preview-admin-portrait .widget-control.is-active {
  background: rgba(21, 21, 21, 0.06);
  border: none;
}

.phone.preview-admin-portrait .widget-control span::before,
.phone.preview-admin-portrait .widget-control span::after {
  height: 2px;
  background: currentColor;
}

.phone.preview-admin-portrait #screen-home,
.phone.preview-admin-portrait #screen-home.is-active {
  /* Explicit card-bg here beats any general `.phone.iframe-mode
     #screen-home { background: var(--bg) }` rule (which was hardcoded
     white and hid the tenant's card color on the Voice tab in every
     iframe context — dock widget, embed.js widget, EmbedPage preview).
     admin-portrait skin is applied unconditionally in index.html, so
     this rule always wins by cascade specificity (0,3,1 vs 0,2,1). */
  background: var(--card-bg);
}

.phone.preview-admin-portrait #screen-home.is-active {
  padding: var(--widget-head-space) 14px 82px;
  gap: 14px;
}

.phone.preview-admin-portrait.phone.iframe-mode #screen-home {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 0;
  background: var(--card-bg);
}

.phone.preview-admin-portrait.phone.iframe-mode #screen-home.is-active {
  padding: var(--widget-head-space) 14px 82px;
}

.phone.preview-admin-portrait .hero,
.phone.preview-admin-portrait.phone.iframe-mode .hero {
  position: relative;
  inset: auto;
  width: 100%;
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  margin: 0;
  border-radius: 18px;
  background: transparent;
  overflow: hidden;
}

.phone.preview-admin-portrait .avatar-video,
.phone.preview-admin-portrait.phone.iframe-mode .avatar-video {
  object-fit: contain;
  object-position: center bottom;
  padding: 12px 8px 0;
  border-radius: 18px;
  background: transparent;
}

.phone.preview-admin-portrait .bottom-sheet,
.phone.preview-admin-portrait .composer-home,
.phone.preview-admin-portrait .debug-panel,
.phone.preview-admin-portrait .crm-sync-indicator,
.phone.preview-admin-portrait .grabber {
  display: none !important;
}

.phone.preview-admin-portrait .mode-switcher {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  padding: 0;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: nowrap;
}

/* Preview-admin-portrait mode had a hard-coded #7d37ff border/text
   that beat the tenant-driven .mode-tab-voice / -chat / -manager
   rules because of equal specificity + later cascade position. Was
   the reason nothing in the admin preview responded to Branding
   changes. Fall back to --brand-primary so preview always reflects
   the current tenant's primary color. Per-tab overrides
   (.mode-tab-voice etc.) still win on top of this. */
.phone.preview-admin-portrait .mode-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1.5px solid var(--brand-primary);
  background: var(--card-bg);
  color: var(--brand-primary);
  box-shadow: none;
  font-size: 12px;
  font-weight: 600;
}

/* Preview per-tab styles — same pattern as non-preview: inactive
   tabs are outlined only, active tab fills with its color. */
.phone.preview-admin-portrait .mode-tab.mode-tab-voice {
  border-color: var(--chip-voice-border-color, var(--brand-primary));
  color: var(--chip-voice-border-color, var(--brand-primary));
}
.phone.preview-admin-portrait .mode-tab.mode-tab-chat {
  border-color: var(--chip-chat-border-color, var(--brand-primary));
  color: var(--chip-chat-border-color, var(--brand-primary));
}
.phone.preview-admin-portrait .mode-tab.mode-tab-manager {
  border-color: var(--chip-support-color, var(--brand-primary));
  color: var(--chip-support-color, var(--brand-primary));
}
.phone.preview-admin-portrait .mode-tab.mode-tab-voice.is-active {
  background: var(--chip-voice-border-color, var(--brand-primary));
  border-color: var(--chip-voice-border-color, var(--brand-primary));
  color: #fff;
}
.phone.preview-admin-portrait .mode-tab.mode-tab-chat.is-active {
  background: var(--chip-chat-border-color, var(--brand-primary));
  border-color: var(--chip-chat-border-color, var(--brand-primary));
  color: #fff;
}
.phone.preview-admin-portrait .mode-tab.mode-tab-manager.is-active {
  background: var(--chip-support-color, var(--brand-primary));
  border-color: var(--chip-support-color, var(--brand-primary));
  color: #fff;
}

.phone.preview-admin-portrait .mode-tab .mode-tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phone.preview-admin-portrait .mode-tab:hover:not(:disabled) {
  background: rgba(var(--brand-primary-rgb), 0.05);
  color: var(--brand-primary-hover);
  border-color: var(--brand-primary);
}

.phone.preview-admin-portrait .mode-tab.is-active {
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-hover) 100%);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 12px 24px rgba(var(--brand-primary-rgb), 0.22);
}

.phone.preview-admin-portrait .mode-tab.is-live {
  background: linear-gradient(135deg, #ff7d6a 0%, #ff5b76 100%);
  color: #ffffff;
}

.phone.preview-admin-portrait .mode-tab-icon {
  color: currentColor;
}

.phone.preview-admin-portrait .chat-canvas {
  inset: 72px 14px 138px;
}

.phone.preview-admin-portrait .composer-chat {
  left: 14px;
  width: calc(100% - 28px);
  bottom: 74px;
}

.phone.preview-admin-portrait #screen-chat,
.phone.preview-admin-portrait #screen-manager {
  background: var(--card-bg);
}

@media (max-width: 560px) {
  .phone.preview-admin-portrait {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }

  .phone.preview-admin-portrait #screen-home.is-active,
  .phone.preview-admin-portrait.phone.iframe-mode #screen-home.is-active {
    padding: 42px 12px 82px;
  }

  .phone.preview-admin-portrait .mode-switcher {
    gap: 8px;
  }

  .phone.preview-admin-portrait .mode-tab {
    min-height: 40px;
    font-size: 11.5px;
    padding: 0 10px;
  }
}

/* ===== Visitor auth gate (Google sign-in overlay) ===== */
.visitor-auth-gate {
  position: absolute;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.visitor-auth-gate[hidden] { display: none; }

.visitor-auth-card {
  background: #ffffff;
  color: #0f172a;
  border-radius: 18px;
  padding: 28px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.visitor-auth-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  color: #4f46e5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.visitor-auth-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 8px;
  line-height: 1.3;
}

.visitor-auth-desc {
  font-size: 13px;
  color: #64748b;
  line-height: 1.5;
  margin: 0 0 18px;
}

.visitor-auth-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #d4dbe6;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.visitor-auth-google:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}
.visitor-auth-google:active {
  background: #f1f5f9;
}
.visitor-auth-google[disabled] {
  opacity: 0.6;
  cursor: wait;
}

.visitor-auth-error {
  font-size: 12px;
  color: #b91c1c;
  margin: 12px 0 0;
}

/* === SuperQR / compact chrome (config- or URL-param-driven) ============== */
/* Icons-only mode tabs: drop the text label, center the glyph. */
.phone.chrome-icons .mode-tab-label { display: none; }
.phone.chrome-icons .mode-tab { justify-content: center; gap: 0; padding-left: 0; padding-right: 0; }
.phone.chrome-icons .mode-tab-icon svg { width: 18px; height: 18px; }
/* Hide the «Помощь» (support) tab when showSupport is off. */
.phone.chrome-no-support .mode-tab-manager { display: none; }
/* Corner embed: floating panel gets BOTH minimize (collapse to launcher) and
   close (dismiss). Compact control is dropped; the host owns the launcher, so
   the widget's own restore button never shows (it would look like a stray
   bubble inside the panel). */
.phone.chrome-corner #widget-compact,
.phone.chrome-corner #widget-restore-btn { display: none; }
/* Inline (in the 2mv feed): show minimize + close, drop the compact control. */
.phone.chrome-inline #widget-compact { display: none; }

/* «minimal»-mode viewport — виджет невозможно свернуть/закрыть,
   постоянно виден. Прячем ВСЕ кнопки правого верхнего угла. */
.phone.chrome-no-controls #widget-minimize,
.phone.chrome-no-controls #widget-compact,
.phone.chrome-no-controls #widget-close { display: none; }
