/* ═══════════════════════════════════════════════════
   SUPPORT WIDGET
   ═══════════════════════════════════════════════════ */

/* CSS variable bridge */
.wc-support-widget,
.wc-support-fab {
  --sw-accent:    var(--m2-accent, var(--accent, #4f86ff));
  --sw-bg:        var(--m2-card-bg, #0d1630);
  --sw-text:      var(--m2-text, #e2eaff);
  --sw-text-2:    color-mix(in srgb, var(--sw-text) 60%, transparent);
  --sw-text-3:    color-mix(in srgb, var(--sw-text) 30%, transparent);
  --sw-border:    var(--m2-border, rgba(79,134,255,.18));
  --sw-surface:   color-mix(in srgb, var(--sw-accent) 8%, transparent);
  --sw-radius:    20px;
}

body.light-v2-body .wc-support-widget,
body.light-v2-body .wc-support-fab,
body:not([class*="-body"]) .wc-support-widget,
body:not([class*="-body"]) .wc-support-fab {
  --sw-bg:      #ffffff;
  --sw-text:    #1e2d5a;
  --sw-text-2:  #6b7ab8;
  --sw-text-3:  #b0bbd4;
  --sw-border:  rgba(79,134,255,.14);
  --sw-surface: rgba(79,134,255,.05);
}

/* ══ FAB BUTTON ══ */
.wc-support-fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sw-accent), color-mix(in srgb, var(--sw-accent) 70%, #7c3aed));
  color: #fff;
  border: none;
  box-shadow: 0 8px 28px color-mix(in srgb, var(--sw-accent) 45%, transparent), 0 2px 6px rgba(0,0,0,.3);
  z-index: 1040;
  text-decoration: none;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease;
  animation: sw-fab-pulse 3.5s ease-in-out infinite;
}
.wc-support-fab-icon { width: 24px; height: 24px; flex-shrink: 0; }
.wc-support-fab-badge {
  position: absolute;
  inset-block-start: -3px;
  inset-inline-end: -3px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ef4444;
  border: 2px solid var(--sw-bg, #0a0f1e);
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.wc-support-fab:hover  { transform: translateY(-2px); box-shadow: 0 14px 36px color-mix(in srgb, var(--sw-accent) 55%, transparent); }
.wc-support-fab:active { transform: translateY(0); }
.wc-support-fab:focus-visible { outline: 2px solid var(--sw-accent); outline-offset: 3px; }

@keyframes sw-fab-pulse {
  0%, 100% { box-shadow: 0 8px 28px color-mix(in srgb, var(--sw-accent) 45%, transparent), 0 0 0 0   color-mix(in srgb, var(--sw-accent) 30%, transparent); }
  50%       { box-shadow: 0 8px 28px color-mix(in srgb, var(--sw-accent) 45%, transparent), 0 0 0 9px transparent; }
}

/* ══ WIDGET PANEL ══ */
.wc-support-widget {
  position: fixed;
  right: 18px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  width: min(360px, calc(100vw - 32px));
  height: min(560px, calc(100svh - 120px));
  border-radius: var(--sw-radius);
  background: var(--sw-bg);
  border: 1px solid var(--sw-border);
  box-shadow: 0 24px 64px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.03);
  z-index: 1041;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: inherit;
  font-size: 14px;
  color: var(--sw-text);
  transform-origin: bottom right;
  animation: sw-widget-in .22s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes sw-widget-in {
  from { opacity: 0; transform: scale(.85) translateY(12px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* Header */
.wc-sw-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--sw-accent) 18%, transparent), color-mix(in srgb, #7c3aed 12%, transparent));
  border-bottom: 1px solid var(--sw-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
}
.wc-sw-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.wc-sw-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--sw-accent), #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.wc-sw-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--sw-text);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.wc-sw-unread-badge {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ef4444;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.wc-sw-status {
  font-size: 11px;
  color: var(--sw-text-2);
  margin-block-start: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wc-sw-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--sw-text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.wc-sw-close-btn:hover { background: var(--sw-surface); color: var(--sw-text); }
.wc-sw-close-btn svg { width: 14px; height: 14px; }

/* Messages area */
.wc-sw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
.wc-sw-messages::-webkit-scrollbar { width: 4px; }
.wc-sw-messages::-webkit-scrollbar-track { background: transparent; }
.wc-sw-messages::-webkit-scrollbar-thumb { background: var(--sw-border); border-radius: 4px; }

.wc-sw-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  color: var(--sw-text-2);
  font-size: 12px;
  padding: 24px 0;
}
.wc-sw-loader-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--sw-border);
  border-top-color: var(--sw-accent);
  border-radius: 50%;
  animation: sw-spin .7s linear infinite;
}
@keyframes sw-spin { to { transform: rotate(360deg); } }

.wc-sw-empty {
  text-align: center;
  color: var(--sw-text-3);
  font-size: 13px;
  padding: 32px 16px;
  margin: auto;
}
.wc-sw-date-divider {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--sw-text-3);
  padding: 4px 0;
}

/* Message rows */
.wc-sw-msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 90%;
  animation: sw-msg-in .18s ease both;
}
@keyframes sw-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wc-sw-msg.from-user    { align-self: flex-end;  flex-direction: row-reverse; }
.wc-sw-msg.from-support { align-self: flex-start; }

.wc-sw-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--sw-surface);
  border: 1px solid var(--sw-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.wc-sw-msg-body  { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.wc-sw-msg-bubble {
  padding: 8px 11px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.from-user .wc-sw-msg-bubble {
  background: color-mix(in srgb, var(--sw-accent) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--sw-accent) 30%, transparent);
  color: var(--sw-text);
  border-end-end-radius: 4px;
}
.from-support .wc-sw-msg-bubble {
  background: var(--sw-surface);
  border: 1px solid var(--sw-border);
  color: var(--sw-text);
  border-end-start-radius: 4px;
}
.wc-sw-msg-time { font-size: 10px; color: var(--sw-text-3); padding: 0 4px; }
.from-user .wc-sw-msg-time { text-align: right; }

.wc-sw-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 10px;
  background: var(--sw-surface);
  border: 1px solid var(--sw-border);
  color: var(--sw-accent);
  font-size: 12px;
  text-decoration: none;
  transition: background .12s;
}
.wc-sw-attachment:hover { background: color-mix(in srgb, var(--sw-accent) 15%, transparent); }
.wc-sw-attachment svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Reply form */
.wc-sw-form {
  border-top: 1px solid var(--sw-border);
  background: var(--sw-bg);
  flex-shrink: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.wc-sw-form-inner  { display: flex; flex-direction: column; gap: 8px; }
.wc-sw-textarea {
  width: 100%;
  background: var(--sw-surface);
  border: 1px solid var(--sw-border);
  border-radius: 12px;
  color: var(--sw-text);
  font-size: 13px;
  font-family: inherit;
  padding: 9px 12px;
  resize: none;
  outline: none;
  line-height: 1.45;
  transition: border-color .15s;
  min-height: 58px;
  max-height: 120px;
}
.wc-sw-textarea::placeholder { color: var(--sw-text-3); }
.wc-sw-textarea:focus { border-color: color-mix(in srgb, var(--sw-accent) 60%, transparent); }
.wc-sw-form-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wc-sw-form-tools   { display: flex; align-items: center; gap: 6px; min-width: 0; }
.wc-sw-tool-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--sw-text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.wc-sw-tool-btn:hover { background: var(--sw-surface); color: var(--sw-accent); }
.wc-sw-tool-btn svg   { width: 16px; height: 16px; }
.wc-sw-file-name {
  font-size: 11px;
  color: var(--sw-text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}
.wc-sw-send-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--sw-accent), color-mix(in srgb, var(--sw-accent) 70%, #7c3aed));
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .15s, transform .12s;
  position: relative;
}
.wc-sw-send-btn:hover:not(:disabled)  { opacity: .9; transform: translateY(-1px); }
.wc-sw-send-btn:active:not(:disabled) { transform: translateY(0); }
.wc-sw-send-btn:disabled { opacity: .5; cursor: default; }
.wc-sw-send-btn svg      { width: 15px; height: 15px; flex-shrink: 0; }

.wc-sw-send-btn.is-loading .wc-sw-send-label,
.wc-sw-send-btn.is-loading svg { opacity: 0; }
.wc-sw-send-btn .wc-sw-send-spinner {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}
.wc-sw-send-btn.is-loading .wc-sw-send-spinner { display: flex; }
.wc-sw-send-btn .wc-sw-send-spinner::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: sw-spin .65s linear infinite;
}

.wc-support-widget-file-input {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* Ensure [hidden] attribute properly hides elements even when display:flex is set */
.wc-support-widget[hidden],
.wc-support-fab[hidden] {
  display: none !important;
}

/* Narrow screens: full-width bottom sheet */
@media (max-width: 400px) {
  .wc-support-fab {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .wc-support-widget {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: min(85svh, 600px);
    border-radius: var(--sw-radius) var(--sw-radius) 0 0;
  }
}

/* ══════════════════════════════════════════════════════
   FAB offset above mobile bottom nav — all themes
   .wc-mobile-nav (modern_v2, solo, light_v2):
     bottom: calc(12px + safe-area), height ≈ 66px → top ≈ 78px
   .wc-neo-mobile-tabbar (wc-neo):
     same positioning, shown at ≤980px
   ══════════════════════════════════════════════════════ */

/* modern_v2 + solo (m2-body) — nav at ≤900px */
@media (max-width: 900px) {
  .m2-body .wc-support-fab {
    bottom: calc(92px + env(safe-area-inset-bottom));
  }
  .m2-body .wc-support-widget {
    bottom: calc(162px + env(safe-area-inset-bottom));
    height: min(520px, calc(100svh - 218px));
  }
}
@media (max-width: 400px) {
  .m2-body .wc-support-fab {
    right: 12px;
    bottom: calc(88px + env(safe-area-inset-bottom));
  }
  .m2-body .wc-support-widget {
    right: 0; left: 0;
    bottom: calc(78px + env(safe-area-inset-bottom));
    width: 100%;
    height: min(78svh, calc(100svh - 108px));
    border-radius: var(--sw-radius) var(--sw-radius) 0 0;
  }
}

/* light_v2 (light-v2-body) — same nav, same breakpoint */
@media (max-width: 900px) {
  .light-v2-body .wc-support-fab {
    bottom: calc(92px + env(safe-area-inset-bottom));
  }
  .light-v2-body .wc-support-widget {
    bottom: calc(162px + env(safe-area-inset-bottom));
    height: min(520px, calc(100svh - 218px));
  }
}
@media (max-width: 400px) {
  .light-v2-body .wc-support-fab {
    right: 12px;
    bottom: calc(88px + env(safe-area-inset-bottom));
  }
  .light-v2-body .wc-support-widget {
    right: 0; left: 0;
    bottom: calc(78px + env(safe-area-inset-bottom));
    width: 100%;
    height: min(78svh, calc(100svh - 108px));
    border-radius: var(--sw-radius) var(--sw-radius) 0 0;
  }
}

/* wc-neo (default template, wc-neo-body) — tabbar at ≤980px */
@media (max-width: 980px) {
  .wc-neo-body .wc-support-fab {
    bottom: calc(92px + env(safe-area-inset-bottom));
  }
  .wc-neo-body .wc-support-widget {
    bottom: calc(162px + env(safe-area-inset-bottom));
    height: min(520px, calc(100svh - 218px));
  }
}
@media (max-width: 400px) {
  .wc-neo-body .wc-support-fab {
    right: 12px;
    bottom: calc(88px + env(safe-area-inset-bottom));
  }
  .wc-neo-body .wc-support-widget {
    right: 0; left: 0;
    bottom: calc(78px + env(safe-area-inset-bottom));
    width: 100%;
    height: min(78svh, calc(100svh - 108px));
    border-radius: var(--sw-radius) var(--sw-radius) 0 0;
  }
}
