/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary:         #4f46e5;
  --primary-dark:    #3730a3;
  --primary-light:   #eef2ff;
  --primary-mid:     #6366f1;
  --surface:         #ffffff;
  --surface-alt:     #f8fafc;
  --border:          #e2e8f0;
  --border-light:    #f1f5f9;
  --text-primary:    #1e293b;
  --text-secondary:  #64748b;
  --text-muted:      #94a3b8;
  --bot-bubble:      #f1f5f9;
  --user-bubble:     #4f46e5;
  --user-bubble-txt: #ffffff;
  --error:           #ef4444;
  --success:         #22c55e;
  --sidebar-w:       272px;
  --channel-w:       60px;
  --inbox-w:         360px;
  --shadow-sm:       0 1px 3px rgba(0,0,0,.07);
  --shadow-md:       0 4px 16px rgba(0,0,0,.10);
  --shadow-lg:       0 12px 40px rgba(0,0,0,.15);
  --radius:          10px;
  --radius-lg:       16px;
  --radius-full:     9999px;
  --font:            -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--surface-alt);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }
.hidden { display: none !important; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .22s ease-out;
}

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

.modal h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: .4rem;
}

.modal-desc {
  color: var(--text-secondary);
  font-size: .875rem;
  margin-bottom: 1.25rem;
}

.form-group { margin-bottom: .9rem; }

.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: .3rem;
}

.form-group input {
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface-alt);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.13);
}

.modal-actions {
  display: flex;
  gap: .6rem;
  margin-top: 1.25rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .55rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s, border-color .15s;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover { background: var(--border-light); }

.btn-outline {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.btn-outline:hover { background: var(--surface-alt); }

/* ===== App Shell ===== */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s ease;
  z-index: 100;
}

.sidebar.collapsed {
  width: 64px;
  min-width: 64px;
}

.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .trial-card,
.sidebar.collapsed .user-name,
.sidebar.collapsed .chevron-btn {
  display: none;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: .7rem 0;
}

.sidebar.collapsed .user-row {
  justify-content: center;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  overflow: hidden;
}

.brand-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon svg { width: 32px; height: 32px; }

.brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: .3rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}

.sidebar-collapse-btn svg { width: 18px; height: 18px; }
.sidebar-collapse-btn:hover { color: var(--text-primary); background: var(--surface-alt); }

/* ===== Sidebar Nav ===== */
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: .75rem .75rem 0;
  overflow-y: auto;
  gap: .15rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .62rem .85rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: .9rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item:hover {
  background: var(--surface-alt);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg { width: 20px; height: 20px; }

/* ===== Sidebar Bottom ===== */
.sidebar-bottom {
  padding: .75rem;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.trial-card {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: .8rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  position: relative;
  overflow: hidden;
}

.trial-info { position: relative; z-index: 1; }

.trial-title {
  font-size: .85rem;
  font-weight: 700;
  color: var(--primary);
}

.trial-sub {
  font-size: .75rem;
  color: var(--primary-mid);
  margin-top: .1rem;
}

.trial-diamond {
  position: absolute;
  right: .5rem;
  top: .5rem;
  width: 36px;
  height: 36px;
  opacity: .7;
}

.trial-diamond svg { width: 36px; height: 36px; }

.upgrade-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .45rem .8rem;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .3rem;
  transition: background .15s;
}

.upgrade-btn:hover { background: var(--primary-dark); }

.user-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .3rem .2rem;
}

.user-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}

.chevron-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: .1rem .3rem;
  transition: color .15s;
}

.chevron-btn:hover { color: var(--text-primary); }

.action-row {
  display: flex;
  gap: .4rem;
  padding: .1rem .1rem;
}

.action-btn {
  background: none;
  border: none;
  border-radius: var(--radius);
  padding: .4rem;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}

.action-btn svg { width: 17px; height: 17px; }
.action-btn:hover { color: var(--text-primary); background: var(--surface-alt); }

/* ===== Main Area ===== */
.main-area {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ===== Pages ===== */
.page {
  display: none;
  flex: 1;
  overflow: hidden;
}

.page.active {
  display: flex;
  flex-direction: column;
}

/* ===== Home Page ===== */
#page-home.active {
  overflow-y: auto;
  background: var(--surface-alt);
  align-items: center;
  justify-content: flex-start;
}

.home-content {
  width: 100%;
  max-width: 860px;
  padding: 2.5rem 2rem;
  margin: 0 auto;
}

.home-welcome-card {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.home-welcome-avatar {
  font-size: 2.8rem;
  line-height: 1;
  flex-shrink: 0;
}

.home-welcome-text h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: .3rem;
}

.home-welcome-text p {
  font-size: .875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.onboarding-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.onboarding-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: box-shadow .18s;
}

.onboarding-card:hover { box-shadow: var(--shadow-md); }

.card-icons { font-size: 1.3rem; letter-spacing: .1rem; }

.onboarding-card h3 {
  font-size: .975rem;
  font-weight: 700;
  color: var(--text-primary);
}

.onboarding-card p {
  font-size: .82rem;
  color: var(--text-secondary);
  line-height: 1.55;
  flex: 1;
}

.card-link {
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  margin-top: .25rem;
  display: inline-block;
}

.card-link:hover { text-decoration: underline; }

/* ===== Conversations Page ===== */
#page-conversations.active {
  flex-direction: row;
}

/* Channel Sidebar */
.channel-sidebar {
  width: var(--channel-w);
  min-width: var(--channel-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .75rem 0;
  gap: .5rem;
  overflow-y: auto;
}

.channel-filter-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: .4rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
  margin-bottom: .25rem;
}

.channel-filter-btn svg { width: 18px; height: 18px; }
.channel-filter-btn:hover { color: var(--text-primary); background: var(--surface-alt); }

.channel-icon-list {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  width: 100%;
  align-items: center;
}

.ch-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform .15s, opacity .15s;
  flex-shrink: 0;
}

.ch-icon svg { width: 20px; height: 20px; }
.ch-icon:hover { transform: scale(1.1); opacity: .9; }

.ch-green  { background: #25D366; }
.ch-teal   { background: #06B6A2; }
.ch-blue   { background: #1877F2; }
.ch-pink   { background: linear-gradient(135deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888); }
.ch-cyan   { background: #229ED9; }
.ch-red    { background: #EF4444; }
.ch-olive  { background: #07C160; }

/* Inbox Panel */
.inbox-panel {
  width: var(--inbox-w);
  min-width: var(--inbox-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.inbox-search-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem .85rem;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.inbox-search-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  padding: .35rem .75rem;
  gap: .45rem;
  transition: border-color .15s;
}

.inbox-search-input-wrap:focus-within {
  border-color: var(--primary);
}

.inbox-search-icon { width: 14px; height: 14px; color: var(--text-muted); flex-shrink: 0; }

#inbox-search {
  border: none;
  background: transparent;
  outline: none;
  font-size: .82rem;
  color: var(--text-primary);
  font-family: var(--font);
  width: 100%;
}

#inbox-search::placeholder { color: var(--text-muted); }

.inbox-export-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: .35rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}

.inbox-export-btn svg { width: 16px; height: 16px; }
.inbox-export-btn:hover { color: var(--text-primary); background: var(--surface-alt); }

.inbox-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.inbox-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: .65rem .5rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.inbox-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.inbox-tab:hover:not(.active) { color: var(--text-primary); }

.inbox-conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: .5rem;
}

.inbox-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: .75rem;
  color: var(--text-muted);
  font-size: .875rem;
  padding: 2rem;
  text-align: center;
}

.empty-envelope { width: 90px; opacity: .8; }

/* Conversation items */
.conv-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .6rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid var(--border-light);
}

.conv-item:hover { background: var(--surface-alt); }
.conv-item.active { background: var(--primary-light); }

/* Delete button – hidden by default, appears on hover */
.conv-delete-btn {
  position: absolute;
  right: .4rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: .25rem;
  cursor: pointer;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.conv-item { position: relative; }
.conv-item:hover .conv-delete-btn { opacity: 1; }
.conv-delete-btn:hover { color: var(--error, #ef4444); border-color: var(--error, #ef4444); }

.conv-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  font-weight: 700;
  flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }

.conv-name {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: .35rem;
}

.conv-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.conv-channel-badge {
  font-size: .68rem;
  font-weight: 500;
  padding: .1rem .35rem;
  border-radius: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}

.conv-channel-wa {
  background: #dcfce7;
  color: #15803d;
}

.conv-preview {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: .1rem;
}

.conv-time {
  font-size: .72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* New Conv Button */
.new-conv-btn {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(79,70,229,.4);
  transition: background .15s, transform .1s;
  z-index: 10;
}

.new-conv-btn svg { width: 20px; height: 20px; }
.new-conv-btn:hover { background: var(--primary-dark); transform: scale(1.05); }
.new-conv-btn:active { transform: scale(.95); }

/* ===== Right Panel ===== */
.right-panel {
  flex: 1;
  min-width: 0;
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Right Welcome */
.right-welcome {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.right-welcome-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.right-welcome-avatar { font-size: 2.4rem; flex-shrink: 0; }

.right-welcome-text h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: .25rem;
}

.right-welcome-text p {
  font-size: .83rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.right-cards {
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.right-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s;
}

.right-card:hover { box-shadow: var(--shadow-md); }

.right-card-icons { font-size: 1.25rem; letter-spacing: .05rem; margin-bottom: .35rem; }

.right-card h4 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: .3rem;
}

.right-card p {
  font-size: .82rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: .5rem;
}

.right-card-link {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  padding: 0;
  font-family: var(--font);
  transition: opacity .15s;
}

.right-card-link:hover { opacity: .75; }

/* ===== Active Chat ===== */
.active-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.active-chat.hidden { display: none; }

.active-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.25rem;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
}

.active-chat-info {
  display: flex;
  align-items: center;
  gap: .7rem;
}

.active-chat-avatar { font-size: 1.5rem; line-height: 1; }

.active-chat-name {
  font-size: .95rem;
  font-weight: 700;
}

.active-chat-status {
  font-size: .72rem;
  opacity: .85;
  color: #a5f3fc;
}

.active-chat-status.offline { color: #fca5a5; }

.active-chat-actions {
  display: flex;
  gap: .35rem;
}

.chat-action-btn {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: var(--radius);
  padding: .4rem .5rem;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.chat-action-btn svg { width: 16px; height: 16px; }
.chat-action-btn:hover { background: rgba(255,255,255,.25); }

.chat-messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  background: var(--surface-alt);
  scroll-behavior: smooth;
}

.chat-messages-area::-webkit-scrollbar { width: 4px; }
.chat-messages-area::-webkit-scrollbar-track { background: transparent; }
.chat-messages-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

.chat-footer {
  flex-shrink: 0;
  padding: .75rem 1.25rem .65rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .45rem .45rem .45rem .85rem;
  transition: border-color .15s, box-shadow .15s;
}

.chat-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text-primary);
  outline: none;
  max-height: 110px;
  overflow-y: auto;
  line-height: 1.5;
  padding: .1rem 0;
}

#message-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

.send-btn:disabled { background: var(--border); cursor: not-allowed; }
.send-btn:not(:disabled):hover { background: var(--primary-dark); }
.send-btn:not(:disabled):active { transform: scale(.92); }
.send-btn svg { width: 16px; height: 16px; }

.chat-input-hint {
  font-size: .7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: .4rem;
}

/* Message bubbles */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: .45rem;
  animation: fadeIn .2s ease-out;
}

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

.message-row.user { flex-direction: row-reverse; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar.bot-avatar-sm  { background: var(--primary-light); }
.avatar.user-avatar-sm { background: var(--primary); color: #fff; }

.bubble-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  gap: .15rem;
}

.message-row.user .bubble-wrapper { align-items: flex-end; }

.bubble {
  padding: .6rem .95rem;
  border-radius: 18px;
  font-size: .88rem;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble.bot  { background: var(--bot-bubble); color: var(--text-primary); border-bottom-left-radius: 4px; }
.bubble.user { background: var(--user-bubble); color: var(--user-bubble-txt); border-bottom-right-radius: 4px; }
.bubble.error { background: #fee2e2; color: var(--error); border: 1px solid #fecaca; }

.timestamp { font-size: .67rem; color: var(--text-muted); padding: 0 .2rem; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: .45rem;
  animation: fadeIn .2s ease-out;
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: .6rem .95rem;
  background: var(--bot-bubble);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: var(--radius-full);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
  0%,80%,100% { transform: scale(.7); opacity: .5; }
  40%          { transform: scale(1);  opacity: 1;  }
}

/* ===== Page Inner Layout (Customers / Channels / AppStore) ===== */
.page-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface-alt);
}

#page-customers.active,
#page-channels.active,
#page-whatsapp.active,
#page-appstore.active { background: var(--surface-alt); }

.page-title-bar {
  padding: 1.25rem 1.5rem .75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.page-title-bar h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== Customers Page ===== */
.customer-filters {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: .75rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.filter-field label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.filter-field input,
.filter-field select {
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface);
  outline: none;
  min-width: 180px;
  transition: border-color .15s;
}

.filter-field input:focus,
.filter-field select:focus { border-color: var(--primary); }

.filter-actions {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.customer-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.5rem;
}

.customer-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  font-size: .875rem;
}

.customer-table th {
  background: var(--surface-alt);
  padding: .75rem 1rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.customer-table td {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.table-empty-row td { padding: 0; border-bottom: none; }

.table-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
}

.table-empty-state svg { width: 160px; height: 130px; opacity: .85; }

/* Pagination */
.pagination-bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.5rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: .825rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.pagination-total { margin-right: .5rem; }

.pagination-controls {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.page-btn {
  min-width: 30px;
  height: 30px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  font-size: .82rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0 .4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s, color .15s;
}

.page-btn:disabled { opacity: .45; cursor: not-allowed; }

.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.page-btn:not(.active):not(:disabled):hover { border-color: var(--primary); color: var(--primary); }

.page-size-select {
  padding: .3rem .5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .82rem;
  color: var(--text-secondary);
  background: var(--surface);
  cursor: pointer;
  outline: none;
}

.page-jump-input {
  width: 48px;
  padding: .3rem .4rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .82rem;
  text-align: center;
  color: var(--text-primary);
  outline: none;
  font-family: var(--font);
}

.page-jump-input:focus { border-color: var(--primary); }

/* ===== AI Bot Page ===== */
#page-aibot.active {
  background: var(--surface-alt);
}

.aibot-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.aibot-tabs-bar {
  display: flex;
  align-items: center;
  gap: .25rem;
  padding: .85rem 1.5rem .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.aibot-tab {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  padding: .5rem 1.1rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.aibot-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.aibot-tab:not(.active):hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

.aibot-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.aibot-search-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  padding: .4rem .85rem;
  flex: 1;
  max-width: 360px;
  transition: border-color .15s;
}

.aibot-search-wrap:focus-within { border-color: var(--primary); }

.aibot-search-icon { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }

.aibot-search-input {
  border: none;
  background: transparent;
  outline: none;
  font-size: .875rem;
  font-family: var(--font);
  color: var(--text-primary);
  width: 100%;
}

.aibot-search-input::placeholder { color: var(--text-muted); }

.aibot-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
}

.aibot-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 4rem 1rem;
  color: var(--text-muted);
  font-size: .9rem;
}

.aibot-empty svg { width: 100px; height: 100px; }

/* ===== Generic Empty (Channels / App Store) ===== */
.generic-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: .9rem;
  gap: .75rem;
}

.generic-empty svg { width: 100px; height: 100px; }

/* ===== Required field star ===== */
.req-star { color: var(--error); margin-left: .1rem; }

/* ===== New Bot Modal ===== */
.nb-modal { max-width: 560px; }

.nb-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.nb-modal-header h2 { margin-bottom: 0; }

.nb-close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}

.nb-close-btn:hover { background: var(--surface-alt); color: var(--text-primary); }
.nb-close-btn svg { width: 18px; height: 18px; }

.nb-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .85rem;
  margin-bottom: 1.5rem;
}

.nb-avatar-label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-primary);
  align-self: flex-start;
}

.nb-avatar-preview-wrap {
  display: flex;
  justify-content: center;
  padding: .25rem 0;
}

.nb-avatar-preview {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border: 3px solid var(--primary);
  box-shadow: 0 4px 16px rgba(79,70,229,.25);
  transition: background .2s, border-color .2s;
}

.nb-avatar-preview svg { width: 48px; height: 48px; }

.nb-avatar-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  justify-content: center;
}

.nb-avatar-opt {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color .15s, transform .15s;
}

.nb-avatar-opt:hover { transform: scale(1.07); }
.nb-avatar-opt.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.nb-avatar-opt svg { width: 30px; height: 30px; }

.nb-textarea {
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface-alt);
  resize: vertical;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.nb-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.13);
}

/* ===== Bot Cards in aibot-content ===== */
.bot-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.bot-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.bot-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }

.bot-card-top {
  display: flex;
  align-items: center;
  gap: .85rem;
}

.bot-card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bot-card-avatar svg { width: 26px; height: 26px; }

.bot-card-info { flex: 1; min-width: 0; }

.bot-card-name {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-card-desc {
  font-size: .8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: .2rem;
}

.bot-card-footer { display: flex; justify-content: flex-end; gap: .5rem; }

.bot-card-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .75rem;
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.bot-card-edit-btn:hover { background: #ddd6fe; }
.bot-card-edit-btn svg { width: 13px; height: 13px; }

.bot-card-delete-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .75rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.bot-card-delete-btn:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.bot-card-delete-btn svg { width: 13px; height: 13px; }

.bot-card-meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.bot-card-model-badge {
  display: inline-block;
  padding: .15rem .5rem;
  background: var(--surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 500;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-card-status {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}

.bot-card-status--draft {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #cbd5e1;
}

.bot-card-status--published {
  background: #dcfce7;
  color: #16a34a;
  border: 1px solid #86efac;
}

.bot-card-assign-badge {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .72rem;
  color: var(--text-secondary);
  padding: .2rem .5rem;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  width: fit-content;
}

.bot-card-assign-badge--active {
  background: #ede9fe;
  color: #6d28d9;
  border-color: #c4b5fd;
}

.bc-topbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ===== Bot Config Page ===== */
#page-aibot-config.active {
  background: var(--surface-alt);
  overflow: hidden;
}

.bc-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.bc-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.bc-back-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  padding: .4rem .6rem;
  transition: background .15s, color .15s;
}

.bc-back-btn:hover { background: var(--surface-alt); color: var(--text-primary); }
.bc-back-btn svg { width: 16px; height: 16px; }

.bc-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Left form panel */
.bc-form-panel {
  flex: 0 0 58%;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.bc-section {
  padding: 1.5rem 1.75rem;
  border-bottom: 1px solid var(--border);
}

.bc-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.bc-input-wrap { position: relative; }

.bc-input-wrap input {
  width: 100%;
  padding: .6rem .85rem;
  padding-right: 4.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface-alt);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.bc-input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.13);
}

.bc-counter {
  position: absolute;
  right: .75rem;
  bottom: .65rem;
  font-size: .75rem;
  color: var(--text-muted);
  pointer-events: none;
}

.bc-textarea {
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface-alt);
  resize: vertical;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.6;
}

.bc-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.13);
}

.bc-textarea-wrap { position: relative; }

.bc-textarea-counter { bottom: .5rem; }

.bc-persona-presets {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .6rem;
}

.bc-preset-tag {
  background: var(--primary-light);
  color: var(--primary);
  border: 1.5px solid #c7d2fe;
  border-radius: var(--radius-full);
  padding: .3rem .8rem;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.bc-preset-tag:hover { background: #ddd6fe; border-color: var(--primary); }

.bc-add-product-btn {
  width: 100%;
  justify-content: flex-start;
  border-style: dashed;
}

.bc-knowledge-row {
  display: flex;
  gap: .75rem;
  align-items: center;
}

.bc-knowledge-select {
  flex: 1;
  padding: .55rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface-alt);
  outline: none;
  cursor: pointer;
}

.bc-knowledge-select:focus { border-color: var(--primary); }

/* Version badge */
.bc-version-badge {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .2rem .65rem;
  letter-spacing: .03em;
  white-space: nowrap;
}

/* Toggle switch */
.bc-toggle-row {
  display: flex;
  align-items: center;
  margin-bottom: .5rem;
}

.bc-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  cursor: pointer;
  font-size: .875rem;
  color: var(--text-primary);
  user-select: none;
}

.bc-toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.bc-toggle-switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  background: var(--border);
  border-radius: 999px;
  transition: background .2s;
  flex-shrink: 0;
}

.bc-toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}

.bc-toggle-input:checked + .bc-toggle-switch {
  background: var(--primary);
}

.bc-toggle-input:checked + .bc-toggle-switch::after {
  transform: translateX(14px);
}

/* Channel behavior blocks */
.bc-channel-block {
  margin-bottom: 1rem;
}

.bc-channel-block:last-child { margin-bottom: 0; }

.bc-channel-hint { margin-top: .25rem; }

/* Preview channel segmented control */
.bc-channel-seg {
  display: inline-flex;
  align-items: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}

.bc-channel-seg-btn {
  padding: .25rem .65rem;
  font-size: .8rem;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.bc-channel-seg-btn:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.bc-channel-seg-btn.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* Skills list */
.bc-skill-list {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.bc-skill-row {
  display: flex;
  align-items: center;
}

/* Mobile tab bar (hidden on desktop) */
.bc-tab-bar {
  display: none;
}

/* Right preview panel */
.bc-preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.bc-preview-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-shrink: 0;
}

.bc-preview-info {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  flex: 1;
  min-width: 0;
}

.bc-preview-title {
  font-size: .875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.bc-preview-desc {
  font-size: .75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.bc-preview-controls {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-shrink: 0;
}

.bc-btn-sm { padding: .3rem .65rem; font-size: .8rem; }

.bc-model-group {
  display: flex;
  align-items: center;
  gap: .4rem;
}

.bc-model-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.bc-model-dropdown { position: relative; }

.bc-model-btn {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: .35rem .7rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  min-width: 130px;
  transition: border-color .15s;
}

.bc-model-btn:hover { border-color: var(--primary); }
.bc-model-btn[aria-expanded="true"] { border-color: var(--primary); }

.bc-model-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 100;
  min-width: 160px;
  overflow: hidden;
  animation: slideUp .15s ease-out;
}

.bc-model-option {
  padding: .55rem 1rem;
  font-size: .875rem;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  transition: background .12s;
}

.bc-model-option:hover { background: var(--surface-alt); }
.bc-model-option.selected { color: var(--primary); font-weight: 600; }
.bc-model-option.unavailable { color: var(--text-muted); cursor: default; }
.bc-model-option.unavailable:hover { background: none; }

.bc-model-check { width: 14px; height: 14px; color: var(--primary); flex-shrink: 0; }

.bc-model-separator {
  padding: .3rem 1rem;
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--surface-alt);
  font-weight: 600;
  letter-spacing: .03em;
}

.bc-preview-chat {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.bc-preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
  font-size: .875rem;
  text-align: center;
  padding: 2rem;
  min-height: 180px;
}

/* Preview chat message rows */
.bc-msg-row {
  display: flex;
  gap: .6rem;
  align-items: flex-end;
}

.bc-msg-row.user { flex-direction: row-reverse; }

.bc-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  flex-shrink: 0;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.bc-msg-bubble {
  max-width: 75%;
  padding: .55rem .9rem;
  border-radius: var(--radius-lg);
  font-size: .875rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.bc-msg-row.bot  .bc-msg-bubble { background: var(--bot-bubble); color: var(--text-primary); border-bottom-left-radius: 4px; }
.bc-msg-row.user .bc-msg-bubble { background: var(--user-bubble); color: var(--user-bubble-txt); border-bottom-right-radius: 4px; }
.bc-msg-row.error .bc-msg-bubble { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }

.bc-preview-footer {
  border-top: 1px solid var(--border);
  padding: .85rem 1.25rem;
  flex-shrink: 0;
}

.bc-preview-input-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  padding: .4rem .4rem .4rem .9rem;
  transition: border-color .15s;
}

.bc-preview-input-row:focus-within { border-color: var(--primary); }

.bc-preview-input-row input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: .875rem;
  font-family: var(--font);
  color: var(--text-primary);
}

.bc-preview-input-row input::placeholder { color: var(--text-muted); }

.bc-preview-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border: none;
  cursor: pointer;
  color: #fff;
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}

.bc-preview-send-btn:hover { background: var(--primary-dark); }
.bc-preview-send-btn:disabled { background: var(--border); cursor: not-allowed; }
.bc-preview-send-btn:not(:disabled):active { transform: scale(.92); }
.bc-preview-send-btn svg { width: 14px; height: 14px; }

/* Preview typing dots (reuses bounce keyframe from typing-dots) */
.bc-typing-wrap { display: flex; gap: 4px; align-items: center; padding: .2rem .1rem; }
.bc-typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce .9s infinite ease-in-out;
}
.bc-typing-dot:nth-child(2) { animation-delay: .15s; }
.bc-typing-dot:nth-child(3) { animation-delay: .3s; }

/* ===== WhatsApp Channel Page ===== */
#page-whatsapp.active { background: var(--surface-alt); }

.wa-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
}

.wa-header-left {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.wa-header-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: #25D366;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wa-header-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== Channel Cards Grid (Channels page) ===== */
.channel-cards-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  padding: 1.5rem;
}

.channel-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  min-width: 120px;
}

.channel-card:hover {
  border-color: #25D366;
  box-shadow: var(--shadow-md);
}

.channel-card-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.channel-card-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ===== WhatsApp Status Badge ===== */
.wa-status-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  font-weight: 600;
  padding: .2rem .6rem;
  border-radius: var(--radius-full);
}

.wa-status-badge.active {
  background: #dcfce7;
  color: #16a34a;
}

.wa-status-badge.inactive {
  background: var(--surface-alt);
  color: var(--text-muted);
}

.wa-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.wa-status-badge.active .wa-status-dot { background: #22c55e; }
.wa-status-badge.inactive .wa-status-dot { background: var(--text-muted); }

/* ===== WhatsApp action menu button ===== */
.wa-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: .25rem .4rem;
  border-radius: var(--radius);
  font-size: .875rem;
  transition: background .12s;
}

.wa-action-btn:hover { background: var(--surface-alt); }

/* ===== WhatsApp New Account Modal ===== */
.wa-modal { max-width: 480px; }

/* ===== WhatsApp QR Modal ===== */
.wa-qr-modal-inner {
  max-width: 700px;
  width: 100%;
}

.wa-qr-body {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  margin: 1.25rem 0 1.5rem;
}

.wa-qr-instructions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: .5rem;
}

.wa-qr-step {
  font-size: .9rem;
  color: var(--text-primary);
  line-height: 1.5;
  padding-left: 1.1rem;
  position: relative;
}

.wa-qr-step::before {
  content: '';
  position: absolute;
  left: 0;
  top: .55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #25D366;
}

.wa-qr-canvas-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.wa-qr-canvas-wrap canvas {
  width: 200px !important;
  height: 200px !important;
}

.wa-qr-success {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
}

.wa-qr-success svg { width: 52px; height: 52px; }

.wa-qr-success span {
  font-size: 1rem;
  font-weight: 700;
  color: #16a34a;
}

.wa-qr-phone-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 20px 0;
}

.wa-qr-phone-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.wa-qr-phone-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--surface-alt, #f8f9fa);
  color: var(--text-primary);
  box-sizing: border-box;
}

.wa-qr-phone-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Dark mode ===== */
body.dark {
  --surface:         #1e1e2d;
  --surface-alt:     #16161f;
  --border:          #2d2d3f;
  --border-light:    #252535;
  --text-primary:    #e2e8f0;
  --text-secondary:  #94a3b8;
  --text-muted:      #64748b;
  --bot-bubble:      #252535;
  --primary-light:   #1e1b4b;
  --shadow-sm:       0 1px 3px rgba(0,0,0,.3);
  --shadow-md:       0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:       0 12px 40px rgba(0,0,0,.5);
}

body.dark .modal-overlay { background: rgba(0,0,0,.7); }

body.dark .form-group input,
body.dark .form-group textarea,
body.dark .nb-textarea { background: var(--surface); color: var(--text-primary); border-color: var(--border); }

body.dark .wa-qr-phone-input { background: var(--surface); }

body.dark .wa-qr-success { background: rgba(30,30,45,.92); }
body.dark .wa-qr-success span { color: #4ade80; }

body.dark .wa-dropdown-item-danger:hover { background: rgba(239,68,68,.15); }

body.dark .wa-bot-tag { background: #2d1f5e; color: #a78bfa; }
body.dark .conv-ai-badge { background: #2d1f5e; color: #a78bfa; }

body.dark .action-btn:hover { background: rgba(255,255,255,.08); }

body.dark #theme-btn { color: #fbbf24; }

body.dark .mobile-top-bar { background: var(--surface); border-bottom-color: var(--border); }
body.dark .mobile-menu-btn:hover { background: rgba(255,255,255,.08); }
body.dark .mobile-action-btn:hover { background: rgba(255,255,255,.08); }
body.dark #mobile-theme-btn { color: #fbbf24; }

/* ===== Mobile Top Bar ===== */
.mobile-top-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 .75rem;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
  position: sticky;
  top: 0;
}

.mobile-menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  padding: .4rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.mobile-menu-btn svg { width: 22px; height: 22px; }
.mobile-menu-btn:hover { background: var(--surface-alt); }

.mobile-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.mobile-brand-icon { width: 28px; height: 28px; flex-shrink: 0; }
.mobile-brand-icon svg { width: 28px; height: 28px; }

.mobile-brand-name {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.mobile-top-actions {
  display: flex;
  gap: .2rem;
}

.mobile-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: .4rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}

.mobile-action-btn svg { width: 18px; height: 18px; }
.mobile-action-btn:hover { color: var(--text-primary); background: var(--surface-alt); }

/* ===== Sidebar Overlay Backdrop ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 399;
  backdrop-filter: blur(2px);
}

/* ===== Sidebar Mobile Close Button ===== */
.sidebar-mobile-close {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: .3rem;
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}

.sidebar-mobile-close svg { width: 18px; height: 18px; }
.sidebar-mobile-close:hover { color: var(--text-primary); background: var(--surface-alt); }

/* ===== Chat Back Button (mobile) ===== */
.chat-back-btn {
  display: none;
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: var(--radius);
  padding: .4rem .5rem;
  cursor: pointer;
  color: #fff;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  margin-right: .35rem;
  flex-shrink: 0;
}

.chat-back-btn svg { width: 18px; height: 18px; }
.chat-back-btn:hover { background: rgba(255,255,255,.25); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  :root { --inbox-w: 280px; }
}

/* Tablet: icon-only sidebar, hide channel sidebar (not applied on mobile where overlay is used) */
@media (min-width: 641px) and (max-width: 768px) {
  .sidebar { width: 64px; min-width: 64px; }
  .sidebar .brand-name,
  .sidebar .nav-text,
  .sidebar .trial-card,
  .sidebar .user-name,
  .sidebar .chevron-btn { display: none; }
  .sidebar .nav-item { justify-content: center; padding: .7rem 0; }
  .sidebar .user-row { justify-content: center; }

  .channel-sidebar { display: none; }
  :root { --inbox-w: 260px; }
}

@media (max-width: 560px) {
  .new-conv-btn { bottom: .75rem; right: .75rem; }
  .customer-filters { flex-direction: column; align-items: stretch; }
  .filter-field input, .filter-field select { min-width: unset; width: 100%; }
  .modal { max-height: 90vh; overflow-y: auto; }
}

/* ===== Mobile layout (≤ 640px) ===== */
@media (max-width: 640px) {
  /* Show mobile top bar */
  .mobile-top-bar { display: flex; }

  /* Sidebar becomes fixed overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    z-index: 400;
    transform: translateX(-100%);
    transition: transform .25s ease, box-shadow .25s;
    box-shadow: none;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* Sidebar content is fully visible in mobile overlay */
  .sidebar .nav-item { justify-content: flex-start; padding: .65rem .75rem; }
  .sidebar .user-row { justify-content: flex-start; }

  /* Show sidebar close button, hide collapse button */
  .sidebar-mobile-close { display: flex; }
  .sidebar-collapse-btn { display: none; }

  /* Show sidebar overlay when active */
  .sidebar-overlay { display: block; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar-overlay.active { opacity: 1; pointer-events: auto; }

  /* Main area occupies full width */
  .main-area { width: 100%; }

  /* Conversations page: default shows inbox, hides chat */
  .channel-sidebar { display: none; }
  .inbox-panel {
    display: flex;
    width: 100%;
    min-width: 0;
  }
  .right-panel { display: none; }

  /* When mobile chat is active: show chat, hide inbox */
  #page-conversations.mobile-chat-active .inbox-panel { display: none; }
  #page-conversations.mobile-chat-active .right-panel {
    display: flex;
    flex: 1;
    width: 100%;
  }

  /* Show back button in chat header */
  #page-conversations.mobile-chat-active .chat-back-btn { display: flex; }

  /* Page inner layouts on mobile */
  .page-inner { overflow-y: auto; }
  .page-title-bar { padding: 1rem 1rem .6rem; }

  /* Home page padding */
  .home-content { padding: 1.25rem 1rem; }
  .home-welcome-card { padding: 1rem; gap: .85rem; }

  /* Modals full-width on mobile */
  .modal { padding: 1.5rem 1.25rem; border-radius: var(--radius); }
  .modal-overlay { padding: .75rem; }

  /* Customer filters */
  .customer-filters { flex-direction: column; align-items: stretch; }
  .filter-field input, .filter-field select { min-width: unset; width: 100%; }

  /* nb-modal full-width */
  .nb-modal { max-width: 100%; }

  /* Chat input padding */
  .chat-footer { padding: .65rem .85rem .55rem; }
  .chat-messages-area { padding: .85rem .9rem; }

  /* Active chat header padding */
  .active-chat-header { padding: .7rem .85rem; }

  /* === AI Bot Config page mobile layout === */

  /* Compact topbar: wrap to two lines if needed */
  .bc-topbar {
    flex-wrap: wrap;
    gap: .4rem;
    padding: .6rem 1rem;
  }
  .bc-topbar-actions { gap: .35rem; }
  .bc-topbar-actions .btn { padding: .35rem .6rem; font-size: .8rem; }
  .bc-version-badge { font-size: .75rem; padding: .15rem .45rem; }
  .bc-back-btn { font-size: .85rem; }

  /* Show mobile tab bar */
  .bc-tab-bar {
    display: flex;
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .bc-tab-btn {
    flex: 1;
    padding: .6rem 0;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color .15s, border-color .15s;
  }
  .bc-tab-btn--active {
    color: var(--accent, #6d28d9);
    border-bottom-color: var(--accent, #6d28d9);
  }

  /* Stack panels vertically; each panel fills the remaining space */
  .bc-body {
    flex-direction: column;
    overflow: hidden;
  }
  .bc-form-panel {
    flex: 1;
    border-right: none;
    border-bottom: 1px solid var(--border);
    width: 100%;
    min-height: 0;
  }
  .bc-preview-panel {
    flex: 1;
    width: 100%;
    min-height: 0;
    display: none;
  }

  /* When preview tab is active, swap visibility */
  .bc-body.bc-show-preview .bc-form-panel { display: none; }
  .bc-body.bc-show-preview .bc-preview-panel { display: flex; }

  /* Compact preview topbar on mobile */
  .bc-preview-topbar {
    flex-wrap: wrap;
    padding: .75rem 1rem;
    gap: .5rem;
  }
  .bc-preview-controls {
    flex-wrap: wrap;
    gap: .4rem;
  }
}

/* ===== WA Action Dropdown ===== */
.wa-action-dropdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 120px;
  padding: .25rem 0;
  overflow: hidden;
}

.wa-dropdown-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  width: 100%;
  padding: .5rem .85rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .85rem;
  color: var(--text-primary);
  text-align: left;
  transition: background .12s;
}

.wa-dropdown-item:hover { background: var(--surface-alt); }

.wa-dropdown-item-danger { color: var(--error); }
.wa-dropdown-item-danger:hover { background: #fef2f2; }

/* ===== WA Bot Tag (in status column) ===== */
.wa-bot-tag {
  display: inline-block;
  font-size: .72rem;
  padding: .1rem .4rem;
  border-radius: var(--radius);
  background: #ede9fe;
  color: #6d28d9;
  margin-left: .35rem;
  vertical-align: middle;
}

/* ===== AI 託管 Toggle (chat header) ===== */
.ai-managed-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  cursor: pointer;
  margin-right: .4rem;
}

.ai-managed-text {
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.ai-managed-checkbox {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ai-managed-slider {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  background: var(--text-muted);
  border-radius: 10px;
  transition: background .2s;
  flex-shrink: 0;
}

.ai-managed-slider::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}

.ai-managed-checkbox:checked ~ .ai-managed-slider {
  background: var(--primary);
}

.ai-managed-checkbox:checked ~ .ai-managed-slider::after {
  transform: translateX(14px);
}

/* ===== AI 託管 Badge (conversation list) ===== */
.conv-ai-badge {
  font-size: .68rem;
  font-weight: 600;
  padding: .1rem .35rem;
  border-radius: 4px;
  flex-shrink: 0;
  white-space: nowrap;
  background: #ede9fe;
  color: #5b21b6;
  margin-left: .25rem;
}

/* ===== User Menu Dropdown ===== */
.user-menu-dropdown {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  padding: .3rem 0;
  z-index: 2000;
  min-width: 170px;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  width: 100%;
  padding: .5rem .9rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .875rem;
  color: var(--text-primary);
  text-align: left;
  transition: background .12s;
}

.user-menu-item:hover { background: var(--surface-alt); }

.user-menu-separator {
  height: 1px;
  background: var(--border-light);
  margin: .3rem 0;
}

.user-menu-lang-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .5rem .9rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .875rem;
  color: var(--text-primary);
  text-align: left;
  transition: background .12s;
}

.user-menu-lang-row:hover { background: var(--surface-alt); }

.user-menu-lang-arrow {
  font-size: .8rem;
  color: var(--text-muted);
  line-height: 1;
}

.user-lang-submenu {
  display: none;
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  padding: .3rem 0;
  z-index: 2001;
  min-width: 150px;
}

.user-menu-lang-row:hover .user-lang-submenu,
.user-lang-submenu:hover { display: block; }

.lang-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .5rem .9rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .875rem;
  color: var(--text-primary);
  text-align: left;
  transition: background .12s;
  gap: .5rem;
}

.lang-option:hover { background: var(--surface-alt); }

.lang-option.active { color: var(--primary); font-weight: 600; }

.lang-check-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--primary);
}

/* ── Voice AI Page ─────────────────────────────────────────────────── */
.voice-ai-page { display: flex; flex-direction: column; height: 100%; padding: 0; }
.voice-ai-page .page-title-bar { padding: 1.25rem 1.5rem .75rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.voice-ai-page .page-title-bar h2 { margin: 0; font-size: 1.25rem; font-weight: 600; color: var(--text-primary); }

/* Call form */
.voice-call-form { padding: .75rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.voice-call-form .form-row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.voice-call-form .form-group { display: flex; flex-direction: column; gap: .25rem; }
.voice-call-form .form-group label { font-size: .8rem; font-weight: 500; color: var(--text-secondary); }
.voice-call-form .form-group input { padding: .45rem .75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-alt); color: var(--text-primary); font-size: .875rem; min-width: 200px; }
.voice-call-form .form-group--btn { flex-direction: row; gap: .5rem; }
.voice-call-status { margin-top: .5rem; padding: .5rem .75rem; border-radius: 6px; font-size: .875rem; }
.voice-call-status.success { background: #d1fae5; color: #065f46; }
.voice-call-status.error   { background: #fee2e2; color: #991b1b; }

/* Two-column body */
.voice-ai-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* Call list sidebar */
.voice-call-list { width: 280px; min-width: 220px; border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; background: var(--surface); flex-shrink: 0; }
.voice-call-list__header { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 1px solid var(--border); font-size: .8rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; flex-shrink: 0; }
.voice-call-items { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.voice-call-item { display: flex; flex-direction: column; gap: 3px; padding: .75rem 1rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.voice-call-item:hover { background: var(--surface-alt); }
.voice-call-item.active { background: color-mix(in srgb, var(--primary) 10%, transparent); border-left: 3px solid var(--primary); }
.voice-call-item__phone { font-weight: 500; font-size: .875rem; color: var(--text-primary); }
.voice-call-item__meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.voice-call-item__date { font-size: .7rem; color: var(--text-muted, #a0aec0); }
.voice-badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: .7rem; font-weight: 500; }
.voice-badge--outbound { background: #bee3f8; color: #2b6cb0; }
.voice-badge--inbound  { background: #c6f6d5; color: #276749; }
.voice-badge--unknown  { background: var(--border); color: var(--text-secondary); }
.voice-badge--started  { background: #fefcbf; color: #744210; }
.voice-badge--ended    { background: var(--border); color: var(--text-secondary); }
.voice-badge--failed   { background: #fed7d7; color: #9b2c2c; }
.voice-state-msg { padding: .75rem 1rem; font-size: .8rem; color: var(--text-secondary); }
.voice-state-msg--error { color: #e53e3e; }

/* Detail panel */
.voice-call-detail { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; background: var(--surface-alt, #f9fafb); }
.voice-call-detail__empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 1rem; color: var(--text-secondary); font-size: .875rem; }
.voice-call-detail__content { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.voice-call-detail__header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.voice-call-detail__phone { margin: 0 0 .5rem; font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.voice-call-detail__meta { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; font-size: .75rem; color: var(--text-secondary); }
.voice-detail-recordings { padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.voice-recording-item { display: flex; align-items: center; gap: .75rem; padding: .4rem 0; }
.voice-recording-item audio { flex: 1; height: 32px; min-width: 0; }
.voice-recording-label { font-size: .75rem; font-weight: 500; color: var(--primary); min-width: 60px; }
.voice-detail-transcript { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: .75rem 1.25rem; }
.voice-transcript-title { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); margin-bottom: .5rem; flex-shrink: 0; }
.voice-transcript-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .75rem; padding-right: 4px; }
.voice-bubble { display: flex; flex-direction: column; max-width: 72%; padding: .6rem .9rem; border-radius: 12px; word-break: break-word; }
.voice-bubble--ai       { align-self: flex-start; background: #eef2ff; border-bottom-left-radius: 2px; }
.voice-bubble--customer { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 2px; }
.voice-bubble__sender { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; opacity: .7; margin-bottom: 3px; }
.voice-bubble__content { margin: 0; font-size: .875rem; line-height: 1.5; }
.voice-bubble__time { font-size: .65rem; margin-top: 4px; opacity: .6; align-self: flex-end; }

/* Responsive */
@media (max-width: 640px) {
  .voice-ai-body { flex-direction: column; }
  .voice-call-list { width: 100%; max-height: 220px; border-right: none; border-bottom: 1px solid var(--border); }
  .voice-bubble { max-width: 90%; }
}

/* =========================================================
   Unified WhatsApp + Voice AI Page
   ========================================================= */

/* Page layout: full-height two-column */
#page-unified { padding: 0; overflow: hidden; }
.unified-page {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ── Left panel ──────────────────────────────── */
.unified-left-panel {
  width: 320px;
  min-width: 240px;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  overflow: hidden;
}
.unified-search-bar {
  padding: .75rem 1rem .5rem;
  border-bottom: 1px solid var(--border);
}
.unified-search-input {
  width: 100%;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: .875rem;
  outline: none;
  box-sizing: border-box;
}
.unified-search-input:focus { border-color: var(--primary); }
.unified-filter-chips {
  display: flex;
  gap: .4rem;
  padding: .5rem 1rem;
  flex-wrap: wrap;
}
.unified-chip {
  padding: .25rem .7rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: .75rem;
  cursor: pointer;
  transition: all .15s;
}
.unified-chip:hover { border-color: var(--primary); color: var(--primary); }
.unified-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.unified-contact-list {
  flex: 1;
  overflow-y: auto;
}
.unified-contact-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: .875rem;
}
.unified-contact-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
  min-height: 64px;
}
.unified-contact-item:hover { background: var(--surface); }
.unified-contact-item.active { background: var(--surface); border-left: 3px solid var(--primary); }
.unified-contact-item__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}
.unified-contact-item__body { flex: 1; min-width: 0; }
.unified-contact-item__name {
  font-weight: 600;
  font-size: .875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unified-contact-item__snippet {
  font-size: .75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.unified-contact-item__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .25rem;
  flex-shrink: 0;
}
.unified-contact-item__ts {
  font-size: .68rem;
  color: var(--text-secondary);
}
.unified-ai-badge {
  font-size: .6rem;
  background: #7c3aed;
  color: #fff;
  border-radius: 10px;
  padding: 1px 5px;
  font-weight: 600;
}

/* ── Right panel ─────────────────────────────── */
.unified-right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.unified-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 1rem;
  color: var(--text-secondary);
  padding: 2rem;
  text-align: center;
}
.unified-welcome-icon { font-size: 3rem; }
.unified-welcome h3 { margin: 0; color: var(--text-primary); font-size: 1.1rem; }
.unified-welcome p { margin: 0; font-size: .9rem; }
.unified-contact-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Top bar */
.unified-topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.unified-back-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: .25rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.unified-back-btn:hover { background: var(--surface); }
.unified-contact-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .875rem;
  color: #fff;
  flex-shrink: 0;
}
.unified-contact-info { flex: 1; min-width: 0; }
.unified-contact-name {
  font-weight: 600;
  font-size: .95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unified-contact-name[contenteditable="true"] {
  border-bottom: 1px dashed var(--primary);
  outline: none;
  cursor: text;
}
.unified-contact-phone { font-size: .75rem; color: var(--text-secondary); }
.unified-topbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.unified-ai-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  cursor: pointer;
  font-size: .8rem;
  color: var(--text-secondary);
}
.unified-ai-text { white-space: nowrap; }
.unified-bot-select,
.unified-wa-select {
  font-size: .8rem;
  padding: .25rem .5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-primary);
  max-width: 160px;
}
.unified-call-btn { font-size: .8rem; padding: .3rem .7rem; }

/* Timeline feed */
.unified-timeline {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.unified-timeline-loading {
  text-align: center;
  color: var(--text-secondary);
  font-size: .875rem;
  padding: 1rem;
}
.unified-load-more {
  text-align: center;
  padding: .5rem 0 0;
}

/* Timeline event bubbles */
.unified-event { display: flex; flex-direction: column; }
.unified-event--inbound { align-items: flex-start; }
.unified-event--outbound { align-items: flex-end; }
.unified-bubble {
  max-width: 72%;
  padding: .6rem .9rem;
  border-radius: 12px;
  word-break: break-word;
  font-size: .875rem;
  line-height: 1.5;
  position: relative;
}
.unified-bubble--wa-inbound  { background: var(--surface); border-bottom-left-radius: 2px; color: var(--text-primary); }
.unified-bubble--wa-outbound-human { background: #22c55e; color: #fff; border-bottom-right-radius: 2px; }
.unified-bubble--wa-outbound-ai  { background: #7c3aed; color: #fff; border-bottom-right-radius: 2px; }
.unified-bubble__label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .75;
  margin-bottom: 3px;
}
.unified-bubble__text { margin: 0; white-space: pre-wrap; }
.unified-bubble__ts { font-size: .65rem; opacity: .65; margin-top: 4px; align-self: flex-end; display: block; }

/* Voice call card */
.unified-voice-card {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .75rem 1rem;
  background: var(--surface);
  cursor: pointer;
}
.unified-voice-card:hover { border-color: var(--primary); }
.unified-voice-card__header {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.unified-voice-icon { font-size: 1.2rem; }
.unified-voice-card__detail {
  display: none;
  margin-top: .75rem;
  border-top: 1px solid var(--border);
  padding-top: .75rem;
  flex-direction: column;
  gap: .5rem;
}
.unified-voice-card.expanded .unified-voice-card__detail { display: flex; }
.unified-voice-transcript-item { font-size: .8rem; }
.unified-voice-sender { font-weight: 600; margin-right: .25rem; }

/* Input bar */
.unified-input-bar {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.unified-source-toggle {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  flex-shrink: 0;
}
.unified-source-btn {
  padding: .2rem .5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: .72rem;
  cursor: pointer;
  white-space: nowrap;
}
.unified-source-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.unified-message-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .6rem .85rem;
  background: var(--surface);
  color: var(--text-primary);
  font-size: .9rem;
  line-height: 1.4;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
}
.unified-message-input:focus { border-color: var(--primary); }

/* Responsive: stack on small screens */
@media (max-width: 640px) {
  .unified-page { flex-direction: column; }
  .unified-left-panel {
    width: 100%;
    max-width: 100%;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .unified-topbar { flex-wrap: wrap; }
  .unified-topbar-actions { width: 100%; }
  .unified-back-btn { display: flex !important; }
  .unified-bubble { max-width: 90%; }
}
@media (min-width: 641px) {
  .unified-back-btn { display: none; }
}
