/* ========================================================================
   WFC Chat — modern, polished chat UI
   Default = light. Override the wrapper with `data-wfc-theme="dark"` to
   force dark, `data-wfc-theme="light"` to force light, or leave it as
   `auto` (default) to follow the user's system preference.
   ======================================================================== */

.wfc-chat {
  /* Light theme tokens */
  --wfc-bg:            #ffffff;
  --wfc-bg-soft:       #f7f8fb;
  --wfc-bg-input:      #ffffff;
  --wfc-bg-bubble:     #f1f3f8;
  --wfc-bg-bubble-mine:#eaf2ff;
  --wfc-border:        #e5e8ee;
  --wfc-border-soft:   #eef0f4;
  --wfc-text:          #161a22;
  --wfc-muted:         #6b7280;
  --wfc-primary:       #4f7df7;
  --wfc-primary-2:     #2f5fe0;
  --wfc-primary-soft:  rgba(79, 125, 247, 0.10);
  --wfc-accent:        #7c5cff;
  --wfc-tab-active-fg: #4f7df7;
  --wfc-live-bg:       #ef4444;
  --wfc-live-fg:       #ffffff;
  --wfc-online-dot:    #22c55e;
  --wfc-system:        #94a3b8;
  --wfc-shadow:        0 10px 30px rgba(20, 28, 50, .10), 0 2px 6px rgba(20, 28, 50, .04);
  --wfc-shadow-fab:    0 8px 20px rgba(79, 125, 247, .35);
  --wfc-gradient:      linear-gradient(135deg, #4f7df7 0%, #7c5cff 100%);

  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  background: var(--wfc-bg);
  color: var(--wfc-text);
  /* box-shadow: var(--wfc-shadow); */
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  isolation: isolate;
  transition: box-shadow .25s ease, transform .25s ease;

  max-width: 100%;
	height: 100%;
	border-radius: 0px;
	border-top: 1px solid #1e3a5f ;
	border-bottom: 1px solid #1e3a5f;
	border-right: 1px solid #1e3a5f;
	border-left: 0px;
	box-shadow: none;
  aspect-ratio: 1/1;
}
.wfc-chat:hover { box-shadow: 0 14px 38px rgba(20, 28, 50, .12), 0 3px 8px rgba(20, 28, 50, .05); }

/* Forced dark mode */
.wfc-chat[data-wfc-theme="dark"] {
  --wfc-bg:            #0f1320;
  --wfc-bg-soft:       #161b2c;
  --wfc-bg-input:      #1b2236;
  --wfc-bg-bubble:     #1c2235;
  --wfc-bg-bubble-mine:#23304f;
  --wfc-border:        #262d44;
  --wfc-border-soft:   #1d2336;
  --wfc-text:          #e6ebf5;
  --wfc-muted:         #8b94a8;
  --wfc-primary:       #6c93ff;
  --wfc-primary-2:     #4f7df7;
  --wfc-primary-soft:  rgba(108, 147, 255, 0.14);
  --wfc-accent:        #9c83ff;
  --wfc-tab-active-fg: #8aa8ff;
  --wfc-live-bg:       #f85149;
  --wfc-online-dot:    #34d399;
  --wfc-system:        #6e7892;
  --wfc-shadow:        0 14px 40px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .35);
  --wfc-shadow-fab:    0 8px 22px rgba(108, 147, 255, .45);
  --wfc-gradient:      linear-gradient(135deg, #6c93ff 0%, #9c83ff 100%);
}

/* Auto mode — system preference */
@media (prefers-color-scheme: dark) {
  .wfc-chat[data-wfc-theme="auto"] {
    --wfc-bg:            #0f1320;
    --wfc-bg-soft:       #161b2c;
    --wfc-bg-input:      #1b2236;
    --wfc-bg-bubble:     #1c2235;
    --wfc-bg-bubble-mine:#23304f;
    --wfc-border:        #262d44;
    --wfc-border-soft:   #1d2336;
    --wfc-text:          #e6ebf5;
    --wfc-muted:         #8b94a8;
    --wfc-primary:       #6c93ff;
    --wfc-primary-2:     #4f7df7;
    --wfc-primary-soft:  rgba(108, 147, 255, 0.14);
    --wfc-accent:        #9c83ff;
    --wfc-tab-active-fg: #8aa8ff;
    --wfc-live-bg:       #f85149;
    --wfc-online-dot:    #34d399;
    --wfc-system:        #6e7892;
    --wfc-shadow:        0 14px 40px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .35);
    --wfc-shadow-fab:    0 8px 22px rgba(108, 147, 255, .45);
    --wfc-gradient:      linear-gradient(135deg, #6c93ff 0%, #9c83ff 100%);
  }
}

/* ---------- Header bar ---------- */
.wfc-chat-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* padding: 14px 16px; */
  background: var(--wfc-gradient);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .2px;

  padding: 7px 16px;
}
.wfc-chat-header::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 100% at 0% 0%, rgba(255,255,255,.18), transparent 60%);
  pointer-events: none;
}
.wfc-chat-header .wfc-online {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,.12);
}
.wfc-chat-header .wfc-online::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--wfc-online-dot);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
  animation: wfc-pulse 2s ease-in-out infinite;
}
.wfc-chat[data-wfc-status-state="offline"] .wfc-chat-header .wfc-online::before {
  background: #cbd5e1; box-shadow: 0 0 0 3px rgba(255,255,255,.18); animation: none;
}
.wfc-chat[data-wfc-status-state="error"] .wfc-chat-header .wfc-online::before {
  background: #fecaca; box-shadow: 0 0 0 3px rgba(255,255,255,.18); animation: none;
}

@keyframes wfc-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
  50%      { box-shadow: 0 0 0 6px rgba(255,255,255,.0); }
}


.wfc-toggle-theme,
.wfc-toggle-chat {
  background: rgba(255,255,255,.14);
  border: 0;
  color: #fff;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .2s ease, transform .15s ease;
  backdrop-filter: blur(4px);
}
.wfc-toggle-theme { 
  padding: 6px 8px; 
  display: none;
}
.wfc-toggle-theme:hover,
.wfc-toggle-chat:hover { background: rgba(255,255,255,.26); }
.wfc-toggle-theme:active,
.wfc-toggle-chat:active { transform: scale(.96); }
.wfc-header-actions { display: flex; align-items: center; gap: 6px; position: relative; z-index: 1; }

.wfc-toggle-chat{
  display: none;
}

/* ---------- Tabs ---------- */
.wfc-tabs {
  display: flex;
  background: var(--wfc-bg-soft);
  border-bottom: 1px solid var(--wfc-border);
  padding: 4px 8px 0;
  gap: 4px;
}
.wfc-tab {
  flex: 1;
  position: relative;
  background: transparent;
  border: 0;
  padding: 12px 8px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  color: var(--wfc-muted);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: color .2s ease, background .2s ease;
}
.wfc-tab:hover { color: var(--wfc-text); background: var(--wfc-primary-soft); }
.wfc-tab.is-active { color: var(--wfc-tab-active-fg); }
.wfc-tab.is-active::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--wfc-gradient);
}

/* ---------- Messages ---------- */
.wfc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background:
    radial-gradient(700px 200px at 0% 0%, var(--wfc-primary-soft), transparent 60%),
    var(--wfc-bg);
  scrollbar-width: thin;
  scrollbar-color: var(--wfc-border) transparent;
}
.wfc-messages::-webkit-scrollbar { width: 6px; }
.wfc-messages::-webkit-scrollbar-thumb { background: var(--wfc-border); border-radius: 3px; }
.wfc-messages::-webkit-scrollbar-thumb:hover { background: var(--wfc-muted); }

.wfc-message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  background: var(--wfc-bg-bubble);
  border-radius: 14px;
  word-break: break-word;
  max-width: 92%;
  align-self: flex-start;
  box-shadow: 0 1px 2px rgba(20, 28, 50, .04);
  animation: wfc-msg-in .25s ease both;
  border: 1px solid var(--wfc-border-soft);
}
@keyframes wfc-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.wfc-live {
  flex-shrink: 0;
  display: inline-block;
  background: var(--wfc-live-bg);
  color: var(--wfc-live-fg);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .8px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 2px;
  text-transform: uppercase;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, .55);
  animation: wfc-live-pulse 1.8s ease-out infinite;
}
@keyframes wfc-live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, .55); }
  70%  { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.wfc-name {
  font-weight: 700;
  color: var(--wfc-primary);
  margin-right: 2px;

  min-width: 5px;
  width: fit-content;
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;  
}
.wfc-text { color: var(--wfc-text); }

.wfc-message.wfc-system {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: var(--wfc-system);
  font-style: italic;
  font-size: 12px;
  padding: 2px 4px;
  align-self: center;
  text-align: center;
  max-width: 100%;
}
.wfc-message.wfc-system .wfc-live { display: none; }

/* ---------- Typing indicator ---------- */
.wfc-typing {
  min-height: 22px;
  padding: 2px 16px 4px;
  font-size: 12px;
  color: var(--wfc-muted);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}
.wfc-typing:not(:empty)::before {
  content: "";
  width: 28px;
  height: 8px;
  background-image:
    radial-gradient(circle, var(--wfc-muted) 2px, transparent 2.5px),
    radial-gradient(circle, var(--wfc-muted) 2px, transparent 2.5px),
    radial-gradient(circle, var(--wfc-muted) 2px, transparent 2.5px);
  background-size: 8px 8px;
  background-repeat: no-repeat;
  background-position: 0 50%, 10px 50%, 20px 50%;
  animation: wfc-dots 1.2s ease-in-out infinite;
}
@keyframes wfc-dots {
  0%, 100% { opacity: .4; }
  50%      { opacity: 1; }
}

/* ---------- Scroll-to-bottom FAB ---------- */
.wfc-scroll-bottom {
  position: absolute;
  right: 14px;
  /* bottom: 130px; */
  /* width: 38px; */
  /* height: 38px; */
  border-radius: 50%;
  border: 0;
  background: var(--wfc-gradient);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--wfc-shadow-fab);
  /* font-size: 18px; */
  font-weight: 700;
  transition: transform .15s ease, box-shadow .2s ease;
  z-index: 2;

  width: 30px;
  height: 30px;
  font-size: 13px;
  bottom: 138px;
}
.wfc-scroll-bottom:hover { transform: translateY(-2px); }
.wfc-scroll-bottom:active { transform: translateY(0) scale(.96); }
.wfc-scroll-bottom.is-visible { display: inline-flex; animation: wfc-fab-in .2s ease both; }
@keyframes wfc-fab-in {
  from { opacity: 0; transform: translateY(6px) scale(.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Footer / form ---------- */
.wfc-footer {
  padding: 12px 14px 14px;
  background: var(--wfc-bg-soft);
  border-top: 1px solid var(--wfc-border);
}
.wfc-name-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--wfc-border);
  border-radius: 10px;
  background: var(--wfc-bg-input);
  color: var(--wfc-text);
  font: inherit;
  margin-bottom: 8px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  box-sizing: border-box;
}
.wfc-name-input[hidden] { display: none; }
.wfc-name-input::placeholder,
.wfc-input::placeholder { color: var(--wfc-muted); }

/* Compact "Chatting as <name> · Edit" badge shown after the name is saved */
.wfc-name-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 6px 12px;
  margin-bottom: 8px;
  background: var(--wfc-primary-soft);
  color: var(--wfc-text);
  border: 1px solid var(--wfc-border-soft);
  border-radius: 999px;
  font-size: 12px;
}
.wfc-name-badge[hidden] { display: none; }
.wfc-name-badge-label { color: var(--wfc-muted); }
.wfc-name-badge-label strong {
  color: var(--wfc-primary);
  font-weight: 700;
  margin-left: 4px;
}
.wfc-name-edit {
  background: transparent;
  border: 0;
  color: var(--wfc-primary);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  transition: background .15s ease;
}
.wfc-name-edit:hover { background: rgba(79, 125, 247, .12); }
.wfc-name-input:focus,
.wfc-input:focus {
  border-color: var(--wfc-primary);
  box-shadow: 0 0 0 3px var(--wfc-primary-soft);
}

.wfc-form {
  display: flex;
  gap: 8px;
  /* align-items: stretch; */
  align-items: center;
}
.wfc-input {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  -webkit-font-smoothing: antialiased;
  unicode-bidi: plaintext;
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--wfc-border);
  border-radius: 999px;
  background: var(--wfc-bg-input);
  color: var(--wfc-text);
  font: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  font-size: 13px;
}
.wfc-send {
  background: var(--wfc-gradient);
  color: #fff;
  border: 0;
  border-radius: 999px;
  /* padding: 10px 18px; */
  padding: 7px 18px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  letter-spacing: .2px;
  box-shadow: 0 4px 12px rgba(79, 125, 247, .28);
  transition: transform .15s ease, box-shadow .2s ease, opacity .15s ease;
  white-space: nowrap;
}
.wfc-send:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(79, 125, 247, .35); }
.wfc-send:active { transform: translateY(0) scale(.98); }
.wfc-send:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

/* When the name has not been set yet, the form input doubles as the
   username field. The input stays visible; only the button copy changes
   ("Tham gia" → "Send"). A subtle visual hint differentiates the two modes. */
.wfc-form.is-locked .wfc-input {
  border-color: var(--wfc-primary);
  box-shadow: 0 0 0 3px var(--wfc-primary-soft);
}

/* ---------- Collapsed state ---------- */
.wfc-chat[data-wfc-collapsed="true"] .wfc-tabs,
.wfc-chat[data-wfc-collapsed="true"] .wfc-messages,
.wfc-chat[data-wfc-collapsed="true"] .wfc-typing,
.wfc-chat[data-wfc-collapsed="true"] .wfc-footer,
.wfc-chat[data-wfc-collapsed="true"] .wfc-scroll-bottom { display: none; }
.wfc-chat[data-wfc-collapsed="true"] { 
  height: auto;
  aspect-ratio: inherit;
}

/* ---------- Top-level error block (when plugin not configured) ---------- */
.wfc-error {
  color: #b91c1c;
  padding: 16px;
  border: 1px solid #fecaca;
  border-radius: 10px;
  background: #fff5f5;
  font-size: 13px;
}
@media (prefers-color-scheme: dark) {
  .wfc-error {
    color: #fca5a5;
    border-color: #7f1d1d;
    background: rgba(127, 29, 29, .25);
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .wfc-chat,
  .wfc-message,
  .wfc-scroll-bottom,
  .wfc-send,
  .wfc-toggle-chat,
  .wfc-toggle-theme,
  .wfc-chat-header .wfc-online::before,
  .wfc-live,
  .wfc-typing:not(:empty)::before {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Small screens ---------- */
/* @media (max-width: 420px) {
  .wfc-chat { max-width: 100%; height: 80vh; border-radius: 14px; }
} */

@media (max-width: 1250px) {
	.wfc-chat{
		font-size: 12px;
	}
}


@media (max-width: 850px) {
	.wfc-chat-header{
		padding: 8px 10px;
	}
	.wfc-name-badge{
		padding: 6px 12px;
	}
	.wfc-footer {
		padding: 10px 8px;
	}
	.wfc-input{
		font-size: 12px;
	}
	.wfc-toggle-theme, .wfc-toggle-chat{
		font-size: 10px;
	}
	.wfc-messages{
		height: 280px;
	}
	.wfc-toggle-chat{
		display: block;
	}
	.wfc-chat{
		aspect-ratio: inherit;
    border-left: 1px solid #1e3a5f;
    height: 500px;
	}
	.wfc-messages{
		padding: 10px 4px 4px;
	}
}


/* ===== EMOJI PICKER ===== */
.wfc-emoji-wrap {
  position: relative;
  flex-shrink: 0;
}
.wfc-emoji-btn img{
    display: inline !important;
    border: none !important;
    box-shadow: none !important;
    height: 1.3em !important;
    width: 1.3em !important;
    max-width: 1.3em !important;
    margin: 0 0.07em !important;
    vertical-align: -0.1em !important;
    background: none !important;
    padding: 0 !important;
}

.wfc-emoji-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 15px;
  width: 32px;
  height: 32px;
  max-width: 1rem;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  transition:  transform 0.1s;
  line-height: 1;
}

.wfc-emoji-btn:hover {
  /* background: var(--wfc-primary-soft); */
  transform: scale(1.15);
}

.wfc-emoji-btn:active {
  transform: scale(0.95);
}

/* Popup picker */
.wfc-emoji-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 280px;
  background: var(--wfc-bg);
  border: 1px solid var(--wfc-border);
  border-radius: 14px;
  box-shadow: var(--wfc-shadow);
  z-index: 1000;
  overflow: hidden;
  animation: wfc-picker-in 0.18s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes wfc-picker-in {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Category tabs */
.wfc-emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--wfc-border-soft);
  background: var(--wfc-bg-soft);
}

.wfc-emoji-cat {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 18px;
  padding: 5px 0;
  cursor: pointer;
  transition: background 0.12s;
  line-height: 1;
}

.wfc-emoji-cat:hover {
  background: var(--wfc-bg-bubble);
}

.wfc-emoji-cat.is-active {
  background: var(--wfc-primary-soft);
  box-shadow: 0 0 0 1.5px var(--wfc-primary);
}

/* Emoji grid */
.wfc-emoji-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--wfc-border) transparent;
}

.wfc-emoji-grid button {
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 20px;
  padding: 4px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  line-height: 1;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wfc-emoji-grid button:hover {
  background: var(--wfc-primary-soft);
  transform: scale(1.2);
}

.wfc-emoji-grid button:active {
  transform: scale(0.9);
}

/* Đảm bảo form flex đúng */
.wfc-form {
  display: flex;
  align-items: center;
  gap: 6px;
}
