:root {
  --brand: #0f5c52;
  --brand-hover: #0c4a42;
  --brand-deep: #08332e;
  --on-brand: #ffffff;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --ink: #12202b;
  --muted: #5d6b76;
  --line: #dfe5ea;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --danger: #b42318;
  --human: #b54708;
  --ok-bg: #e8f7ef;
  --ok-ink: #087443;
  --warn-bg: #fff4e5;
  --warn-ink: #b54708;
  --sidebar: #ffffff;
  --sidebar-ink: #1b2a34;
  --sidebar-muted: #6b7a86;
  --sidebar-hover: #f3f6f8;
  --login-bg: #0f1720;
  --login-hero: none;
  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: color-mix(in srgb, var(--brand) 16%, #d9fdd3);
  --composer-bar: #f0f2f5;
  --unread: #25d366;
  --rail-width: 400px;
}

html[data-theme="dark"] {
  --bg: #0e141b;
  --surface: #161d26;
  --surface-2: #1d2631;
  --ink: #e8eef3;
  --muted: #93a1ae;
  --line: #2a3542;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  --sidebar: #121922;
  --sidebar-ink: #e8eef3;
  --sidebar-muted: #8b99a6;
  --sidebar-hover: #1c2530;
  --login-bg: #0b1016;
  --ok-bg: #123526;
  --ok-ink: #6ee7b7;
  --warn-bg: #3a2712;
  --warn-ink: #fbbf24;
  --chat-bg: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: color-mix(in srgb, var(--brand) 28%, #005c4b);
  --composer-bar: #202c33;
  --unread: #00a884;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: -0.011em;
}

.hidden { display: none !important; }

.kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand);
  font-weight: 700;
}

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.03em; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 420px at 15% -10%, color-mix(in srgb, var(--brand) 45%, transparent), transparent 60%),
    var(--login-bg);
}
.login.has-hero {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.78) 0%, rgba(0, 0, 0, 0.42) 52%, rgba(0, 0, 0, 0.28) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.22) 0%, rgba(0, 0, 0, 0.58) 100%),
    var(--login-hero) center / cover no-repeat,
    #111111;
}
.login.has-hero .login-card {
  background: color-mix(in srgb, #ffffff 94%, transparent);
  backdrop-filter: blur(10px);
}
html[data-theme="dark"] .login.has-hero .login-card {
  background: color-mix(in srgb, #161d26 90%, transparent);
}
.login-card {
  width: min(420px, 92vw);
  background: var(--surface);
  padding: 36px 32px;
  display: grid;
  gap: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 28px; }
.login-card .sub { margin: 0 0 8px; color: var(--muted); }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input, .search input, .composer textarea, .sim input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 11px 12px;
  font: inherit;
  color: var(--ink);
  border-radius: var(--radius-sm);
}
.login-card button, .composer > button[type="submit"], .sim button, .actions button, .rail-foot button, .wa-actions button {
  border: 0;
  background: var(--brand);
  color: var(--on-brand);
  font: inherit;
  font-weight: 650;
  padding: 12px 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.login-card button:hover, .composer > button[type="submit"]:hover, .sim button:hover, .actions button:hover, .wa-actions button:hover {
  background: var(--brand-hover);
}
.actions button.ghost, .rail-foot button, .wa-actions button.ghost {
  background: transparent;
  color: inherit;
  border: 1px solid var(--line);
}
.actions button.ghost:hover, .rail-foot button:hover, .wa-actions button.ghost:hover { background: var(--surface-2); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--rail-width, 400px) 1fr;
}

.rail {
  position: relative;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  overflow-x: hidden;
  min-width: 0;
}
.rail-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 50;
  background: transparent;
  transition: background 0.15s ease;
}
.rail-resizer:hover, .rail-resizer.dragging {
  background: var(--brand);
}
.rail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 14px 12px;
  gap: 8px;
  min-width: 0;
}
.biz-logo {
  height: 38px;
  width: auto;
  max-width: 145px;
  object-fit: contain;
  display: block;
  background: transparent;
  flex-shrink: 0;
}
.login-logo {
  height: auto;
  width: auto;
  max-height: 96px;
  max-width: 320px;
  object-fit: contain;
  display: block;
  margin: 0 auto 10px;
  background: transparent;
  padding: 0;
}
.login:not(.has-hero) .login-logo {
  max-height: 180px;
  max-width: 340px;
  background: #07090d;
  padding: 14px 20px;
  border-radius: 16px;
}
html[data-theme="light"] .login:not(.has-hero) .login-logo {
  background: transparent;
  padding: 8px 12px;
}
.login-card.has-lockup > .kicker { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--brand);
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.plugin-nav { display: flex; gap: 6px; padding: 0 14px 10px; flex-wrap: wrap; }
.plugin-nav button {
  background: var(--surface-2);
  color: var(--brand);
  border: 0;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  border-radius: 999px;
}
.search { padding: 0 14px 10px; }
.search input {
  background: var(--surface-2);
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  width: 100%;
  box-sizing: border-box;
}
.filters {
  display: flex;
  gap: 6px;
  padding: 0 14px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar {
  display: none;
}
.filters button {
  background: var(--surface-2, rgba(255, 255, 255, 0.05));
  color: var(--sidebar-muted);
  border: 1px solid transparent;
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  border-radius: 9999px;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: center;
  transition: all 0.15s ease;
}
.filters button:hover {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface-2));
  color: var(--ink);
}
.filters button.on {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  border-color: color-mix(in srgb, var(--brand) 35%, transparent);
  font-weight: 650;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  width: 100%;
}
.list li {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}
.list li:hover, .list li.active { background: var(--sidebar-hover); }
.list li.active { background: var(--composer-bar); }
.list li.unread .name { font-weight: 700; }
.list li.unread .time { color: var(--unread); font-weight: 650; }
.list li.unread .preview { color: var(--ink); }
.list .body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
  width: 100%;
}
.list .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}
.list .name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}
.list .time {
  font-size: 11px;
  color: var(--sidebar-muted);
  flex-shrink: 0;
  white-space: nowrap;
  margin-left: auto;
}
.list .preview {
  font-size: 13px;
  color: var(--sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}
.list .meta {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
}
.list .chip {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 5px;
  border-radius: 999px;
  flex-shrink: 0;
}
.list .chip.bot { background: var(--ok-bg); color: var(--ok-ink); }
.list .chip.human { background: var(--warn-bg); color: var(--human); }
.list li.empty-row {
  display: block;
  padding: 28px 16px;
  text-align: center;
  color: var(--sidebar-muted);
  cursor: default;
  border: 0;
  grid-template-columns: none;
}
.list li.empty-row:hover { background: transparent; }
.list .assignee {
  font-size: 10px;
  color: var(--sidebar-muted);
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge {
  min-width: 19px;
  height: 19px;
  border-radius: 10px;
  background: var(--unread);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.rail-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--sidebar-muted);
}
.rail-foot a { color: var(--brand); text-decoration: none; font-weight: 650; }

.head-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
.head-pills {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: stretch;
  flex-shrink: 0;
}
.head-pills .pill {
  white-space: nowrap;
  padding: 3px 8px;
  font-size: 10px;
  line-height: 1.2;
}
.wa-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.wa-pill svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
  flex-shrink: 0;
}
.pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 0;
  cursor: pointer;
  font-family: inherit;
}
.pill.on { background: var(--ok-bg); color: var(--ok-ink); }
.pill.off { background: var(--warn-bg); color: var(--warn-ink); }
.pill.bot { background: var(--ok-bg); color: var(--ok-ink); }
.pill.human { background: var(--warn-bg); color: var(--human); }

.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.empty {
  margin: auto;
  max-width: 460px;
  padding: 32px 24px;
  text-align: center;
}
.empty-mark {
  width: 88px;
  height: 88px;
  margin: 0 auto 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
}
.empty-mark svg { width: 42px; height: 42px; }
.empty h1 { font-size: 32px; margin: 8px 0 10px; font-weight: 300; letter-spacing: -0.02em; }
.empty p { color: var(--muted); line-height: 1.5; }
.sim { display: grid; gap: 8px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }

.thread-wrap { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.thread-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--composer-bar);
  align-items: center;
  flex-wrap: nowrap;
  min-height: 64px;
  box-sizing: border-box;
}
.thread-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
.thread-id {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
.thread-back { display: none; flex-shrink: 0; width: 36px; height: 36px; }
.thread-head h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-head p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
  flex-shrink: 0;
}
.actions .icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.actions .icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}
.actions .icon-btn:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
  border-color: var(--line);
}

/* Specific Action Icon Buttons */
.actions .action-btn-assume {
  color: var(--brand, #0F5C52);
  background: color-mix(in srgb, var(--brand, #0F5C52) 12%, transparent);
  border-color: color-mix(in srgb, var(--brand, #0F5C52) 30%, transparent);
}
.actions .action-btn-assume:hover {
  background: var(--brand, #0F5C52);
  color: #ffffff;
  border-color: var(--brand, #0F5C52);
}

.actions .action-btn-transfer {
  color: #3b82f6;
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.3);
}
.actions .action-btn-transfer:hover {
  background: #3b82f6;
  color: #ffffff;
  border-color: #3b82f6;
}

.actions .action-btn-release {
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
}
.actions .action-btn-release:hover {
  background: #10b981;
  color: #ffffff;
  border-color: #10b981;
}

/* Mode badge indicator */
.mode-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  cursor: default;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.mode-badge svg {
  width: 18px;
  height: 18px;
  display: block;
}
.mode-badge.human {
  background: rgba(245, 158, 11, 0.14);
  color: #d97706;
  border-color: rgba(245, 158, 11, 0.35);
}
[data-theme="dark"] .mode-badge.human {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
}
.mode-badge.bot {
  background: rgba(16, 185, 129, 0.14);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.35);
}
[data-theme="dark"] .mode-badge.bot {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}
.mode-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--surface, #1e1e1e);
}
.mode-dot.human {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}
.mode-dot.bot {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.thread-find {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.thread-find input {
  flex: 1;
  border: 0;
  background: var(--surface-2);
  padding: 8px 12px;
  font: inherit;
  color: var(--ink);
  border-radius: 8px;
}
.muted { color: var(--muted); font-size: 12px; }

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

.thread-loading {
  align-self: center;
  margin: auto 0;
  padding: 8px 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  font-size: 13px;
}

.thread {
  flex: 1;
  overflow: auto;
  padding: 12px 7% 18px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(circle at 18% 22%, color-mix(in srgb, var(--ink) 5%, transparent) 1.2px, transparent 1.4px),
    radial-gradient(circle at 72% 64%, color-mix(in srgb, var(--ink) 4%, transparent) 1px, transparent 1.2px);
  background-size: 28px 28px, 18px 18px;
}

/* WhatsApp Web style history loader */
.thread-history-loader {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 12px;
}

.btn-load-history {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(11, 20, 26, 0.1);
  transition: all 0.15s ease;
}

.btn-load-history:hover {
  background: color-mix(in srgb, var(--brand, #0F5C52) 12%, var(--surface-2));
  border-color: var(--brand, #0F5C52);
  color: var(--brand, #0F5C52);
}

.btn-load-history:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn-load-all-history {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-load-all-history:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
  border-color: var(--muted);
}

.btn-load-all-history:disabled {
  opacity: 0.5;
  cursor: wait;
}

.history-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinHistory 0.7s linear infinite;
}

@keyframes spinHistory {
  to { transform: rotate(360deg); }
}

.thread-history-end {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 10px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--muted);
}

.thread-history-end .end-text {
  font-weight: 500;
  opacity: 0.8;
}

.btn-sync-history-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 3px 8px;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sync-history-inline:hover {
  color: var(--brand, #0F5C52);
  border-color: var(--brand, #0F5C52);
  background: color-mix(in srgb, var(--brand, #0F5C52) 10%, transparent);
}

.btn-sync-history-inline:disabled {
  opacity: 0.5;
  cursor: wait;
}

.day-chip {
  align-self: center;
  margin: 10px 0 8px;
  padding: 5px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 1px 1px rgba(11, 20, 26, 0.08);
}

.bubble {
  max-width: 65%;
  padding: 6px 8px 4px 9px;
  background: var(--bubble-in);
  border: 0;
  display: block;
  border-radius: 7.5px;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  position: relative;
}
.bubble.in { align-self: flex-start; border-top-left-radius: 0; }
.bubble.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-top-right-radius: 0;
}
.bubble.system {
  align-self: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.08);
  max-width: 80%;
  padding: 6px 12px;
  border-radius: 8px;
}
.bubble .who { display: block; font-size: 12.8px; font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.bubble.out .who { color: var(--human); }
.bubble .txt { white-space: pre-wrap; word-break: break-word; font-size: 14.2px; line-height: 1.35; }
.bubble .when {
  float: right;
  margin: 4px 0 -2px 12px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.bubble .ticks { width: 16px; height: 11px; display: inline-block; opacity: 0.7; }
.bubble.hit { outline: 2px solid var(--brand); outline-offset: 2px; }
.bubble.ticket-anchor { box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 55%, transparent); }

.bubble-actions-btn {
  position: absolute;
  top: 3px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(4px);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease, transform 0.12s ease;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  padding: 0;
}
.bubble:hover .bubble-actions-btn,
.bubble-actions-btn:focus,
.bubble-actions-btn.active {
  opacity: 1;
  pointer-events: auto;
}
.bubble-actions-btn:hover {
  background: var(--surface);
  color: var(--ink);
  transform: scale(1.08);
}
@media (max-width: 768px) {
  .bubble-actions-btn {
    opacity: 0.7;
    pointer-events: auto;
  }
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px 10px;
  background: var(--composer-bar);
  border-top: 0;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.macro-select {
  max-width: 92px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 0;
  cursor: pointer;
}
.composer textarea {
  resize: none;
  min-height: 42px;
  max-height: 140px;
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  background: var(--surface);
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  width: auto;
}
.composer .error { margin: 0; }
.composer-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.composer-preview.hidden { display: none; }
.composer-preview button {
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 0;
}
.composer-tools { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.send-btn {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.send-btn svg { width: 20px; height: 20px; margin-left: 2px; }
.send-btn:hover { background: var(--brand-hover); }
.icon-btn.ghost-icon {
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 50%;
}
.icon-btn.ghost-icon:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }
.icon-btn.rec {
  background: #c0392b;
  color: #fff;
}
.bubble .media-img-card {
  display: flex;
  flex-direction: column;
  max-width: min(320px, 70vw);
  margin: 4px 0 6px;
  border-radius: 8px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--line);
}
.bubble .media-img-wrap {
  position: relative;
  cursor: zoom-in;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.05);
}
.bubble .media-img {
  width: 100%;
  max-width: 100%;
  max-height: 380px;
  object-fit: contain;
  display: block;
  border-radius: 0;
  margin: 0;
  transition: transform 0.18s ease;
}
.bubble .media-img-wrap:hover .media-img {
  transform: scale(1.015);
}
.bubble .media-img-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.22);
  opacity: 0;
  transition: opacity 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.bubble .media-img-wrap:hover .media-img-overlay {
  opacity: 1;
}
.bubble .media-img-zoom-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  background: rgba(15, 23, 32, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  backdrop-filter: blur(4px);
}
.bubble .media-img-zoom-hint svg {
  width: 13px;
  height: 13px;
}
.bubble .media-img-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 6px 8px;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  border-top: 1px solid var(--line);
}
.bubble .media-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}
.bubble .media-action-btn svg {
  width: 13px;
  height: 13px;
}
.bubble .media-action-btn:hover {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  color: var(--brand);
  border-color: var(--brand);
}
.bubble .media-action-btn.download-btn {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  color: var(--brand);
  border-color: color-mix(in srgb, var(--brand) 30%, transparent);
  font-weight: 600;
}
.bubble .media-action-btn.download-btn:hover {
  background: var(--brand);
  color: var(--on-brand, #fff);
  border-color: var(--brand);
}
.bubble audio {
  width: min(280px, 75vw);
  margin: 4px 0 6px;
  display: block;
  border-radius: 20px;
}
.bubble .bubble-audio-wrap {
  display: flex;
  flex-direction: column;
  margin: 2px 0 4px;
}
.thread-skeleton-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 16px 8px;
  width: 100%;
  box-sizing: border-box;
}
.thread-skeleton-bubble {
  height: 38px;
  border-radius: 12px;
  background: var(--line, #333);
  opacity: 0.35;
  animation: skeleton-pulse 1s ease-in-out infinite alternate;
}
@keyframes skeleton-pulse {
  0% { opacity: 0.2; }
  100% { opacity: 0.5; }
}
.bubble .file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  font-size: 13px;
}
.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.icon-btn svg { width: 18px; height: 18px; pointer-events: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.is-muted {
  color: var(--muted);
  opacity: 0.65;
}
.icon-btn.is-muted:hover {
  color: var(--danger, #ef4444);
  opacity: 1;
}
.icon-btn#sound-toggle:not(.is-muted),
.icon-btn#btn-sound-thread:not(.is-muted) {
  color: var(--brand);
}
[data-theme="dark"] .icon-btn#sound-toggle:not(.is-muted),
[data-theme="dark"] .icon-btn#btn-sound-thread:not(.is-muted) {
  color: #10b981;
}
.actions #btn-sound-thread:not(.is-muted) {
  color: var(--brand);
}
[data-theme="dark"] .actions #btn-sound-thread:not(.is-muted) {
  color: #10b981;
}
.qc-wrap { position: relative; }
.qc-btn { color: var(--on-brand); background: var(--brand); border-color: var(--brand); }
.qc-btn:hover { background: var(--brand-hover); }
.qc-btn.is-open { background: var(--brand-deep); }
.qc-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 55;
  min-width: 230px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.qc-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--ink);
  border: 0;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.qc-item:hover { background: var(--surface-2); }
.qc-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--brand); }
.wa-lines { list-style: none; padding: 0; margin: 10px 0 14px; display: grid; gap: 6px; }
.wa-line {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
  font: inherit;
  border-radius: 8px;
  cursor: pointer;
}
.wa-line.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--surface)); }
.wa-line .muted { margin-left: auto; font-size: 12px; }

#wa-modal:empty { display: none; }
.wa-back {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 22, 0.48);
  display: grid;
  place-items: center;
  z-index: 80;
  padding: 18px;
}
.wa-card {
  width: min(420px, 100%);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.wa-card h2 { font-size: 20px; margin-bottom: 6px; }
.wa-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.wa-card img.qr {
  width: 240px;
  height: 240px;
  display: block;
  margin: 12px auto;
  background: #fff;
  border-radius: 10px;
  padding: 8px;
}
.wa-card .pair {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 22px;
  letter-spacing: 0.18em;
  text-align: center;
  font-weight: 700;
  margin: 8px 0 14px;
}
.wa-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.wa-actions button { flex: 1; min-width: 120px; }
.wa-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--warn-ink);
}
.wa-dot.on { background: var(--ok-ink); }

.wa-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  user-select: none;
}
.wa-avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.wa-avatar.has-photo {
  background: #d9d9d9;
  overflow: hidden;
  padding: 0;
}
.wa-avatar.has-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.emoji-panel {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  background: var(--surface);
  border-radius: 8px;
  max-height: 180px;
  overflow: auto;
}
.emoji-panel button {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1.3;
  cursor: pointer;
  border-radius: 6px;
  padding: 4px;
}
.emoji-panel button:hover { background: var(--surface-2); }

.macro-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25);
  margin-bottom: 8px;
  z-index: 50;
  overscroll-behavior: contain;
}
.macro-panel.hidden {
  display: none !important;
}
.macro-panel-header {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  border-top-left-radius: 9px;
  border-top-right-radius: 9px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 2;
}
.macro-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(128, 128, 128, 0.08);
  transition: background 0.1s ease;
  user-select: none;
}
.macro-item:last-child {
  border-bottom: 0;
}
.macro-item:hover,
.macro-item.selected {
  background: var(--surface-2);
}
.macro-item-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
  min-width: 0;
}
.macro-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
.macro-item-shortcut {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  font-size: 12px;
  color: var(--brand);
  background: rgba(16, 185, 129, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
[data-theme="dark"] .macro-item-shortcut {
  color: #34d399;
  background: rgba(16, 185, 129, 0.2);
}
.macro-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.macro-item-preview {
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 520px;
}
.macro-item-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.jump-bottom {
  position: absolute;
  right: 18px;
  bottom: 16px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
}
.jump-bottom svg { width: 20px; height: 20px; }
.jump-bottom:hover { color: var(--ink); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: rgba(10, 15, 20, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  cursor: zoom-out;
}
.lightbox.hidden {
  display: none !important;
}
.lightbox-dialog {
  display: flex;
  flex-direction: column;
  max-width: min(980px, 95vw);
  max-height: 94vh;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  cursor: default;
}
.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  gap: 12px;
  flex-shrink: 0;
}
.lightbox-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.lightbox-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
  flex-shrink: 0;
}
.lightbox-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.lightbox-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}
.lightbox-btn svg {
  width: 14px;
  height: 14px;
}
.lightbox-btn:hover {
  background: color-mix(in srgb, var(--ink) 8%, var(--surface-2));
  color: var(--ink);
}
.lightbox-btn.highlight {
  background: var(--brand);
  color: var(--on-brand, #fff);
  border-color: var(--brand);
  font-weight: 600;
}
.lightbox-btn.highlight:hover {
  background: var(--brand-hover);
}
.lightbox-btn.close-btn {
  font-size: 20px;
  padding: 3px 10px;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--muted);
}
.lightbox-btn.close-btn:hover {
  color: var(--ink);
  background: var(--surface-2);
}
.lightbox-body {
  padding: 16px;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  max-height: calc(94vh - 56px);
}
.lightbox-img {
  max-width: 100%;
  max-height: calc(94vh - 90px);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  cursor: zoom-in;
}

.list li.pinned .name::before {
  content: "📌 ";
  font-size: 11px;
}
.pin-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.pin-chip {
  flex: 0 0 auto;
  max-width: 220px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-left: 4px solid var(--brand);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  font-size: 13px;
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}
.reply-bar.hidden { display: none; }
.reply-bar p { margin: 0; }
.reply-bar #reply-bar-title {
  font-weight: 700;
  color: var(--brand);
  font-size: 11.5px;
  margin-bottom: 2px;
}
.reply-bar #reply-bar-text {
  color: var(--muted);
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-bar #reply-bar-clear {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.1s ease, background 0.1s ease;
}
.reply-bar #reply-bar-clear:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
}

.quote {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 6px;
  padding: 5px 8px;
  border-left: 3.5px solid var(--brand);
  border-radius: 4px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  max-width: 100%;
  transition: background 0.12s ease;
}
.quote:hover {
  background: color-mix(in srgb, var(--ink) 11%, transparent);
}
.quote-author {
  font-weight: 700;
  font-size: 11.5px;
  color: var(--brand);
}
.bubble.out .quote-author {
  color: var(--human);
}
.quote-body {
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble.deleted .txt { font-style: italic; color: var(--muted); }
.bubble.pinned { box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 35%, transparent); }
.edited-mark { font-size: 11px; color: var(--muted); margin-right: 4px; }

.ctx-menu {
  position: fixed;
  z-index: 99999;
  min-width: 175px;
  padding: 6px;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22), 0 0 1px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
}
.ctx-menu.hidden { display: none; }
.ctx-menu button,
.ctx-menu .ctx-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
}
.ctx-menu button:hover,
.ctx-menu .ctx-menu-item:hover {
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  color: var(--brand);
}
.ctx-menu button.danger,
.ctx-menu .ctx-menu-item.danger {
  color: var(--danger);
}
.ctx-menu button.danger:hover,
.ctx-menu .ctx-menu-item.danger:hover {
  background: #fee2e2;
  color: #dc2626;
}
.ctx-menu .ctx-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  opacity: 0.85;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .rail-resizer { display: none !important; }
  .stage { display: none; }
  .app[data-thread="1"] .rail { display: none; }
  .app[data-thread="1"] .stage { display: flex; min-height: 0; }
  .thread-back { display: grid; }
  .thread { padding: 8px 10px 16px; }
  .bubble { max-width: 88%; }
  .macro-select { max-width: 72px; }
}

.bulletin-back {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 32, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
}
.bulletin-card {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
}
.bulletin-back[data-priority="URGENT"] .bulletin-card { border-color: #b42318; }
.bulletin-back[data-priority="WARNING"] .bulletin-card { border-color: #b54708; }
.bulletin-body { margin: 12px 0 18px; line-height: 1.5; }
.bulletin-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Ticket badge in conversation list */
.badge.ticket-badge {
  background: #193b73;
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 600;
  margin-left: 2px;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.badge.ticket-badge:hover {
  transform: scale(1.1);
  filter: brightness(1.2);
}
[data-theme="light"] .badge.ticket-badge {
  background: #193b73;
  color: #ffffff;
}

/* Modal styles for New WhatsApp Chat */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
  padding: 16px;
}
.modal-box {
  background: var(--surface, #111827);
  color: var(--ink, #f9fafb);
  border: 1px solid var(--line, #374151);
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  padding: 24px;
}
[data-theme="light"] .modal-box {
  background: #ffffff;
  color: #111827;
  border-color: #e5e7eb;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--muted, #9ca3af);
  cursor: pointer;
  padding: 0;
}
.modal-close:hover {
  color: var(--ink, #111827);
}
#new-chat-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}
#new-chat-form input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line, #374151);
  background: var(--surface-2, #1f2937);
  color: inherit;
  font-size: 14px;
}
[data-theme="light"] #new-chat-form input {
  background: #f9fafb;
  border-color: #d1d5db;
}
#new-chat-form small {
  font-size: 11px;
  opacity: 0.7;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions button {
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.modal-actions button[type="submit"] {
  background: var(--brand, #193b73);
  color: #ffffff;
  border: 0;
}
.modal-actions button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

/* Document / PDF Chip in Chat */
.bubble .file-chip {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-size: 13px;
  max-width: 320px;
  box-sizing: border-box;
}
[data-theme="light"] .bubble .file-chip {
  background: rgba(0, 0, 0, 0.04);
}
.file-chip-main {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-width: 0;
}
.file-chip-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.file-chip-icon svg {
  width: 20px;
  height: 20px;
}
.file-chip-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.file-chip-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.file-chip-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.file-chip-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 8px;
  margin-top: 2px;
}
[data-theme="light"] .file-chip-actions {
  border-top-color: rgba(0, 0, 0, 0.06);
}
.file-action-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  transition: all 0.15s ease;
}
[data-theme="light"] .file-action-btn {
  background: #ffffff;
}
.file-action-btn:hover {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}
.file-action-btn svg {
  width: 14px;
  height: 14px;
}

/* PDF Preview Modal */
.pdf-modal-box {
  width: min(920px, 94vw);
  height: min(88vh, 850px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
}
.pdf-modal-box .modal-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pdf-modal-body {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #2b2b2b;
  position: relative;
}
.pdf-modal-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Ticket Popup Modal */
.ticket-modal-box {
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 24px;
}
.ticket-modal-kicker {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted, #9ca3af);
  letter-spacing: 0.05em;
}
.ticket-modal-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line, #374151);
}
.ticket-tab-btn {
  background: var(--surface-2, #1f2937);
  color: var(--muted, #9ca3af);
  border: 1px solid var(--line, #374151);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.ticket-tab-btn.active {
  background: color-mix(in srgb, var(--brand, #0284c7) 20%, transparent);
  color: var(--brand, #38bdf8);
  border-color: var(--brand, #38bdf8);
  font-weight: 600;
}
.ticket-modal-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}
.ticket-context-card {
  background: var(--surface-2, #1f2937);
  border: 1px solid var(--line, #374151);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
[data-theme="light"] .ticket-context-card {
  background: #f9fafb;
  border-color: #e5e7eb;
}
.ticket-brief-row {
  font-size: 13px;
  line-height: 1.45;
}
.ticket-brief-row strong {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted, #9ca3af);
  margin-bottom: 3px;
}
.ticket-brief-row.resolution {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
}
.ticket-brief-row.resolution strong {
  color: #10b981;
}
.ticket-modal-reply-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ticket-reply-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ticket-reply-label .label-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
}
.ticket-reply-label .label-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted, #9ca3af);
}
.ticket-reply-label textarea {
  width: 100%;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  background: var(--surface-2, #1f2937);
  color: var(--ink, #f9fafb);
  border: 1px solid var(--line, #374151);
  resize: vertical;
  box-sizing: border-box;
}
[data-theme="light"] .ticket-reply-label textarea {
  background: #ffffff;
  color: #111827;
  border-color: #d1d5db;
}
.ticket-reply-label textarea:focus {
  outline: none;
  border-color: var(--brand, #0284c7);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand, #0284c7) 35%, transparent);
}
.ticket-ai-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.ticket-badge.RESOLVED {
  background: #123526;
  color: #6ee7b7;
}
.ticket-badge.CLOSED {
  background: #243040;
  color: #94a3b8;
}
.ticket-badge.OPEN {
  background: rgba(14, 165, 233, 0.2);
  color: #7dd3fc;
}
[data-theme="light"] .ticket-badge.RESOLVED {
  background: #dcfce7;
  color: #15803d;
}
[data-theme="light"] .ticket-badge.CLOSED {
  background: #f1f5f9;
  color: #64748b;
}
[data-theme="light"] .ticket-badge.OPEN {
  background: #e0f2fe;
  color: #0369a1;
}

/* Contact Header & Modal */
.thread-id-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 6px;
  margin: -2px -6px;
  transition: background 0.15s ease, color 0.15s ease;
  text-decoration: none;
  color: inherit;
}
.thread-id-link:hover {
  background: var(--surface-2, rgba(255, 255, 255, 0.08));
}
.thread-id-link:hover #thread-name {
  color: var(--brand, #38bdf8);
}
.contact-edit-icon {
  width: 14px;
  height: 14px;
  opacity: 0.5;
  transition: opacity 0.15s ease, color 0.15s ease;
  vertical-align: middle;
}
.thread-id-link:hover .contact-edit-icon {
  opacity: 1;
  color: var(--brand, #38bdf8);
}
.contact-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: none;
  transition: filter 0.15s ease;
}
.contact-badge:hover {
  filter: brightness(1.15);
}
.contact-badge.CLIENT {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}
.contact-badge.LEAD {
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
}
.contact-badge.GROUP {
  background: rgba(168, 85, 247, 0.18);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.4);
}
[data-theme="light"] .contact-badge.CLIENT {
  background: #dcfce7;
  color: #15803d;
  border-color: #86efac;
}
[data-theme="light"] .contact-badge.LEAD {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #93c5fd;
}
[data-theme="light"] .contact-badge.GROUP {
  background: #f3e8ff;
  color: #7e22ce;
  border-color: #d8b4fe;
}
.contact-modal-box {
  max-width: 480px;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.contact-modal-kicker {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted, #9ca3af);
  letter-spacing: 0.05em;
}
.contact-form-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.contact-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.contact-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #9ca3af);
}
.contact-field input {
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2, #1f2937);
  border: 1px solid var(--line, #374151);
  color: var(--ink, #f9fafb);
  font-size: 14px;
  box-sizing: border-box;
  width: 100%;
}
[data-theme="light"] .contact-field input {
  background: #ffffff;
  color: #111827;
  border-color: #d1d5db;
}
.contact-field input:focus {
  outline: none;
  border-color: var(--brand, #0284c7);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand, #0284c7) 35%, transparent);
}
.contact-field input:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}
.contact-crm-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2, #1f2937);
  border: 1px solid var(--line, #374151);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  gap: 12px;
}
[data-theme="light"] .contact-crm-box {
  background: #f8fafc;
  border-color: #e2e8f0;
}
.contact-crm-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--brand, #38bdf8);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  font-size: 12px;
}
.contact-crm-link:hover {
  text-decoration: underline;
}

/* Transfer Modal & Selects */
.transfer-modal-box {
  max-width: 440px;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.contact-field select {
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2, #1f2937);
  border: 1px solid var(--line, #374151);
  color: var(--ink, #f9fafb);
  font-size: 14px;
  box-sizing: border-box;
  width: 100%;
}
[data-theme="light"] .contact-field select {
  background: #ffffff;
  color: #111827;
  border-color: #d1d5db;
}
.contact-field select:focus {
  outline: none;
  border-color: var(--brand, #0284c7);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand, #0284c7) 35%, transparent);
}

/* Ticket Macro Select in Chat */
.ticket-macro-select {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2, rgba(255, 255, 255, 0.08));
  border: 1px solid var(--line, #374151);
  color: var(--ink, #f9fafb);
  cursor: pointer;
  max-width: 170px;
}
[data-theme="light"] .ticket-macro-select {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #1e293b;
}

/* Group Info Modal */
.group-modal-box {
  max-width: 520px;
  padding: 24px;
}
.group-info-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line, #374151);
}
.group-desc-wrap {
  margin-bottom: 16px;
}
.group-desc-wrap label,
.group-participants-section label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted, #9ca3af);
  margin-bottom: 6px;
  letter-spacing: 0.05em;
}
.group-desc-wrap p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2, rgba(255,255,255,0.04));
  padding: 8px 12px;
  border-radius: 8px;
}
.group-participants-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--line, #374151);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface-2, rgba(255,255,255,0.02));
}
.participant-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.participant-item:hover {
  background: var(--surface-3, rgba(255, 255, 255, 0.05));
}
.participant-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.participant-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-3, #374151);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.participant-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--brand, #0284c7) 20%, transparent);
  color: var(--brand, #38bdf8);
  border: 1px solid color-mix(in srgb, var(--brand, #0284c7) 40%, transparent);
  text-transform: uppercase;
}

/* Danger Button */
.btn-danger {
  background: #dc2626 !important;
  color: #ffffff !important;
  border: none !important;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.btn-danger:hover {
  background: #b91c1c !important;
}
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Leave Group Dialog Box */
.leave-group-box {
  max-width: 400px;
}

/* Drag & Drop Overlay */
.drag-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border: 3px dashed var(--brand, #38bdf8);
  border-radius: 12px;
  margin: 8px;
}
.drag-drop-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.drag-drop-box svg {
  width: 48px;
  height: 48px;
  color: var(--brand, #38bdf8);
}




/* Aviso quando a conversa ainda nao tem mensagens (evita corpo em branco) */
.thread-empty-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  color: #8a8f98;
  font-size: 13px;
  padding: 28px 12px;
}
