/* Painel WhatsApp: design system (tokens em :root, tema escuro por data-theme ou pelo sistema) */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --surface-3: #e7eaee;
  --hover: rgba(17, 24, 39, 0.045);
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --text: #15181d;
  --text-2: #4f5763;
  --text-3: #66707c;
  --accent: #0b7a5c;
  --accent-hover: #09684e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3ec;
  --accent-text: #08664c;
  --bubble-in: #ffffff;
  --bubble-out: #dcf1e7;
  --bubble-out-text: #10261e;
  --chat-bg: #eef0f2;
  --warn: #a35a00;
  --warn-soft: #fdf0dc;
  --danger: #c2352b;
  --danger-soft: #fbe7e5;
  --read: #1f8fd6;
  --mark: #c98a00;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 20px -6px rgba(16, 24, 40, 0.16), 0 2px 6px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, 0.28);
  --veil: rgba(15, 18, 22, 0.42);
  --line-0: #c27803; --line-1: #6d4ae0; --line-2: #0a7fbf; --line-3: #d0365e; --line-4: #0e8f86; --line-5: #5f7a0e;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --rail-w: 220px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1013;
  --surface: #14181d;
  --surface-2: #1a1f25;
  --surface-3: #232930;
  --hover: rgba(255, 255, 255, 0.05);
  --border: #252b32;
  --border-strong: #343b44;
  --text: #e8ebee;
  --text-2: #a9b1bb;
  --text-3: #8b94a0;
  --accent: #2fbf8f;
  --accent-hover: #4fd3a6;
  --accent-ink: #04130d;
  --accent-soft: rgba(47, 191, 143, 0.14);
  --accent-text: #5fd6ad;
  --bubble-in: #1c2228;
  --bubble-out: #133a2e;
  --bubble-out-text: #e3f4ec;
  --chat-bg: #0f1317;
  --warn: #f2a93b;
  --warn-soft: rgba(242, 169, 59, 0.14);
  --danger: #f2685c;
  --danger-soft: rgba(242, 104, 92, 0.14);
  --read: #4fb6f2;
  --mark: #f0b429;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 56px -12px rgba(0, 0, 0, 0.75);
  --veil: rgba(0, 0, 0, 0.6);
  --line-0: #f0a73a; --line-1: #a58bff; --line-2: #4fb6f2; --line-3: #f26d8f; --line-4: #3ccfc2; --line-5: #a7c94a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1013;
    --surface: #14181d;
    --surface-2: #1a1f25;
    --surface-3: #232930;
    --hover: rgba(255, 255, 255, 0.05);
    --border: #252b32;
    --border-strong: #343b44;
    --text: #e8ebee;
    --text-2: #a9b1bb;
    --text-3: #8b94a0;
    --accent: #2fbf8f;
    --accent-hover: #4fd3a6;
    --accent-ink: #04130d;
    --accent-soft: rgba(47, 191, 143, 0.14);
    --accent-text: #5fd6ad;
    --bubble-in: #1c2228;
    --bubble-out: #133a2e;
    --bubble-out-text: #e3f4ec;
    --chat-bg: #0f1317;
    --warn: #f2a93b;
    --warn-soft: rgba(242, 169, 59, 0.14);
    --danger: #f2685c;
    --danger-soft: rgba(242, 104, 92, 0.14);
    --read: #4fb6f2;
    --mark: #f0b429;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 56px -12px rgba(0, 0, 0, 0.75);
    --veil: rgba(0, 0, 0, 0.6);
    --line-0: #f0a73a; --line-1: #a58bff; --line-2: #4fb6f2; --line-3: #f26d8f; --line-4: #3ccfc2; --line-5: #a7c94a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: 100vh;
  grid-template-rows: 100dvh;
  overflow: hidden;
}
::selection { background: var(--accent-soft); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
input, select, textarea { accent-color: var(--accent); caret-color: var(--accent); }
.ic { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic-xl { width: 40px; height: 40px; stroke-width: 1.4; }

/* ---------- Botões ---------- */
.btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 36px; padding: 0 0.95rem; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.875rem; border: 1px solid transparent; white-space: nowrap;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-sm { min-height: 32px; padding: 0 0.75rem; font-size: 0.8125rem; }
.danger { color: var(--danger) !important; }
.btn-secondary.danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
button:disabled { opacity: 0.45; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0;
  border: none; background: transparent; color: var(--text-2); border-radius: var(--radius-sm);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--mark); }
.icon-btn.on .ic { fill: currentColor; }
.icon-btn.on.note-on { color: var(--accent-text); }
.icon-btn.on.note-on .ic { fill: none; }

/* ---------- Campos ---------- */
input[type="text"], input[type="search"], input[type="tel"], input[type="url"], input[type="number"],
input[type="password"], input[type="date"], input[type="time"], select, textarea {
  width: 100%; min-height: 38px; padding: 0.45rem 0.7rem;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
::placeholder { color: var(--text-3); opacity: 1; }
textarea { resize: vertical; line-height: 1.5; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8125rem; font-weight: 600; color: var(--text-2); }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; color: var(--text); }
label.check input { width: 16px; height: 16px; margin: 0; }
.form-grid { display: flex; flex-direction: column; gap: 0.85rem; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.form-grid h3 { margin: 0.4rem 0 0; font-size: 0.875rem; }
.form-grid > button { align-self: flex-start; }

/* ---------- Chips e avatares ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem; height: 26px; padding: 0 0.6rem;
  border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; border: none;
}
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-stage { background: var(--accent-soft); color: var(--accent-text); }
.chip-stage:hover { filter: brightness(0.97); }
.avatar {
  --lc: var(--text-3);
  position: relative; width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%;
  display: grid; place-items: center; font-weight: 650; font-size: 0.95rem;
  background: var(--surface-3); color: var(--text-2);
}
.avatar-sm { width: 30px; height: 30px; font-size: 0.8rem; }
.avatar .line-dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--lc); box-shadow: 0 0 0 2px var(--surface); }
.lc-0 { --lc: var(--line-0); } .lc-1 { --lc: var(--line-1); } .lc-2 { --lc: var(--line-2); }
.lc-3 { --lc: var(--line-3); } .lc-4 { --lc: var(--line-4); } .lc-5 { --lc: var(--line-5); }

/* ---------- Navegação lateral ---------- */
#topbar {
  grid-column: 1; grid-row: 1; display: flex; flex-direction: column; gap: 0.25rem;
  padding: 1rem 0.75rem; background: var(--surface); border-right: 1px solid var(--border); min-height: 0;
}
.brand { display: flex; align-items: center; gap: 0.6rem; padding: 0.25rem 0.5rem 1.1rem; min-width: 0; }
#header-logo { max-height: 30px; max-width: 120px; width: auto; object-fit: contain; }
.brand-mark { color: var(--accent); flex-shrink: 0; }
#header-logo:not([hidden]) + .brand-mark { display: none; }
#header-title { font-weight: 700; font-size: 0.95rem; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top-tabs { display: flex; flex-direction: column; gap: 2px; }
.top-tab {
  text-decoration: none;
  display: flex; align-items: center; gap: 0.7rem; width: 100%; min-height: 38px; padding: 0 0.7rem;
  border: none; border-radius: var(--radius-sm); background: transparent; color: var(--text-2);
  font-weight: 550; font-size: 0.9rem; text-align: left;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.top-tab:hover { background: var(--hover); color: var(--text); }
.top-tab.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 650; }
.tab-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center;
  font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--accent); color: var(--accent-ink);
}
.nav-badge.alert { background: var(--danger); color: #fff; }
#user-menu { margin-top: auto; position: relative; }
#user-menu-button {
  display: flex; align-items: center; gap: 0.6rem; width: 100%; min-height: 44px; padding: 0 0.5rem;
  border: none; background: transparent; border-radius: var(--radius-sm); text-align: left; font-weight: 550; font-size: 0.875rem;
}
#user-menu-button:hover { background: var(--hover); }
.menu {
  position: absolute; z-index: 60; min-width: 220px; padding: 0.35rem; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md);
  animation: pop 0.16s var(--ease);
}
#user-menu-items { left: 0; bottom: calc(100% + 6px); }
.menu-right { right: 0; top: calc(100% + 6px); }
.menu button, .menu a {
  display: flex; align-items: center; gap: 0.6rem; min-height: 36px; padding: 0 0.65rem; border: none; background: transparent;
  border-radius: var(--radius-sm); text-align: left; font-size: 0.875rem; color: var(--text); text-decoration: none; white-space: nowrap;
}
.menu button:hover, .menu a:hover { background: var(--hover); }
.menu-who { padding: 0.5rem 0.65rem 0.6rem; border-bottom: 1px solid var(--border); margin-bottom: 0.3rem; font-size: 0.8rem; color: var(--text-3); }
.menu-who strong { display: block; color: var(--text); font-size: 0.875rem; }
.menu-wrap { position: relative; display: inline-flex; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Áreas ---------- */
#app, #crm-view, #settings-modal { grid-column: 2; grid-row: 1; min-width: 0; min-height: 0; }
#app { display: grid; grid-template-columns: 372px minmax(0, 1fr); }
.view-title { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.015em; }
.view-sub { margin: 0.15rem 0 0; font-size: 0.8125rem; color: var(--text-3); }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.5rem 1rem; }
.view-actions { display: flex; gap: 0.5rem; }

#status-message {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 90;
  max-width: min(560px, calc(100vw - 32px)); padding: 0.65rem 1rem; border-radius: var(--radius);
  background: var(--text); color: var(--surface); font-size: 0.875rem; font-weight: 500; box-shadow: var(--shadow-lg);
}
#status-message:empty { display: none; }

/* ---------- Lista de conversas ---------- */
#chat-list { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); }
#chat-filters { display: flex; flex-direction: column; gap: 0.7rem; padding: 1.1rem 1rem 0.6rem; border-bottom: 1px solid var(--border); }
.list-head { display: flex; align-items: center; gap: 0.5rem; }
.list-head .view-title { flex: 1; }
.pill-select {
  width: auto !important; max-width: 150px; min-height: 32px !important; padding: 0 1.8rem 0 0.7rem !important;
  border-radius: 999px !important; font-size: 0.8125rem; font-weight: 600; color: var(--text-2);
  appearance: none; -webkit-appearance: none; text-overflow: ellipsis;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2366707c' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.65rem center !important;
  border-color: transparent !important;
}
.search-field { position: relative; display: block; }
.search-field .ic { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-field input { padding-left: 2.2rem; background: var(--surface-2); border-color: transparent; }
.search-field input:focus { background: var(--surface); }
.seg { display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; margin: 0 -0.25rem; padding: 0 0.25rem 0.15rem; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  display: inline-flex; align-items: center; gap: 0.35rem; flex-shrink: 0; height: 30px; padding: 0 0.7rem;
  border: none; border-radius: 999px; background: transparent; color: var(--text-2); font-size: 0.8125rem; font-weight: 600;
}
.seg button:hover { background: var(--hover); color: var(--text); }
.seg button.on { background: var(--text); color: var(--surface); }
.seg-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; display: inline-grid; place-items: center; font-size: 0.7rem; background: var(--warn-soft); color: var(--warn); font-variant-numeric: tabular-nums; }
.seg button.on .seg-count { background: var(--warn); color: #fff; }
#select-row { display: flex; align-items: center; gap: 0.25rem; font-size: 0.8125rem; color: var(--text-3); }
#select-hint { flex: 1; }
#chat-list-items { flex: 1; overflow-y: auto; padding: 0.35rem 0.5rem 0.75rem; }
.list-section {
  display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 0.6rem 0.35rem;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3);
}
.list-section.waiting { color: var(--warn); }
.chat-list-empty { padding: 3rem 1.5rem; color: var(--text-3); text-align: center; font-size: 0.875rem; }
.chat-item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem; border-radius: var(--radius);
  cursor: pointer; transition: background-color 0.12s var(--ease);
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--accent-soft); }
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-name-row { display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.chat-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.chat-item-marks { display: inline-flex; gap: 2px; color: var(--mark); }
.chat-item-marks .ic { width: 13px; height: 13px; fill: currentColor; }
.chat-item-time { font-size: 0.75rem; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chat-item-wait { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.75rem; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-2); }
.chat-item-wait .ic { width: 13px; height: 13px; }
.chat-item-wait.wait-2 { color: var(--warn); }
.chat-item-wait.wait-3 { color: var(--danger); }
.chat-item-sub { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.1rem; min-width: 0; }
.chat-item-preview { flex: 1; min-width: 0; font-size: 0.8125rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-tag { display: inline-flex; align-items: center; gap: 0.3rem; max-width: 40%; flex-shrink: 0; font-size: 0.72rem; font-weight: 600; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line-tag i { width: 7px; height: 7px; border-radius: 50%; background: var(--lc); flex-shrink: 0; }
.chat-item.has-unread .chat-item-name { font-weight: 700; }
.chat-item.has-unread .chat-item-preview { color: var(--text); font-weight: 550; }
.chat-item.has-unread .chat-item-time { color: var(--accent-text); font-weight: 650; }
.unread {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.select-box { flex-shrink: 0; width: 18px; height: 18px; margin: 0; }
#bulk-bar { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); background: var(--surface); box-shadow: 0 -6px 16px -10px rgba(0, 0, 0, 0.2); }
#bulk-count { font-size: 0.8125rem; font-weight: 650; }
#bulk-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
#bulk-buttons .btn-secondary { min-height: 32px; padding: 0 0.7rem; font-size: 0.8125rem; }

/* ---------- Conversa ---------- */
#thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
#thread:not(.has-chat) > :not(#thread-empty) { display: none !important; }
#thread.has-chat > #thread-empty { display: none; }
.empty-state { margin: auto; text-align: center; color: var(--text-3); max-width: 320px; padding: 2rem; }
.empty-state .ic-xl { color: var(--border-strong); }
.empty-title { margin: 0.9rem 0 0.25rem; font-size: 1rem; font-weight: 650; color: var(--text); }
.empty-text { margin: 0; font-size: 0.875rem; }
#thread-header {
  display: flex; align-items: center; gap: 0.5rem; min-height: 64px; padding: 0.6rem 1rem 0.6rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
#thread-back { display: none; margin-left: -0.5rem; }
#thread-header-info { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }
.thread-who { min-width: 0; }
.thread-name { font-weight: 700; font-size: 0.975rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-meta { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-meta .line-tag { max-width: none; }
#thread-actions { display: flex; align-items: center; gap: 0.1rem; margin-left: 0.25rem; padding-left: 0.4rem; border-left: 1px solid var(--border); }
#thread-marks { display: inline-flex; }

#messages { flex: 1; overflow-y: auto; padding: 1.25rem clamp(1rem, 4vw, 3.5rem); display: flex; flex-direction: column; gap: 0.3rem; }
.day-divider { align-self: center; margin: 0.9rem 0 0.5rem; padding: 0.2rem 0.75rem; border-radius: 999px; background: var(--surface); color: var(--text-3); font-size: 0.75rem; font-weight: 600; box-shadow: var(--shadow-sm); }
.new-messages-divider { align-self: center; margin: 0.6rem 0; padding: 0.2rem 0.8rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 0.75rem; font-weight: 700; }
.msg {
  position: relative; max-width: min(68%, 560px); padding: 0.45rem 0.7rem 0.35rem; border-radius: 12px;
  line-height: 1.42; box-shadow: var(--shadow-sm); cursor: pointer; overflow-wrap: anywhere;
}
.msg.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); border-top-right-radius: 4px; }
.msg.msg-new { box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-sm); }
.msg-deleted { cursor: default; font-style: italic; opacity: 0.65; }
.msg-caption { white-space: pre-wrap; }
.msg-time { margin-top: 0.15rem; font-size: 0.6875rem; color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; }
.msg.out .msg-time { color: color-mix(in srgb, var(--bubble-out-text) 62%, transparent); }
.msg-ticks { font-weight: 700; letter-spacing: -0.12em; margin-left: 0.2rem; }
.tick-sent, .tick-delivered, .tick-pending { opacity: 0.75; }
.tick-read { color: var(--read); }
.msg-actions { display: none; position: absolute; top: -14px; right: 6px; gap: 2px; padding: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-md); }
.msg:hover .msg-actions { display: flex; }
.msg-actions button { display: grid; place-items: center; width: 26px; height: 26px; border: none; border-radius: 6px; background: transparent; color: var(--text-2); }
.msg-actions button:hover { background: var(--hover); color: var(--text); }
.msg-actions .ic { width: 15px; height: 15px; }
.msg-quote {
  margin-bottom: 0.3rem; padding: 0.3rem 0.55rem; border-radius: 6px;
  background: color-mix(in srgb, currentColor 7%, transparent); box-shadow: inset 2px 0 0 var(--accent);
  font-size: 0.8125rem; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-media { display: block; max-width: 100%; border-radius: 8px; }
.msg-image { max-height: 320px; object-fit: contain; }
.msg-audio { width: 270px; max-width: 100%; height: 40px; }
.msg-document {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.55rem 0.7rem; border-radius: 8px; text-decoration: none; color: inherit;
  background: color-mix(in srgb, currentColor 6%, transparent); font-weight: 550;
}
.msg-document:hover { background: color-mix(in srgb, currentColor 10%, transparent); }
.msg-media + .msg-caption, .msg-document + .msg-caption { margin-top: 0.3rem; }
.msg-transcript { margin-top: 0.35rem; font-size: 0.85rem; line-height: 1.45; opacity: 0.85; max-width: 420px; }
.transcribe-button { margin-top: 0.3rem; height: 26px; padding: 0 0.65rem; border: none; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: color-mix(in srgb, currentColor 8%, transparent); }
.transcribe-button:hover { background: color-mix(in srgb, currentColor 14%, transparent); }

#reply-preview { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 1rem 0 1.25rem; background: var(--surface); color: var(--accent-text); border-top: 1px solid var(--border); }
#reply-preview-text {
  flex: 1; min-width: 0; padding: 0.4rem 0.7rem; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2);
  box-shadow: inset 2px 0 0 var(--accent); font-size: 0.8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#send-form { display: flex; align-items: center; gap: 0.3rem; padding: 0.65rem 1rem; background: var(--surface); border-top: 1px solid var(--border); }
#reply-preview:not([hidden]) + #send-form { border-top: none; }
#text-input { flex: 1; min-height: 42px; border-radius: 999px; padding: 0 1rem; background: var(--surface-2); border-color: transparent; }
#text-input:focus { background: var(--surface); }
#send-button { min-height: 42px; border-radius: 999px; padding: 0 1.05rem; }
#recording-indicator { flex: 1; display: flex; align-items: center; gap: 0.55rem; padding: 0 0.75rem; font-weight: 600; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.recording-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: recording-pulse 1s ease-in-out infinite; }
@keyframes recording-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
#mic-button.recording { color: var(--danger); background: var(--danger-soft); }

/* ---------- CRM ---------- */
#crm-view { display: flex; flex-direction: column; background: var(--bg); }
#crm-alerts { margin: 0 1.5rem 0.75rem; padding: 0.7rem 0.9rem; display: flex; flex-direction: column; gap: 0.45rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.crm-alerts-header { display: inline-flex; align-items: center; gap: 0.4rem; align-self: flex-start; border: none; background: transparent; padding: 0; font-weight: 700; font-size: 0.875rem; color: var(--text); }
.crm-alerts-header .ic { width: 15px; height: 15px; color: var(--text-3); transform: rotate(90deg); transition: transform 0.2s var(--ease); }
.crm-alerts-header[aria-expanded="false"] .ic { transform: none; }
.crm-alerts-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.crm-alerts-title { display: inline-flex; align-items: center; gap: 0.4rem; min-width: 150px; font-size: 0.78rem; font-weight: 650; color: var(--text-2); }
.crm-alerts-title i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.crm-alerts-title.overdue i { background: var(--danger); }
.crm-alerts-title.no-reply i { background: var(--warn); }
.crm-alerts-item { height: 28px; padding: 0 0.65rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: 0.78rem; font-weight: 550; }
.crm-alerts-item:hover { border-color: var(--border-strong); background: var(--surface); }
#crm-board { flex: 1; min-height: 0; display: flex; gap: 0.75rem; overflow-x: auto; padding: 0 1.5rem 1.25rem; }
.crm-column { flex: 0 0 264px; display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); border-radius: var(--radius-lg); transition: box-shadow 0.15s var(--ease), background-color 0.15s var(--ease); }
.crm-column.drag-over { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.crm-column-header { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; padding: 0.8rem 0.9rem 0.55rem; }
.crm-column-name { display: flex; align-items: center; gap: 0.45rem; font-weight: 700; font-size: 0.875rem; }
.crm-column-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.crm-column-total { font-size: 0.78rem; font-weight: 650; color: var(--accent-text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.crm-column-cards { flex: 1; overflow-y: auto; padding: 0 0.5rem 0.6rem; display: flex; flex-direction: column; gap: 0.45rem; min-height: 60px; }
.crm-column-empty { padding: 1rem 0.5rem; text-align: center; font-size: 0.78rem; color: var(--text-3); }
.crm-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 0.75rem 0.55rem; cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease); }
.crm-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.crm-card[draggable="true"] { cursor: grab; }
.crm-card-name { font-weight: 650; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-card-meta { font-size: 0.78rem; color: var(--text-3); margin-top: 0.15rem; }
.crm-card-meta .money { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.crm-card-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.5rem; }
.crm-card-tags:empty { display: none; }
.crm-followup, .crm-card-alert { display: inline-flex; align-items: center; gap: 0.25rem; height: 22px; padding: 0 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 650; }
.crm-followup .ic { width: 12px; height: 12px; }
.crm-followup-overdue { background: var(--danger-soft); color: var(--danger); }
.crm-followup-today { background: var(--warn-soft); color: var(--warn); }
.crm-followup-future { background: var(--surface-2); color: var(--text-2); }
.crm-card-alert { background: var(--warn-soft); color: var(--warn); }
.crm-card-actions { display: flex; gap: 0.15rem; margin-top: 0.45rem; margin-left: -0.3rem; }
.crm-card-btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem; min-width: 30px; height: 30px; padding: 0 0.45rem; border: none; border-radius: var(--radius-sm); background: transparent; color: var(--text-3); font-size: 0.78rem; font-weight: 600; }
.crm-card-btn:hover { background: var(--hover); color: var(--text); }
.crm-card-btn .ic { width: 16px; height: 16px; }
.crm-card-btn.active { background: var(--accent); color: var(--accent-ink); }
.crm-card-inline { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.45rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.crm-card-inline .crm-card-btn { background: var(--surface-2); color: var(--text); }
.crm-card-inline .crm-card-btn.active { background: var(--accent); color: var(--accent-ink); }
.crm-card-inline input { flex: 1; min-width: 0; min-height: 32px; }
#crm-board.crm-mobile { flex-direction: column; padding: 0 16px 1rem; gap: 0.6rem; }
.crm-stage-tabs { display: flex; gap: 0.3rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 0.2rem; flex-shrink: 0; }
.crm-stage-tab { flex-shrink: 0; height: 32px; padding: 0 0.8rem; border: none; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }
.crm-stage-tab.active { background: var(--text); color: var(--surface); }
.crm-mobile-list { display: flex; flex-direction: column; gap: 0.5rem; overflow-y: auto; }
.crm-mobile .crm-card { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.crm-mobile .crm-card-btn { min-width: 38px; height: 38px; }

#crm-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 70; width: 400px; max-width: 100vw;
  display: flex; flex-direction: column; gap: 0.9rem; padding: 1.1rem 1.25rem 1.5rem; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: drawer 0.25s var(--ease);
}
@keyframes drawer { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.crm-panel-header { display: flex; align-items: center; gap: 0.5rem; }
.crm-panel-header h3 { flex: 1; margin: 0; font-size: 1.05rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#crm-panel-saved { display: inline-flex; align-items: center; height: 22px; padding: 0 0.55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 0.72rem; font-weight: 700; }
.crm-panel-actions .btn-primary { width: 100%; }
#crm-panel h4 { margin: 0.4rem 0 0; font-size: 0.8125rem; font-weight: 700; color: var(--text-2); }
#crm-panel-events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.crm-event { position: relative; display: flex; flex-direction: column; gap: 0.1rem; padding: 0.45rem 0 0.45rem 1rem; font-size: 0.8125rem; border-left: 1px solid var(--border); margin-left: 0.3rem; }
.crm-event::before { content: ""; position: absolute; left: -4px; top: 0.75rem; width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.crm-event-note::before { background: var(--accent); }
.crm-event-when { color: var(--text-3); font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.crm-event-stage .crm-event-text, .crm-event-created .crm-event-text { color: var(--text-2); }
#crm-panel-remove { align-self: flex-start; margin-top: auto; }

/* ---------- Ajustes ---------- */
.settings-page { display: flex; flex-direction: column; background: var(--bg); overflow-y: auto; }
.settings-page > .view-head { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--border); }
#settings-message { margin: 1rem 1.5rem 0; padding: 0.6rem 0.9rem; border-radius: var(--radius-sm); font-size: 0.875rem; font-weight: 550; }
.settings-message.error { background: var(--danger-soft); color: var(--danger); }
.settings-message.ok { background: var(--accent-soft); color: var(--accent-text); }
.settings-layout { display: grid; grid-template-columns: 180px minmax(0, 680px); gap: 2rem; padding: 1.25rem 1.5rem 4rem; }
.settings-nav { position: sticky; top: 104px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 0.45rem 0.7rem; border-radius: var(--radius-sm); color: var(--text-2); font-size: 0.875rem; font-weight: 550; text-decoration: none; }
.settings-nav a:hover { background: var(--hover); color: var(--text); }
.settings-body { display: flex; flex-direction: column; gap: 1.25rem; }
.set-section { scroll-margin-top: 110px; padding: 1.25rem 1.35rem 1.4rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); display: flex; flex-direction: column; gap: 1rem; }
.set-section header h2 { margin: 0; font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.set-section header p { margin: 0.2rem 0 0; font-size: 0.8125rem; color: var(--text-3); }
.row-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row-list:empty { display: none; }
.line-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.7rem 0.85rem; font-size: 0.8125rem; border-bottom: 1px solid var(--border); }
.line-row:last-child { border-bottom: none; }
.line-row .line-label { flex: 1; min-width: 9rem; font-weight: 650; font-size: 0.875rem; }
.line-row .line-label small { display: block; font-weight: 450; color: var(--text-3); font-size: 0.78rem; }
.line-row .btn-ghost { min-height: 30px; padding: 0 0.6rem; font-size: 0.8125rem; }
.line-row label.check { font-size: 0.8125rem; }
.line-state { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--text-3); font-weight: 550; }
.line-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.line-state.ok { color: var(--accent-text); } .line-state.ok::before { background: var(--accent); }
.line-state.off { color: var(--danger); } .line-state.off::before { background: var(--danger); }
#line-qr { display: flex; align-items: center; gap: 1rem; padding: 1rem; border-radius: var(--radius); background: var(--surface-2); }
#line-qr img { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: var(--radius); }
#line-qr p { margin: 0; font-size: 0.875rem; color: var(--text-2); }
.logo-row { display: flex; align-items: center; gap: 1rem; }
#brand-logo-preview { max-height: 44px; max-width: 160px; padding: 6px; border-radius: var(--radius-sm); background: var(--surface-2); }
#digest-line-hint { color: var(--warn); font-size: 0.8125rem; }
#digest-line-hint:empty { display: none; }
#user-password-box { padding: 0.8rem 0.9rem; border-radius: var(--radius); background: var(--warn-soft); font-size: 0.8125rem; }
#user-password-box p { margin: 0 0 0.35rem; font-weight: 650; color: var(--warn); }
#user-password-value { font-size: 1rem; font-weight: 700; user-select: all; margin-right: 0.5rem; }
input[type="file"] { font-size: 0.8125rem; font-weight: 500; color: var(--text-2); }
input[type="file"]::file-selector-button { margin-right: 0.7rem; height: 32px; padding: 0 0.8rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; }

/* ---------- Modais ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--veil); animation: fade 0.15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal-content {
  width: 420px; max-width: 100%; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 1.35rem; display: flex; flex-direction: column; gap: 0.8rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop 0.2s var(--ease);
}
.modal-content h3 { margin: 0 0 0.15rem; font-size: 1.05rem; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.3rem; }
#contact-results { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; }
#contact-results:empty { display: none; }
.contact-result { text-align: left; min-height: 36px; padding: 0 0.7rem; border: none; border-radius: var(--radius-sm); background: transparent; }
.contact-result:hover { background: var(--hover); }
#my-password-message { margin: 0; padding: 0.55rem 0.75rem; border-radius: var(--radius-sm); font-size: 0.8125rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Tablet: trilho só com ícones ---------- */
@media (min-width: 768px) and (max-width: 1080px) {
  :root { --rail-w: 72px; }
  .brand { justify-content: center; padding: 0.25rem 0 1rem; }
  #header-title, .tab-label, #user-menu-name { display: none; }
  #header-logo { max-width: 40px; }
  .top-tab, #user-menu-button { justify-content: center; padding: 0; position: relative; }
  .nav-badge { position: absolute; top: 2px; right: 4px; min-width: 17px; height: 17px; font-size: 0.65rem; }
  #app { grid-template-columns: 320px minmax(0, 1fr); }
}

/* ---------- Celular: barra inferior, lista e conversa em telas separadas ---------- */
@media (max-width: 767px) {
  body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  #app, #crm-view, #settings-modal { grid-column: 1; grid-row: 1; }
  #topbar {
    grid-column: 1; grid-row: 2; flex-direction: row; align-items: stretch; gap: 0;
    padding: 0.25rem 0.4rem calc(0.25rem + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--border);
  }
  .brand { display: none; }
  #top-tabs { flex-direction: row; flex: 3; gap: 0; }
  #top-tabs .top-tab, #user-menu-button {
    position: relative; flex: 1; flex-direction: column; justify-content: center; gap: 0.15rem; min-height: 52px; padding: 0.2rem;
    font-size: 0.6875rem; text-align: center;
  }
  #top-tabs .top-tab.active { background: transparent; }
  .top-tab .tab-label, #user-menu-name { flex: none; }
  .nav-badge { position: absolute; top: 3px; left: calc(50% + 4px); min-width: 18px; height: 18px; font-size: 0.65rem; }
  #user-menu { flex: 1; margin-top: 0; display: flex; }
  #user-menu-name { max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #user-menu-items { left: auto; right: 0; }
  #app { grid-template-columns: minmax(0, 1fr); }
  #chat-list { border-right: none; }
  #chat-filters { padding: 0.9rem 16px 0.5rem; }
  #chat-list-items { padding: 0.25rem 8px 0.75rem; }
  body.thread-open #chat-list { display: none; }
  body:not(.thread-open) #thread { display: none; }
  body.thread-open #topbar { display: none; }
  body.thread-open { grid-template-rows: minmax(0, 1fr); }
  #thread-back { display: inline-grid; }
  #thread-header { padding: 0.5rem 0.5rem 0.5rem 16px; min-height: 58px; gap: 0.25rem; }
  #thread-header .avatar { display: none; }
  #add-to-crm-button { padding: 0 0.6rem; }
  #thread-actions { border-left: none; padding-left: 0; margin-left: 0; }
  #thread-marks { display: none; }
  #messages { padding: 1rem 12px; }
  .msg { max-width: 84%; }
  #send-form { padding: 0.5rem 8px calc(0.5rem + env(safe-area-inset-bottom)); gap: 0.15rem; }
  #contact-button { display: none; }
  #send-button span { display: none; }
  #send-button { width: 42px; padding: 0; }
  .view-head { padding: 1rem 16px 0.75rem; }
  #crm-alerts { margin: 0 16px 0.6rem; }
  .crm-alerts-title { min-width: 0; width: 100%; }
  #crm-panel { width: 100%; border-left: none; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; padding: 0.75rem 16px 3rem; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .settings-nav a { flex-shrink: 0; background: var(--surface-2); border-radius: 999px; font-size: 0.8125rem; }
  .settings-page > .view-head { flex-wrap: wrap; align-items: center; }
  .settings-page .view-sub { display: none; }
  .set-section { padding: 1rem; }
  .form-grid-2 { grid-template-columns: minmax(0, 1fr); }
  #line-qr { flex-direction: column; align-items: flex-start; }
  #status-message { bottom: calc(76px + env(safe-area-inset-bottom)); }
  body.thread-open #status-message { bottom: calc(72px + env(safe-area-inset-bottom)); }
}
