/* =========================================================
   FLOATING CHAT WIDGET STYLES (JOB_79 PHASE 1)
   Vanilla CSS with CLG Design System Tokens ONLY
   ========================================================= */

/* --- TAB CHAT NGANG (Bottom-Left) --- */
:root {
  --chat-tab-height: 48px;
}

#chatFab {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 60;
  width: 104px;
  height: var(--chat-tab-height);
  padding: 0;
  font: inherit;
  border: 1px solid var(--border);
  border-bottom: none;
  border-left: none;
  border-radius: 0 var(--radius-lg) 0 0;
  background: var(--surface-2);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--text-muted);
  transition: background var(--dur-quick, 0.15s) var(--ease-out, ease-out),
              color var(--dur-quick, 0.15s) var(--ease-out, ease-out),
              border-color var(--dur-quick, 0.15s) var(--ease-out, ease-out);
  user-select: none;
}

#chatFab:hover {
  background: var(--surface-3);
  color: var(--text);
}

#chatFab.active {
  background: var(--surface);
  color: var(--brand, var(--accent, #22d3ee));
  border-color: var(--brand, var(--accent, #22d3ee));
}

#chatFab .chat-fab-icon {
  font-size: 18px;
  line-height: 1;
}

.chat-rail-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}

#chatFabBadge {
  position: absolute;
  top: 4px;
  right: 5px;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-pill, 999px);
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 1.5px solid var(--surface-2, #111827);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* --- CHAT PANEL --- */
#chatPanel {
  position: fixed;
  bottom: var(--chat-tab-height);
  left: 0;
  z-index: 90;
  width: 340px;
  height: 420px;
  min-width: 280px;
  max-width: 520px;
  min-height: 300px;
  max-height: 70vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  --chat-opacity: 1;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(calc(100% + var(--chat-tab-height)));
  transition: transform var(--dur-normal, 0.25s) var(--ease-out, ease-out),
              opacity var(--dur-normal, 0.25s) var(--ease-out, ease-out),
              visibility var(--dur-normal, 0.25s);
}

#chatPanel:hover {
  /* Temp reveal readability when in low opacity mode */
  opacity: max(var(--chat-opacity), 0.85);
}

#chatPanel:not(.hidden) {
  transform: translateY(0);
  opacity: var(--chat-opacity);
  pointer-events: auto;
  visibility: visible;
}

#chatPanel.hidden {
  transform: translateY(calc(100% + var(--chat-tab-height)));
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Header */
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  user-select: none;
  flex-shrink: 0;
}

.chat-head-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-head-btn {
  background: none;
  border: none;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.chat-head-btn:hover {
  color: var(--text);
  background: var(--bg-2);
}

/* Tabs */
.chat-tabs {
  display: flex;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
  overflow-x: auto;
  flex-shrink: 0;
  user-select: none;
}

.chat-tab {
  flex: 1;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  transition: color 0.15s, border-color 0.15s;
}

.chat-tab:hover {
  color: var(--text);
}

.chat-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.chat-tab-badge {
  background: var(--danger, #ef4444);
  color: #fff;
  border-radius: var(--radius-pill, 999px);
  font-size: 10px;
  font-weight: 700;
  padding: 0 5px;
  min-width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Body / Messages List */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.chat-body-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px;
}

/* Message Item */
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  align-self: flex-start;
  font-size: 13px;
}

.chat-msg.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-av {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  user-select: none;
}

.chat-msg-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  word-break: break-word;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-msg.mine .chat-msg-bubble {
  background: color-mix(in srgb, var(--accent) 15%, var(--surface-2));
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.chat-msg-sender {
  font-weight: 700;
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  line-height: 1.2;
  margin-bottom: 2px;
}

.chat-msg-sender:hover {
  text-decoration: underline;
}

.chat-msg-text {
  line-height: 1.4;
  white-space: pre-wrap;
}

.chat-msg-time {
  font-size: 10px;
  color: var(--text-muted);
  align-self: flex-end;
  margin-top: 2px;
}

/* System Message */
.chat-msg.system {
  align-self: center;
  max-width: 100%;
}

.chat-msg.system .chat-msg-bubble {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  font-style: italic;
  padding: 2px 6px;
}

/* Shout Message (📢 Loa Chat) */
.chat-msg.shout {
  max-width: 95%;
  align-self: center;
}

.chat-msg.shout .chat-msg-bubble {
  border: 1.5px solid var(--brand, #fbbf24);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--brand, #fbbf24) 12%, var(--surface-2));
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.15);
}

/* Direct Messages Thread List */
.chat-dm-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.chat-dm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chat-dm-item:hover {
  background: var(--bg-2);
  border-color: var(--accent);
}

.chat-dm-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-dm-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-dm-last {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-dm-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  flex-shrink: 0;
}

/* Chat Input Footer */
.chat-input {
  opacity: 1 !important;
  padding: 8px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-input-opts {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
}

.chat-shout-label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--brand, #fbbf24);
  font-weight: 600;
}

.chat-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 8px;
  font-size: 13px;
  resize: none;
  min-height: 36px;
  max-height: 80px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
}

.chat-textarea:focus {
  border-color: var(--accent);
}

.chat-send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  height: 36px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-send-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-kid-notice {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 6px;
  font-weight: 600;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

/* Resize Handle (Desktop Only - Top-Right corner because panel is docked bottom-left) */
.chat-resize {
  position: absolute;
  top: 0;
  right: 0;
  width: 14px;
  height: 14px;
  cursor: ne-resize;
  z-index: 10;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.chat-resize:hover {
  opacity: 1;
}

.chat-resize::after {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-top: 2px solid var(--text-muted);
  border-right: 2px solid var(--text-muted);
}

/* Mobile Bottom Sheet (<= 600px) */
@media (max-width: 600px) {
  #chatPanel {
    left: 0 !important;
    right: 0 !important;
    bottom: var(--chat-tab-height) !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 55vh !important;
    border-radius: var(--radius) var(--radius) 0 0 !important;
  }
  #chatFab { width: 92px; }
  .chat-resize {
    display: none !important;
  }
}
