* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #eae6df;
  --panel-bg: #ffffff;
  --panel-header: #f0f2f5;
  --surface: #f0f2f5;
  --surface2: #e9edef;
  --border: #e2e2e2;
  --text: #111b21;
  --text-dim: #667781;
  --teal: #008069;
  --teal-dark: #006a56;
  --teal-light: #00a884;
  --outgoing: #d9fdd3;
  --incoming: #ffffff;
  --blue: #027eb5;
  --orange: #e68a00;
  --red: #ea0038;
  --wa-green: #25d366;
  --email-blue: #027eb5;
  --chat-bg: #efeae2;
  --search-bg: #f0f2f5;
  --hover: #f5f6f6;
  --selected: #f0f2f5;
  --unread: #25d366;
  --bubble-shadow: rgba(0,0,0,0.06);
}

body {
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: fixed;
  width: 100%;
}

.screen { display: none; height: 100vh; height: 100dvh; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }

/* Login */
#login-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(180deg, var(--teal) 0%, var(--teal) 220px, var(--bg) 220px);
}
.login-box {
  background: var(--panel-bg);
  padding: 2.5rem 2rem;
  border-radius: 8px;
  width: 340px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.login-box h1 {
  margin-bottom: 1.5rem;
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text);
}
.login-box form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-box select,
.login-box input {
  padding: 0.65rem 0.75rem;
  background: var(--panel-bg);
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.login-box select:focus,
.login-box input:focus { border-bottom-color: var(--teal); }
.login-box select option { background: var(--panel-bg); }
.login-box button {
  padding: 0.7rem;
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.95rem;
  margin-top: 0.5rem;
  transition: background 0.15s;
}
.login-box button:hover { background: var(--teal-dark); }
.error { color: var(--red); font-size: 0.85rem; text-align: center; }
.success-msg { color: var(--teal); font-size: 0.85rem; text-align: center; }
.login-link { display: block; text-align: center; margin-top: 0.5rem; color: var(--teal); font-size: 0.85rem; text-decoration: none; }
.login-link:hover { text-decoration: underline; }
.login-subtitle { color: var(--text-secondary, #888); font-size: 0.9rem; margin-bottom: 0.25rem; }

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--panel-header);
  min-height: 50px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.header-left h1 { font-size: 1rem; font-weight: 500; color: var(--text-dim); }
#user-display { color: var(--text-dim); font-size: 0.8rem; }
.header-right { display: flex; gap: 0.5rem; align-items: center; }
.review-status { font-size: 0.75rem; padding: 0.25rem 0.6rem; border-radius: 12px; white-space: nowrap; cursor: default; }
.review-status.ok { background: rgba(39,174,96,0.15); color: #27ae60; }
.review-status.idle { background: rgba(150,150,150,0.15); color: #999; }
.review-status.alert { background: rgba(231,76,60,0.15); color: #e74c3c; font-weight: 600; }

/* WhatsApp Health Indicator */
.wa-health { position: relative; }
.wa-health-badge {
  font-size: 0.75rem; padding: 0.25rem 0.6rem; border-radius: 12px;
  white-space: nowrap; cursor: pointer; display: inline-block;
  transition: background 0.3s, color 0.3s;
}
.wa-health-badge.low { background: rgba(39,174,96,0.15); color: #27ae60; }
.wa-health-badge.medium { background: rgba(243,156,18,0.2); color: #d4a017; font-weight: 600; }
.wa-health-badge.high { background: rgba(230,126,34,0.2); color: #e67e22; font-weight: 600; }
.wa-health-badge.critical { background: rgba(231,76,60,0.25); color: #e74c3c; font-weight: 700; animation: wa-pulse 1.5s infinite; }
.wa-health-badge.offline { background: rgba(150,150,150,0.15); color: #999; }
@keyframes wa-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
.wa-health-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--panel-bg, #1e1e2e); border: 1px solid var(--border, #333);
  border-radius: 8px; padding: 0.75rem; min-width: 260px; z-index: 999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3); font-size: 0.8rem;
}
.wa-health.open .wa-health-dropdown { display: block; }
.wa-health-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.wa-health-header strong { font-size: 0.85rem; }
#wa-health-score { font-size: 0.75rem; opacity: 0.7; }
#wa-health-reasons { margin-bottom: 0.5rem; }
#wa-health-reasons div { padding: 0.15rem 0; font-size: 0.78rem; }
#wa-health-stats { font-size: 0.72rem; opacity: 0.6; border-top: 1px solid var(--border, #333); padding-top: 0.4rem; }
#wa-health-stats span { margin-right: 0.75rem; }
.btn-small {
  padding: 0.4rem 0.9rem;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.78rem;
  background: var(--teal);
  color: white;
  transition: background 0.15s;
}
.btn-small:hover { background: var(--teal-dark); }
.btn-muted {
  background: transparent;
  color: var(--text-dim);
  border: none;
}
.btn-muted:hover { color: var(--text); background: var(--hover); }

/* Dashboard */
.dashboard {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Left Panel */
.panel-left {
  width: 400px;
  min-width: 280px;
  max-width: 700px;
  border-right: none;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
}

.panel-resize-handle {
  width: 4px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
}
.panel-resize-handle:hover,
.panel-resize-handle.dragging {
  background: var(--teal);
}

.filters {
  padding: 0.5rem 0.75rem;
  background: var(--panel-bg);
}
.filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 0.5rem;
}
.tab {
  flex: 1;
  padding: 0.4rem 0.25rem;
  border: none;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 20px;
  font-size: 0.78rem;
  transition: all 0.15s;
}
.tab.active {
  background: rgba(0,128,105,0.12);
  color: var(--teal);
  font-weight: 500;
}
.tab:hover:not(.active) { background: var(--hover); }
#search-input {
  width: 100%;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
#search-input::placeholder { color: var(--text-dim); }

.enquiry-list {
  flex: 1;
  overflow-y: auto;
}

/* Chat Cards */
.enquiry-card {
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  border-bottom: none;
  transition: background 0.1s;
}
.enquiry-card:hover { background: var(--hover); }
.enquiry-card.selected { background: var(--selected); }
.enquiry-card.followup { border-left: 3px solid #9b59b6; background: rgba(155, 89, 182, 0.12); }
.enquiry-card.followup.selected { background: rgba(155, 89, 182, 0.18); border-left: 3px solid #9b59b6; }
.enquiry-card.archived { border-left: 3px solid #e74c3c; background: rgba(231, 76, 60, 0.12); }
.enquiry-card.archived.selected { background: rgba(231, 76, 60, 0.18); border-left: 3px solid #e74c3c; }

.card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #dfe5e7;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #ffffff;
  font-weight: 500;
  text-transform: uppercase;
  background-color: #6a7175;
}

.unread-dot {
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--unread);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: white;
  font-weight: 600;
}
.unread-dot:empty {
  width: 20px;
  height: 20px;
}
.unread-dot.hidden { display: none; }

.card-body { flex: 1; min-width: 0; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.card-name { font-weight: 400; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.card-time { color: var(--text-dim); font-size: 0.7rem; white-space: nowrap; }
.card-time.unread { color: var(--unread); }

.card-bottom { display: flex; justify-content: space-between; align-items: center; }

.card-meta { display: flex; gap: 0.35rem; align-items: center; }
.badge {
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-wa { background: #e7ffdb; color: #1d6e3a; }
.badge-email { background: #e3f2fd; color: #1565c0; }
.badge-web { background: #fff3e0; color: #e65100; }
.badge-manual { background: var(--surface); color: var(--text-dim); }
.badge-livechat { background: #e8f5e9; color: #2e7d32; }
.badge-booked { background: #dcf8c6; color: #1d6e3a; }
.draft-badge { font-size: 0.7rem; color: var(--teal); font-weight: 600; font-style: italic; margin-right: 2px; }
.badge-status { font-size: 0.65rem; color: var(--text-dim); }
.badge-assigned { font-size: 0.65rem; color: var(--teal); }

.card-preview {
  color: var(--text-dim);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Right Panel */
.panel-right {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}
.empty-state {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  color: var(--text-dim);
  font-size: 0.9rem;
  flex-direction: column;
  gap: 0.5rem;
}
.empty-state::before {
  content: '';
  display: block;
  width: 260px;
  height: 260px;
  background: #d4dbe0;
  border-radius: 50%;
  opacity: 0.3;
}

/* Conversation Header */
.convo-header {
  padding: 0.6rem 1rem;
  background: var(--panel-header);
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 50px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.convo-client { display: flex; flex-direction: column; gap: 1px; }
.convo-client-name { font-weight: 400; font-size: 0.95rem; color: var(--text); }
.convo-client-info { font-size: 0.75rem; color: var(--text-dim); }
.enquiry-info { font-size: 0.72rem; color: #5b6abf; font-weight: 500; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.booking-info { font-size: 0.72rem; color: #1d6e3a; font-weight: 500; margin-top: 1px; }
.booking-info span { background: #dcf8c6; padding: 1px 6px; border-radius: 4px; margin-right: 4px; }
.convo-actions { display: flex; gap: 0.5rem; align-items: center; }
.convo-actions select {
  padding: 0.3rem 0.5rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  outline: none;
  cursor: pointer;
}

.btn-archive {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.btn-archive:hover { background: var(--border); color: var(--text); }

.card-context-menu {
  position: fixed;
  z-index: 1000;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  padding: 4px 0;
  min-width: 140px;
}
.ctx-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  transition: background 0.1s;
}
.ctx-item:hover { background: var(--hover); }
.ctx-item.ctx-danger { color: var(--red); }
.ctx-item.ctx-danger:hover { background: rgba(234,0,56,0.08); }

/* Chat Bubbles */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 3.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background-color: var(--chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg width='412' height='412' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='p' width='20.6' height='20.6' patternUnits='userSpaceOnUse'%3E%3Ccircle cx='3' cy='3' r='0.8' fill='%23c9c4bc' fill-opacity='0.3'/%3E%3Ccircle cx='13' cy='10' r='0.6' fill='%23c9c4bc' fill-opacity='0.2'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='412' height='412' fill='url(%23p)'/%3E%3C/svg%3E");
}

.msg {
  max-width: 65%;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  font-size: 0.87rem;
  line-height: 1.35;
  position: relative;
  margin-bottom: 1px;
  box-shadow: 0 1px 0.5px var(--bubble-shadow);
  overflow-wrap: break-word;
  word-break: break-word;
}
/* Invisible hover extension so mouse can reach the react button outside the bubble */
.msg-client::after {
  content: '';
  position: absolute;
  top: 0;
  right: -40px;
  width: 40px;
  height: 100%;
}
.msg-agent::before {
  content: '';
  position: absolute;
  top: 0;
  left: -40px;
  width: 40px;
  height: 100%;
}
.msg-client {
  align-self: flex-start;
  background: var(--incoming);
  border-top-left-radius: 0;
}
.msg-agent {
  align-self: flex-end;
  background: var(--outgoing);
  color: var(--text);
  border-top-right-radius: 0;
}
.msg-body-text {
  white-space: pre-wrap;
}

/* Bubble tails */
.msg-client::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 8px solid var(--incoming);
}
.msg-agent::after {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 8px solid var(--outgoing);
}

/* Email bubble colours */
.msg-client[data-channel="email"] { background: #e8f0fe; }
.msg-client[data-channel="email"]::before { border-right-color: #e8f0fe; }
.msg-agent[data-channel="email"] { background: #c4d9f5; }
.msg-agent[data-channel="email"]::after { border-left-color: #c4d9f5; }

/* Hide tails on consecutive same-side messages */
.msg-client + .msg-client::before,
.msg-agent + .msg-agent::after { display: none; }
.msg-client + .msg-client { border-top-left-radius: 8px; }
.msg-agent + .msg-agent { border-top-right-radius: 8px; }

.msg-system {
  align-self: center;
  max-width: 80%;
  background: #fef9e7;
  border: 1px solid #f0e6c0;
  border-radius: 8px;
  padding: 8px 14px;
  text-align: center;
  font-size: 0.85em;
  color: #5a5a3e;
  margin: 6px auto;
}
.msg-system-body { line-height: 1.4; }
.msg-system-time { font-size: 0.75em; color: #999; margin-top: 4px; }

/* Internal notes */
.msg-internal {
  align-self: flex-end;
  max-width: 75%;
  background: #fef3cd;
  border: 1px solid #f0dfa0;
  border-left: 3px solid #e0a800;
  border-radius: 12px 12px 4px 12px;
  padding: 6px 10px;
  position: relative;
  margin: 4px 8px;
}
.msg-internal .msg-menu-btn {
  position: absolute; top: 2px; right: 4px;
  background: none; border: none; cursor: pointer; font-size: 0.85rem; color: #b0960a; opacity: 0;
}
.msg-internal:hover .msg-menu-btn { opacity: 1; }
.msg-internal-label {
  font-size: 0.72em;
  font-weight: 600;
  color: #856404;
  margin-bottom: 2px;
}
.btn-note-toggle {
  background: none; border: none; font-size: 1.1rem; cursor: pointer; opacity: 0.4;
  padding: 2px 4px; border-radius: 4px; transition: all 0.15s;
}
.btn-note-toggle:hover { opacity: 0.7; }
.btn-note-toggle.active {
  opacity: 1; background: #fef3cd; box-shadow: 0 0 0 1px #e0a800;
}
.reply-area.note-mode {
  background: #fef9e7;
  border-left: 3px solid #e0a800;
}

.msg code.wa-mono {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.85em;
}
.msg-sender-name {
  font-weight: 600;
  color: var(--primary);
}
.msg-meta {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 2px;
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 0;
}
.msg-channel-icon { font-size: 0.65rem; }
.msg-status { font-size: 0.7rem; color: #92a58c; letter-spacing: -1px; }
.msg-status.read { color: #53bdeb; }
.msg-sending { opacity: 0.65; }
.msg-sending-indicator { animation: typing-pulse 1.5s ease-in-out infinite; }
.msg-failed { border-left: 3px solid var(--red); opacity: 0.9; background: rgba(231, 76, 60, 0.08); }
.msg-fail-label { color: var(--red); font-size: 0.72rem; font-weight: 600; }
.msg-retry-btn { background: none; border: 1px solid var(--red); color: var(--red); font-size: 0.7rem; padding: 1px 8px; border-radius: 10px; cursor: pointer; margin-left: 6px; }
.msg-retry-btn:hover { background: var(--red); color: #fff; }
.msg-media-pending { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 4px; }
.typing-indicator { font-size: 0.72rem; color: var(--teal); font-style: italic; animation: typing-pulse 1.5s ease-in-out infinite; }
@keyframes typing-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.msg-subject { font-weight: 500; margin-bottom: 3px; font-size: 0.8rem; color: var(--teal); }

.msg-media { margin-bottom: 4px; }
.msg-media img { max-width: 280px; max-height: 300px; border-radius: 6px; cursor: pointer; display: block; }
.msg-media video { max-width: 280px; max-height: 300px; border-radius: 6px; display: block; }
.msg-media audio { max-width: 260px; display: block; }
.msg-doc-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 6px 10px; border-radius: 6px;
  background: var(--surface2); color: var(--text);
  text-decoration: none; font-size: 0.82rem;
}
.msg-doc-link:hover { background: var(--border); }
.msg-download-btn {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 8px 14px; border-radius: 6px; border: 1px dashed var(--teal);
  background: transparent; color: var(--teal); font-size: 0.82rem;
  cursor: pointer; transition: background 0.15s;
}
.msg-download-btn:hover { background: rgba(0,128,105,0.08); }
.msg-download-btn:disabled { cursor: wait; opacity: 0.7; border-style: solid; }

/* Emoji Reactions */
.msg-react-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: -32px;
  width: 28px;
  height: 28px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: background 0.15s;
  padding: 0;
}
.msg:hover .msg-react-btn { display: flex; }
.msg-react-btn:hover { background: var(--hover); color: var(--text); }
.msg-agent .msg-react-btn { right: auto; left: -32px; }

/* Message dropdown chevron (WhatsApp Web style) */
.msg-menu-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: #d0d0d0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  z-index: 3;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.msg:hover .msg-menu-btn { display: flex; }
.msg-menu-btn:hover { background: #bbb; color: var(--text); }
.msg-client .msg-menu-btn { right: 4px; }
.msg-agent .msg-menu-btn { right: 4px; }

.msg-react-picker {
  position: absolute;
  top: -40px;
  right: -32px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 6px;
  display: flex;
  gap: 2px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  z-index: 10;
}
.msg-agent .msg-react-picker { right: auto; left: -32px; }
.msg-react-emoji {
  cursor: pointer;
  font-size: 1.2rem;
  padding: 2px 4px;
  border-radius: 6px;
  transition: background 0.1s, transform 0.1s;
  line-height: 1;
}
.msg-react-emoji:hover { background: var(--surface); transform: scale(1.25); }

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
}
.msg-reaction {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1px 6px;
  font-size: 0.78rem;
  line-height: 1.4;
  cursor: default;
}

/* Message Context Menu (WhatsApp Web style) */
.msg-context-menu {
  position: fixed;
  background: var(--panel-bg);
  border-radius: 12px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.18);
  z-index: 50;
  min-width: 180px;
  padding: 6px 0;
  overflow: hidden;
  animation: ctx-menu-in 0.12s ease-out;
}
@keyframes ctx-menu-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.msg-context-menu-item {
  padding: 10px 18px;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.1s;
  color: var(--text);
}
.msg-context-menu-item:hover { background: var(--hover); }
.msg-context-menu-item.danger { color: var(--red); }
.msg-context-menu-item.danger:hover { background: rgba(234,0,56,0.06); }
.msg-context-menu-item .ctx-icon { font-size: 0.9rem; width: 18px; text-align: center; }

/* Deleted message placeholder */
.msg-deleted { opacity: 0.7; }
.msg-deleted-text { font-style: italic; color: var(--text-dim); font-size: 0.84rem; }
.msg-edited-indicator { font-style: italic; color: var(--text-dim); font-size: 0.65rem; margin-right: 2px; }
#reply-preview.edit-mode { border-left-color: var(--orange); }

.msg-date-sep {
  align-self: center;
  background: var(--panel-bg);
  color: var(--text-dim);
  font-size: 0.72rem;
  padding: 4px 12px;
  border-radius: 8px;
  margin: 8px 0;
  box-shadow: 0 1px 0.5px var(--bubble-shadow);
}

/* Reply Area */
.reply-area {
  padding: 0.5rem 0.75rem;
  background: var(--panel-header);
  border-top: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.reply-resize-handle {
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 8px;
  cursor: ns-resize;
  z-index: 5;
}
.reply-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transition: background 0.15s;
}
.reply-resize-handle:hover::after {
  background: var(--teal);
}
@media (max-width: 768px) {
  .reply-resize-handle { display: none; }
}
.reply-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  align-items: center;
}
.reply-controls select,
.reply-controls input {
  padding: 0.35rem 0.6rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
}
.reply-controls input { flex: 1; }
.reply-controls input::placeholder { color: var(--text-dim); }
.reply-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.reply-row #reply-text {
  flex: 1;
  padding: 0.55rem 0.75rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  min-height: 42px;
  max-height: 310px; /* ~15 lines on desktop */
  font-family: inherit;
  outline: none;
  line-height: 1.35;
  overflow-y: auto;
  word-wrap: break-word;
  white-space: pre-wrap;
}
#reply-text:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  pointer-events: none;
}
#reply-text code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.85em;
}
/* Emoji picker button */
.btn-emoji {
  width: 36px;
  height: 36px;
  background: transparent !important;
  color: var(--text-dim) !important;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
  padding: 0;
}
.btn-emoji:hover { color: var(--teal) !important; background: var(--hover) !important; }
/* Emoji picker container */
.emoji-picker-container {
  position: absolute;
  bottom: 100%;
  right: 48px;
  z-index: 100;
  margin-bottom: 8px;
}
.emoji-picker-container emoji-picker {
  --num-columns: 8;
  --emoji-size: 1.4rem;
  --border-color: var(--border);
  --background: var(--panel-bg);
  --input-border-color: var(--border);
  --indicator-color: var(--teal);
  --category-font-color: var(--text-dim);
  height: 320px;
}
/* Floating format toolbar */
.format-toolbar {
  position: absolute;
  z-index: 100;
  display: flex;
  gap: 2px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  pointer-events: auto;
}
.format-toolbar button {
  width: 30px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.1s;
}
.format-toolbar button:hover { background: var(--hover); }
.format-toolbar::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--panel-bg);
}
/* placeholder handled via :empty::before for contenteditable */
.reply-row button {
  width: 42px;
  height: 42px;
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.reply-row button:hover { background: var(--teal-dark); }
.reply-row button:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-attach {
  width: 36px;
  height: 36px;
  background: transparent !important;
  color: var(--text-dim) !important;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}
.btn-attach:hover { color: var(--teal) !important; background: var(--hover) !important; }
.btn-camera {
  width: 36px;
  height: 36px;
  background: transparent !important;
  color: var(--text-dim) !important;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}
.btn-camera:hover { color: var(--teal) !important; background: var(--hover) !important; }

/* Camera overlay */
.camera-overlay {
  position: fixed; inset: 0; z-index: 10000; background: #000;
  display: flex; flex-direction: column;
  width: 100vw; height: 100vh; height: 100dvh;
  touch-action: none;
}
.camera-overlay video {
  flex: 1; width: 100%; min-height: 0; object-fit: cover;
}
.camera-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-around;
  padding: 1.5rem 1rem 2.5rem; background: linear-gradient(transparent, rgba(0,0,0,0.6));
}
.camera-shutter {
  width: 64px; height: 64px; border-radius: 50%;
  border: 4px solid #fff; background: rgba(255,255,255,0.3);
  cursor: pointer; transition: background 0.15s;
}
.camera-shutter:active { background: rgba(255,255,255,0.7); }
.camera-close, .camera-flip {
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.2);
  color: #fff; font-size: 1.4rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.camera-close:hover, .camera-flip:hover { background: rgba(255,255,255,0.35); }

/* Translate */
#translate-lang {
  padding: 0.3rem 0.5rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.78rem;
  outline: none;
  cursor: pointer;
}
#translate-lang:not([value=""]) { border-color: var(--teal); color: var(--teal); }
.translate-preview {
  display: none;
  font-size: 0.78rem;
  color: var(--text-dim);
  background: #f0faf7;
  border: 1px solid rgba(0,128,105,0.15);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  margin-bottom: 0.35rem;
  position: relative;
  line-height: 1.4;
}
.translate-preview.active { display: block; }
.translate-original-label {
  font-weight: 600;
  color: var(--teal);
}
#translate-undo {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1;
}
#translate-undo:hover { color: var(--red); }

/* Link Preview Card */
.link-preview-card {
  display: none;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  position: relative;
}
.link-preview-card.active { display: flex; }
.link-preview-card .lp-image {
  width: 72px;
  min-height: 72px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface);
  flex-shrink: 0;
}
.link-preview-card .lp-body {
  padding: 0.4rem 0.6rem;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.link-preview-card .lp-site {
  font-size: 0.68rem;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.link-preview-card .lp-title {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-preview-card .lp-desc {
  color: var(--text-dim);
  font-size: 0.75rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview-card .lp-close {
  position: absolute;
  top: 2px;
  right: 4px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1;
}
.link-preview-card .lp-close:hover { color: var(--text); }
.lp-loading {
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 0.3rem 0.6rem;
}

/* Link preview inside sent messages */
.msg-link-preview {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 0.3rem;
  text-decoration: none;
  color: inherit;
  font-size: 0.8rem;
  background: rgba(0,0,0,0.08);
}
.msg-link-preview:hover { opacity: 0.85; }
.msg-link-preview .lp-image {
  width: 64px;
  min-height: 64px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface);
  flex-shrink: 0;
}
.msg-link-preview .lp-body {
  padding: 0.3rem 0.5rem;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.msg-link-preview .lp-site {
  font-size: 0.65rem;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.msg-link-preview .lp-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-link-preview .lp-desc {
  color: var(--text-dim);
  font-size: 0.72rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  z-index: 100;
  justify-content: center;
  align-items: center;
}
.modal.active { display: flex; }
.modal-content {
  background: var(--panel-bg);
  padding: 1.5rem;
  border-radius: 8px;
  width: 420px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.modal-content h2 { margin-bottom: 1rem; font-size: 1.05rem; font-weight: 500; }
.modal-content form { display: flex; flex-direction: column; gap: 0.6rem; }
.modal-content input,
.modal-content textarea {
  padding: 0.55rem 0.75rem;
  background: var(--panel-bg);
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.modal-content input:focus,
.modal-content textarea:focus { border-bottom-color: var(--teal); }
.modal-content textarea { min-height: 80px; resize: vertical; border-radius: 8px; border: 1px solid var(--border); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; }
.modal-actions button {
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.85rem;
  background: var(--teal);
  color: white;
  transition: background 0.15s;
}
.modal-actions button:hover { background: var(--teal-dark); }
.modal-actions .btn-muted { background: transparent; color: var(--text-dim); }
.modal-actions .btn-muted:hover { background: var(--hover); color: var(--text); }
.btn-danger-outline { background: transparent; color: #e74c3c; border: 1px solid #e74c3c; border-radius: 6px; cursor: pointer; padding: 0.5rem 1rem; font-size: 0.85rem; transition: background 0.15s, color 0.15s; }
.btn-danger-outline:hover { background: #e74c3c; color: #fff; }

/* Urgency Badges */
.urgency-badge {
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 600;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.2px;
}
.urgency-green { background: #dcf8c6; color: #1d6e3a; }
.urgency-yellow { background: #fff3cd; color: #856404; }
.urgency-orange { background: #ffe0b2; color: #e65100; }
.urgency-red { background: #ffcdd2; color: #c62828; animation: pulse-urgency 2s ease-in-out infinite; }

@keyframes pulse-urgency {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Workshop Countdown Badges */
.ws-countdown {
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 600;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.2px;
}
.ws-overdue { background: #ffcdd2; color: #c62828; animation: pulse-urgency 2s ease-in-out infinite; }
.ws-today { background: #ff8a80; color: #fff; font-weight: 700; animation: pulse-urgency 1.5s ease-in-out infinite; }
.ws-tomorrow { background: #ffe0b2; color: #e65100; }
.ws-urgent { background: #fff3cd; color: #856404; }
.ws-soon { background: #e3f2fd; color: #1565c0; }
.ws-ok { background: #e8f5e9; color: #2e7d32; }

/* Photo Lightbox */
#photo-lightbox {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  justify-content: center;
  align-items: center;
}
#photo-lightbox.active { display: flex; }
.lb-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity 0.2s ease;
}
#photo-lightbox.visible .lb-backdrop { opacity: 1; }
.lb-content {
  position: relative;
  z-index: 1;
  transform: scale(0.8);
  opacity: 0;
  transition: all 0.2s ease;
}
#photo-lightbox.visible .lb-content {
  transform: scale(1);
  opacity: 1;
}
.lb-content img {
  max-width: 80vw;
  max-height: 80vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.lb-close {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: background 0.15s;
}
.lb-close:hover { background: var(--hover); }

.card-avatar.has-photo { cursor: pointer; }
.card-avatar.has-photo:hover { opacity: 0.85; }

/* Duplicate Warning */
.dup-warning {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
  color: #856404;
}
.dup-warning strong { display: block; margin-bottom: 4px; }
.dup-match {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.dup-match:last-child { border-bottom: none; }
.dup-match-info { font-size: 0.78rem; }
.dup-match-btn {
  background: none;
  border: 1px solid #856404;
  color: #856404;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.72rem;
  cursor: pointer;
}
.dup-match-btn:hover { background: #856404; color: white; }

/* Quick Reply Dropdown */
.qr-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
  z-index: 50;
}
.qr-dropdown.active { display: block; }
.qr-dropdown-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--surface);
}
.qr-dropdown-item:last-child { border-bottom: none; }
.qr-dropdown-item:hover,
.qr-dropdown-item.selected { background: var(--hover); }
.qr-shortcut {
  font-weight: 600;
  color: var(--teal);
  min-width: 60px;
}
.qr-label { color: var(--text-dim); flex: 1; }
.qr-media-badge {
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 3px;
  background: #e3f2fd;
  color: #1565c0;
}
.qr-attach-indicator {
  font-size: 0.72rem;
  color: var(--teal);
  padding: 0;
  display: none;
}
.qr-attach-indicator.active { display: block; }
.attach-previews { display: flex; gap: 6px; flex-wrap: wrap; }
.attach-preview { position: relative; display: block; background: var(--bg-dark); border-radius: 8px; padding: 6px; margin: 4px 0; }
.attach-preview img { display: block; max-height: 120px; max-width: 140px; border-radius: 6px; object-fit: contain; }
.attach-preview.attach-file { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.attach-file-icon { font-size: 1.2rem; }
.attach-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-light); font-size: 0.8rem; }
.attach-remove { cursor: pointer; color: #fff; background: rgba(0,0,0,0.55); border-radius: 50%; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; position: absolute; top: 4px; right: 4px; line-height: 1; transition: background 0.15s; z-index: 1; }
.attach-remove:hover { background: rgba(200,50,50,0.8); }

/* Quick Reply Translations */
.qr-translations {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.qr-trans-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.qr-trans-lang {
  min-width: 24px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  padding-top: 6px;
  text-align: right;
}
.qr-trans-row textarea {
  flex: 1;
  min-height: 36px;
  font-size: 0.82rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  resize: vertical;
  background: var(--panel-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.qr-trans-row textarea:focus { border-color: var(--teal); }
.qr-trans-row textarea:not(:placeholder-shown) { background: #f0faf7; }
.qr-trans-count {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-left: 30px;
  margin-top: 2px;
}

/* Quick Reply Management Modal — Card-Based Redesign */
.modal-qr {
  width: 90vw;
  max-width: 1400px;
  max-height: 90vh;
  padding: 0;
  overflow: hidden;
  position: relative;
}
.modal-qr .qr-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  min-height: 54px;
}
.modal-qr .qr-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  flex: 1;
}
.qr-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#qr-search {
  padding: 0.35rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
  width: 180px;
  transition: border-color 0.2s;
}
#qr-search:focus { border-color: var(--teal); }
#qr-search::placeholder { color: var(--text-dim); }

/* Slide-over views */
.modal-qr .qr-views-wrapper {
  display: flex;
  width: 200%;
  transition: transform 0.3s ease;
}
.modal-qr.editing .qr-views-wrapper {
  transform: translateX(-50%);
}
.modal-qr .qr-view {
  width: 50%;
  flex-shrink: 0;
  overflow-y: auto;
}
.modal-qr .qr-form-view {
  display: flex;
  flex-direction: column;
  overflow-y: hidden;
  max-height: calc(90vh - 54px);
}

/* Cards view */
.qr-cards-body { padding: 1rem 1.25rem; }
.qr-cat-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.qr-cat-filter-btn {
  padding: 4px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}
.qr-cat-filter-btn:hover {
  border-color: var(--cat-color, var(--teal));
  background: color-mix(in srgb, var(--cat-color, var(--teal)) 10%, transparent);
}
.qr-cat-filter-btn.active {
  background: var(--cat-color, var(--teal));
  color: #fff;
  border-color: var(--cat-color, var(--teal));
}
.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.qr-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  position: relative;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.qr-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-color: #ccc;
}
.qr-card-shortcut {
  font-weight: 600;
  color: var(--teal);
  font-size: 0.92rem;
  margin-bottom: 2px;
}
.qr-card-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.qr-card-preview {
  font-size: 0.76rem;
  color: #999;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
  margin-bottom: 8px;
  min-height: 1.35em;
}
.qr-card-footer {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.qr-card-footer .lang-pill {
  font-size: 0.58rem;
  padding: 1px 5px;
  border-radius: 6px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.qr-card-footer .media-icon {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-left: auto;
}
.qr-card-edit {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--teal);
  background: rgba(0,128,105,0.08);
  border: none;
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.qr-card-edit:hover { background: rgba(0,128,105,0.18); }
.qr-card-delete {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}
.qr-card:hover .qr-card-delete { opacity: 1; }
.qr-card-delete:hover { color: var(--red); background: rgba(234,0,56,0.08); }

.qr-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
  padding: 2.5rem 1rem;
}
.qr-empty.hidden { display: none; }

/* Form view */
.qr-form-body {
  padding: 1rem 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.btn-back-qr {
  background: none;
  border: none;
  color: var(--teal);
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: background 0.15s;
}
.btn-back-qr:hover { background: rgba(0,128,105,0.08); }

.qr-form-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.qr-field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.qr-field-row label {
  font-size: 0.82rem;
  color: var(--text-dim);
  min-width: 70px;
  font-weight: 500;
}
.qr-field-row input,
.qr-field-row select {
  flex: 1;
  padding: 0.45rem 0.65rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.qr-field-row input:focus,
.qr-field-row select:focus { border-color: var(--teal); }

.qr-section-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

/* Translation rows in form */
.qr-form-trans-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 6px;
}
.qr-form-trans-row .qr-trans-badge {
  min-width: 28px;
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
  padding: 6px 0 0;
  text-transform: uppercase;
}
.qr-quill-wrap {
  flex: 1;
  min-width: 0;
}
.qr-quill-wrap .ql-toolbar {
  border-radius: 6px 6px 0 0;
  border-color: var(--border);
  padding: 4px 6px;
  background: var(--bg);
}
.qr-quill-wrap .ql-toolbar .ql-formats { margin-right: 8px; }
.qr-quill-wrap .ql-container {
  border-radius: 0 0 6px 6px;
  border-color: var(--border);
  font-size: 0.85rem;
  font-family: inherit;
  min-height: 60px;
  background: var(--panel-bg);
  color: var(--text);
}
.qr-quill-wrap .ql-editor {
  min-height: 60px;
  padding: 8px 10px;
  line-height: 1.5;
}
.qr-quill-wrap .ql-editor.ql-blank::before {
  font-style: normal;
  color: var(--text-dim);
}
.qr-quill-wrap .ql-container:focus-within { border-color: var(--teal); }
.qr-quill-wrap .ql-editor img {
  max-width: 120px;
  max-height: 90px;
  border-radius: 6px;
  border: 2px solid var(--border);
  vertical-align: middle;
  margin: 2px 4px;
  cursor: pointer;
  object-fit: cover;
}
.qr-form-trans-row textarea {
  flex: 1;
  min-height: 44px;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  resize: vertical;
  background: var(--panel-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.qr-form-trans-row textarea:focus { border-color: var(--teal); }
.qr-form-trans-row textarea:not(:placeholder-shown) { background: #f0faf7; }

/* File drop zone */
.qr-drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-top: 6px;
}
.qr-drop-zone:hover,
.qr-drop-zone.drag-over {
  border-color: var(--teal);
  background: rgba(0,128,105,0.04);
}
/* Multi-media grid for QR form */
.qr-media-grid:empty { display: none; }
.qr-media-grid { margin-top: 6px; }
.qr-media-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 6px;
}
.qr-media-item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  text-align: center;
  cursor: grab;
  transition: box-shadow 0.15s, opacity 0.15s;
}
.qr-media-item:active { cursor: grabbing; }
.qr-media-item.dragging { opacity: 0.4; box-shadow: 0 0 0 2px var(--teal); }
.qr-media-item.drag-over-item { box-shadow: 0 0 0 2px var(--teal); }
.qr-media-item.pending { border-style: dashed; }
.qr-media-item img {
  max-height: 80px;
  max-width: 100%;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  margin: 0 auto 4px;
}
.qr-media-item .qr-media-name {
  font-size: 0.7rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.qr-media-item .qr-media-icon {
  font-size: 2rem;
  display: block;
  margin: 4px auto;
}
.qr-media-item .qr-media-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 0.75rem;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.qr-media-item:hover .qr-media-remove { opacity: 1; }

/* Variables bar (sticky above form) */
.qr-variables-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.qr-variables-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.3px;
  margin-right: 4px;
}

/* Placeholder chips */
.qr-placeholders {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.qr-placeholder-chip {
  font-size: 0.75rem;
  padding: 3px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--teal);
  cursor: pointer;
  transition: background 0.15s;
  font-family: monospace;
}
.qr-placeholder-chip:hover { background: rgba(0,128,105,0.1); }

/* Form actions */
.qr-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.qr-form-actions button {
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.qr-btn-save { background: var(--teal); color: white; }
.qr-btn-save:hover { background: var(--teal-dark); }
.qr-btn-delete-form { background: transparent; color: var(--red); }
.qr-btn-delete-form:hover { background: rgba(234,0,56,0.08); }

/* Language Badge */
.lang-badge {
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 700;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.lang-en { background: #e3f2fd; color: #1565c0; }
.lang-es { background: #fff3e0; color: #e65100; }
.lang-fr { background: #ede7f6; color: #4527a0; }
.lang-de { background: #fce4ec; color: #c62828; }
.lang-pt { background: #e8f5e9; color: #2e7d32; }
.lang-it { background: #fff8e1; color: #f57f17; }
.lang-pl { background: #fce4ec; color: #ad1457; }
.lang-nl { background: #e0f2f1; color: #00695c; }
.lang-ru { background: #e8eaf6; color: #283593; }
.lang-fi { background: #e1f5fe; color: #0277bd; }
.lang-se { background: #fffde7; color: #f9a825; }
.lang-no { background: #fbe9e7; color: #bf360c; }
.lang-da { background: #f3e5f5; color: #6a1b9a; }
.lang-cs { background: #e0f7fa; color: #00838f; }
.lang-hu { background: #f1f8e9; color: #558b2f; }
.lang-ro { background: #fff3e0; color: #e65100; }
.lang-ar { background: #efebe9; color: #4e342e; }

/* Reply Preview Bar (above text input) */
.reply-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.65rem;
  background: var(--panel-bg);
  border-left: 3px solid var(--teal);
  border-radius: 6px;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
}
.reply-preview-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.reply-preview-sender {
  font-weight: 600;
  color: var(--teal);
  font-size: 0.75rem;
}
.reply-preview-body {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-preview-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-dim);
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.reply-preview-close:hover { color: var(--text); }

/* Quoted Message Snippet Inside Bubble */
.msg-quoted {
  background: rgba(0,0,0,0.06);
  border-left: 3px solid var(--teal);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1.3;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.msg-quoted:hover { background: rgba(0,0,0,0.1); }
.msg-quoted-sender {
  font-weight: 600;
  color: var(--teal);
  font-size: 0.72rem;
}
.msg-quoted-body {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-agent .msg-quoted { background: rgba(0,0,0,0.04); }

/* Pinned Messages Bar */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  cursor: pointer;
  min-height: 36px;
}
.pinned-bar:hover { background: var(--hover); }
.pinned-bar-icon { font-size: 0.9rem; flex-shrink: 0; }
.pinned-bar-body {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pinned-bar-count {
  color: var(--text-dim);
  font-size: 0.72rem;
  flex-shrink: 0;
}

/* Pin Submenu */
.has-submenu { position: relative; }
.pin-submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: -6px;
  background: var(--panel-bg);
  border-radius: 12px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.18);
  min-width: 130px;
  padding: 6px 0;
  z-index: 51;
}
.has-submenu:hover .pin-submenu { display: block; }

/* Star & Pin Indicators */
.msg-star-indicator, .msg-pin-indicator {
  font-size: 0.6rem;
  line-height: 1;
}

/* Context Menu Separator */
.ctx-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Forward Modal */
.forward-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  z-index: 110;
  display: flex;
  justify-content: center;
  align-items: center;
}
.forward-modal-content {
  background: var(--panel-bg);
  border-radius: 12px;
  width: 360px;
  max-height: 480px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  overflow: hidden;
}
.forward-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.forward-modal-header h3 { font-size: 1rem; font-weight: 500; margin: 0; }
.forward-modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-dim);
  line-height: 1;
  padding: 0 4px;
}
.forward-modal-close:hover { color: var(--text); }
.forward-search {
  margin: 0.5rem 0.75rem;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
.forward-search:focus { border-color: var(--teal); }
.forward-search::placeholder { color: var(--text-dim); }
.forward-list { flex: 1; overflow-y: auto; }
.forward-item {
  padding: 0.55rem 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-bottom: 1px solid var(--surface);
}
.forward-item:hover { background: var(--hover); }
.forward-item:last-child { border-bottom: none; }
.forward-item-name { font-size: 0.88rem; color: var(--text); }
.forward-item-info { font-size: 0.75rem; color: var(--text-dim); }

/* Voice Recording */
.btn-mic {
  width: 42px;
  height: 42px;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.btn-mic:hover { color: var(--teal); background: var(--hover); }
.btn-mic.recording {
  background: var(--red);
  color: white;
  animation: pulse-recording 1.5s ease-in-out infinite;
}
.btn-mic.recording:hover { background: #c62828; }
@keyframes pulse-recording {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
.voice-timer {
  font-size: 0.78rem;
  color: var(--red);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  flex-shrink: 0;
}

/* Voice Recording Bar */
.voice-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  padding: 0 0.25rem;
}
.voice-bar-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.voice-discard {
  background: transparent;
  color: var(--red);
  font-size: 1.2rem;
}
.voice-discard:hover { background: rgba(234,0,56,0.08); }
.voice-pause {
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  letter-spacing: -2px;
}
.voice-pause:hover { background: var(--hover); color: var(--text); }
.voice-send {
  background: var(--teal);
  color: white;
}
.voice-send:hover { background: var(--teal-dark); }
.voice-bar .voice-timer {
  font-size: 0.85rem;
  color: var(--red);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}
.voice-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
  animation: pulse-recording 1.5s ease-in-out infinite;
}
.voice-pulse-dot.paused {
  background: var(--text-dim);
  animation: none;
}

/* Settings Dropdown */
.settings-dropdown-wrap {
  position: relative;
  display: inline-block;
}
.settings-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  z-index: 200;
  min-width: 180px;
  padding: 0.3rem 0;
}
.settings-dropdown-wrap.open .settings-dropdown { display: block; }
.settings-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.settings-item:hover {
  background: var(--bg-elevated, #f0f0f0);
}
[data-theme="dark"] .settings-dropdown {
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* Action Items Bar */
.action-items-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.action-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
  user-select: none;
}
.action-chip:hover { opacity: 0.85; }
.action-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.action-count {
  font-weight: 700;
  min-width: 16px;
  text-align: center;
}
.action-red { background: #fde8e8; color: #b91c1c; }
.action-red .action-dot { background: #dc2626; }
.action-yellow { background: #fef3c7; color: #92400e; }
.action-yellow .action-dot { background: #f59e0b; }
.action-green { background: #d1fae5; color: #065f46; }
.action-green .action-dot { background: #10b981; }
.action-chip.action-active {
  outline: 2px solid currentColor;
  outline-offset: 1px;
  font-weight: 700;
}
[data-theme="dark"] .action-red { background: rgba(220,38,38,0.15); color: #fca5a5; }
[data-theme="dark"] .action-yellow { background: rgba(245,158,11,0.15); color: #fcd34d; }
[data-theme="dark"] .action-green { background: rgba(16,185,129,0.15); color: #6ee7b7; }

/* Card Select Mode */
.card-action-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--panel-header);
  border-bottom: 1px solid var(--border);
}
#card-select-count {
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 500;
  margin-right: auto;
}
.card-select-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-dim);
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--panel-bg);
  transition: all 0.15s;
}
.card-select-checkbox.checked {
  background: var(--teal);
  border-color: var(--teal);
}
.card-select-checkbox.checked::after {
  content: '\2713';
  color: white;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.enquiry-card.card-checked {
  background: rgba(0, 128, 105, 0.1);
}
.enquiry-card.card-checked:hover {
  background: rgba(0, 128, 105, 0.15);
}

/* Select Mode */
.select-mode .msg { cursor: pointer; transition: background 0.1s; }
.select-mode .msg:hover { filter: brightness(0.97); }
.msg-select-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-dim);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 4;
  background: var(--panel-bg);
  transition: all 0.15s;
}
.msg-client .msg-select-checkbox { left: -30px; }
.msg-agent .msg-select-checkbox { right: -30px; }
.msg-select-checkbox.checked {
  background: var(--teal);
  border-color: var(--teal);
}
.msg-select-checkbox.checked::after {
  content: '\2713';
  color: white;
  font-size: 0.7rem;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

/* Select Action Bar */
.select-action-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--panel-header);
  border-top: 1px solid var(--border);
}
#select-count {
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 500;
  margin-right: auto;
}
.select-act-btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s;
}
.select-act-btn:hover { background: var(--hover); }
.select-cancel { border-color: var(--text-dim); color: var(--text-dim); }
.select-cancel:hover { color: var(--text); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* Back button (hidden on desktop) */
.btn-back {
  display: none;
  background: none;
  border: none;
  color: var(--teal);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.4rem;
  margin-right: 0.3rem;
  flex-shrink: 0;
  line-height: 1;
}

/* ─── Mobile Responsive ─── */
@media (max-width: 768px) {
  header {
    padding: 0.4rem 0.6rem;
    min-height: 44px;
  }
  .header-left h1 { font-size: 0.9rem; }
  .btn-small { font-size: 0.72rem; padding: 0.35rem 0.7rem; }

  .dashboard {
    position: relative;
  }

  .panel-resize-handle { display: none; }

  .panel-left {
    width: 100%;
    min-width: 0;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 2;
    border-right: none;
    transition: transform 0.25s ease;
  }

  .panel-right {
  min-width: 0;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* When conversation is open: slide right panel in, slide left panel out */
  .dashboard.show-conversation .panel-left {
    transform: translateX(-100%);
  }
  .dashboard.show-conversation .panel-right {
  min-width: 0;
    transform: translateX(0);
    z-index: 3;
  }

  .btn-back { display: block; }

  /* Conversation adjustments */
  .convo-header {
    padding: 0.4rem 0.6rem;
    min-height: 44px;
    flex-shrink: 0;
    max-height: 30vh;
    overflow-y: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .convo-header::-webkit-scrollbar { display: none; }
  .reply-area {
    flex-shrink: 0;
  }
  .convo-client-name { font-size: 0.9rem; }
  .convo-client-info { font-size: 0.7rem; }
  .convo-actions select { font-size: 0.75rem; padding: 0.25rem 0.4rem; }

  .messages { padding: 0.6rem 0.8rem; }
  .msg { max-width: 85%; font-size: 0.85rem; }

  .reply-area { padding: 0.4rem 0.5rem; }
  .reply-controls { flex-wrap: wrap; gap: 0.3rem; }
  .reply-controls select, .reply-controls input { font-size: 0.75rem; padding: 0.25rem 0.4rem; }

  /* Mobile reply row: emoji | [text area with paperclip+camera inside] | mic/send */
  .reply-row { gap: 0.3rem; flex-wrap: nowrap; align-items: flex-end; }
  .reply-row .btn-emoji { order: 1; width: 34px; height: 34px; flex-shrink: 0; }
  .reply-row #reply-text { order: 2; flex: 1; min-width: 0; font-size: 0.85rem; min-height: 38px; max-height: 170px; padding-right: 68px; }
  .reply-row .btn-attach {
    order: unset; position: absolute; right: 82px; bottom: 5px;
    width: 28px; height: 28px; font-size: 0.95rem; z-index: 2;
  }
  .reply-row .btn-camera {
    order: unset; position: absolute; right: 52px; bottom: 5px;
    display: inline-flex; width: 28px; height: 28px; font-size: 0.95rem; z-index: 2;
  }
  .reply-row #btn-send { order: 3; display: none; }
  .reply-row .btn-mic { order: 4; flex-shrink: 0; width: 38px; height: 38px; background: var(--teal); color: #fff; border-radius: 50%; }

  /* When typing: swap mic for send, hide camera, keep paperclip inside */
  .reply-row.has-text .btn-camera { display: none !important; }
  .reply-row.has-text .btn-mic { display: none !important; }
  .reply-row.has-text #btn-send { display: flex !important; order: 4; width: 38px; height: 38px; font-size: 0.95rem; flex-shrink: 0; }
  .reply-row.has-text .btn-attach { right: 48px; }
  .reply-row.has-text #reply-text { padding-right: 36px; }

  /* Card adjustments */
  .card-avatar { width: 42px; height: 42px; font-size: 0.95rem; }
  .enquiry-card { padding: 0.55rem 0.7rem; gap: 0.6rem; }

  /* Filters */
  .filters { padding: 0.4rem 0.6rem; }
  .tab { font-size: 0.72rem; padding: 0.35rem 0.2rem; }
  #search-input { font-size: 0.82rem; padding: 0.4rem 0.6rem; }

  /* Modals full-width on mobile */
  .modal-content { width: calc(100% - 2rem); max-width: 420px; }
  .modal-qr {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .qr-grid { grid-template-columns: 1fr; }
  #qr-search { width: 120px; }

  /* Mobile emoji picker: docked to bottom like a keyboard */
  .emoji-picker-container {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    margin: 0 !important;
    z-index: 9999;
    background: var(--panel-bg);
    border-top: 1px solid var(--border);
  }
  .emoji-picker-container emoji-picker {
    width: 100%;
    height: 260px;
    --num-columns: 8;
  }
  /* Push reply area up when picker is open */
  .reply-area.emoji-open {
    padding-bottom: 268px;
  }

  /* Empty state smaller circle on mobile */
  .empty-state::before { width: 160px; height: 160px; }
}

/* Enquiry Notes Display (rich HTML in conversation header) */
.enquiry-notes-display {
  cursor: pointer;
  font-style: italic;
  color: var(--text-dim);
  display: inline;
  transition: color 0.15s;
}
.enquiry-notes-display:hover { color: var(--teal); text-decoration: underline; }
.enquiry-notes-display p { display: inline; margin: 0; }
.enquiry-notes-display ul,
.enquiry-notes-display ol { display: inline; margin: 0; padding-left: 1em; }

/* Quill Editor Overrides for Edit Modal */
#notes-editor {
  min-height: 80px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--panel-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
}
#notes-editor .ql-editor { min-height: 80px; }
#notes-editor .ql-editor.ql-blank::before { color: var(--text-dim); font-style: italic; }
#modal-edit-enquiry .ql-toolbar.ql-snow {
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
}
#modal-edit-enquiry .ql-snow .ql-stroke { stroke: var(--text-dim); }
#modal-edit-enquiry .ql-snow .ql-fill { fill: var(--text-dim); }
#modal-edit-enquiry .ql-snow .ql-picker-label { color: var(--text-dim); }

/* AI Sales Assistant */
.ai-toggle {
  padding: 0.2rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: none;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.15s;
}
.ai-toggle.active {
  border-color: #7c3aed;
  color: #7c3aed;
  background: rgba(124, 58, 237, 0.08);
}
.ai-preview {
  display: none;
  font-size: 0.8rem;
  color: var(--text);
  background: #f5f0ff;
  border: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.35rem;
  position: relative;
  line-height: 1.45;
}
.ai-preview.active { display: block; }
.ai-label {
  font-weight: 600;
  color: #7c3aed;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 0.25rem;
}
.ai-section { margin-bottom: 0.4rem; }
.ai-section:last-of-type { margin-bottom: 0.5rem; }
.ai-suggested {
  background: #fff;
  border: 1px solid rgba(124, 58, 237, 0.15);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  margin-top: 0.2rem;
  white-space: pre-wrap;
}
.ai-actions {
  display: flex;
  gap: 0.5rem;
}
.ai-actions button {
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  border: none;
  font-size: 0.78rem;
  cursor: pointer;
  font-weight: 600;
}
.ai-actions .ai-use {
  background: #7c3aed;
  color: #fff;
}
.ai-actions .ai-use:hover { background: #6d28d9; }
.ai-actions .ai-dismiss {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.ai-actions .ai-dismiss:hover { background: var(--border); }
.ai-loading {
  color: #7c3aed;
  font-size: 0.78rem;
  padding: 0.4rem 0;
  animation: aiPulse 1.2s ease-in-out infinite;
}
@keyframes aiPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* AI Prompts Modal */
.modal-aip {
  width: 90vw;
  max-width: 1200px;
  max-height: 90vh;
  padding: 0;
  overflow: hidden;
  position: relative;
}
.modal-aip .aip-views-wrapper {
  display: flex;
  width: 200%;
  transition: transform 0.3s ease;
}
.modal-aip.editing .aip-views-wrapper {
  transform: translateX(-50%);
}
.modal-aip .aip-view {
  width: 50%;
  flex-shrink: 0;
  overflow-y: auto;
  max-height: calc(90vh - 54px);
}
.aip-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel-bg);
  z-index: 2;
}
.aip-header h2 { flex: 1; font-size: 1rem; margin: 0; }
.aip-header-actions { display: flex; gap: 0.5rem; align-items: center; }
.aip-list-body, .aip-form-body { padding: 1rem; }
.aip-grid { display: flex; flex-direction: column; gap: 8px; }
.aip-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  position: relative;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.aip-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-color: #ccc;
}
.aip-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.aip-default-badge {
  font-size: 0.65rem;
  background: #7c3aed;
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.aip-card-preview {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aip-card-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  margin-top: 6px;
  font-size: 0.75rem;
}
.aip-card-edit {
  background: none;
  border: none;
  color: #7c3aed;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
}
.aip-card-delete {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s;
}
.aip-card:hover .aip-card-delete { opacity: 1; }
.aip-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
  font-size: 0.85rem;
}
.aip-empty.hidden { display: none; }
.aip-form-fields { display: flex; flex-direction: column; gap: 0.75rem; }
.aip-form-fields textarea {
  width: 100%;
  resize: vertical;
  min-height: 200px;
}

/* AI Prompt Selector (inline in reply controls) */
.ai-prompt-selector {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.ai-prompt-selector select {
  font-size: 0.72rem;
  padding: 0.15rem 0.3rem;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  background: none;
  color: var(--text-dim);
  max-width: 120px;
  cursor: pointer;
}
.ai-prompt-gear {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0;
  line-height: 1;
}
.ai-prompt-gear:hover { color: #7c3aed; }

/* AI Ask Row */
.ai-ask-row {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 0 0.4rem;
}
.ai-ask-input {
  flex: 1;
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.ai-ask-input:focus {
  border-color: #7c3aed;
}
.ai-ask-input::placeholder {
  color: var(--text-dim);
  font-size: 0.72rem;
}

/* AI Knowledge Base section */
.aip-kb-section { margin-bottom: 0.25rem; }
.aip-kb-header {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 0.3rem 0;
  font-size: 0.85rem;
  user-select: none;
}
.aip-kb-header:hover { color: #7c3aed; }
.aip-kb-arrow { font-size: 0.65rem; transition: transform 0.15s; }
.aip-kb-body { margin-top: 0.4rem; }
.aip-kb-body textarea {
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  background: var(--surface);
  color: var(--text);
  min-height: 150px;
}
.aip-kb-body textarea:focus { border-color: #7c3aed; outline: none; }

/* AI Chat Thread */
.ai-chat-thread {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.ai-chat-msg {
  font-size: 0.8rem;
  line-height: 1.45;
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
}
.ai-chat-user {
  background: rgba(124, 58, 237, 0.06);
  border-left: 3px solid #7c3aed;
  color: var(--text);
}
.ai-chat-ai {
  background: #fff;
  border: 1px solid rgba(124, 58, 237, 0.12);
}

/* ─── AI Advisor Sidebar ─── */
.ai-advisor {
  width: 280px;
  min-width: 200px;
  max-width: 500px;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.advisor-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: ew-resize;
  z-index: 5;
}
.advisor-resize-handle::after {
  content: '';
  position: absolute;
  left: 1px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 28px;
  background: var(--border);
  border-radius: 2px;
}
.advisor-resize-handle:hover::after {
  background: #7c3aed;
}
.ai-advisor.visible {
  display: flex;
}
.advisor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--panel-header);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: #7c3aed;
}
.advisor-header button {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-dim);
  padding: 0 4px;
  line-height: 1;
}
.advisor-header button:hover { color: var(--text); }
#advisor-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.advisor-empty {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
  padding: 2rem 0.5rem;
}
.advisor-loading {
  text-align: center;
  padding: 1.5rem 0.5rem;
  color: #7c3aed;
  font-size: 0.8rem;
}
.advisor-loading::after {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #7c3aed;
  border-top-color: transparent;
  border-radius: 50%;
  animation: advisor-spin 0.8s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}
@keyframes advisor-spin { to { transform: rotate(360deg); } }

.advisor-intent {
  font-size: 0.78rem;
  color: var(--text);
  background: rgba(124, 58, 237, 0.06);
  border-left: 3px solid #7c3aed;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  line-height: 1.4;
}
.advisor-coaching {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
  padding: 0.25rem 0.4rem;
  line-height: 1.4;
}
.advisor-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}
.advisor-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.3rem;
}
.advisor-text {
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}
.advisor-use-btn, .advisor-use-qr-btn {
  display: block;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.35rem 0.6rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  transition: background 0.15s;
}
.advisor-use-btn {
  background: #7c3aed;
  color: #fff;
}
.advisor-use-btn:hover { background: #6d28d9; }
.advisor-use-qr-btn {
  background: var(--teal);
  color: #fff;
}
.advisor-use-qr-btn:hover { background: var(--teal-dark); }
.advisor-qr-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--teal);
}
.advisor-qr-reason {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
  line-height: 1.35;
}
.advisor-error {
  font-size: 0.78rem;
  color: var(--red);
  text-align: center;
  padding: 1rem 0.5rem;
}

/* Resizable AI preview pane (drag handle) */
.ai-preview-resize-handle {
  height: 12px;
  cursor: ns-resize;
  background: rgba(124, 58, 237, 0.05);
  position: relative;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(124, 58, 237, 0.1);
}
.ai-preview-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 4px;
  background: rgba(124, 58, 237, 0.25);
  border-radius: 2px;
}
.ai-preview-resize-handle:hover::after {
  background: #7c3aed;
}

/* ─── Categories ─── */
.cat-section { padding: 0 1rem; }
.cat-header {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; padding: 0.5rem 0; user-select: none;
  font-size: 0.85rem;
}
.cat-arrow { font-size: 0.6rem; transition: transform 0.15s; display: inline-block; }
.cat-arrow.open { transform: rotate(90deg); }
.cat-body { padding: 0.4rem 0 0.6rem; }
.cat-list-item {
  display: flex; align-items: center; gap: 8px;
  padding: 0.3rem 0.5rem; font-size: 0.82rem; border-radius: 6px;
}
.cat-list-item:hover { background: var(--hover); }
.cat-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cat-name { flex: 1; }
.cat-delete {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 1rem; padding: 0 4px; opacity: 0; transition: opacity 0.15s;
}
.cat-list-item:hover .cat-delete { opacity: 1; }
.cat-add-row {
  display: flex; gap: 6px; align-items: center; margin-top: 0.5rem;
}
.cat-add-row input[type=text] {
  flex: 1; padding: 0.35rem 0.6rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.82rem; background: var(--panel-bg); color: var(--text);
}
.cat-add-row input[type=color] {
  width: 28px; height: 28px; border: 1px solid var(--border);
  border-radius: 6px; padding: 1px; cursor: pointer; background: none;
}
.category-badge {
  display: inline-block; font-size: 0.6rem; font-weight: 600;
  padding: 1px 6px; border-radius: 8px; color: #fff;
  margin-left: 4px; vertical-align: middle; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.qr-cat-badge {
  display: inline-block; font-size: 0.6rem; font-weight: 600;
  padding: 1px 5px; border-radius: 6px; color: #fff;
  margin-left: 4px; text-transform: uppercase; letter-spacing: 0.3px;
}
.qr-cat-checkboxes {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0;
}
.qr-cat-check {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.82rem; cursor: pointer; user-select: none;
  padding: 3px 8px; border-radius: 12px; border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}
.qr-cat-check:has(input:checked) { border-color: transparent; }
.qr-cat-check input { margin: 0; cursor: pointer; }

/* Hide advisor on mobile/tablet */
@media (max-width: 1024px) {
  .ai-advisor { display: none !important; }
}

/* ═══════════════════════════════════════════
   Navigation Tabs
   ═══════════════════════════════════════════ */
.header-nav {
  display: flex;
  gap: 4px;
  margin-left: 0.5rem;
}
.nav-tab {
  padding: 0.35rem 0.85rem;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  background: transparent;
  color: var(--text-dim);
  transition: all 0.15s;
}
.nav-tab:hover {
  background: var(--hover);
  color: var(--text);
}
.nav-tab.active {
  background: var(--teal);
  color: white;
}

/* ═══════════════════════════════════════════
   App Views (analytics + calendar)
   ═══════════════════════════════════════════ */
.app-view {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

/* ─── KPI Cards ─── */
.analytics-container {
  max-width: 1200px;
  margin: 0 auto;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 1.2rem 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.kpi-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}
.kpi-value {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}
.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* ─── Trends Section ─── */
.trends-section {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 1.2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 1.5rem;
}
.trends-section h3 {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 1rem;
}
.trends-subtitle {
  font-weight: 400;
  font-size: 0.72rem;
  opacity: 0.7;
}
.trends-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.trend-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
}
.trend-period {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}
.trend-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
}
.trend-row:last-child { margin-bottom: 0; }
.trend-metric-label {
  font-size: 0.72rem;
  color: var(--text-dim);
}
.trend-metric-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.trend-change {
  font-size: 0.68rem;
  font-weight: 500;
  margin-left: 0.3rem;
}
.trend-change.up { color: #27ae60; }
.trend-change.down { color: #e74c3c; }
.trend-change.flat { color: var(--text-dim); }

/* ─── Payment Reminders Section ─── */
.reminders-section {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 1.2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 1.5rem;
}
.reminders-header h3 {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 1rem;
}
.reminders-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1.2rem;
}
.reminder-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
}
.reminder-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.reminder-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
.reminder-desc {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--teal);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* Upcoming reminders table */
.reminders-upcoming h4 {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}
.reminders-upcoming-sub {
  font-weight: 400;
  font-size: 0.68rem;
  opacity: 0.7;
}
.reminders-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.reminders-table th {
  text-align: left;
  font-weight: 500;
  color: var(--text-dim);
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.reminders-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.reminders-table tr:last-child td {
  border-bottom: none;
}
.reminders-table .status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 500;
}
.status-badge.sent { background: rgba(0,128,105,0.12); color: var(--teal); }
.status-badge.pending { background: rgba(230,138,0,0.12); color: var(--orange); }
.status-badge.skipped { background: rgba(102,119,129,0.12); color: var(--text-dim); }
.reminders-empty {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-dim);
  font-size: 0.78rem;
}

/* ─── Charts ─── */
.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.chart-card {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.chart-card h3 {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}
.chart-card canvas {
  width: 100% !important;
  max-height: 240px;
}

/* ─── Pipeline Funnel ─── */
.pipeline-section {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 1.2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.pipeline-section h3 {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 1rem;
}
.pipeline-period {
  font-weight: 400;
  font-size: 0.72rem;
  opacity: 0.7;
}
.pipeline-funnel {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.75rem;
  height: 140px;
  margin-bottom: 1.2rem;
}
.funnel-bar {
  flex: 1;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  height: 100%;
  justify-content: flex-end;
}
.funnel-fill {
  width: 100%;
  border-radius: 6px 6px 0 0;
  min-height: 8px;
  transition: height 0.4s ease;
}
#funnel-enquiries .funnel-fill { background: var(--teal); }
#funnel-proposals .funnel-fill { background: var(--orange); }
#funnel-converted .funnel-fill { background: #27ae60; }
.funnel-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
  text-align: center;
}
.funnel-count {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}
.funnel-arrow {
  font-size: 1.2rem;
  color: var(--text-dim);
  opacity: 0.4;
  align-self: center;
  flex-shrink: 0;
}

.pipeline-metrics {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.metric {
  text-align: center;
}
.metric-value {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}
.metric-label {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* ─── Team Performance Table ─── */
.team-perf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.team-perf-table th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 2px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.team-perf-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.team-perf-table tr:last-child td { border-bottom: none; }
.team-perf-table .close-rate {
  font-weight: 700;
  color: #008069;
}

/* ─── Calendar View ─── */
#calendar-container {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  max-width: 1200px;
  margin: 0 auto;
  min-height: 600px;
}

/* FullCalendar theme overrides */
#calendar-container .fc {
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 0.82rem;
}
#calendar-container .fc .fc-button-primary {
  background: var(--teal);
  border-color: var(--teal);
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
  border-radius: 16px;
  text-transform: capitalize;
}
#calendar-container .fc .fc-button-primary:hover {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}
#calendar-container .fc .fc-button-primary:disabled {
  background: var(--teal);
  border-color: var(--teal);
  opacity: 0.5;
}
#calendar-container .fc .fc-button-primary:not(:disabled).fc-button-active {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}
#calendar-container .fc .fc-toolbar-title {
  font-size: 1.05rem;
  font-weight: 500;
}
#calendar-container .fc .fc-daygrid-day-number {
  font-size: 0.78rem;
  color: var(--text-dim);
}
#calendar-container .fc .fc-daygrid-day.fc-day-today {
  background: rgba(0,128,105,0.06);
}
#calendar-container .fc .fc-event {
  border-radius: 4px;
  font-size: 0.72rem;
  padding: 1px 4px;
  border: none;
  cursor: pointer;
}
#calendar-container .fc .fc-timegrid-slot {
  height: 3em;
}
#calendar-container .fc .fc-col-header-cell-cushion {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
}
#calendar-container .fc .fc-more-link {
  color: var(--teal);
  font-size: 0.7rem;
  font-weight: 600;
}
#calendar-container .fc td, #calendar-container .fc th {
  border-color: var(--border);
}

/* Calendar tooltip */
.cal-tooltip {
  position: absolute;
  background: var(--text);
  color: white;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.72rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-row {
    grid-template-columns: 1fr;
  }
  .pipeline-metrics {
    flex-wrap: wrap;
    gap: 1rem;
  }
  .trends-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .reminders-cards {
    grid-template-columns: 1fr;
  }
  .reminders-table th:nth-child(3),
  .reminders-table td:nth-child(3) {
    display: none;
  }
  .header-nav {
    gap: 2px;
  }
  .nav-tab {
    font-size: 0.72rem;
    padding: 0.3rem 0.6rem;
  }
}

/* Review Messages Modal */
.rm-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 0.6rem;
}
.rm-tabs button {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-bg);
  color: var(--text-dim);
  cursor: pointer;
}
.rm-tabs button.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}
.rm-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}
.rm-hint code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.8rem;
}
#modal-review-messages .ql-container {
  min-height: 200px;
  max-height: 350px;
  overflow-y: auto;
  font-size: 0.9rem;
}
#modal-review-messages .ql-editor {
  min-height: 200px;
}
.rm-test {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.8rem;
}
.rm-test input {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  width: 160px;
}

/* ─── Workflow Templates ─── */
.wf-templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}
.wf-template-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.wf-template-card:hover { border-color: var(--primary); }
.wf-template-header { font-weight: 600; font-size: 0.9rem; }
.wf-template-desc { font-size: 0.78rem; color: var(--text-dim); line-height: 1.4; }
.wf-template-meta { font-size: 0.7rem; color: var(--text-dim); opacity: 0.7; }
.wf-template-install { align-self: flex-end; margin-top: 0.3rem; }
.wf-template-install.installed { background: #28a745; pointer-events: none; }

/* ─── Workflow Builder ─── */
.wf-fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.wf-fieldset legend {
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 0 0.5rem;
}
.wf-steps-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  font-weight: 500;
}
.wf-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.wf-step {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  position: relative;
  background: var(--panel-bg);
}
.wf-step[data-type="filter"] { border-left: 3px solid #3498db; }
.wf-step[data-type="delay"] { border-left: 3px solid #f39c12; }
.wf-step[data-type="action"] { border-left: 3px solid #27ae60; }
.wf-step-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.wf-step-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  color: #fff;
}
.wf-step[data-type="filter"] .wf-step-badge { background: #3498db; }
.wf-step[data-type="delay"] .wf-step-badge { background: #f39c12; }
.wf-step[data-type="action"] .wf-step-badge { background: #27ae60; }
.wf-step-del {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.3rem;
}
.wf-step-del:hover { color: #e74c3c; }
.wf-step-body { font-size: 0.85rem; }
.wf-step-body select,
.wf-step-body input[type="text"],
.wf-step-body input[type="number"] {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 0.82rem;
}
.wf-step-body textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 140px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  line-height: 1.45;
}
.wf-connector {
  display: flex;
  justify-content: center;
  padding: 0.15rem 0;
  color: var(--text-dim);
  font-size: 0.9rem;
  user-select: none;
}
.wf-cond-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}
.wf-cond-row select,
.wf-cond-row input {
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
}
.wf-add-step {
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: 0.5rem;
}
.wf-add-menu {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 10;
  overflow: hidden;
  min-width: 200px;
}
.wf-add-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
}
.wf-add-menu button:hover { background: var(--hover); }
.wf-msg-tabs { display: flex; gap: 0.25rem; margin-bottom: 0.3rem; }
.wf-msg-tab {
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--text-dim);
}
.wf-msg-tab.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.wf-placeholder-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}
.wf-placeholder-hint code {
  background: var(--hover, #f0f0f0);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.wf-placeholder-hint code:hover {
  background: var(--teal);
  color: #fff;
}
.wf-placeholder-hint code.copied {
  background: #27ae60;
  color: #fff;
}

/* ─── Message Search Results ─── */
.msg-search-divider {
  padding: 0.5rem 1rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}
.msg-match-card {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}
.msg-match-card:hover {
  background: var(--hover);
  border-left-color: var(--teal);
}
.msg-match-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
}
.msg-match-preview {
  flex: 1;
  min-width: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text);
}
.msg-match-preview .msg-match-name {
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 0.1rem;
}
.msg-match-preview .msg-match-snippet {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.msg-match-preview mark {
  background: rgba(0, 128, 105, 0.2);
  color: inherit;
  padding: 0 0.1em;
  border-radius: 2px;
}

/* ─── Undo Send Bar ─── */
.msg-undo-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  margin-top: 0.3rem;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  font-size: 0.78rem;
  overflow: hidden;
}
.msg-undo-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  background: rgba(0, 128, 105, 0.12);
  border-radius: 6px;
  pointer-events: none;
}
.msg-undo-label {
  position: relative;
  color: var(--text-dim);
  z-index: 1;
}
.msg-undo-countdown {
  font-weight: 600;
  color: var(--text);
}
.msg-undo-btn {
  position: relative;
  z-index: 1;
  margin-left: auto;
  background: none;
  border: 1px solid var(--teal);
  color: var(--teal);
  padding: 0.2rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 600;
}
.msg-undo-btn:hover {
  background: var(--teal);
  color: white;
}
.msg-undo-pending { opacity: 0.85; }

/* ─── Email Compose Panel ─── */
.email-compose {
  display: none;
  flex-direction: column;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  max-height: 60vh;
  min-height: 280px;
}
.email-compose.active { display: flex; }

.email-compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--panel-header);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.email-compose-header .email-from {
  color: var(--text-dim);
  font-size: 0.78rem;
}
.email-compose-header .email-compose-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.email-compose-fields {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-bottom: 1px solid var(--border);
}
.email-field-row {
  display: flex;
  align-items: center;
  padding: 0.3rem 0.75rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
  gap: 0.5rem;
  font-size: 0.82rem;
}
.email-field-row:last-child { border-bottom: none; }
.email-field-row label {
  color: var(--text-dim);
  font-size: 0.78rem;
  min-width: 55px;
  flex-shrink: 0;
}
.email-field-row input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  padding: 0.25rem 0;
}
.email-field-row input::placeholder { color: var(--text-dim); }
.email-cc-toggle {
  color: var(--teal);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}
.email-cc-toggle:hover { background: color-mix(in srgb, var(--teal) 15%, transparent); }
.email-cc-row { display: none; }
.email-cc-row.visible { display: flex; }

.email-compose-body {
  flex: 1;
  overflow-y: auto;
  min-height: 120px;
}
.email-compose-body .ql-container {
  border: none !important;
  font-size: 0.88rem;
  font-family: inherit;
}
.email-compose-body .ql-editor {
  min-height: 100px;
  padding: 0.75rem;
  line-height: 1.5;
}
.email-compose-body .ql-editor.ql-blank::before {
  font-style: normal;
  color: var(--text-dim);
}
.email-compose-body .ql-toolbar {
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
  padding: 0.3rem 0.5rem !important;
}
.email-compose-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--panel-header);
}
.email-compose-footer .btn-email-send {
  padding: 0.45rem 1.2rem;
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
}
.email-compose-footer .btn-email-send:hover { background: var(--teal-dark); }
.email-compose-footer .btn-email-send:disabled { opacity: 0.4; cursor: not-allowed; }
.email-compose-footer .email-footer-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}
.email-compose-footer .email-footer-controls label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.email-sig-preview {
  padding: 0 0.75rem 0.5rem;
  border-top: 1px dashed var(--border);
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Hide chat-style reply row when email compose is active */
.reply-area.email-mode .reply-row,
.reply-area.email-mode .reply-controls,
.reply-area.email-mode .reply-resize-handle,
.reply-area.email-mode .ai-ask-row,
.reply-area.email-mode .ai-preview,
.reply-area.email-mode .translate-preview,
.reply-area.email-mode #reply-preview,
.reply-area.email-mode #link-preview-card,
.reply-area.email-mode #qr-attach-indicator {
  display: none !important;
}
.reply-area.email-mode {
  padding: 0;
  border-top: none;
}

@media (max-width: 768px) {
  .email-compose { max-height: 70vh; }
  .email-field-row { padding: 0.25rem 0.5rem; }
  .email-compose-body .ql-editor { padding: 0.5rem; }
}

/* ========== DARK MODE ========== */

[data-theme="dark"] {
  --bg: #0b141a;
  --panel-bg: #111b21;
  --panel-header: #202c33;
  --surface: #202c33;
  --surface2: #2a3942;
  --border: #2a3942;
  --text: #e9edef;
  --text-dim: #8696a0;
  --teal: #00a884;
  --teal-dark: #00a884;
  --teal-light: #06cf9c;
  --outgoing: #005c4b;
  --incoming: #202c33;
  --blue: #53bdeb;
  --orange: #f5a623;
  --red: #ef5350;
  --wa-green: #25d366;
  --email-blue: #53bdeb;
  --chat-bg: #0b141a;
  --search-bg: #202c33;
  --hover: #202c33;
  --selected: #2a3942;
  --unread: #25d366;
  --bubble-shadow: rgba(0,0,0,0.2);
}

/* Login */
[data-theme="dark"] #login-screen {
  background: linear-gradient(180deg, var(--teal) 0%, var(--teal) 220px, var(--bg) 220px);
}
[data-theme="dark"] .login-box {
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Scrollbars */
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--panel-bg); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--surface2); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #3b4a54; }

/* Avatar placeholder */
[data-theme="dark"] .avatar-placeholder {
  background: #2a3942;
}
[data-theme="dark"] .avatar-placeholder-circle {
  background-color: #3b4a54;
}

/* Enquiry cards */
[data-theme="dark"] .enquiry-card:hover { background: var(--hover); }
[data-theme="dark"] .enquiry-card.active { background: var(--selected); }
[data-theme="dark"] .enquiry-info { color: #7c9ad6; }
[data-theme="dark"] .booking-info { color: #25d366; }
[data-theme="dark"] .booking-info span { background: rgba(37,211,102,0.15); }

/* Channel badges */
[data-theme="dark"] .badge-wa { background: rgba(37,211,102,0.15); color: #25d366; }
[data-theme="dark"] .badge-email { background: rgba(83,189,235,0.15); color: #53bdeb; }
[data-theme="dark"] .badge-web { background: rgba(245,166,35,0.15); color: #f5a623; }
[data-theme="dark"] .badge-livechat { background: rgba(37,211,102,0.15); color: #25d366; }
[data-theme="dark"] .badge-booked { background: rgba(37,211,102,0.15); color: #25d366; }

/* Message bubbles */
[data-theme="dark"] .msg-client::before { border-right-color: var(--incoming); }
[data-theme="dark"] .msg-agent::after { border-left-color: var(--outgoing); }

[data-theme="dark"] .msg-client[data-channel="email"] { background: #1a2a3a; }
[data-theme="dark"] .msg-client[data-channel="email"]::before { border-right-color: #1a2a3a; }
[data-theme="dark"] .msg-agent[data-channel="email"] { background: #0d3b5e; }
[data-theme="dark"] .msg-agent[data-channel="email"]::after { border-left-color: #0d3b5e; }

/* System messages */
[data-theme="dark"] .msg-system {
  background: #1a1f14;
  border-color: #2a3020;
  color: #b5b88a;
}
[data-theme="dark"] .msg-system-time { color: #8696a0; }

/* Internal notes */
[data-theme="dark"] .msg-internal {
  background: #2a2510;
  border-color: #3a3520;
  border-left-color: #b08d00;
}
[data-theme="dark"] .msg-internal .msg-menu-btn { color: #b08d00; }
[data-theme="dark"] .msg-internal-label { color: #d4a800; }

/* Message status */
[data-theme="dark"] .msg-status { color: #667781; }
[data-theme="dark"] .msg-status.read { color: #53bdeb; }

/* Message menu */
[data-theme="dark"] .msg-menu-btn { background: #2a3942; color: var(--text-dim); }
[data-theme="dark"] .msg-menu-btn:hover { background: #3b4a54; color: var(--text); }

/* Urgency badges */
[data-theme="dark"] .urgency-green { background: rgba(37,211,102,0.15); color: #25d366; }
[data-theme="dark"] .urgency-yellow { background: rgba(245,166,35,0.15); color: #f5a623; }
[data-theme="dark"] .urgency-orange { background: rgba(230,126,34,0.15); color: #e67e22; }
[data-theme="dark"] .urgency-red { background: rgba(239,83,80,0.2); color: #ef5350; }

/* Workshop countdown */
[data-theme="dark"] .ws-overdue { background: rgba(239,83,80,0.2); color: #ef5350; }
[data-theme="dark"] .ws-today { background: rgba(255,138,128,0.3); color: #ff8a80; }
[data-theme="dark"] .ws-tomorrow { background: rgba(230,126,34,0.15); color: #e67e22; }
[data-theme="dark"] .ws-urgent { background: rgba(245,166,35,0.15); color: #f5a623; }
[data-theme="dark"] .ws-soon { background: rgba(83,189,235,0.15); color: #53bdeb; }
[data-theme="dark"] .ws-ok { background: rgba(37,211,102,0.15); color: #25d366; }

/* Duplicate warning */
[data-theme="dark"] .dup-warning { background: #2a2510; }
[data-theme="dark"] .dup-warning-title { color: #d4a800; }
[data-theme="dark"] .dup-match-btn:hover { background: #b08d00; color: #111; }

/* Duplicate info */
[data-theme="dark"] .dup-info-bar { background: rgba(83,189,235,0.1); }
[data-theme="dark"] .dup-info-bar { color: #53bdeb; }

/* Language badges */
[data-theme="dark"] .lang-en { background: rgba(83,189,235,0.15); color: #53bdeb; }
[data-theme="dark"] .lang-es { background: rgba(245,166,35,0.15); color: #f5a623; }
[data-theme="dark"] .lang-fr { background: rgba(149,117,205,0.2); color: #9575cd; }
[data-theme="dark"] .lang-de { background: rgba(239,83,80,0.15); color: #ef5350; }
[data-theme="dark"] .lang-pt { background: rgba(37,211,102,0.15); color: #25d366; }
[data-theme="dark"] .lang-it { background: rgba(255,213,79,0.15); color: #ffd54f; }
[data-theme="dark"] .lang-pl { background: rgba(236,64,122,0.15); color: #ec407a; }
[data-theme="dark"] .lang-nl { background: rgba(38,166,154,0.15); color: #26a69a; }
[data-theme="dark"] .lang-ru { background: rgba(92,107,192,0.15); color: #5c6bc0; }
[data-theme="dark"] .lang-fi { background: rgba(41,182,246,0.15); color: #29b6f6; }
[data-theme="dark"] .lang-se { background: rgba(255,238,88,0.15); color: #ffee58; }
[data-theme="dark"] .lang-no { background: rgba(255,112,67,0.15); color: #ff7043; }
[data-theme="dark"] .lang-da { background: rgba(171,71,188,0.15); color: #ab47bc; }
[data-theme="dark"] .lang-cs { background: rgba(38,198,218,0.15); color: #26c6da; }
[data-theme="dark"] .lang-hu { background: rgba(156,204,101,0.15); color: #9ccc65; }
[data-theme="dark"] .lang-ro { background: rgba(245,166,35,0.15); color: #f5a623; }
[data-theme="dark"] .lang-ar { background: rgba(161,136,127,0.15); color: #a1887f; }

/* Buttons */
[data-theme="dark"] .btn-danger-outline { color: #ef5350; border-color: #ef5350; }
[data-theme="dark"] .btn-danger-outline:hover { background: #ef5350; color: #fff; }

/* Context menu */
[data-theme="dark"] .ctx-menu {
  background: var(--panel-bg);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* Modals */
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,0.6); }
[data-theme="dark"] .modal-content {
  background: var(--panel-bg);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

/* Inputs and selects in dark mode */
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: var(--text-dim);
}
[data-theme="dark"] select option {
  background: var(--panel-bg);
  color: var(--text);
}

/* Quick reply textareas */
[data-theme="dark"] .qr-trans-row textarea:not(:placeholder-shown) { background: rgba(0,168,132,0.1); }
[data-theme="dark"] .qr-form-trans-row textarea:not(:placeholder-shown) { background: rgba(0,168,132,0.1); }

/* AI Sales Assistant */
[data-theme="dark"] .ai-toggle.active {
  border-color: #a78bfa;
  color: #a78bfa;
  background: rgba(167,139,250,0.1);
}
[data-theme="dark"] .ai-preview {
  background: #1a1528;
  border-color: rgba(167,139,250,0.2);
}
[data-theme="dark"] .ai-label { color: #a78bfa; }
[data-theme="dark"] .ai-suggested {
  background: var(--surface);
  border-color: rgba(167,139,250,0.15);
}
[data-theme="dark"] .ai-actions .ai-use { background: #7c3aed; }
[data-theme="dark"] .ai-actions .ai-use:hover { background: #6d28d9; }
[data-theme="dark"] .ai-loading { color: #a78bfa; }

/* AI Advisor sidebar */
[data-theme="dark"] .ai-advisor-panel { background: var(--panel-bg); }
[data-theme="dark"] .advisor-msg.user { background: var(--surface2); }
[data-theme="dark"] .advisor-msg.assistant { background: var(--surface); }
[data-theme="dark"] .advisor-use-btn { background: #7c3aed; color: #fff; }
[data-theme="dark"] .advisor-use-btn:hover { background: #6d28d9; }
[data-theme="dark"] .ai-prompt-gear:hover { color: #a78bfa; }
[data-theme="dark"] .aip-kb-header:hover { color: #a78bfa; }
[data-theme="dark"] .aip-kb-body textarea:focus { border-color: #a78bfa; }

/* Analytics */
[data-theme="dark"] .kpi-card { background: var(--panel-bg); }
[data-theme="dark"] .trend-change.up { color: #25d366; }
[data-theme="dark"] .trend-change.down { color: #ef5350; }
[data-theme="dark"] .funnel-label { color: var(--text-dim); }

/* Calendar */
[data-theme="dark"] .cal-day { background: var(--panel-bg); border-color: var(--border); }
[data-theme="dark"] .cal-day.today { border-color: var(--teal); }

/* Workflow builder */
[data-theme="dark"] .wf-step[data-type="filter"] .wf-step-badge { background: #2196f3; }
[data-theme="dark"] .wf-step[data-type="delay"] .wf-step-badge { background: #f39c12; }
[data-theme="dark"] .wf-step[data-type="action"] .wf-step-badge { background: #27ae60; }
[data-theme="dark"] .wf-step-del:hover { color: #ef5350; }
[data-theme="dark"] .wf-msg-tab.active { background: var(--teal); color: #fff; border-color: var(--teal); }
[data-theme="dark"] .wf-template-install.installed { background: #28a745; }

/* Lightbox */
[data-theme="dark"] .lightbox-overlay { background: #000; }

/* WhatsApp health */
[data-theme="dark"] .wa-health-dropdown {
  background: var(--panel-bg);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* Review status badges */
[data-theme="dark"] .review-status.ok { background: rgba(39,174,96,0.2); color: #27ae60; }
[data-theme="dark"] .review-status.idle { background: rgba(150,150,150,0.15); color: #8696a0; }
[data-theme="dark"] .review-status.alert { background: rgba(231,76,60,0.2); color: #e74c3c; }

/* Quill editor */
[data-theme="dark"] .ql-toolbar.ql-snow { background: var(--surface); border-color: var(--border) !important; }
[data-theme="dark"] .ql-container.ql-snow { border-color: var(--border) !important; }
[data-theme="dark"] .ql-snow .ql-stroke { stroke: var(--text-dim) !important; }
[data-theme="dark"] .ql-snow .ql-fill { fill: var(--text-dim) !important; }
[data-theme="dark"] .ql-snow .ql-picker-label { color: var(--text-dim) !important; }
[data-theme="dark"] .ql-snow .ql-picker-options { background: var(--panel-bg) !important; border-color: var(--border) !important; }
[data-theme="dark"] .ql-editor { background: var(--panel-bg); color: var(--text); }
[data-theme="dark"] .ql-editor.ql-blank::before { color: var(--text-dim) !important; }

/* Emoji picker */
[data-theme="dark"] emoji-picker { --background: var(--panel-bg); --border-color: var(--border); --input-border-color: var(--border); --category-font-color: var(--text-dim); }

/* Recording button */
[data-theme="dark"] .btn-mic.recording:hover { background: #c62828; }

/* Progress bars */
[data-theme="dark"] .funnel-bar { background: var(--surface2); }

/* Attachment remove button */
[data-theme="dark"] .attach-remove { background: rgba(0,0,0,0.7); }

/* Dark mode toggle button */
.btn-theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  color: var(--text-dim);
  transition: all 0.15s;
}
.btn-theme-toggle:hover { background: var(--hover); }
