/* ===== Theme variables ===== */
[data-theme="dark"] {
  --bg: #0f1116;
  --bg-secondary: #171a21;
  --bg-tertiary: #1c2030;
  --surface: #1e2230;
  --panel: #171a21;
  --muted: #8b94a7;
  --text: #e8ecf3;
  --text-secondary: #a0a8ba;
  --line: #2a3040;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --ok: #22c55e;
  --warn-bg: #4b2e1e;
  --warn-border: #d97706;
  --user-bubble: #1f2937;
  --bot-bubble: #0f766e;
  --operator-bubble: #1d4ed8;
  --input-bg: #10141c;
  --shadow: rgba(0, 0, 0, 0.3);
  --scrollbar-thumb: #3a3f50;
}

[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eef1f6;
  --surface: #ffffff;
  --panel: #ffffff;
  --muted: #6b7280;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --line: #e5e7eb;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --ok: #16a34a;
  --warn-bg: #fef3c7;
  --warn-border: #d97706;
  --user-bubble: #e5e7eb;
  --bot-bubble: #d1fae5;
  --operator-bubble: #dbeafe;
  --input-bg: #f3f4f6;
  --shadow: rgba(0, 0, 0, 0.08);
  --scrollbar-thumb: #c4c8d0;
}

/* ===== iOS Safe Area Support ===== */
:root {
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --btn-height: 36px;
  --btn-radius: 10px;
  --btn-radius-round: 50%;
  --btn-font-size: 13px;
  --btn-icon-size: 20px;
  --btn-transition: all 0.15s ease;
}

/* ===== Reset & base ===== */
html,
body {
  margin: 0;
  padding: 0;
}

html {
  overflow: hidden;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* Prevent iOS Safari auto-zoom on focus (requires font-size >= 16px on inputs) */
input,
textarea,
select {
  font-size: 16px;
}

.hidden {
  display: none !important;
}

/* ============================================
   UNIFIED BUTTON DESIGN SYSTEM
   ============================================ */

/* ===== Base reset for ALL buttons ===== */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  outline: none;
}

/* ===== 1. Ghost Button (default) — EXACT 36px height ===== */
.btn,
.header-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px !important;
  min-height: 36px !important;
  max-height: 36px !important;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius, 10px);
  background: transparent;
  color: var(--text);
  font-size: var(--btn-font-size, 13px);
  font-weight: 500;
  white-space: nowrap;
  box-sizing: border-box;
  flex-shrink: 0;
  transition: var(--btn-transition, all 0.15s ease);
  line-height: 1;
  overflow: hidden;
}

.btn:hover,
.header-action-btn:hover {
  background: var(--surface);
  border-color: var(--muted);
}

.btn:active,
.header-action-btn:active {
  transform: scale(0.97);
}

/* ===== 2. Primary Button ===== */
.btn.primary,
.header-action-btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover,
.header-action-btn.accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ===== 3. Danger Button ===== */
.btn.danger,
.header-action-btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn.danger:hover,
.header-action-btn.danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ===== 4. Warn Button ===== */
.btn.warn,
.header-action-btn.warn {
  background: transparent;
  border-color: var(--warn-border);
  color: var(--warn-border);
}

.btn.warn:hover,
.header-action-btn.warn:hover {
  background: rgba(234, 179, 8, 0.15);
  border-color: var(--warn-border);
  color: var(--warn-border);
}

/* ===== 5. Icon-Only Buttons — EXACT 36x36, no exceptions ===== */
.icon-btn,
.header-icon-btn,
.header-action-btn.icon-only,
.sidebar-toggle-btn,
.sidebar-back-btn,
.modal-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  padding: 0 !important;
  border: none;
  border-radius: var(--btn-radius, 10px);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  transition: var(--btn-transition, all 0.15s ease);
  flex-shrink: 0;
  cursor: pointer;
  box-sizing: border-box;
  overflow: hidden;
}

.icon-btn:hover,
.header-icon-btn:hover,
.header-action-btn.icon-only:hover,
.sidebar-toggle-btn:hover,
.sidebar-back-btn:hover,
.modal-close-btn:hover {
  background: var(--surface);
  color: var(--text);
}

/* Settings expand is icon-only style — same 36x36 */
.settings-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  padding: 0 !important;
  border: none;
  border-radius: var(--btn-radius, 10px);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  transition: var(--btn-transition, all 0.15s ease);
  flex-shrink: 0;
  cursor: pointer;
  box-sizing: border-box;
  overflow: hidden;
}

.settings-expand-btn:hover {
  background: var(--surface);
  color: var(--text);
}

/* Force emoji inside icon-only buttons to not affect sizing */
.header-action-btn.icon-only,
.icon-btn {
  text-align: center;
  vertical-align: middle;
}

.icon-btn .icon.hidden {
  display: none;
}

/* ===== SVG inside ALL buttons — consistent size, no HTML overrides ===== */
button svg {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px;
  min-height: 20px;
  max-width: 20px;
  max-height: 20px;
  flex-shrink: 0;
}

/* Composer: attach button icon stays 22px (do not touch .btn-attach / .send-btn) */
.btn-attach svg {
  width: 22px !important;
  height: 22px !important;
  min-width: 22px;
  min-height: 22px;
  max-width: 22px;
  max-height: 22px;
}

/* ===== Special: Icon-only with border (log download) ===== */
.log-download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--btn-height);
  height: var(--btn-height);
  min-width: var(--btn-height);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--accent);
  transition: var(--btn-transition);
}

.log-download-btn:hover {
  background: var(--surface);
}

/* ===== Special: Settings buttons ===== */
.settings-seg-btn {
  position: relative;
  z-index: 1;
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--btn-font-size);
  font-weight: 500;
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: color 0.15s ease;
  white-space: nowrap;
}

.settings-seg-btn:hover {
  color: var(--text);
}

.settings-seg-btn.active {
  color: #fff;
}

.settings-play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--btn-height);
  height: var(--btn-height);
  min-width: var(--btn-height);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
  transition: var(--btn-transition);
}

.settings-play-btn:hover {
  background: var(--surface);
}

.settings-template-item-actions button {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: var(--btn-transition);
}

.settings-template-item-actions button:hover {
  background: var(--surface);
  color: var(--text);
}

.settings-template-item-actions button.delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

/* ===== Special: Moderation buttons ===== */
.mod-action-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--text);
  font-size: var(--btn-font-size);
  cursor: pointer;
  transition: var(--btn-transition);
  text-align: center;
}

.mod-action-btn:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.mod-action-btn.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

.warn-btn.active {
  border-color: var(--warn-border);
  background: rgba(234, 179, 8, 0.1);
}

.mute-btn.active {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

.ban-btn.active {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.mod-dur-btn {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: var(--btn-transition);
}

.mod-dur-btn:hover {
  border-color: var(--accent);
}

.mod-dur-btn.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
  color: var(--text);
}

.mod-confirm-btn {
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  font-size: 14px;
}

/* ===== Special: AI chat buttons ===== */
.ai-insert-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  transition: var(--btn-transition);
}

.ai-insert-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
}

.ai-clear-btn {
  font-size: 12px;
  padding: 3px 10px;
}

/* ===== Special: Auth button ===== */
.auth-modal-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--btn-radius);
  margin-top: 4px;
}

/* ===== Special: Retry button (chat) ===== */
.retry-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: var(--btn-radius-round);
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  margin-left: 4px;
  transition: var(--btn-transition);
  padding: 0;
  line-height: 1;
}

.retry-btn:hover {
  transform: scale(1.15);
  filter: brightness(1.1);
}

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

/* ===== Send button states ===== */
.send-btn.sending,
.send-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

/* ===== Hidden state (universal) ===== */
.header-action-btn.hidden,
.header-icon-btn.hidden,
.btn.hidden {
  display: none;
}

/* ===== Mobile overrides ===== */
@media (max-width: 768px) {
  .header-action-btn .btn-label {
    display: none;
  }

  .header-action-btn {
    padding: 0 8px;
    font-size: 16px;
  }

  .header-action-btn.icon-only {
    font-size: 18px;
  }

  .icon-btn,
  .header-icon-btn,
  .header-action-btn.icon-only,
  .sidebar-toggle-btn,
  .sidebar-back-btn {
    width: var(--btn-height);
    height: var(--btn-height);
    min-width: var(--btn-height);
    min-height: var(--btn-height);
  }

  .sidebar-toggle-btn {
    display: flex !important;
  }

  .sidebar-back-btn {
    display: flex !important;
  }

  .header-actions .header-icon-btn {
    margin-left: auto;
  }
}

/* ===== Settings-driven appearance ===== */

body.compact .conversation-item { padding: 6px 10px; }
body.compact .chat-messages { padding: 8px; gap: 4px; }
body.compact .bubble { padding: 6px 10px; }

body[data-show-time="hover"] .bubble-time { opacity: 0; transition: opacity 0.15s; }
body[data-show-time="hover"] .bubble:hover .bubble-time { opacity: 1; }
body[data-show-time="hidden"] .bubble-time { display: none; }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width, 320px) 1fr;
  height: 100dvh;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--line);
}

/* ===== Sidebar header ===== */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 8px;
}

.sidebar-brand {
  display: flex;
  align-items: baseline;
  gap: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-logo {
  color: var(--accent);
}

.brand-name {
  color: var(--text);
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== Operator row ===== */
.sidebar-operator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
}

.operator-name {
  font-size: 13px;
  color: var(--muted);
}

.sidebar-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.sidebar-input:focus {
  border-color: var(--accent);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  position: relative;
}
.conversation-item:hover {
  background: var(--bg-tertiary);
}
.conversation-item.active {
  background: var(--bg-tertiary);
  border-color: var(--accent);
  border-left-color: var(--accent);
  border-left-width: 3px;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.08);
}
.conversation-item.needs-operator {
  border-color: var(--warn-border);
  background: var(--warn-bg);
}
.conversation-item.needs-operator.active {
  border-left-color: var(--accent);
  border-left-width: 3px;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.12);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.status {
  font-size: 10px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.status.bot {
  color: var(--ok);
  background: rgba(34, 197, 94, 0.12);
}
.status.operator {
  color: var(--warn-border);
  background: rgba(217, 119, 6, 0.12);
}
.status.closed {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
}

/* ===== Main area ===== */
.main {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Chat header ===== */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
  gap: 12px;
  min-height: 52px;
}

/* -- Left side: user info -- */
.header-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  min-height: 36px;
}

.header-username {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-platform {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-height: 22px;
  flex-shrink: 0;
}

.header-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-height: 22px;
  flex-shrink: 0;
}

.platform-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-height: 22px;
  font-size: 10px;
  font-weight: 600;
  padding: 0 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #fff;
  background: #6b7280;
}
.platform-badge.tg { background: #2AABEE; }
.platform-badge.vk { background: #0077FF; }

.status-badge-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-height: 22px;
  padding: 0 8px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1;
}
.status-badge-inline.bot {
  color: var(--ok);
  background: rgba(34, 197, 94, 0.12);
}
.status-badge-inline.operator {
  color: var(--warn-border);
  background: rgba(217, 119, 6, 0.12);
}
.status-badge-inline.closed {
  color: var(--muted);
  background: rgba(107, 114, 128, 0.12);
}

.header-wait-time {
  font-size: 11px;
  font-weight: 600;
  color: var(--danger);
  white-space: nowrap;
}

.btn-copy-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.btn-copy-link:hover {
  color: var(--text);
  background: var(--hover);
}
.btn-copy-link.hidden { display: none; }

.header-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}
.header-meta-row.hidden { display: none; }

.header-assigned-operator.hidden { display: none; }

/* -- Right side: controls -- */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.header-actions .autocorrect-toggle {
  display: inline-flex;
  align-items: center;
  height: 36px;
}

/* ===== Chat area ===== */
.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.chat-messages {
  flex: 1;
  flex-grow: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
}
.bubble.user {
  align-self: flex-start;
  background: var(--user-bubble);
  border-bottom-left-radius: 4px;
}
[data-theme="light"] .bubble.user {
  color: #1f2937;
}
.bubble.bot {
  align-self: flex-end;
  background: var(--bot-bubble);
  border-bottom-right-radius: 4px;
}
[data-theme="light"] .bubble.bot {
  color: #065f46;
}
.bubble.operator {
  align-self: flex-end;
  background: var(--operator-bubble);
  border-bottom-right-radius: 4px;
}
[data-theme="light"] .bubble.operator {
  color: #1e40af;
}

.bubble-meta {
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.6;
  display: none; /* replaced by bubble-time in chat.css */
}

/* ===== Telegram-style Composer ===== */
.composer {
  background: var(--panel);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  border-top: none;
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 5;
}

[data-theme="dark"] .composer {
  box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.3);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 0;
}

/* ---- Attach button (Telegram-style: transparent, icon only) ---- */
.btn-attach {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.btn-attach:hover {
  color: var(--text);
  background: transparent;
  transform: scale(1.08);
}

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

.btn-attach.active {
  color: var(--accent);
}

.btn-attach svg {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
}

/* ---- Textarea (Telegram-style: borderless, clean) ---- */
.reply-textarea,
.text-input,
#chat-input {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  font-family: inherit;
  resize: none;
  outline: none;
  overflow-y: auto;
  box-sizing: border-box;
  transition: background 0.2s ease;
  min-width: 0;
}

.reply-textarea::placeholder,
.text-input::placeholder,
#chat-input::placeholder {
  color: var(--muted);
  opacity: 0.7;
  font-weight: 400;
}

.reply-textarea:focus,
.text-input:focus,
#chat-input:focus {
  border: none;
  outline: none;
  background: var(--input-bg);
}

/* ---- Send button (Telegram-style: accent circle, animated) ---- */
.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.send-btn:hover {
  transform: scale(1.08);
  filter: brightness(1.1);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
  background: var(--accent);
  color: #ffffff;
  opacity: 1;
}

.send-btn:active {
  transform: scale(0.95);
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.2);
}

.send-btn svg {
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
}

/* ---- Drag & drop zone ---- */
.drop-zone {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  margin: 0 0 8px 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  background: rgba(59, 130, 246, 0.05);
  transition: background 0.2s ease;
}

.drop-zone.visible {
  display: flex;
}

.composer.drag-over {
  background: var(--bg-tertiary);
}

/* ---- Upload preview ---- */
.upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 4px 4px;
}

.upload-preview.hidden {
  display: none;
}

/* ---- Autocorrect preview ---- */
.autocorrect-preview {
  background: var(--surface);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  animation: acSlideUp 0.2s ease-out;
}

.preview-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preview-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  padding: 6px 0;
}

.preview-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

@keyframes acSlideUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Mobile ---- */
@media (max-width: 768px) {
  .composer {
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    padding-left: calc(8px + var(--safe-area-left));
    padding-right: calc(8px + var(--safe-area-right));
  }

  .composer-row {
    gap: 4px;
  }

  .btn-attach {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }

  .btn-attach svg {
    width: 20px;
    height: 20px;
  }

  .send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }

  .reply-textarea,
  .text-input,
  #chat-input {
    min-height: 36px;
    padding: 8px 14px;
    font-size: 16px;
  }
}

body.compact .composer {
  padding: 4px 8px 6px;
}

/* ===== Hidden file input ===== */
.hidden-file-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* ===== Placeholder ===== */
.placeholder {
  color: var(--muted);
  padding: 24px;
  text-align: center;
  font-size: 14px;
}

/* ===== Attachments in chat ===== */
.attachment {
  margin-top: 8px;
}
.attachment img {
  max-width: 300px;
  max-height: 300px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--line);
}
.attachment img:hover {
  opacity: 0.85;
}

.log-toggle {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}
.log-toggle:hover {
  background: var(--bg-tertiary);
}

.log-content {
  display: none;
  margin-top: 6px;
  max-height: 400px;
  overflow: auto;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}
.log-content.open {
  display: block;
}

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
}
.file-link:hover {
  background: var(--bg-tertiary);
}

.sidebar-toggle-btn {
  display: none;
}

.sidebar-back-btn {
  display: none;
}

/* ===== Mobile responsive ===== */
@media (max-width: 768px) {
  /* Switch to single column */
  .layout {
    grid-template-columns: 1fr;
    position: relative;
  }

  /* Chat page: fixed to visual viewport so keyboard resize doesn't push header off-screen. Height/top set by JS (Visual Viewport API). */
  .chat-page {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .chat-page .chat-header {
    flex-shrink: 0;
    position: relative;
    z-index: 10;
  }

  .chat-page .chat-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .chat-page .chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .chat-page .chat-composer {
    flex-shrink: 0;
    position: relative;
  }

  /* Fix mobile viewport height — address bar pushes content. Safe-area only on header (top) and composer (bottom), not here, to avoid double inset and layout shift. */
  .main {
    height: calc(var(--vh, 1vh) * 100);
    height: 100dvh;
    height: 100svh;
    height: -webkit-fill-available;
    box-sizing: border-box;
  }

  /* Sidebar: full screen overlay, hidden by default */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    height: 100svh;
    height: -webkit-fill-available;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    box-sizing: border-box;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* ===== Mobile header: two-row layout ===== */
  .main-header {
    flex-wrap: wrap;
    padding-top: calc(8px + var(--safe-area-top));
    padding-left: calc(12px + var(--safe-area-left));
    padding-right: calc(12px + var(--safe-area-right));
    padding-bottom: 8px;
    gap: 4px 8px;
    min-height: auto;
  }

  /* Row 1: hamburger + user info — take full width */
  .header-left {
    flex: 1 1 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .header-user-row {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  .header-username {
    font-size: 14px;
    max-width: 45vw;
  }

  .platform-badge,
  .status-badge-inline {
    height: 20px;
    font-size: 9px;
    padding: 0 6px;
  }

  .header-meta-row {
    display: none !important;
  }

  /* Row 2: action buttons — take full width, icon-only on mobile to prevent overflow */
  .header-right {
    flex: 1 1 100%;
    max-width: 100%;
    overflow: hidden;
    justify-content: flex-start;
  }

  .header-actions {
    flex: 1;
    gap: 4px;
    flex-wrap: nowrap;
  }

  /* Autocorrect toggle — hide on mobile */
  .autocorrect-toggle {
    display: none;
  }

  /* Chat messages */
  .chat-messages {
    padding: 10px;
    gap: 6px;
  }

  .bubble {
    max-width: 85%;
    font-size: 13px;
    padding: 8px 12px;
  }

  /* Templates panel — full width overlay */
  .templates-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100dvh;
    z-index: 99;
    border-left: none;
    background: var(--panel);
  }

  /* Online operators — collapse */
  .online-operators-header {
    font-size: 11px;
  }

  /* Conversation list items — more compact */
  .conversation-item {
    padding: 10px 12px;
  }

}

/* ===== Extra small screens ===== */
@media (max-width: 480px) {
  .bubble {
    max-width: 90%;
    font-size: 13px;
  }

  .sidebar-header {
    padding: 10px 12px;
  }
}

.btn-attach,
.btn-attach.btn-attach,
.send-btn,
.send-btn.send-btn {
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  min-height: 40px !important;
  max-width: 40px !important;
  max-height: 40px !important;
}
/* ===== Conversation Avatar ===== */
.conv-item-inner {
  display: flex;
  gap: 12px;
  align-items: center;
}
.avatar-wrapper {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.user-avatar.placeholder {
  background: var(--bg-tertiary);
  position: relative;
}
.user-avatar.placeholder::after {
  content: '👤';
  font-size: 20px;
  color: var(--muted);
}
.conv-info {
  flex-grow: 1;
  min-width: 0;
}

/* ===== Stickers ===== */
.attachment.sticker {
  display: inline-block;
  margin-top: 8px;
  max-width: 160px;
  max-height: 160px;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
}
.attachment.sticker img,
.attachment.sticker video,
.attachment.sticker svg {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 0 !important;
}
.attachment.sticker video {
  pointer-events: none;
}
