/* =====================================================================
   WhatsApp Support Desk — theme
   Light + dark palettes (WhatsApp-Web inspired). Theme is chosen by the
   data-theme attribute on <html>, set before first paint in index.html.
   ===================================================================== */

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-2: #f6f7f9;
  --panel-3: #eceff2;
  --hover: #f3f5f7;
  --border: #e4e7eb;
  --border-strong: #d3d8de;
  --text: #111b21;
  --text-2: #54656f;
  --text-3: #8696a0;
  --brand: #00a884;
  --brand-strong: #008069;
  --brand-ink: #ffffff;
  --brand-soft: #e7f6f2;
  --brand-text: #007a63;
  --focus: rgba(0, 168, 132, 0.28);
  --chat-bg: #efeae2;
  --chat-pattern: rgba(17, 27, 33, 0.045);
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --bubble-text: #111b21;
  --bubble-meta: #667781;
  --bubble-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --tick-read: #53bdeb;
  --system-chip: #ffffff;
  --danger: #dc3545;
  --danger-soft: #fdecee;
  --warning: #b7791f;
  --warning-soft: #fdf3e1;
  --info: #027eb5;
  --info-soft: #e3f3fb;
  --violet: #6d4fd8;
  --violet-soft: #efebfc;
  --avatar-bg: #dfe5e7;
  --avatar-ink: #54656f;
  --rail-bg: #f0f2f5;
  --shadow-1: 0 1px 2px rgba(11, 20, 26, 0.06), 0 1px 3px rgba(11, 20, 26, 0.05);
  --shadow-2: 0 6px 20px rgba(11, 20, 26, 0.10), 0 2px 6px rgba(11, 20, 26, 0.06);
  --shadow-3: 0 24px 60px rgba(11, 20, 26, 0.22);
  --scrim: rgba(11, 20, 26, 0.45);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1014;
  --panel: #111b21;
  --panel-2: #172229;
  --panel-3: #202c33;
  --hover: #1b262d;
  --border: #222e35;
  --border-strong: #2f3c44;
  --text: #e9edef;
  --text-2: #aebac1;
  --text-3: #7d8d96;
  --brand: #00a884;
  --brand-strong: #00c49a;
  --brand-ink: #ffffff;
  --brand-soft: rgba(0, 168, 132, 0.14);
  --brand-text: #2ed3a8;
  --focus: rgba(0, 168, 132, 0.38);
  --chat-bg: #0b141a;
  --chat-pattern: rgba(255, 255, 255, 0.025);
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --bubble-text: #e9edef;
  --bubble-meta: rgba(233, 237, 239, 0.62);
  --bubble-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.3);
  --tick-read: #53bdeb;
  --system-chip: #182229;
  --danger: #f15c6d;
  --danger-soft: rgba(241, 92, 109, 0.14);
  --warning: #f2b544;
  --warning-soft: rgba(242, 181, 68, 0.13);
  --info: #4fc3f7;
  --info-soft: rgba(79, 195, 247, 0.13);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.14);
  --avatar-bg: #2a3942;
  --avatar-ink: #aebac1;
  --rail-bg: #0f171c;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.6);
  --scrim: rgba(0, 0, 0, 0.6);
}

:root {
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --font: 'Inter', 'Noto Sans Bengali', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --rail-w: 76px;
  --list-w: 380px;
  --details-w: 340px;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
}

a {
  color: var(--brand-text);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--panel-3);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.ic {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-3);
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.btn .ic {
  width: 18px;
  height: 18px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: var(--brand-ink);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-strong);
}

.btn-secondary {
  background: var(--panel-3);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--hover);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: transparent;
}

.btn-warning {
  background: transparent;
  color: var(--warning);
  border-color: var(--border);
}
.btn-warning:hover:not(:disabled) {
  background: var(--warning-soft);
  border-color: transparent;
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}
.btn-sm .ic {
  width: 16px;
  height: 16px;
}

.btn-lg {
  height: 46px;
  font-size: 15px;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-2);
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover {
  background: var(--hover);
  color: var(--text);
}
.icon-btn.active {
  background: var(--panel-3);
  color: var(--text);
}
.icon-btn-sm {
  width: 30px;
  height: 30px;
}
.icon-btn-sm .ic {
  width: 16px;
  height: 16px;
}

/* ---------- Forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  min-width: 0;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.field-label em {
  font-style: normal;
  font-weight: 400;
  color: var(--text-3);
}
.field-hint {
  font-size: 12px;
  color: var(--text-3);
}
p.field-hint {
  margin: -8px 0 14px;
}

.input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea.input {
  height: auto;
  padding: 10px 14px;
  resize: vertical;
  line-height: 1.5;
}
select.input {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238696a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.input::placeholder {
  color: var(--text-3);
}
.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus);
}

.input-icon-wrap {
  position: relative;
  display: block;
}
.input-icon-wrap .ic {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-3);
  pointer-events: none;
}
.input-icon-wrap .input {
  padding-left: 42px;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.check-grid label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.check-grid label:hover {
  background: var(--hover);
}
.check-grid label:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
}
.check-grid input {
  accent-color: var(--brand);
  width: 16px;
  height: 16px;
}
.check-grid-empty {
  font-size: 13px;
  color: var(--text-3);
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- Avatars ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: var(--avatar-ink);
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
  position: relative;
}
.avatar .ic {
  width: 55%;
  height: 55%;
}
.avatar-sm { width: 34px; height: 34px; font-size: 13px; }
.avatar-md { width: 42px; height: 42px; font-size: 16px; }
.avatar-lg { width: 49px; height: 49px; font-size: 18px; }
.avatar-xl { width: 96px; height: 96px; font-size: 34px; }
.avatar-brand {
  background: var(--brand);
  color: var(--brand-ink);
}
.avatar-tint {
  background: hsl(var(--h) 52% 88%);
  color: hsl(var(--h) 45% 28%);
}
:root[data-theme="dark"] .avatar-tint {
  background: hsl(var(--h) 28% 26%);
  color: hsl(var(--h) 60% 82%);
}
:root[data-theme="dark"] {
  --author-l: 72%;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
}
.brand-mark .ic {
  width: 24px;
  height: 24px;
}
.brand-mark-lg {
  width: 64px;
  height: 64px;
  border-radius: 18px;
}
.brand-mark-lg .ic {
  width: 38px;
  height: 38px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* =====================================================================
   LOGIN
   ===================================================================== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    linear-gradient(180deg, var(--brand) 0, var(--brand) 220px, var(--bg) 220px);
  overflow-y: auto;
}
:root[data-theme="dark"] .login-screen {
  background: linear-gradient(180deg, #103529 0, #103529 220px, var(--bg) 220px);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
  padding: 36px 32px 32px;
  animation: rise 0.35s ease-out;
}
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-brand .brand-mark {
  margin-bottom: 16px;
}
.login-brand h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}
.login-brand p {
  color: var(--text-2);
  font-size: 14px;
}
.login-form .btn {
  margin-top: 8px;
}

/* =====================================================================
   APP SHELL
   ===================================================================== */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Navigation rail ---------- */
.rail {
  width: var(--rail-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 12px;
  background: var(--rail-bg);
  border-right: 1px solid var(--border);
  z-index: 20;
}
.rail-brand {
  margin-bottom: 18px;
}
.rail-nav,
.rail-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
}
.rail-nav {
  flex: 1;
}
.rail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 64px;
  padding: 6px 0;
  border-radius: var(--radius);
  color: var(--text-2);
  transition: color 0.15s ease;
}
.rail-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 32px;
  border-radius: 999px;
  transition: background-color 0.15s ease;
}
.rail-icon .ic {
  width: 21px;
  height: 21px;
}
.rail-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.rail-item:hover {
  color: var(--text);
}
.rail-item:hover .rail-icon {
  background: var(--panel-3);
}
.rail-item.active {
  color: var(--text);
}
.rail-item.active .rail-icon {
  background: var(--brand-soft);
  color: var(--brand-text);
}
.rail-item-sm .rail-icon {
  height: 30px;
}
.rail-badge {
  position: absolute;
  top: -5px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--rail-bg);
}
.rail-badge-muted {
  background: var(--panel-3);
  color: var(--text-2);
}
.online-dot-lg {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}
.rail-avatar {
  margin-top: 8px;
  border-radius: 50%;
  transition: box-shadow 0.15s ease;
}
.rail-avatar:hover .avatar {
  box-shadow: 0 0 0 3px var(--panel-3);
}

:root[data-theme="dark"] .theme-icon-dark,
:root[data-theme="light"] .theme-icon-light {
  display: none;
}

/* ---------- Collapsible sidebar ---------- */
.rail {
  transition: width 0.18s ease;
}
.rail-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.rail-brand-text,
.rail-online,
.rail-avatar-text,
.profile-online {
  display: none;
}
.rail-toggle {
  width: 36px;
  height: 36px;
}
.rail-toggle .ic {
  width: 19px;
  height: 19px;
}
.rail-avatar {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.app.rail-open {
  --rail-w: 248px;
}
.app.rail-open .rail {
  align-items: stretch;
  padding: 14px 12px 12px;
}
.app.rail-open .rail-brand {
  flex-direction: row;
  gap: 10px;
  padding: 0 4px;
}
.app.rail-open .rail-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.app.rail-open .rail-brand-text strong {
  font-size: 15px;
  font-weight: 700;
}
.app.rail-open .rail-brand-text span {
  font-size: 12px;
  color: var(--text-3);
}
.app.rail-open .rail-toggle {
  margin-left: auto;
}
.app.rail-open .rail-toggle,
.app.rail-open .rail-item.active .rail-icon {
  color: var(--brand-text);
}
.app.rail-open .rail-nav,
.app.rail-open .rail-footer {
  align-items: stretch;
}
.app.rail-open .rail-nav {
  flex: 0 0 auto;
}
.app.rail-open .rail-item {
  flex-direction: row;
  width: 100%;
  gap: 12px;
  padding: 4px 6px;
}
.app.rail-open .rail-item:hover {
  background: var(--panel-3);
}
.app.rail-open .rail-item:hover .rail-icon {
  background: transparent;
}
.app.rail-open .rail-item.active {
  background: var(--brand-soft);
  color: var(--brand-text);
}
.app.rail-open .rail-item.active .rail-icon {
  background: transparent;
}
.app.rail-open .rail-icon {
  width: 34px;
}
.app.rail-open .rail-label {
  font-size: 14px;
  font-weight: 500;
}
.app.rail-open .rail-item.active .rail-label {
  font-weight: 600;
}
.app.rail-open .rail-online-btn {
  display: none;
}
.app.rail-open .rail-online {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin: 14px 0 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.rail-online-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.app.rail-open .rail-online .online-list {
  flex: 1;
  max-height: none;
}
.app.rail-open .rail-avatar {
  width: 100%;
  margin-top: 8px;
  padding: 8px 6px;
  border-radius: var(--radius);
  border-top: 1px solid var(--border);
}
.app.rail-open .rail-avatar:hover {
  box-shadow: none;
  background: var(--panel-3);
}
.app.rail-open .rail-avatar-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.rail-avatar-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail-avatar-role {
  font-size: 12px;
  color: var(--brand-text);
}
.online-person-sub {
  display: block;
  font-size: 11.5px;
  color: var(--text-3);
}
.online-person-name {
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.online-person-you {
  color: var(--text-3);
  font-weight: 400;
}
.app.rail-open .rail-item {
  position: relative;
}
.app.rail-open .rail-icon {
  position: static;
}
.app.rail-open .rail-badge {
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  box-shadow: none;
}

/* ---------- Popovers ---------- */
.popover-anchor {
  position: relative;
}
.popover {
  position: absolute;
  z-index: 60;
  min-width: 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 8px;
  animation: rise 0.15s ease-out;
}
.popover-up {
  left: calc(100% + 10px);
  bottom: 0;
}
.popover-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px 8px;
}
.online-list {
  display: flex;
  flex-direction: column;
  max-height: 260px;
  overflow-y: auto;
}
.online-person {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.online-person .avatar::after {
  content: '';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--panel);
}
.online-person-role {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
}
.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.profile-name {
  font-weight: 600;
}
.profile-role {
  font-size: 12px;
  color: var(--brand-text);
  font-weight: 600;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  text-align: left;
}
.menu-item .ic {
  width: 18px;
  height: 18px;
  color: var(--text-2);
}
.menu-item:hover {
  background: var(--hover);
}
.menu-item-danger,
.menu-item-danger .ic {
  color: var(--danger);
}

/* ---------- Main area & views ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.view {
  display: none;
  flex: 1;
  min-height: 0;
}
.view.active {
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px 48px;
}
.page > * {
  max-width: 1240px;
  margin-left: auto;
  margin-right: auto;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-head h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin-bottom: 4px;
}
.page-head p {
  color: var(--text-2);
  font-size: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}

/* =====================================================================
   INBOX
   ===================================================================== */
.inbox {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- Conversation list ---------- */
.chatlist {
  width: var(--list-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.chatlist-head {
  padding: 14px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.chatlist-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chatlist-title h1 {
  flex-shrink: 0;
}
.chatlist-title h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.search:focus-within {
  background: var(--panel);
  border-color: var(--brand);
}
.search .ic {
  width: 17px;
  height: 17px;
  color: var(--text-3);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 14px;
}
.search input::placeholder {
  color: var(--text-3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}
.status-dot.is-connected {
  background: var(--brand);
}
.status-dot.is-connecting {
  background: var(--warning);
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink {
  50% { opacity: 0.35; }
}

.segmented {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* WhatsApp line picker, next to the "Chats" title */
.line-filter {
  margin-left: auto;
  min-width: 0;
}
.line-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 30px;
  padding: 0 8px 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.line-filter-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
.line-filter-btn.is-filtered {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand-text);
  font-weight: 600;
}
.line-filter-btn .ic {
  width: 16px;
  height: 16px;
}
.line-filter-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.popover-down {
  top: calc(100% + 6px);
  right: 0;
  width: 270px;
  max-height: 60vh;
  overflow-y: auto;
}
.line-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.line-option:hover {
  background: var(--hover);
}
.line-option.active {
  background: var(--brand-soft);
}
.line-option-color {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: #fff;
  flex-shrink: 0;
}
.line-option-color .ic {
  width: 18px;
  height: 18px;
}
.line-option-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.line-option-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.line-option-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-3);
}
.line-option-check {
  color: var(--brand-text);
}
.segmented-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.segmented-btn:hover {
  background: var(--panel-3);
  color: var(--text);
}
.segmented-btn.active {
  background: var(--brand-soft);
  color: var(--brand-text);
  font-weight: 600;
}
.count-pill {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.chatlist-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.list-loading {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.conv {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 0 0 14px;
  text-align: left;
  transition: background-color 0.12s ease;
}
.conv:hover {
  background: var(--hover);
}
.conv.active {
  background: var(--panel-3);
}
.conv .avatar {
  margin: 10px 0;
}
.conv-line-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--panel);
}
.conv-main {
  flex: 1;
  min-width: 0;
  padding: 12px 14px 12px 0;
  border-bottom: 1px solid var(--border);
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.conv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.conv-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time {
  font-size: 12px;
  color: var(--text-3);
  flex-shrink: 0;
}
.conv.unread .conv-time {
  color: var(--brand-text);
  font-weight: 600;
}
.conv.unread .conv-name {
  font-weight: 600;
}
.conv-preview {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv.unread .conv-preview {
  color: var(--text);
}
.conv-preview .ic {
  width: 15px;
  height: 15px;
  vertical-align: -3px;
  margin-right: 3px;
}
.conv-preview .is-missed {
  color: var(--danger);
}
.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  flex-shrink: 0;
}
.line-tag {
  display: inline-flex;
  align-items: center;
  max-width: 120px;
  height: 18px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  background: var(--panel-3);
  color: var(--text-2);
}
.group-tag {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--info);
  background: var(--info-soft);
  border-radius: 5px;
  padding: 1px 6px;
  flex-shrink: 0;
}

.list-empty {
  padding: 56px 28px;
  text-align: center;
  color: var(--text-2);
}
.list-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text-3);
  margin-bottom: 14px;
}
.list-empty-icon .ic {
  width: 26px;
  height: 26px;
}
.list-empty h3 {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}
.list-empty p {
  font-size: 13px;
  margin-bottom: 14px;
}
.list-more {
  padding: 14px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
}

/* ---------- Chat window ---------- */
.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--chat-pattern) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
.chat.drag-over::after {
  content: 'Drop image to send';
  position: absolute;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--brand);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  color: var(--brand-text);
  font-weight: 600;
  font-size: 16px;
  z-index: 30;
  pointer-events: none;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  background: var(--panel-2);
  border-bottom: 6px solid var(--brand);
}
.chat-empty-art {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  border-radius: 28px;
  background: var(--brand-soft);
  color: var(--brand-text);
  margin-bottom: 24px;
}
.chat-empty-art .ic {
  width: 52px;
  height: 52px;
}
.chat-empty h2 {
  font-size: 26px;
  font-weight: 300;
  margin-bottom: 10px;
}
.chat-empty p {
  max-width: 460px;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.6;
}
.chat-empty-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 28px;
  font-size: 12.5px;
  color: var(--text-3);
}
.chat-empty-hint .ic {
  width: 14px;
  height: 14px;
}

.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 62px;
  padding: 0 12px 0 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 5;
}
.chat-back {
  display: none;
  margin-left: -8px;
}
.chat-head-user {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 4px 0;
}
.chat-head-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-head-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
}
.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.collision-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  z-index: 4;
}
.typing-dots {
  display: inline-flex;
  gap: 3px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: typing 1s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-3px); opacity: 1; }
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 6% 12px;
  display: flex;
  flex-direction: column;
}
.messages-loading {
  margin: auto;
}
.messages-error {
  margin: auto;
  text-align: center;
  color: var(--text-2);
}
.messages-error .btn {
  margin-top: 12px;
}

.load-older {
  align-self: center;
  margin: 4px 0 12px;
}

.day-sep {
  align-self: center;
  margin: 10px 0;
  padding: 5px 12px;
  border-radius: 8px;
  background: var(--system-chip);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--bubble-shadow);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: min(66%, 560px);
  margin-top: 2px;
}
.msg.first-of-group {
  margin-top: 10px;
}
.msg.in {
  align-self: flex-start;
}
.msg.out {
  align-self: flex-end;
}
.msg.flash .bubble {
  animation: flash 1.2s ease-out;
}
@keyframes flash {
  0% { box-shadow: 0 0 0 3px var(--focus); }
  100% { box-shadow: var(--bubble-shadow); }
}

.bubble {
  position: relative;
  padding: 6px 9px 8px;
  border-radius: 8px;
  background: var(--bubble-in);
  color: var(--bubble-text);
  box-shadow: var(--bubble-shadow);
  font-size: 14.2px;
  line-height: 1.42;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  min-width: 80px;
}
.msg.out .bubble {
  background: var(--bubble-out);
}
.msg.first-of-group.in .bubble {
  border-top-left-radius: 0;
}
.msg.first-of-group.out .bubble {
  border-top-right-radius: 0;
}
.msg.first-of-group.in .bubble::before,
.msg.first-of-group.out .bubble::before {
  content: '';
  position: absolute;
  top: 0;
  width: 8px;
  height: 13px;
}
.msg.first-of-group.in .bubble::before {
  left: -8px;
  background: var(--bubble-in);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}
.msg.first-of-group.out .bubble::before {
  right: -8px;
  background: var(--bubble-out);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.bubble-author {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg.out .bubble-author {
  color: var(--brand-text);
}
:root[data-theme="dark"] .msg.out .bubble-author {
  color: #7ee2c6;
}

.bubble-text {
  white-space: pre-wrap;
}
.bubble-text a {
  color: var(--info);
}
.bubble-meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 6px 0 -4px 12px;
  font-size: 11px;
  color: var(--bubble-meta);
  white-space: nowrap;
  position: relative;
  top: 2px;
}
.bubble-meta .ic {
  width: 16px;
  height: 16px;
  stroke-width: 2.2;
}
.tick-read {
  color: var(--tick-read);
}
.bubble-clear {
  clear: both;
}

.bubble-media {
  display: block;
  margin: -2px -5px 4px;
  border-radius: 6px;
  overflow: hidden;
}
.bubble-media img,
.bubble-media video {
  display: block;
  max-width: 100%;
  width: 330px;
  max-height: 360px;
  object-fit: cover;
  background: var(--panel-3);
}
.bubble-media img {
  cursor: zoom-in;
}
.media-missing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px;
  margin: -2px -5px 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--bubble-meta);
  font-size: 13px;
}
:root[data-theme="dark"] .media-missing {
  background: rgba(255, 255, 255, 0.05);
}
.media-missing .ic {
  width: 20px;
  height: 20px;
}

.audio-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 270px;
  padding: 2px 0;
}
.audio-wrap .avatar {
  width: 40px;
  height: 40px;
}
.audio-wrap audio {
  flex: 1;
  height: 38px;
  min-width: 0;
}

.doc-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
  padding: 10px 12px;
  margin: -1px -4px 2px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  color: inherit;
  text-decoration: none;
}
:root[data-theme="dark"] .doc-card {
  background: rgba(255, 255, 255, 0.06);
}
.doc-card:hover {
  background: rgba(0, 0, 0, 0.08);
}
.doc-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 44px;
  border-radius: 6px;
  background: var(--danger);
  color: #fff;
  flex-shrink: 0;
}
.doc-icon .ic {
  width: 20px;
  height: 20px;
}
.doc-name {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-sub {
  font-size: 11.5px;
  color: var(--bubble-meta);
}
.doc-dl {
  color: var(--bubble-meta);
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
}
.reaction-chip .emoji {
  font-size: 20px;
}
.sticker-note {
  color: var(--bubble-meta);
  font-style: italic;
}

/* ---------- Replies, forwards & message actions ---------- */
.msg {
  position: relative;
}
.bubble-forwarded {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
  font-size: 12px;
  font-style: italic;
  color: var(--bubble-meta);
}
.bubble-forwarded .ic {
  width: 14px;
  height: 14px;
}
.bubble-quote {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 160px;
  margin: 1px -3px 5px;
  width: calc(100% + 6px);
  padding: 6px 10px 6px 9px;
  border-left: 4px solid hsl(var(--qh, 160) 55% 45%);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  text-align: left;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}
:root[data-theme="dark"] .bubble-quote {
  background: rgba(0, 0, 0, 0.2);
}
.bubble-quote:hover {
  background: rgba(0, 0, 0, 0.08);
}
.bubble-quote-author {
  font-size: 12.5px;
  font-weight: 600;
  color: hsl(var(--qh, 160) 55% var(--author-l, 38%));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
:root[data-theme="dark"] .bubble-quote-author {
  --author-l: 68%;
}
.bubble-quote-text,
.reply-bar-text,
.forward-preview-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--bubble-meta);
  white-space: pre-wrap;
}
.bubble-quote-text .ic,
.reply-bar-text .ic,
.forward-preview-text .ic {
  width: 14px;
  height: 14px;
  margin-right: 4px;
  vertical-align: -2px;
}

/* The buttons sit right against the bubble (the padding is the visual gap), so the
   pointer never leaves the message on its way to them; they also linger briefly. */
.msg-actions {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 2;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.12s ease 0.3s, visibility 0s linear 0.42s;
}
.msg.in .msg-actions {
  left: 100%;
  padding-left: 8px;
}
.msg.out .msg-actions {
  right: 100%;
  padding-right: 8px;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions,
.msg.actions-open .msg-actions {
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}
.msg-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--text-2);
  box-shadow: var(--shadow-1);
  transition: color 0.12s ease, background-color 0.12s ease;
}
.msg-action:hover {
  color: var(--brand-text);
  background: var(--hover);
}
.msg-action .ic {
  width: 16px;
  height: 16px;
}

/* system-style call notice */
.msg.call {
  align-self: center;
  max-width: 90%;
  margin: 10px 0;
}
.call-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 12px;
  border-radius: 12px;
  background: var(--system-chip);
  box-shadow: var(--bubble-shadow);
}
.call-chip-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-text);
  flex-shrink: 0;
}
.call-chip.is-missed .call-chip-icon {
  background: var(--danger-soft);
  color: var(--danger);
}
.call-chip-icon .ic {
  width: 18px;
  height: 18px;
}
.call-chip-title {
  font-size: 14px;
  font-weight: 600;
}
.call-chip-sub {
  font-size: 12px;
  color: var(--text-2);
}

.jump-latest {
  position: absolute;
  right: 20px;
  bottom: 86px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--text-2);
  box-shadow: var(--shadow-2);
}
.jump-latest:hover {
  color: var(--text);
}
.jump-count {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

/* ---------- Composer ---------- */
.composer-area {
  position: relative;
  flex-shrink: 0;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  z-index: 5;
}
.quick-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.quick-bar::-webkit-scrollbar {
  display: none;
}
.quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-2);
  font-size: 12.5px;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.quick-chip strong {
  color: var(--brand-text);
  font-weight: 600;
}
.quick-chip:hover {
  border-color: var(--brand);
  color: var(--text);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 12px 10px;
}
.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 12px 0;
  padding: 4px 4px 4px 0;
  border-radius: 10px;
  background: var(--panel);
  animation: rise 0.12s ease-out;
}
.reply-bar-quote {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px;
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  background: var(--panel-3);
  font-size: 13px;
  line-height: 1.35;
}
.reply-bar-author {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-bar-text {
  color: var(--text-2);
  -webkit-line-clamp: 1;
}
.composer-tools {
  display: flex;
  align-items: center;
  padding-bottom: 1px;
}
.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  max-height: 160px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.45;
  resize: none;
  outline: none;
  overflow-y: auto;
}
.composer textarea:focus {
  border-color: var(--border-strong);
}
.composer textarea::placeholder {
  color: var(--text-3);
}
.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  flex-shrink: 0;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.send-btn:hover {
  background: var(--brand-strong);
}
.send-btn:active {
  transform: scale(0.94);
}
.send-btn .ic {
  width: 19px;
  height: 19px;
}
.send-btn-mic {
  background: transparent;
  color: var(--text-2);
}
.send-btn-mic:hover {
  background: var(--hover);
  color: var(--text);
}
.composer.is-recording .send-btn-mic {
  background: var(--brand);
  color: #fff;
}
.composer.is-recording textarea,
.composer.is-recording .composer-tools {
  display: none;
}

.recording {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 6px 0 2px;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text-2);
  font-size: 14px;
}
.recording .icon-btn {
  color: var(--danger);
}
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s ease-in-out infinite;
}
.rec-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}
.rec-label {
  color: var(--text-3);
  font-size: 13px;
}

.slash-menu,
.emoji-menu {
  position: absolute;
  left: 12px;
  bottom: calc(100% + 6px);
  z-index: 40;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  animation: rise 0.12s ease-out;
}
.slash-menu {
  right: 12px;
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
}
.slash-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.slash-item:hover,
.slash-item.selected {
  background: var(--hover);
}
.slash-item-top {
  display: flex;
  gap: 8px;
  font-size: 13.5px;
}
.slash-item-top strong {
  color: var(--brand-text);
}
.slash-item-body {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slash-empty {
  padding: 10px;
  font-size: 13px;
  color: var(--text-3);
}
.emoji-menu {
  display: grid;
  grid-template-columns: repeat(8, 38px);
  gap: 2px;
  padding: 8px;
}
.emoji-menu button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
}
.emoji-menu button:hover {
  background: var(--hover);
}

/* ---------- Contact details ---------- */
.details {
  width: var(--details-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-2);
  border-left: 1px solid var(--border);
  min-height: 0;
}
.details-head {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 62px;
  padding: 0 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.details-head h3 {
  font-size: 16px;
  font-weight: 600;
}
.details-body {
  flex: 1;
  overflow-y: auto;
}
.details-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 20px 20px;
  background: var(--panel);
  text-align: center;
  margin-bottom: 8px;
}
.details-hero .avatar {
  margin-bottom: 10px;
}
.details-name {
  font-size: 19px;
  font-weight: 600;
  word-break: break-word;
}
.details-phone {
  font-size: 15px;
  color: var(--text-2);
}
.details-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.details-section {
  background: var(--panel);
  padding: 14px 20px;
  margin-bottom: 8px;
}
.details-row + .details-row {
  margin-top: 14px;
}
.details-label {
  font-size: 12.5px;
  color: var(--text-3);
  margin-bottom: 2px;
}
.details-value {
  font-size: 14px;
  word-break: break-all;
}

/* =====================================================================
   LINES (accounts) PAGE
   ===================================================================== */
.steps-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin-bottom: 24px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--border);
  border: 1px solid var(--border);
}
.step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px 18px;
  background: var(--panel);
  font-size: 13.5px;
  color: var(--text-2);
}
.step strong {
  color: var(--text);
  font-weight: 600;
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-text);
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.lines-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 20px;
}
.line-card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.line-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 14px;
}
.line-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: #fff;
  flex-shrink: 0;
}
.line-card-icon .ic {
  width: 24px;
  height: 24px;
}
.line-card-title {
  flex: 1;
  min-width: 0;
}
.line-card-title h3 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.line-card-title p {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}
.line-card-status {
  padding: 0 18px 12px;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--panel-3);
  color: var(--text-2);
}
.status-badge.is-connected {
  background: var(--brand-soft);
  color: var(--brand-text);
}
.status-badge.is-qr {
  background: var(--info-soft);
  color: var(--info);
}
.status-badge.is-connecting {
  background: var(--warning-soft);
  color: var(--warning);
}
.status-badge .status-dot {
  background: currentColor;
}

.line-card-body {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 18px;
  min-height: 236px;
  border-radius: var(--radius);
  background: var(--panel-2);
}
.qr-frame {
  width: 220px;
  height: 220px;
  padding: 10px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-1);
}
.qr-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.line-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-2);
}
.line-state strong {
  color: var(--text);
  font-size: 15px;
}
.line-state-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--panel-3);
  color: var(--text-3);
}
.line-state-icon.is-ok {
  background: var(--brand-soft);
  color: var(--brand-text);
}
.line-state-icon .ic {
  width: 28px;
  height: 28px;
}
.line-card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px 18px;
}
.line-card-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.line-card-actions-row .btn {
  flex: 1 1 auto;
}
.empty-card {
  grid-column: 1 / -1;
  padding: 56px 24px;
  text-align: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--panel);
}
.empty-card h3 {
  font-size: 17px;
  margin-bottom: 6px;
}
.empty-card p {
  color: var(--text-2);
  margin-bottom: 18px;
}

/* =====================================================================
   TEAM TABLE
   ===================================================================== */
.table-card {
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
.table th {
  padding: 12px 18px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}
.table tr:last-child td {
  border-bottom: 0;
}
.table tbody tr:hover td {
  background: var(--hover);
}
.col-actions {
  width: 1%;
}
.agent-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}
.you-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--panel-3);
  border-radius: 5px;
  padding: 1px 6px;
}
.role-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.role-admin {
  background: var(--violet-soft);
  color: var(--violet);
}
.role-agent {
  background: var(--brand-soft);
  color: var(--brand-text);
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.active-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--brand-text);
}
.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* =====================================================================
   QUICK REPLIES
   ===================================================================== */
.replies-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.reply-card {
  display: flex;
  flex-direction: column;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.reply-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.reply-card-title {
  font-weight: 600;
  font-size: 15px;
}
.reply-card-body {
  flex: 1;
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.55;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 16px;
}
.reply-card-actions {
  display: flex;
  gap: 8px;
}

/* =====================================================================
   STATS
   ===================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  margin-bottom: 10px;
}
.stat-icon-green { background: var(--brand-soft); color: var(--brand-text); }
.stat-icon-blue { background: var(--info-soft); color: var(--info); }
.stat-icon-violet { background: var(--violet-soft); color: var(--violet); }
.stat-icon-amber { background: var(--warning-soft); color: var(--warning); }
.stat-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}
.stat-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* =====================================================================
   MODALS
   ===================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: var(--scrim);
  animation: fade 0.15s ease-out;
}
@keyframes fade {
  from { opacity: 0; }
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  animation: rise 0.2s ease-out;
  overflow: hidden;
}
.modal-card > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.modal-card-sm {
  max-width: 400px;
}
.modal-card-md {
  max-width: 560px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 14px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  font-size: 17px;
  font-weight: 600;
}
.modal-body {
  padding: 20px 22px 6px;
  overflow-y: auto;
}
.modal-text {
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 16px;
}
.modal-note {
  margin: 4px 0 16px;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.5;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px 18px;
}

/* Forward dialog */
.forward-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding-bottom: 0;
  overflow: hidden;
}
.forward-preview {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 12px;
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  background: var(--panel-3);
  font-size: 13px;
  line-height: 1.35;
}
.forward-preview-author {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-text);
}
.forward-preview-text {
  color: var(--text-2);
}
.forward-list {
  display: flex;
  flex-direction: column;
  min-height: 120px;
  max-height: min(52vh, 460px);
  overflow-y: auto;
  margin: 0 -10px;
  padding: 0 4px 6px;
}
.fwd-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.fwd-item:hover {
  background: var(--hover);
}
.fwd-item:has(input:checked) {
  background: var(--brand-soft);
}
.fwd-item.is-offline {
  opacity: 0.55;
  cursor: not-allowed;
}
.fwd-item input {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--brand);
}
.fwd-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.fwd-item-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fwd-item-sub {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.forward-empty {
  padding: 18px 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}
.forward-foot {
  align-items: center;
  border-top: 1px solid var(--border);
}
.forward-count {
  margin-right: auto;
  font-size: 13px;
  color: var(--text-2);
}

.call-contact {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0 20px;
  text-align: center;
}
.call-contact .avatar {
  margin-bottom: 10px;
}
.call-contact-name {
  font-size: 18px;
  font-weight: 600;
}
.call-contact-phone {
  font-size: 15px;
  color: var(--brand-text);
  font-weight: 600;
}
.call-contact-line {
  font-size: 12.5px;
  color: var(--text-3);
}
.call-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.image-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  max-height: 52vh;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--panel-3);
  overflow: hidden;
}
.image-stage img {
  max-width: 100%;
  max-height: calc(52vh - 24px);
  object-fit: contain;
  border-radius: 6px;
}
.image-caption-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 8px;
}

/* =====================================================================
   INCOMING CALL + TOASTS
   ===================================================================== */
.call-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  width: 360px;
  max-width: calc(100vw - 32px);
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  animation: rise 0.2s ease-out;
}
.call-toast-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.call-toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-text);
  flex-shrink: 0;
  animation: ring 1.4s ease-in-out infinite;
}
@keyframes ring {
  0%, 100% { box-shadow: 0 0 0 0 var(--focus); }
  50% { box-shadow: 0 0 0 8px transparent; }
}
.call-toast-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.call-toast-type {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brand-text);
}
.call-toast-caller {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.call-toast-number {
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.call-toast-line {
  font-size: 12.5px;
  color: var(--text-3);
}
.call-toast-actions {
  display: flex;
  gap: 8px;
}
.call-toast-actions .btn {
  flex: 1;
}

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 10px;
  background: #1f2c33;
  color: #f1f5f7;
  font-size: 14px;
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: rise 0.2s ease-out;
}
:root[data-theme="dark"] .toast {
  background: #e9edef;
  color: #111b21;
}
.toast .ic {
  width: 18px;
  height: 18px;
}
.toast-success .ic { color: #25d366; }
.toast-error .ic { color: #f15c6d; }
.toast.leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.2s ease;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 1280px) {
  :root {
    --list-w: 340px;
    --details-w: 300px;
  }
  .messages {
    padding-left: 4%;
    padding-right: 4%;
  }
}

/* Details panel overlays the chat on medium screens */
@media (max-width: 1100px) {
  .details {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    box-shadow: var(--shadow-3);
  }
  .inbox {
    position: relative;
  }
  .steps-card {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* One pane at a time: list OR chat */
@media (max-width: 860px) {
  .chatlist {
    width: 100%;
    border-right: 0;
  }
  .chat {
    display: none;
  }
  .inbox.chat-open .chatlist {
    display: none;
  }
  .inbox.chat-open .chat {
    display: flex;
  }
  .chat-back {
    display: inline-flex;
  }
  .details {
    width: 100%;
  }
  .msg {
    max-width: 85%;
  }
  .messages {
    padding: 12px 12px 8px;
  }
  .page {
    padding: 24px 20px 40px;
  }
}

/* Phone: the rail becomes a bottom bar */
@media (max-width: 640px) {
  .app {
    flex-direction: column-reverse;
  }
  .rail {
    width: 100%;
    flex-direction: row;
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--border);
  }
  .rail-brand,
  .rail-footer .popover-anchor:first-child,
  .rail-footer > .rail-item-sm,
  .app.rail-open .rail-online,
  .app.rail-open .rail-avatar-text {
    display: none;
  }
  /* The bottom bar can't expand; online agents are listed in the profile menu instead */
  .app.rail-open {
    --rail-w: 100%;
  }
  .app.rail-open .rail {
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  }
  .app.rail-open .rail-brand {
    display: none;
  }
  .app.rail-open .rail-nav {
    flex: 1;
  }
  .app.rail-open .rail-nav,
  .app.rail-open .rail-footer {
    align-items: center;
  }
  .app.rail-open .rail-item {
    flex-direction: column;
    width: 56px;
    gap: 3px;
    padding: 6px 0;
  }
  .app.rail-open .rail-label {
    font-size: 11px;
  }
  .app.rail-open .rail-avatar {
    width: auto;
    margin: 0 4px 0 2px;
    padding: 0;
    border-top: 0;
  }
  .profile-online {
    display: block;
    padding-bottom: 6px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
  }
  .rail-nav {
    flex-direction: row;
    justify-content: space-around;
    flex: 1;
  }
  .rail-footer {
    flex-direction: row;
    width: auto;
    gap: 0;
  }
  .rail-item {
    width: 56px;
  }
  .rail-avatar {
    margin: 0 4px 0 2px;
  }
  .popover-up {
    left: auto;
    right: 0;
    bottom: calc(100% + 10px);
  }
  .page {
    padding: 20px 16px 32px;
  }
  .page-head {
    flex-direction: column;
    align-items: stretch;
  }
  .page-head h1 {
    font-size: 21px;
  }
  .steps-card {
    grid-template-columns: 1fr;
  }
  .lines-grid,
  .replies-grid {
    grid-template-columns: 1fr;
  }
  .field-row {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .chat-head {
    padding: 0 4px 0 12px;
  }
  .chat-head-actions .icon-btn:nth-child(2) {
    display: none;
  }
  .composer {
    padding: 6px 8px 8px;
  }
  .composer-tools .icon-btn {
    width: 36px;
  }
  .emoji-menu {
    grid-template-columns: repeat(7, 38px);
  }
  .jump-latest {
    right: 12px;
  }
  .call-toast {
    top: 12px;
    right: 16px;
  }
  .table th:nth-child(2),
  .table td:nth-child(2),
  .table th:nth-child(5),
  .table td:nth-child(5) {
    display: none;
  }
}
