/* ── Chat Widget (visitor side) ─────────────────────────────────────────── */

#chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent, #0071e3);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transition: transform 0.2s, box-shadow 0.2s;
}
#chat-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,0.25); }

#chat-panel {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 340px;
  height: 480px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.85);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
#chat-panel.open { transform: scale(1); opacity: 1; pointer-events: auto; }

.chat-header {
  background: var(--color-accent, #0071e3);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header-avatar { font-size: 22px; }
.chat-header-info { flex: 1; }
.chat-header-title { font-size: 15px; font-weight: 600; }
.chat-header-status { font-size: 12px; opacity: 0.85; }
.chat-status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4caf50;
  margin-right: 4px;
  vertical-align: middle;
}
.chat-status-dot.offline { background: #aaa; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}
.chat-msg.visitor {
  align-self: flex-end;
  background: var(--color-accent, #0071e3);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.operator {
  align-self: flex-start;
  background: #f0f0f5;
  color: #1d1d1f;
  border-bottom-left-radius: 4px;
}
.chat-msg.system {
  align-self: center;
  background: transparent;
  color: #86868b;
  font-size: 12px;
  padding: 4px 0;
}
.chat-msg-name { font-size: 11px; opacity: 0.7; margin-bottom: 2px; }

.chat-offline-msg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: #86868b;
  font-size: 14px;
  line-height: 1.6;
}

.chat-input-area {
  border-top: 1px solid #e5e5ea;
  padding: 10px;
  display: flex;
  gap: 8px;
}
.chat-input-area textarea {
  flex: 1;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  resize: none;
  height: 38px;
  max-height: 80px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input-area textarea:focus { border-color: var(--color-accent, #0071e3); }
.chat-send-btn {
  background: var(--color-accent, #0071e3);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 18px;
  transition: opacity 0.2s;
}
.chat-send-btn:hover { opacity: 0.85; }
.chat-send-btn:disabled { opacity: 0.4; cursor: default; }


/* ── Operator Chat Panel (admin/chat) ───────────────────────────────────── */

.chat-workspace {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: calc(100vh - 120px);
  border: 1px solid #e5e5ea;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.chat-sessions-panel {
  border-right: 1px solid #e5e5ea;
  display: flex;
  flex-direction: column;
}
.chat-sessions-header {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e5ea;
  font-size: 13px;
  font-weight: 600;
  color: #1d1d1f;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-online-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 400;
  color: #86868b;
}
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  cursor: pointer;
  display: inline-block;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: #d1d1d6;
  border-radius: 10px;
  transition: background 0.2s;
}
.toggle-switch input:checked + .toggle-track { background: #34c759; }
.toggle-thumb {
  position: absolute;
  width: 16px; height: 16px;
  left: 2px; top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  pointer-events: none;
}
.toggle-switch input:checked ~ .toggle-thumb { left: 18px; }

.chat-session-list { flex: 1; overflow-y: auto; }
.chat-session-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f2f2f7;
  transition: background 0.15s;
}
.chat-session-item:hover { background: #f5f5f7; }
.chat-session-item.active { background: #e8f0fe; }
.chat-session-name { font-size: 14px; font-weight: 500; color: #1d1d1f; }
.chat-session-preview { font-size: 12px; color: #86868b; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-session-time { font-size: 11px; color: #aeaeb2; margin-top: 2px; }
.chat-no-sessions { padding: 32px 16px; text-align: center; color: #aeaeb2; font-size: 13px; }

.chat-main-panel {
  display: flex;
  flex-direction: column;
}
.chat-main-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #86868b;
  font-size: 15px;
}
.chat-main-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e5e5ea;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-main-title { font-size: 15px; font-weight: 600; }
.chat-close-btn {
  background: none;
  border: 1px solid #ff3b30;
  color: #ff3b30;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.chat-close-btn:hover { background: #ff3b30; color: #fff; }

.op-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.op-msg {
  max-width: 70%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.op-msg.visitor {
  align-self: flex-start;
  background: #f0f0f5;
  color: #1d1d1f;
  border-bottom-left-radius: 4px;
}
.op-msg.operator {
  align-self: flex-end;
  background: var(--color-accent, #0071e3);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.op-msg.system {
  align-self: center;
  background: transparent;
  color: #86868b;
  font-size: 12px;
}
.op-msg-meta { font-size: 11px; opacity: 0.65; margin-bottom: 3px; }

.op-input-area {
  border-top: 1px solid #e5e5ea;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.op-input-row {
  display: flex;
  gap: 8px;
}
.op-input-area textarea {
  flex: 1;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  resize: none;
  height: 44px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.op-input-area textarea:focus { border-color: var(--color-accent, #0071e3); }
.op-send-btn {
  background: var(--color-accent, #0071e3);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.2s;
}
.op-send-btn:hover { opacity: 0.85; }
.op-send-btn:disabled { opacity: 0.4; cursor: default; }

.op-templates {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.op-tpl-btn {
  background: #f0f0f5;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  color: #1d1d1f;
  transition: background 0.15s;
}
.op-tpl-btn:hover { background: #e0e0e8; }

.chat-status-bar {
  padding: 8px 16px;
  background: #f9f9fb;
  border-top: 1px solid #e5e5ea;
  font-size: 12px;
  color: #86868b;
  display: flex;
  align-items: center;
  gap: 6px;
}
