/* ==========================================================================
   Niwa Chatbot – Centerstage (Center Pill → Full Chat)
   ---------------------------------------------------------------------------
   Expands SYMMETRICALLY from center (both left and right).
   Uses left:50% + translateX(-50%) for centering.

   SEQUENCE:
     Open:  width 224→494px (350ms) → height 48→580px (200ms, delay 350ms)
     Close: height 580→48px (150ms) → width 494→224px (350ms, delay 150ms)

   STRUCTURE:
     .niwa-center
       .niwa-center__chat     (header + body — clipped until tall)
       .niwa-center__pill     (bottom input bar — always visible)
   ========================================================================== */

.niwa-center {
  position: fixed;
  bottom: var(--niwa-flyout-offset-bottom);
  left: 50%;
  transform: translateX(-50%);
  z-index: 99998;

  display: flex;
  flex-direction: column;
  width: 224px;
  height: 48px;
  overflow: clip;
  overflow-clip-margin: 20px;

  /* Glass — light */
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
  border-radius: 24px;
  cursor: pointer;

  /* OPEN: width first (350ms), then height (200ms after 350ms) */
  transition:
    width 350ms cubic-bezier(0.4, 0, 0.2, 1),
    height 200ms cubic-bezier(0.4, 0, 0.2, 1) 350ms,
    border-radius 350ms cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 350ms ease,
    background 200ms ease;
}

/* Dark glass */
.niwa-widget[data-niwa-theme="dark"] .niwa-center {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

/* Light glass — frosted glass visible on light backgrounds */
.niwa-widget[data-niwa-theme="light"] .niwa-center {
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.08),
    0 1px 3px rgba(0, 0, 0, 0.06);
}

/* Hover (collapsed only) */
.niwa-center:not(.niwa-center--open):hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.3);
}
.niwa-widget[data-niwa-theme="light"] .niwa-center:not(.niwa-center--open):hover {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(0, 0, 0, 0.12);
}
.niwa-widget[data-niwa-theme="dark"] .niwa-center:not(.niwa-center--open):hover {
  background: rgba(0, 0, 0, 0.7);
  border-color: rgba(255, 255, 255, 0.12);
}

/* ── Expanded ───────────────────────────────────────────────────────────── */
.niwa-center--open {
  width: 494px;
  height: var(--niwa-flyout-height);
  max-height: var(--niwa-flyout-max-height);
  border-radius: var(--niwa-radius-lg);
  cursor: default;
  overflow: hidden;
}

/* Animated gradient tint — light theme only */
.niwa-widget[data-niwa-theme="light"] .niwa-center--open::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.15;
  border-radius: inherit;
  pointer-events: none;
  transform: scale(1.5);
  background:
    radial-gradient(ellipse 80% 50% at 20% 8%,  rgba(255, 120,  50, 0.70) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 75% 15%, rgba( 99,  51, 238, 0.60) 0%, transparent 55%),
    radial-gradient(ellipse 90% 50% at 50% 35%, rgba( 59, 200, 246, 0.50) 0%, transparent 55%),
    radial-gradient(ellipse 70% 45% at 30% 55%, rgba(236,  72, 153, 0.60) 0%, transparent 55%),
    radial-gradient(ellipse 80% 50% at 80% 65%, rgba( 45, 200, 120, 0.50) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 15% 80%, rgba(147,  51, 234, 0.60) 0%, transparent 55%),
    radial-gradient(ellipse 90% 50% at 70% 90%, rgba(255, 180,  50, 0.50) 0%, transparent 55%);
  animation: niwa-gradient-drift 30s linear infinite;
}

/* Keep chat + pill above the gradient layer */
.niwa-widget[data-niwa-theme="light"] .niwa-center--open > .niwa-center__chat,
.niwa-widget[data-niwa-theme="light"] .niwa-center--open > .niwa-center__pill {
  position: relative;
  z-index: 1;
}

/* CLOSE: height fast (150ms), then width (350ms after 150ms) */
.niwa-center--closing {
  transition:
    height 150ms cubic-bezier(0.4, 0, 0.2, 1),
    width 350ms cubic-bezier(0.4, 0, 0.2, 1) 150ms,
    border-radius 350ms cubic-bezier(0.4, 0, 0.2, 1) 150ms,
    box-shadow 350ms ease,
    background 200ms ease;
}

/* ==========================================================================
   Chat Area
   ========================================================================== */

.niwa-center__chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease 350ms;
}

.niwa-center--open .niwa-center__chat {
  opacity: 1;
  pointer-events: auto;
}

.niwa-center--closing .niwa-center__chat {
  opacity: 0;
  transition: opacity 100ms ease;
}

/* Header */
.niwa-center__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--niwa-space-md) var(--niwa-space-lg);
  flex-shrink: 0;
}

.niwa-center__close {
  width: 28px;
  height: 28px;
  border-radius: var(--niwa-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--niwa-color-text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background var(--niwa-transition-fast);
}
.niwa-center__close:hover { background: rgba(0, 0, 0, 0.08); }
[data-niwa-theme="dark"] .niwa-center__close:hover { background: rgba(255, 255, 255, 0.1); }
.niwa-center__close svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}

/* Body (scrollable, acts as message list container) */
.niwa-center__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--niwa-color-border-default) transparent;

  /* Flex column layout — messages, typing, suggestions, date separators
     are appended here directly by JS (no .niwa-messages wrapper in WP). */
  display: flex;
  flex-direction: column;
  padding: var(--niwa-space-sm) 0;
  gap: var(--niwa-space-xs);
}
.niwa-center__body::-webkit-scrollbar { width: 6px; }
.niwa-center__body::-webkit-scrollbar-track { background: transparent; }
.niwa-center__body::-webkit-scrollbar-thumb {
  background: var(--niwa-color-border-default);
  border-radius: var(--niwa-radius-full);
}

/* ==========================================================================
   Pill Bar
   ========================================================================== */

.niwa-center__pill {
  display: flex;
  align-items: center;
  gap: var(--niwa-space-sm);
  height: 48px;
  padding: 0 var(--niwa-space-md);
  flex-shrink: 0;
  position: relative;
}

/* Badge — left side */
.niwa-center__badge {
  position: absolute;
  top: -6px;
  left: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--niwa-radius-full);
  background: var(--niwa-color-error);
  color: #FFFFFF;
  font-size: var(--niwa-font-size-xs);
  font-weight: var(--niwa-font-weight-bold);
  line-height: 20px;
  text-align: center;
  animation: niwa-pop-in 300ms var(--niwa-animation-bounce) both;
  pointer-events: none;
}

.niwa-center__badge:empty { display: none; }
.niwa-center--open .niwa-center__badge { display: none; }

/* Label */
.niwa-center__label {
  font-size: var(--niwa-font-size-md);
  font-weight: var(--niwa-font-weight-normal);
  color: #6B7280;
  white-space: nowrap;
  line-height: 48px;
}
[data-niwa-theme="dark"] .niwa-center__label {
  color: #9CA3AF;
}
.niwa-center--open .niwa-center__label {
  display: none;
}

/* Input — visible after width finishes */
.niwa-center__input {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 4px;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}
.niwa-center--open .niwa-center__input {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 150ms ease 350ms;
}

/* Textarea — !important on layout-critical props to override WordPress themes */
.niwa-widget .niwa-center__textarea {
  flex: 1;
  height: 22px;
  min-height: 22px !important;
  max-height: 96px !important;
  resize: none !important;
  overflow-y: auto;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  padding: 4px 8px !important;
  margin: 0 !important;
  font-family: var(--niwa-font-family) !important;
  font-size: 14px !important;
  font-weight: 400;
  line-height: 22px !important;
  letter-spacing: -0.14px;
  color: var(--niwa-color-text-primary);
  box-shadow: none !important;
  border-radius: 0 !important;
}
.niwa-widget .niwa-center__textarea::placeholder { color: #6B7280; }
.niwa-widget[data-niwa-theme="dark"] .niwa-center__textarea::placeholder { color: #FFFFFF; opacity: 1; }
.niwa-widget[data-niwa-theme="dark"] .niwa-center__textarea { color: #E8E6E1; }

/* Send button */
.niwa-center__send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: none;
  padding: 0;
  cursor: pointer;
  background: #0A1217;
  color: #FFFFFF;
  opacity: 0.9;
  transition: opacity 200ms ease, transform 200ms ease;
}
.niwa-center__send:hover { opacity: 1; }
.niwa-center__send:active { transform: scale(0.95); }
.niwa-center__send svg { display: block; }
.niwa-center__send--disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
  background: #9CA3AF;
}
[data-niwa-theme="dark"] .niwa-center__send {
  background: #E8E6E1;
  color: #111318;
}
[data-niwa-theme="dark"] .niwa-center__send--disabled {
  background: #4B5563;
}

/* Responsive */
@media (max-width: 480px) {
  /* Default: keep desktop size on mobile */
  .niwa-center--open {
    width: var(--niwa-flyout-width);
    max-height: var(--niwa-flyout-max-height);
  }

  /* Fullscreen mode (toggled via admin setting) */
  .niwa-center--open.niwa-morph--fullscreen {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    right: 0 !important; bottom: 0 !important;
    width: 100vw !important; height: 100dvh !important;
    max-height: none !important; border-radius: 0 !important;
    transform: none !important;
    overflow: hidden !important;
  }

  /* ── Fullscreen input bar — visibility boost ──────────────────────────── */

  /* Taller pill with separator lines */
  .niwa-center--open.niwa-morph--fullscreen .niwa-center__pill {
    height: auto !important;
    padding: 10px var(--niwa-space-md) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12) !important;
  }

  /* Light theme separator lines */
  .niwa-widget[data-niwa-theme="light"] .niwa-center--open.niwa-morph--fullscreen .niwa-center__pill {
    border-top-color: rgba(0, 0, 0, 0.08) !important;
    border-bottom-color: rgba(0, 0, 0, 0.08) !important;
  }

  /* Send button always white in dark fullscreen (not dim when disabled) */
  [data-niwa-theme="dark"] .niwa-center--open.niwa-morph--fullscreen .niwa-center__send,
  [data-niwa-theme="dark"] .niwa-center--open.niwa-morph--fullscreen .niwa-center__send--disabled {
    background: #E8E6E1 !important;
    color: #111318 !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
  }
}
