/* Wulin Saga — chat HUD (client/js/ui/chat.js) + the shared social popup menu. Owned by ui-social.
   Zone: bottom-left, above the EXP bar, left of the hotbar (docs/ARCHITECTURE.md §7.5). */

.chat-root {
  --chat-log-h: 170px;
  --chat-send: #f4eee2;
  --chat-gold: var(--c-gold, #e8c46a);
  position: absolute;
  left: 10px;
  bottom: calc(var(--hud-exp-h, 15px) + 8px);
  width: clamp(290px, calc(50vw - 292px), 430px);
  z-index: 3;
  font-family: var(--font, 'Kanit', 'Leelawadee UI', Tahoma, sans-serif);
  font-size: 13px;
  color: var(--c-text, #f3e6c8);
  pointer-events: auto;
}

/* ------------------------------------------------------------------ frame */
.chat-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 7px;
  border: 1px solid rgba(232, 196, 106, 0.42);
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(150, 50, 25, 0.16), transparent 65%),
    linear-gradient(180deg, rgba(34, 19, 12, 0.84) 0%, rgba(16, 9, 6, 0.86) 100%);
  box-shadow:
    0 0 0 1px rgba(10, 5, 2, 0.85),
    inset 0 0 0 1px rgba(255, 220, 160, 0.07),
    inset 0 0 18px rgba(0, 0, 0, 0.45),
    0 8px 22px rgba(0, 0, 0, 0.45);
  transition: background 0.45s ease, border-color 0.45s ease, box-shadow 0.45s ease;
}
/* Gold corner brackets (like .win, smaller). */
.chat-frame::before {
  content: '';
  position: absolute;
  inset: -3px;
  pointer-events: none;
  border-radius: 8px;
  --o: var(--chat-gold);
  background:
    linear-gradient(var(--o), var(--o)) top left / 12px 2px no-repeat,
    linear-gradient(var(--o), var(--o)) top left / 2px 12px no-repeat,
    linear-gradient(var(--o), var(--o)) top right / 12px 2px no-repeat,
    linear-gradient(var(--o), var(--o)) top right / 2px 12px no-repeat,
    linear-gradient(var(--o), var(--o)) bottom left / 12px 2px no-repeat,
    linear-gradient(var(--o), var(--o)) bottom left / 2px 12px no-repeat,
    linear-gradient(var(--o), var(--o)) bottom right / 12px 2px no-repeat,
    linear-gradient(var(--o), var(--o)) bottom right / 2px 12px no-repeat;
  filter: drop-shadow(0 0 1px #000);
  opacity: 0.85;
  transition: opacity 0.45s ease;
}

/* ------------------------------------------------------------------ tabs */
.chat-head {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 5px 26px 0 6px;
  border-bottom: 1px solid rgba(232, 196, 106, 0.32);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0));
  border-radius: 7px 7px 0 0;
  transition: opacity 0.45s ease;
}
.chat-tabs { display: flex; align-items: flex-end; gap: 2px; min-width: 0; overflow: hidden; }
.chat-tab {
  position: relative;
  flex: none;
  margin: 0 0 -1px;
  padding: 3px 8px 4px;
  font: inherit;
  font-size: 12px;
  line-height: 1.25;
  color: var(--c-muted, #a8977a);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  text-shadow: 0 1px 1px #000;
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
}
.chat-tab:hover { color: var(--c-text, #f3e6c8); background: rgba(232, 196, 106, 0.09); }
.chat-tab.active {
  color: var(--c-gold-light, #fff0b8);
  font-weight: 500;
  background: linear-gradient(180deg, rgba(150, 38, 26, 0.95) 0%, rgba(78, 17, 11, 0.95) 100%);
  border-color: rgba(232, 196, 106, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 210, 150, 0.22);
}
.chat-tab.active::after {
  content: '';
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--chat-gold), transparent);
}
.chat-dot {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: none;
  background: var(--dot, #ffdc5e);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.8), 0 0 6px var(--dot, #ffdc5e);
}
.chat-tab.unread .chat-dot { display: block; animation: chat-dot-pulse 1.3s ease-in-out infinite; }
.chat-tab.unread { color: var(--c-text, #f3e6c8); }
@keyframes chat-dot-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.72); opacity: 0.7; } }

/* Resize grip (top-right). */
.chat-grip {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 18px;
  height: 16px;
  cursor: ns-resize;
  border-radius: 3px;
  opacity: 0.6;
  background:
    linear-gradient(var(--chat-gold), var(--chat-gold)) center 4px / 10px 1px no-repeat,
    linear-gradient(var(--chat-gold), var(--chat-gold)) center 8px / 10px 1px no-repeat,
    linear-gradient(var(--chat-gold), var(--chat-gold)) center 12px / 10px 1px no-repeat;
  transition: opacity 0.15s, background-color 0.15s;
}
.chat-grip:hover, .chat-root.resizing .chat-grip { opacity: 1; background-color: rgba(232, 196, 106, 0.12); }
.chat-root.resizing, .chat-root.resizing * { cursor: ns-resize !important; user-select: none; }

/* ------------------------------------------------------------------ log */
.chat-body { position: relative; }
.chat-log {
  height: var(--chat-log-h);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 4px 8px 5px 9px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-user-select: text;
  user-select: text;
}
#ui-root .chat-log::-webkit-scrollbar { width: 6px; }
.chat-line {
  padding: 1px 0;
  color: var(--ch, #f4eee2);
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 1px #000, 0 0 3px rgba(0, 0, 0, 0.95), 0 0 1px #000;
  animation: chat-line-in 0.18s ease-out;
}
@keyframes chat-line-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.chat-time {
  margin-right: 5px;
  font-size: 10.5px;
  color: rgba(214, 196, 165, 0.5);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}
.chat-tag { margin-right: 4px; font-weight: 500; color: var(--tag, var(--ch)); }
.chat-name {
  font-weight: 600;
  color: var(--name, var(--ch));
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s;
}
.chat-name[role="button"]:hover { text-decoration: underline; text-underline-offset: 2px; background: rgba(255, 255, 255, 0.06); }
.chat-name.self { cursor: default; }
.ch-local .chat-name { --name: #ffe19c; }
.ch-local .chat-name.self { --name: #fff4d4; }
.chat-dir { opacity: 0.85; }
.chat-sep { opacity: 0.9; }
.ch-whisper.out .chat-text { opacity: 0.88; }
.ch-sys .chat-text { color: var(--ch); }
.ch-err .chat-text { color: var(--ch); }
.chat-err-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  margin: 0 4px 0 0;
  vertical-align: 1px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: #2a0906;
  background: radial-gradient(circle at 40% 35%, #ffb3a8, #ff6b5b 60%, #b3261e);
  text-shadow: none;
}

.chat-jump {
  position: absolute;
  right: 12px;
  bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font: inherit;
  font-size: 11.5px;
  color: #2a1608;
  background: linear-gradient(180deg, #fff0b8 0%, #e8c46a 55%, #b08a3a 100%);
  border: 1px solid #fff0b8;
  border-radius: 11px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), 0 0 10px rgba(232, 196, 106, 0.4);
  cursor: pointer;
  animation: chat-jump-in 0.2s ease-out;
}
.chat-jump:hover { filter: brightness(1.1); }
.chat-jump-arrow { font-size: 9px; }
@keyframes chat-jump-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ input bar */
.chat-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 5px 6px 6px;
  border-top: 1px solid rgba(232, 196, 106, 0.22);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.22));
  border-radius: 0 0 7px 7px;
  transition: opacity 0.45s ease;
}
.chat-ch {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 7px 0 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--chat-send);
  text-shadow: 0 1px 1px #000;
  white-space: nowrap;
  background: linear-gradient(180deg, #43291b 0%, #26160e 100%);
  border: 1px solid rgba(232, 196, 106, 0.45);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 220, 160, 0.14), 0 1px 2px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: filter 0.12s, border-color 0.12s;
}
.chat-ch:hover { filter: brightness(1.18); border-color: var(--chat-gold); }
.chat-ch-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chat-ch-caret { display: inline-flex; margin-left: 1px; color: var(--c-muted, #a8977a); }
.chat-ch-caret svg { display: block; width: 9px; height: 9px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.chat-ch:hover .chat-ch-caret { color: var(--c-gold, #e8c46a); }

#ui-root .chat-bar input.chat-input,
#ui-root .chat-bar input.chat-to,
.chat-bar input.chat-input,
.chat-bar input.chat-to {
  min-height: 28px;
  height: 28px;
  padding: 3px 9px;
  font-size: 13px;
  color: var(--c-text, #f3e6c8);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(120, 82, 46, 0.9);
  border-radius: 4px;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.8);
}
#ui-root .chat-bar input.chat-input, .chat-bar input.chat-input { flex: 1 1 auto; min-width: 0; }
#ui-root .chat-bar input.chat-to, .chat-bar input.chat-to {
  flex: 0 1 92px;
  width: 92px;
  min-width: 64px;
  padding: 3px 7px;
  color: var(--chat-send);
  font-weight: 500;
}
/* Whisper mode: the pink recipient field already says "whisper", so the selector shrinks to its dot. */
.chat-root[data-channel="whisper"] .chat-ch-label { display: none; }
.chat-root[data-channel="whisper"] .chat-ch { padding: 0 6px 0 8px; }
#ui-root .chat-bar input.chat-input:focus,
#ui-root .chat-bar input.chat-to:focus,
.chat-bar input.chat-input:focus,
.chat-bar input.chat-to:focus {
  border-color: var(--chat-send);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.8), 0 0 0 2px rgba(232, 196, 106, 0.16), 0 0 10px -2px var(--chat-send);
}
.chat-root[data-channel="local"] .chat-bar input.chat-input:focus { border-color: var(--chat-gold); }
.chat-count {
  flex: none;
  min-width: 22px;
  font-size: 11px;
  text-align: right;
  color: var(--c-muted, #a8977a);
  font-variant-numeric: tabular-nums;
}
.chat-count.near { color: var(--c-bad, #ff6b5b); font-weight: 600; }
.chat-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  padding: 0;
  color: #fff3d0;
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(255, 200, 150, 0.25), transparent 70%),
    linear-gradient(180deg, #c9392a 0%, #8e1e15 55%, #66120c 100%);
  border: 1px solid rgba(232, 196, 106, 0.7);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 220, 180, 0.3), 0 1px 3px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: filter 0.12s;
}
.chat-send:hover { filter: brightness(1.2); }
.chat-send:active { transform: translateY(1px); }
.chat-ico svg { display: block; width: 16px; height: 16px; fill: currentColor; }
.chat-ico svg .ln { fill: none; stroke: #6a130c; stroke-width: 1.4; stroke-linecap: round; }

/* ------------------------------------------------------------------ idle / typing */
.chat-root.idle .chat-frame {
  background: linear-gradient(180deg, rgba(16, 9, 6, 0.16), rgba(16, 9, 6, 0.3));
  border-color: rgba(232, 196, 106, 0.1);
  box-shadow: none;
}
.chat-root.idle .chat-frame::before { opacity: 0; }
.chat-root.idle .chat-head { opacity: 0.5; border-bottom-color: rgba(232, 196, 106, 0.12); }
.chat-root.idle .chat-bar { opacity: 0.38; border-top-color: transparent; }
.chat-root.idle .chat-log::-webkit-scrollbar-thumb { background: transparent; border-color: transparent; }
.chat-root.idle .chat-tab.unread { opacity: 1; }
.chat-root.typing .chat-frame {
  border-color: rgba(232, 196, 106, 0.6);
  box-shadow:
    0 0 0 1px rgba(10, 5, 2, 0.85),
    inset 0 0 0 1px rgba(255, 220, 160, 0.08),
    inset 0 0 18px rgba(0, 0, 0, 0.45),
    0 8px 24px rgba(0, 0, 0, 0.5),
    0 0 16px rgba(232, 196, 106, 0.12);
}

/* ------------------------------------------------------------------ shared social popup menu */
.social-menu {
  position: fixed;
  z-index: 58;
  min-width: 150px;
  max-width: 240px;
  padding: 4px;
  pointer-events: auto;
  font-family: var(--font, 'Kanit', 'Leelawadee UI', Tahoma, sans-serif);
  font-size: 13px;
  color: var(--c-text, #f3e6c8);
  background: linear-gradient(180deg, rgba(44, 26, 16, 0.98), rgba(20, 11, 7, 0.98));
  border: 1px solid var(--c-gold-dark, #9a7430);
  border-radius: 5px;
  box-shadow: 0 0 0 1px #000, inset 0 0 0 1px rgba(232, 196, 106, 0.12), 0 10px 26px rgba(0, 0, 0, 0.7);
  animation: social-menu-in 0.12s ease-out;
  user-select: none;
}
@keyframes social-menu-in { from { opacity: 0; transform: translateY(3px) scale(0.98); } to { opacity: 1; transform: none; } }
.social-menu-head {
  padding: 4px 9px 6px;
  margin-bottom: 3px;
  border-bottom: 1px solid rgba(232, 196, 106, 0.25);
}
.social-menu-title { font-weight: 600; color: var(--c-gold, #e8c46a); text-shadow: 0 1px 1px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.social-menu-sub { font-size: 11.5px; color: var(--c-muted, #a8977a); }
.social-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 4px 10px;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--c-text, #f3e6c8);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.social-menu-item:hover:not(:disabled) {
  color: var(--c-gold-light, #fff0b8);
  background: linear-gradient(90deg, rgba(179, 38, 30, 0.45), rgba(179, 38, 30, 0.08));
  border-color: rgba(232, 196, 106, 0.35);
}
.social-menu-item:disabled { opacity: 0.42; cursor: not-allowed; }
.social-menu-item.danger { color: #ffb4a8; }
.social-menu-item.danger .social-menu-dot { background: #ff6b5b; box-shadow: 0 0 6px #ff6b5b; }
.social-menu-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: rgba(232, 196, 106, 0.7); }
.social-menu-label { flex: 1 1 auto; white-space: nowrap; }
.social-menu-hint {
  flex: none;
  padding: 0 5px;
  font-size: 11px;
  line-height: 16px;
  color: var(--c-gold, #e8c46a);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(154, 116, 48, 0.7);
  border-radius: 3px;
}
.social-menu-sep { height: 1px; margin: 4px 6px; background: linear-gradient(90deg, transparent, rgba(232, 196, 106, 0.4), transparent); }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1200px) {
  .chat-tab { padding: 3px 5px 4px; font-size: 11.5px; }
  .chat-head { gap: 2px; padding-left: 4px; }
}
@media (max-width: 1000px) {
  .chat-root { bottom: calc(var(--hud-bottom-reserved, 84px) + 8px); width: min(380px, calc(100vw - 20px)); }
}
@media (max-height: 640px) {
  .chat-log { height: min(var(--chat-log-h), 110px); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-line, .social-menu, .chat-jump { animation: none; }
  .chat-tab.unread .chat-dot { animation: none; }
}
