/* ============================================================
   Gaia Chatview — estilos. Paleta alinhada ao Dashboard Gaia.
   ============================================================ */
:root {
  --topbar-bg: #0a0f1e;
  --topbar-h: 56px;
  --footer-h: 52px;
  --sidebar-bg: #0f172a;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --blue: #3b82f6; --blue-bg: #eff6ff; --blue-text: #1e40af;
  --green: #10b981; --green-bg: #ecfdf5; --green-text: #166534;
  --amber: #f59e0b; --amber-bg: #fffbeb; --amber-text: #92400e;
  --red: #ef4444; --red-bg: #fef2f2; --red-text: #991b1b;
  --purple: #8b5cf6; --purple-bg: #f5f3ff;
  --teal: #14b8a6; --teal-bg: #f0fdfa;
  --gray: #94a3b8;

  /* Controle Total — destaque laranja forte e inequívoco (§19.2/§22) */
  --orange: #f97316; --orange-strong: #ea580c; --orange-bg: #fff7ed; --orange-text: #9a3412;

  --out-bg: #dbeafe;      /* balão enviado */
  --in-bg: #ffffff;       /* balão recebido */
  --chat-bg: #e9eef5;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --touch-min: 44px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.14);
  --t: .16s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
/* overflow hidden evita o body "rolar" sozinho no iOS quando o teclado abre;
   a rolagem real acontece dentro de .messages / .contact-list / .ficha. */
html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  position: relative;
}
button { cursor: pointer; font-family: inherit; font-size: inherit; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; display: block; }

/* A aplicação acompanha a Visual Viewport sem rolar o documento inteiro. */
.app {
  position: relative; width: 100%; min-width: 0; min-height: 0;
  height: var(--app-h, 100dvh); overflow: hidden;
  transform: translateY(var(--app-top, 0));
  display: flex; flex-direction: column; background: var(--bg);
}

/* ==================== TOPBAR ==================== */
.topbar {
  height: var(--topbar-h); flex: 0 0 auto;
  background: var(--topbar-bg); color: #e2e8f0;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; box-shadow: var(--shadow);
  position: relative; z-index: 45;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; display: block; }
.brand-text { font-weight: 600; font-size: 16px; letter-spacing: .2px; }
.brand-text span { color: #38bdf8; }

.topbar-center { flex: 1; display: flex; align-items: center; gap: 12px; }
.env-pill {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: #34d399; background: rgba(16,185,129,.12);
  padding: 3px 9px; border-radius: 999px; border: 1px solid rgba(16,185,129,.3);
}
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #94a3b8; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(245,158,11,.2); }
.conn--live .conn-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.2); }
.conn--down .conn-dot { background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.25); }
.conn--down { color: #fca5a5; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.icon-btn {
  width: var(--touch-min); height: var(--touch-min); border-radius: 9px; color: #cbd5e1;
  display: grid; place-items: center; position: relative; transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.badge-dot {
  position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px; padding: 0 3px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 999px; display: grid; place-items: center; border: 2px solid var(--topbar-bg);
}

/* ---- Painel de notificações (§12.3) ---- */
.notif-wrap { position: relative; }
.notif-panel {
  position: absolute; top: 44px; right: -8px; width: 340px; max-width: 86vw; max-height: 62vh;
  background: var(--surface); color: var(--text); border-radius: 12px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); z-index: 60; display: flex; flex-direction: column; overflow: hidden;
}
.notif-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px 8px 13px; border-bottom: 1px solid var(--border); }
.notif-head strong { font-size: 13px; }
.notif-head-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
.panel-close {
  width: var(--touch-min); height: var(--touch-min); flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 6px; color: var(--muted); font-size: 23px; line-height: 1;
}
.panel-close:hover { background: var(--surface-2); color: var(--text); }
.link-btn { font-size: 11px; color: var(--blue-text); font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.notif-list { overflow-y: auto; }
.notif-empty { padding: 22px 14px; text-align: center; color: var(--faint); font-size: 13px; }
.notif-item { width: 100%; text-align: left; display: flex; gap: 10px; padding: 10px 13px; border-bottom: 1px solid var(--border); transition: background var(--t); align-items: flex-start; }
.notif-item:hover { background: var(--surface-2); }
.notif-item--unread { background: var(--blue-bg); }
.notif-icon { width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto; display: grid; place-items: center; font-size: 14px; background: var(--surface-2); }
.notif-icon--error { background: var(--red-bg); }
.notif-icon--wait { background: var(--amber-bg); }
.notif-body { flex: 1; min-width: 0; }
.notif-text { font-size: 12.5px; line-height: 1.35; }
.notif-meta { font-size: 10.5px; color: var(--faint); margin-top: 2px; display: flex; gap: 6px; }

/* ---- Perfil do operador (§12.4) ---- */
.operator-wrap { position: relative; }
.operator { display: flex; align-items: center; gap: 9px; border-radius: 10px; padding: 3px 6px; }
.operator:hover { background: rgba(255,255,255,.07); }
.operator-avatar {
  width: 34px; height: 34px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(135deg, #8b5cf6, #6366f1); color: #fff;
  font-weight: 700; display: grid; place-items: center; font-size: 14px;
}
.operator-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.operator-meta { display: flex; flex-direction: column; line-height: 1.2; text-align: left; }
.operator-meta strong { font-size: 13px; color: #f1f5f9; }
.role-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; color: #fbbf24; }
.operator-menu {
  position: absolute; top: 46px; right: 0; width: 250px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 60; overflow: hidden;
}
.op-menu-id { display: flex; flex-direction: column; gap: 3px; padding: 13px; border-bottom: 1px solid var(--border); }
.op-menu-id strong { font-size: 14px; }
.op-menu-id span { font-size: 11.5px; color: var(--muted); word-break: break-all; }
.auth-tag { color: var(--green-text) !important; font-weight: 700; font-size: 10.5px !important; text-transform: uppercase; }
.op-menu-item { display: block; width: 100%; min-height: var(--touch-min); text-align: left; padding: 11px 13px; font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); transition: background var(--t); }
.op-menu-item:last-child { border-bottom: none; }
.op-menu-item:hover { background: var(--surface-2); }

.onedrive-doc-list { display: grid; gap: 6px; margin-top: 8px; }
.onedrive-doc {
  width: 100%; min-width: 0; padding: 9px 10px; text-align: left;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 6px; cursor: pointer;
}
.onedrive-doc:hover { border-color: var(--blue); }
.onedrive-doc:disabled { opacity: .58; cursor: not-allowed; border-color: var(--border); }
.onedrive-doc span, .onedrive-doc small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.onedrive-doc span { font-size: 12.5px; font-weight: 700; }
.onedrive-doc small { margin-top: 2px; color: var(--muted); font-size: 10.5px; }

/* ==================== WORKSPACE ==================== */
.workspace { flex: 1; display: grid; grid-template-columns: clamp(248px, 22vw, 280px) minmax(0, 1fr) clamp(320px, 26vw, 360px); min-width: 0; min-height: 0; position: relative; overflow: hidden; }
.col { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--surface); }
.col-agenda { border-right: 1px solid var(--border); }
.col-ficha { border-left: 1px solid var(--border); background: var(--surface-2); }

/* ---------- AGENDA ---------- */
.agenda-head { padding: 12px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.agenda-search-row { display: flex; align-items: stretch; gap: 8px; }
.agenda-search-row .search { flex: 1; min-width: 0; }
.agenda-new-btn {
  width: var(--touch-min); height: var(--touch-min); flex: 0 0 var(--touch-min);
  display: grid; place-items: center; border-radius: 50%;
  background: var(--blue); color: #fff; font-size: 25px; line-height: 1;
  box-shadow: var(--shadow-sm); transition: background var(--t), transform var(--t);
}
.agenda-new-btn:hover { background: #2563eb; transform: translateY(-1px); }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; }
.search svg { width: 18px; height: 18px; color: var(--faint); }
.search input { border: none; outline: none; background: none; width: 100%; font-size: 13px; }
.agenda-filters { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.chip {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 999px; transition: all var(--t);
}
.chip:hover { border-color: var(--border-strong); }
.chip--active { background: var(--blue-bg); color: var(--blue-text); border-color: var(--blue); }

.contact-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.list-empty { padding: 30px 16px; text-align: center; color: var(--faint); font-size: 13px; }
.contact {
  width: 100%; text-align: left; display: flex; gap: 11px; padding: 11px 13px;
  border-bottom: 1px solid var(--border); transition: background var(--t); align-items: flex-start;
}
.contact:hover { background: var(--surface-2); }
.contact--active { background: var(--blue-bg); }
.contact--active:hover { background: var(--blue-bg); }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar--blue { background: linear-gradient(135deg,#3b82f6,#2563eb); }
.avatar--teal { background: linear-gradient(135deg,#14b8a6,#0d9488); }
.avatar--gray { background: linear-gradient(135deg,#94a3b8,#64748b); }
.avatar--purple { background: linear-gradient(135deg,#8b5cf6,#7c3aed); }
.avatar--amber { background: linear-gradient(135deg,#f59e0b,#d97706); }
.avatar--lg { width: 72px; height: 72px; font-size: 24px; }
.avatar-flag {
  position: absolute; bottom: -2px; right: -2px; width: 18px; height: 18px;
  background: var(--red); color: #fff; border-radius: 50%; font-size: 12px; font-weight: 800;
  display: grid; place-items: center; border: 2px solid var(--surface);
}
.contact-body { flex: 1; min-width: 0; }
.contact-line1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.contact-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { font-size: 11px; color: var(--faint); flex: 0 0 auto; }
.contact-line2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.contact-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread {
  flex: 0 0 auto; min-width: 18px; height: 18px; padding: 0 5px; background: var(--green); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 999px; display: grid; place-items: center;
}
.contact-line3 { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }

/* pills / badges */
.pill { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; letter-spacing: .2px; }
.pill-sm { font-size: 10px; padding: 1px 6px; }
.id-verified { background: var(--green-bg); color: var(--green-text); }
.id-unknown { background: #f1f5f9; color: #475569; }
.id-pending { background: var(--amber-bg); color: var(--amber-text); }
.id-ambiguous { background: var(--amber-bg); color: #b45309; }
.id-revoked { background: var(--red-bg); color: var(--red-text); }
.pill-client { background: var(--blue-bg); color: var(--blue-text); }
.pill-assisted { background: var(--purple-bg); color: #6d28d9; }
.pill-auto { background: #f1f5f9; color: #64748b; }
.pill-total { background: var(--orange); color: #fff; }
.pill-closed { background: #e2e8f0; color: #334155; }

/* ---------- CONVERSA ---------- */
.col-conversa { background: var(--chat-bg); }
.conv-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--faint); }
.conv-empty-mark { width: 72px; height: 72px; border-radius: 20px; opacity: .5; }
.conv { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.conv-head {
  flex: 0 0 auto; display: grid; grid-template-columns: minmax(150px, 1fr) auto;
  align-items: center; gap: 10px; padding: 9px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.conv-head-id { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.conv-head-id .avatar { width: 40px; height: 40px; font-size: 14px; }
.conv-head-txt { display: flex; flex-direction: column; min-width: 0; }
.conv-head-txt strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-head-txt span { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; min-width: 0; }
.conv-head-actions {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; min-width: 0; max-width: 100%;
  align-items: center; gap: 7px;
}
.conv-head-actions .icon-btn { color: var(--muted); }
.conv-head-actions .icon-btn:hover { background: var(--surface-2); color: var(--text); }
.back-btn { display: none; color: var(--muted); width: var(--touch-min); height: var(--touch-min); border-radius: 8px; }
.back-btn:hover { background: var(--surface-2); }

/* ---- Botões mutuamente exclusivos Agente Gaia × Operador (§14.2) ---- */
.mode-switch {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0;
  width: min(430px, 49vw); min-width: 330px; max-width: 100%;
  border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface-2);
}
.mode-btn {
  display: flex; min-height: 38px; min-width: 0; align-items: center; justify-content: center; gap: 5px;
  padding: 5px 9px; font-size: 11.5px; font-weight: 700; color: var(--muted);
  transition: all var(--t); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mode-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); transition: all var(--t); }
.mode-btn--active.mode-btn--agent { background: var(--green); color: #fff; }
.mode-btn--active.mode-btn--agent .mode-dot { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.3); }
.mode-btn--active.mode-btn--operator { background: var(--purple); color: #fff; }
.mode-btn--active.mode-btn--operator .mode-dot { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.3); }
.mode-btn--active.mode-btn--total { background: var(--orange); color: #fff; }
.mode-btn--active.mode-btn--total .mode-dot { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.3); }
.mode-btn:disabled { opacity: .6; cursor: wait; }
.mode-btn--resyncing { font-style: italic; }
.mode-sync { font-size: 11px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.mode-sync--error { color: var(--red-text); }
.mode-pill { font-size: 11px; font-weight: 800; padding: 5px 11px; border-radius: 999px; letter-spacing: .5px; }
.mode-pill--total { background: var(--orange); color: #fff; box-shadow: 0 0 0 3px rgba(249,115,22,.25); }
.reopen-conversation-btn {
  min-height: 38px; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--green); background: var(--green-bg); color: var(--green-text);
  font-size: 11.5px; font-weight: 800; white-space: nowrap;
}
.reopen-conversation-btn:hover { background: var(--green); color: #fff; }
.reopen-conversation-btn:disabled { opacity: .55; cursor: wait; }
.conversation-settings { display: grid; gap: 9px; }
.conversation-settings p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.settings-action {
  width: 100%; min-height: var(--touch-min); padding: 9px 12px; text-align: left;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  color: var(--text); font-size: 13px; font-weight: 700;
}
.settings-action:hover { border-color: var(--border-strong); }
.settings-action--primary { background: var(--green-bg); border-color: var(--green); color: var(--green-text); }
.settings-action--danger { background: var(--red-bg); border-color: #fecaca; color: var(--red-text); }

.messages {
  flex: 1; min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 8px;
  background-image: radial-gradient(rgba(148,163,184,.10) 1px, transparent 0); background-size: 22px 22px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y;
}
.msg-row { display: flex; position: relative; min-width: 0; max-inline-size: 100%; }
.msg-row--in { justify-content: flex-start; }
.msg-row--out { justify-content: flex-end; }
.msg-row--center { justify-content: center; }

.bubble { min-width: 0; max-width: 68%; max-inline-size: calc(100% - var(--touch-min)); padding: 8px 11px 6px; border-radius: 12px; box-shadow: var(--shadow-sm); position: relative; overflow-wrap: anywhere; }
.bubble--in { background: var(--in-bg); border-top-left-radius: 4px; }
.bubble--out { background: var(--out-bg); border-top-right-radius: 4px; }
.bubble-text { font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; -webkit-user-select: text; user-select: text; }
.bubble-meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 3px; display: flex; gap: 5px; justify-content: flex-end; align-items: center; }
.ticks { color: var(--faint); font-weight: 700; }
.ticks--read { color: var(--blue); }
.ticks--failed { color: var(--red); }
.author-tag { display: block; font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 800; margin-bottom: 3px; }
.author-tag--gaia { color: var(--green-text); }

/* balão operador assistido (original + final) */
.bubble--operator { max-width: 74%; background: #fff; border: 1px solid var(--border); }
.op-original { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 7px 9px; margin-bottom: 7px; }
.op-final { font-size: 14px; line-height: 1.45; padding: 2px 2px 0; }
.op-tag { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; color: var(--faint); margin-bottom: 3px; }
.op-tag--final { color: var(--blue-text); }
.bubble--draft { border-style: dashed; border-color: var(--amber); }
.review-flag { color: var(--amber-text); font-weight: 700; }

/* balão CONTROLE TOTAL — envio direto humano (§15.1/§19.3) */
.bubble--direct { background: var(--orange-bg); border: 2px solid var(--orange); max-width: 74%; }
.bubble--direct .author-tag { color: var(--orange-text); }
.direct-note { font-size: 10px; color: var(--orange-text); margin-top: 4px; font-style: italic; }

/* balão apagado da interface */
.bubble--deleted { opacity: .65; }
.bubble--deleted .bubble-text { font-style: italic; color: var(--muted); }
.msg-more {
  width: var(--touch-min); height: var(--touch-min); flex: 0 0 var(--touch-min); align-self: flex-start;
  display: grid; place-items: center; border-radius: 50%; color: var(--muted); font-size: 22px;
  opacity: 0; transition: opacity var(--t), background var(--t); touch-action: manipulation;
}
.msg-row:hover .msg-more, .msg-more:focus-visible { opacity: 1; }
.msg-more:hover, .msg-more:focus-visible { background: rgba(255,255,255,.82); outline: 2px solid var(--blue); outline-offset: -2px; }
@media (hover: none), (pointer: coarse) { .msg-more { opacity: .72; } }

/* áudio */
.audio-bubble {
  --audio-progress: 0%; width: min(330px, 64vw); max-width: 100%; min-height: 50px;
  display: flex; align-items: center; gap: 9px; position: relative;
}
.audio-avatar { width: 36px; height: 36px; font-size: 12px; flex: 0 0 36px; }
.audio-avatar--gaia { background: #fff; padding: 2px; border: 1px solid var(--border); }
.audio-play {
  width: var(--touch-min); height: var(--touch-min); border-radius: 50%; flex: 0 0 var(--touch-min); display: grid; place-items: center;
  padding-left: 2px; background: var(--green); color: #fff; font-size: 13px; line-height: 1;
}
.bubble--out .audio-play, .bubble--direct .audio-play, .bubble--operator .audio-play { background: var(--blue); }
.audio-track { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.audio-wave { height: 25px; display: flex; align-items: center; gap: 2px; overflow: hidden; position: relative; }
.audio-wave i { width: 3px; height: 9px; border-radius: 2px; background: #86c99a; flex: 0 0 3px; }
.audio-wave i:nth-child(3n) { height: 21px; }
.audio-wave i:nth-child(4n) { height: 15px; }
.audio-wave i:nth-child(5n) { height: 24px; }
.bubble--out .audio-wave i, .bubble--direct .audio-wave i, .bubble--operator .audio-wave i { background: #7db2ed; }
.audio-wave::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--audio-progress); background: rgba(59,130,246,.13); pointer-events: none; }
.audio-duration { font-size: 10.5px; color: var(--muted); }
.audio-element { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.audio-bubble.is-playing .audio-avatar { box-shadow: 0 0 0 3px rgba(16,185,129,.24); }
.audio-bubble.has-error .audio-duration { color: var(--red-text); font-weight: 700; }
.attachment-pending { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 8px 4px; }
.attachment-pending .spin { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.attachment-error { font-size: 12px; color: var(--red-text); background: var(--red-bg); border-radius: 7px; padding: 7px 9px; display: flex; flex-direction: column; gap: 6px; }
.attachment-error button { align-self: flex-start; font-size: 11px; font-weight: 700; color: var(--red-text); text-decoration: underline; }
.media-expired { font-size: 12px; color: var(--faint); font-style: italic; padding: 6px 4px; }
.media-preview { position: relative; display: inline-block; max-width: 100%; }
.media-preview > a:first-child { display: block; }
.message-image { display: block; max-width: min(360px, 62vw); max-height: 360px; border-radius: 8px; object-fit: contain; background: var(--surface-2); cursor: zoom-in; }
.media-download { position: absolute; right: 7px; bottom: 7px; width: var(--touch-min); height: var(--touch-min); display: grid; place-items: center; border-radius: 50%; background: rgba(15,23,42,.78); color: #fff; text-decoration: none; font-weight: 800; }
.image-caption { margin-top: 7px; }
.transcription { margin-top: 7px; font-size: 12.5px; color: var(--text); background: var(--surface-2); border-left: 3px solid var(--blue); border-radius: 6px; padding: 6px 9px; line-height: 1.4; }
.transcription summary { min-height: 32px; display: flex; align-items: center; cursor: pointer; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--blue-text); font-weight: 700; }
.transcription > div { padding: 3px 0 5px; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }

/* documento */
.doc { display: flex; min-width: 0; max-inline-size: 100%; align-items: center; gap: 10px; padding: 4px 2px; }
.doc-icon { width: 40px; height: 40px; border-radius: 8px; background: var(--red-bg); color: var(--red-text); display: grid; place-items: center; font-size: 11px; font-weight: 800; flex: 0 0 auto; }
.doc-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.doc-meta strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-open { font-size: 13px; font-weight: 700; color: var(--blue-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: underline; text-underline-offset: 2px; }
.doc-meta span { font-size: 11px; color: var(--muted); }
.doc-dl { width: var(--touch-min); height: var(--touch-min); flex: 0 0 var(--touch-min); border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 15px; display: grid; place-items: center; text-decoration: none; }
.doc-dl:hover { background: var(--border); }
.doc-state { font-size: 10px; color: var(--muted); max-width: 110px; text-align: right; }
.doc-actions { display: flex; gap: 6px; margin-top: 7px; }
.doc-actions button { min-height: var(--touch-min); font-size: 11px; font-weight: 700; padding: 5px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); }
.doc-actions .doc-confirm { background: var(--green); border-color: var(--green); color: #fff; }
.doc-actions button:disabled { opacity: .55; cursor: wait; }

/* eventos / handoff / controle */
.event { align-self: center; text-align: center; }
.event span { font-size: 11.5px; color: var(--muted); background: rgba(255,255,255,.85); padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); display: inline-block; }
.event--handoff span { background: var(--amber-bg); color: var(--amber-text); border-color: rgba(245,158,11,.35); font-weight: 600; }
.event--control span { background: var(--orange-bg); color: var(--orange-text); border-color: rgba(249,115,22,.35); font-weight: 600; }

/* compositor (área ampliada ~+70% — §16.1) */
.composer { flex: 0 0 auto; background: var(--surface); border-top: 1px solid var(--border); padding: 12px 14px 9px; }
.composer-review {
  display: flex; align-items: flex-start; gap: 9px; min-width: 0; font-size: 12.5px; color: var(--amber-text);
  background: var(--amber-bg); border: 1px solid rgba(245,158,11,.35); border-radius: 8px; padding: 8px 11px; margin-bottom: 9px;
}
.composer-review svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--amber); }
.composer-review code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.review-content { flex: 1; min-width: 0; }
.review-card { display: grid; gap: 8px; max-height: min(240px, 34vh); overflow-y: auto; margin-top: 7px; color: var(--text); }
.review-card section { min-width: 0; padding: 7px 9px; border: 1px solid rgba(245,158,11,.28); border-radius: 7px; background: rgba(255,255,255,.72); }
.review-card strong { display: block; margin-bottom: 3px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .35px; }
.review-card p, .review-card li { white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.review-card ul { padding-left: 18px; }
.review-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.review-btn { min-height: var(--touch-min); border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); padding: 6px 9px; font-size: 11px; font-weight: 700; }
.review-btn--approve { border-color: var(--blue); background: var(--blue); color: #fff; }
.send-btn:disabled, .review-btn:disabled { opacity: .55; cursor: wait; transform: none; }
.composer-row { display: flex; min-width: 0; max-inline-size: 100%; align-items: flex-end; gap: 8px; }
.composer-tools { display: flex; flex-direction: column; gap: 4px; align-self: flex-start; }
.composer-tools .icon-btn, .composer-actions .icon-btn { color: var(--muted); flex: 0 0 auto; }
.composer-tools .icon-btn:hover, .composer-actions .icon-btn:hover { background: var(--surface-2); color: var(--text); }
.composer-actions { display: flex; align-items: center; gap: 6px; }
#composerInput {
  flex: 1; min-width: 0; max-inline-size: 100%; resize: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 13px; font-size: 14px; line-height: 1.45; min-height: 76px; max-height: 220px;
  outline: none; background: var(--surface-2); overflow-y: auto;
}
#composerInput:focus { border-color: var(--blue); background: #fff; }
#composerInput:disabled { opacity: .6; }
.send-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; flex: 0 0 auto; transition: background var(--t), transform var(--t); }
.send-btn:hover { background: #2563eb; transform: scale(1.05); }
.composer-hint { font-size: 11px; color: var(--faint); margin-top: 6px; line-height: 1.4; }
.composer-hint code { background: var(--surface-2); padding: 1px 4px; border-radius: 3px; }
#audioBtn.recording { background: var(--red); color: #fff; animation: pulse 1.1s ease infinite; }
#audioBtn { touch-action: none; -webkit-touch-callout: none; transition: transform .16s ease, box-shadow .16s ease; }
#audioBtn.recording { transform: scale(1.2); box-shadow: 0 0 0 12px rgba(59,130,246,.2); }
.recording-status {
  flex: 1; min-height: 52px; display: flex; align-items: center; gap: 9px; padding: 10px 12px;
  border: 1px solid #fecaca; border-radius: 8px; background: var(--red-bg); color: var(--red-text);
}
.recording-status > span:last-child { margin-left: auto; font-size: 11px; color: var(--muted); }
.recording-status.will-cancel { background: #fee2e2; border-color: var(--red); }
.recording-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); animation: recording-blink 900ms step-end infinite; }
#composerInput.recording-hidden { display: none; }
.button-spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 5px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(59,130,246,.12); } }
@keyframes recording-blink { 50% { opacity: .25; } }

/* CONTROLE TOTAL ativo: realce laranja forte na área de envio (§19.2) */
.app.total-active .composer { border-top: 3px solid var(--orange); background: var(--orange-bg); }
.app.total-active #composerInput { border: 2px solid var(--orange); background: #fff; box-shadow: 0 0 0 3px rgba(249,115,22,.18); }
.app.total-active #composerInput:focus { border-color: var(--orange-strong); }
.app.total-active .send-btn { background: var(--orange); }
.app.total-active .send-btn:hover { background: var(--orange-strong); }
.app.total-active .composer-tools .icon-btn,
.app.total-active .composer-actions .icon-btn { color: var(--orange-strong); box-shadow: inset 0 0 0 2px var(--orange); border-radius: 9px; background: #fff; }
.app.total-active .composer-hint { color: var(--orange-text); font-weight: 600; }

/* ---------- FICHA — 3 regiões com rolagens independentes (§17.3) ---------- */
.ficha-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--faint); }
.ficha-empty p { font-weight: 600; color: var(--muted); }
.ficha { flex: 1; min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr) minmax(0,1fr); }
.ficha-panel-bar { display: none; flex: 0 0 auto; height: 44px; padding: 0 8px 0 14px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface); }
.ficha-panel-bar strong { font-size: 13px; }
.ficha-hero { display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center; padding: 16px 16px 13px; border-bottom: 1px solid var(--border); background: var(--surface); }
.ficha-hero-name { font-weight: 700; font-size: 16px; }
.ficha-hero-sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ficha-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; width: 100%; margin-top: 4px; }
.ficha-grid > div { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.ficha-k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--faint); font-weight: 700; }
.ficha-v { font-size: 13.5px; font-weight: 600; word-break: break-word; }
.ficha-region { display: flex; flex-direction: column; min-height: 0; border-bottom: 1px solid var(--border); }
.ficha-region h4 { flex: 0 0 auto; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--faint); padding: 11px 16px 7px; background: var(--surface-2); }
.ficha-scroll { flex: 1; overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.ficha-block { padding: 10px 0; border-bottom: 1px solid var(--border); }
.ficha-block:last-child { border-bottom: none; }
.ficha-block h5 { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--faint); margin-bottom: 6px; }
.ficha-none { color: var(--faint); font-size: 13px; padding: 8px 0; }
.ficha-warn { font-size: 12px; color: var(--amber-text); background: var(--amber-bg); border: 1px solid rgba(245,158,11,.3); border-radius: 8px; padding: 8px 10px; margin: 8px 0; line-height: 1.4; }
.ficha-action { display: inline-block; font-size: 12px; font-weight: 700; color: var(--blue-text); background: var(--blue-bg); border: 1px solid rgba(59,130,246,.3); padding: 6px 11px; border-radius: 8px; margin: 4px 6px 4px 0; }
.ficha-action:disabled { opacity: .55; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 4px 9px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.tag-green { background: var(--green-bg); color: var(--green-text); border-color: rgba(16,185,129,.25); }
.tag-amber { background: var(--amber-bg); color: var(--amber-text); border-color: rgba(245,158,11,.25); }
.tag-red { background: var(--red-bg); color: var(--red-text); border-color: rgba(239,68,68,.25); }
.tag-doc { background: var(--blue-bg); color: var(--blue-text); border-color: rgba(59,130,246,.2); }
.company-card { border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; margin-bottom: 7px; background: var(--surface); }
.company-card strong { font-size: 13px; display: block; }
.company-card span { font-size: 11.5px; color: var(--muted); display: block; }

/* timeline (Resumo evolutivo — §9) */
.tl-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); margin-top: 4px; flex: 0 0 auto; }
.tl-dot--control { background: var(--orange); }
.tl-dot--doc { background: var(--teal); }
.tl-dot--process { background: var(--purple); }
.tl-body { flex: 1; min-width: 0; }
.tl-when { font-size: 10.5px; color: var(--faint); font-weight: 700; }
.tl-event { font-size: 13px; font-weight: 600; margin: 1px 0; }
.tl-meta { font-size: 11.5px; color: var(--muted); }

/* ==================== RODAPÉ GLOBAL FIXO (§18) ==================== */
.global-footer {
  flex: 0 0 auto; height: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 14px env(safe-area-inset-bottom, 0px);
  background: var(--topbar-bg); color: #cbd5e1; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 -2px 8px rgba(0,0,0,.15); position: relative; z-index: 44;
}
.footer-left { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: visible; }
.footer-link {
  display: flex; min-height: var(--touch-min); align-items: center; gap: 7px; padding: 7px 12px; border-radius: 10px;
  font-size: 12.5px; font-weight: 700; color: #cbd5e1; text-decoration: none; transition: background var(--t), color var(--t);
  background: rgba(255,255,255,.06); white-space: nowrap;
}
.footer-link:hover { background: rgba(255,255,255,.14); color: #fff; }
.footer-link .fl-icon { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; font-size: 13px; background: rgba(255,255,255,.1); flex: 0 0 auto; }
.footer-menu-wrap { position: relative; }
.footer-menu {
  position: absolute; bottom: 50px; left: 0; min-width: 240px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 70; overflow: hidden;
}
.footer-menu a { display: flex; align-items: center; gap: 9px; padding: 11px 13px; font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.footer-menu a:last-child { border-bottom: none; }
.footer-menu a:hover { background: var(--surface-2); }
.footer-menu .fl-icon { width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 14px; }
.total-btn {
  min-height: var(--touch-min); padding: 9px 16px; border-radius: 10px; font-size: 13px; font-weight: 800; letter-spacing: .3px;
  color: #fed7aa; border: 2px solid var(--orange); background: rgba(249,115,22,.12); transition: all var(--t); white-space: nowrap;
}
.total-btn:hover { background: rgba(249,115,22,.25); color: #fff; }
.total-btn--on { background: var(--orange); color: #fff; box-shadow: 0 0 0 4px rgba(249,115,22,.3); }
.total-btn--on:hover { background: var(--orange-strong); }
.total-btn:disabled { opacity: .6; cursor: wait; }

/* ==================== NAV MOBILE ==================== */
.mobile-nav { display: none; }

/* ==================== MENU DE MENSAGEM / MODAIS ==================== */
.msg-menu {
  position: fixed; z-index: 90; width: 270px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.msg-menu-note { font-size: 10.5px; color: var(--faint); padding: 9px 13px; line-height: 1.4; background: var(--surface-2); }

.modal-backdrop { position: fixed; inset: 0; z-index: 95; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 8px; box-shadow: var(--shadow-lg); width: 100%; max-width: 430px; max-height: calc(var(--app-h, 100dvh) - 24px); overflow-y: auto; padding: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.modal h3 { font-size: 17px; margin: 0; }
.modal-body { font-size: 13.5px; color: var(--muted); line-height: 1.55; }
.modal-body strong { color: var(--text); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.modal-btn { min-height: var(--touch-min); padding: 10px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 700; color: var(--text); }
.modal-btn:hover { background: var(--surface-2); }
.modal-btn--primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.modal-btn--primary:hover { background: #2563eb; }
.modal--danger .modal-btn--primary { background: var(--orange); border-color: var(--orange); }
.modal--danger .modal-btn--primary:hover { background: var(--orange-strong); }
.modal-btn:disabled { opacity: .55; cursor: wait; }
.modal-btn.is-loading { min-width: 112px; }
.modal--preview .preview-body { display: grid; place-items: center; min-height: 120px; margin-bottom: 12px; }
.modal--preview img { max-width: 100%; max-height: 300px; border-radius: 10px; }
.modal--preview audio { width: 100%; }
.modal--preview .doc { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
#previewCaption { width: 100%; border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; font-size: 13px; outline: none; background: var(--surface-2); }
#previewCaption:focus { border-color: var(--blue); background: #fff; }

/* ==================== BLOQUEIO DE TELA (§7/§20) ==================== */
.lock-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(10,15,30,.72);
  -webkit-backdrop-filter: blur(26px); backdrop-filter: blur(26px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.lock-card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 34px 30px; max-width: 340px; width: 100%; text-align: center; }
.lock-logo { width: 58px; height: 58px; border-radius: 15px; margin: 0 auto 14px; display: block; }
.lock-card h1 { font-size: 19px; margin-bottom: 6px; }
.lock-card p { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 18px; }
.lock-pin { display: flex; gap: 8px; margin-top: 12px; }
.lock-pin input { flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; font-size: 16px; text-align: center; letter-spacing: 6px; outline: none; }
.lock-pin input:focus { border-color: var(--blue); }
.lock-pin .login-btn { width: auto; padding: 11px 16px; }
.lock-logout { display: inline-block; margin-top: 16px; font-size: 12px; color: var(--faint); }

/* ==================== SCROLLBARS ==================== */
.contact-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .ficha-scroll::-webkit-scrollbar, .notif-list::-webkit-scrollbar { width: 8px; }
.contact-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .ficha-scroll::-webkit-scrollbar-thumb, .notif-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

/* ==================== LOGIN ==================== */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, #0a0f1e, #131c33);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 34px 30px; max-width: 360px; width: 100%; text-align: center;
}
.login-card h1 { font-size: 20px; margin-bottom: 8px; }
.login-card p { font-size: 14px; color: var(--muted); line-height: 1.5; margin-bottom: 22px; }
.login-btn {
  display: inline-block; width: 100%; padding: 12px 18px; border-radius: 10px;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 14px;
  text-decoration: none; transition: background var(--t); border: none; cursor: pointer;
}
.login-btn:hover { background: #2563eb; }

/* ==================== RESPONSIVO ==================== */

/* Backdrop da ficha (painel deslizante em telas médias) */
.ficha-backdrop { display: none; position: absolute; top: var(--topbar-h); left: 0; right: 0; bottom: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px)); background: rgba(15,23,42,.35); z-index: 39; }

/* 3 colunas: a ficha ocupa ~1/3 da área útil em telas largas (§17.2) */
@media (min-width: 1181px) {
  .workspace { grid-template-columns: clamp(248px, 22vw, 280px) minmax(0, 1fr) clamp(320px, 26vw, 360px); }
}
@media (max-width: 1180px) and (min-width: 1101px) {
  .workspace { grid-template-columns: 280px minmax(0, 1fr) 320px; }
}

/* Quando a coluna central fica estreita, a identidade permanece numa linha
   própria e os controles ocupam uma segunda linha estável, sem sobreposição. */
@media (max-width: 1500px) {
  .conv-head { grid-template-columns: minmax(0, 1fr); }
  .conv-head-actions { width: 100%; }
  .mode-switch { width: 100%; min-width: 0; }
}

/* TABLET / iPad — 2 painéis estilo WhatsApp Web: a LISTA e a CONVERSA ficam
   sempre visíveis; a ficha desliza da direita ocupando ~1/3 da tela. */
@media (max-width: 1100px) and (min-width: 601px) {
  .workspace { grid-template-columns: clamp(248px, 26vw, 280px) minmax(0, 1fr); }
  .col-ficha {
    position: absolute; top: 0; right: 0; bottom: 0;
    width: clamp(320px, 36vw, 360px); max-width: 85vw;
    border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
    transform: translateX(100%); transition: transform .22s ease; z-index: 40;
  }
  body.ficha-open .col-ficha { transform: translateX(0) !important; }
  body.ficha-open .ficha-backdrop { display: block; }
  .ficha-panel-bar { display: flex; }
  .conv-head { grid-template-columns: minmax(0, 1fr); }
  .conv-head-actions { grid-template-columns: minmax(0, 1fr) auto auto auto; width: 100%; }
  .mode-switch { width: 100%; min-width: 0; }
  .mode-btn { min-height: 38px; padding: 5px 7px; font-size: 11px; }
}

/* CELULAR pequeno (empilhado): Contatos → Conversa → Detalhes + barra inferior. */
@media (max-width: 600px) {
  .workspace { display: block; position: relative; }
  .col { position: absolute; inset: 0; width: 100%; }
  .col-agenda, .col-conversa, .col-ficha { display: none; }
  .col-ficha { transform: none; box-shadow: none; border: none; }
  .app[data-view="agenda"] .col-agenda { display: flex; }
  .app[data-view="conversa"] .col-conversa { display: flex; }
  .app[data-view="ficha"] .col-ficha { display: flex; }
  .back-btn { display: grid; }
  .brand-text span { display: none; }
  .conn { display: none; }

  .global-footer { display: none; }
  .mobile-nav {
    display: flex; position: static; height: calc(58px + env(safe-area-inset-bottom, 0px)); flex: 0 0 auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface); border-top: 1px solid var(--border); z-index: 30;
  }
  .mnav { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 11px; font-weight: 600; }
  .mnav svg { width: 22px; height: 22px; }
  .mnav--active { color: var(--blue); }
  body.keyboard-open .mobile-nav { display: none; }
  body.keyboard-open .global-footer { display: none; }
  .bubble { max-width: 82%; max-inline-size: calc(100% - var(--touch-min)); }
  .bubble--operator, .bubble--direct { max-width: 86%; }
  .footer-link span.fl-label { display: none; }
  .footer-link { padding: 7px 9px; }
  .conv-head { grid-template-columns: minmax(0, 1fr); padding: 7px 9px; gap: 6px; }
  .conv-head-actions { grid-template-columns: minmax(0, 1fr) auto auto auto; width: 100%; gap: 4px; }
  .mode-switch { width: 100%; min-width: 0; }
  .mode-btn { min-height: 38px; justify-content: center; padding: 5px 5px; font-size: 10.5px; }
  .mode-dot { width: 6px; height: 6px; }
  .reopen-conversation-btn { padding: 5px 8px; font-size: 10.5px; }
  .composer { padding: 8px 9px max(7px, env(safe-area-inset-bottom, 0px)); }
  #composerInput { min-height: 56px; max-height: 112px; padding: 9px 10px; scrollbar-width: thin; }
  .composer-row { align-items: center; }
  .composer-hint { display: none; }
  .composer-tools { flex-direction: row; }
  .ficha-panel-bar { display: flex; }
  .workspace { padding-bottom: 0; }
}
body.keyboard-open .global-footer { display: none; }
@media (max-width: 420px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .operator-meta { display: none; }
  .brand { min-width: auto; }
}

/* ==================== Agenda interna (salvar contato) ==================== */
.ficha-action {
  display: block;
  width: 100%;
  min-height: var(--touch-min);
  margin: 0 0 10px;
  padding: 9px 12px;
  border: 1px solid var(--border, #d8dee6);
  border-radius: 10px;
  background: var(--accent, #0b7a63);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ficha-action:hover { filter: brightness(1.05); }
.contact-form { display: flex; flex-direction: column; gap: 10px; }
.contact-form-row { display: grid; grid-template-columns: minmax(96px, .7fr) minmax(150px, 1.3fr); gap: 10px; }
.contact-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #5b6572);
}
.contact-form input {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--border, #d8dee6);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg, #fff);
  color: inherit;
}
.contact-form input:focus { outline: 2px solid var(--accent, #0b7a63); outline-offset: 1px; }
.contact-form-hint { font-size: 12px; color: var(--muted, #5b6572); margin: 2px 0 0; }

/* ==================== Bastidor: chat interno com a Gaia ==================== */
.composer-target {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 0;
}
.target-tab {
  min-height: var(--touch-min);
  padding: 5px 14px;
  border: 1px solid var(--border, #d8dee6);
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #5b6572);
  cursor: pointer;
}
.target-tab--active {
  background: var(--accent, #0b7a63);
  border-color: var(--accent, #0b7a63);
  color: #fff;
}
.target-tab--gaia.target-tab--active {
  background: #6d4aff;
  border-color: #6d4aff;
}
.instruct-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 12px;
  color: #6d4aff;
  font-weight: 600;
  cursor: pointer;
}
.instruct-chip input { accent-color: #6d4aff; }
.composer--gaia .composer-row { outline: 2px solid #6d4aff33; outline-offset: -2px; border-radius: 12px; }
.composer--gaia .composer-tools,
.composer--gaia #audioBtn { display: none; }
.bubble--internal {
  background: #f4f0ff;
  border: 1px dashed #6d4aff;
  color: #2c2545;
}
.bubble--internal .bubble-text { white-space: pre-wrap; }
.author-tag--internal {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  color: #6d4aff;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
@media (prefers-color-scheme: dark) {
  .bubble--internal { background: #262040; color: #e8e2ff; }
  .author-tag--internal { color: #b3a1ff; }
}

/* ==================== Painel direito retrátil (setinha na borda) ==================== */
.ficha-toggle {
  position: absolute; z-index: 41;
  right: 0; top: 50%; transform: translateY(-50%);
  width: 22px; height: 76px;
  border-radius: 10px 0 0 10px;
  background: var(--surface); border: 1px solid var(--border); border-right: none;
  box-shadow: var(--shadow-lg); color: var(--faint);
  display: none; align-items: center; justify-content: center;
  opacity: .85;
}
.ficha-toggle:hover { color: var(--text); opacity: 1; }
.ficha-toggle svg { width: 16px; height: 16px; transition: transform .2s ease; }
@media (min-width: 601px) { .ficha-toggle { display: flex; } }
/* seta aponta para dentro quando o painel esta escondido */
body.ficha-collapsed .ficha-toggle svg { transform: rotate(180deg); }
@media (max-width: 1100px) and (min-width: 601px) {
  body:not(.ficha-open) .ficha-toggle svg { transform: rotate(180deg); }
  body.ficha-collapsed .ficha-toggle svg { transform: rotate(180deg); }
}
/* desktop e iPad deitado: colapso real da coluna */
@media (min-width: 1181px) {
  body.ficha-collapsed .workspace { grid-template-columns: clamp(248px, 22vw, 280px) minmax(0, 1fr) 0; }
  body.ficha-collapsed .col-ficha { display: none; }
}
@media (max-width: 1180px) and (min-width: 1101px) {
  body.ficha-collapsed .workspace { grid-template-columns: 280px minmax(0, 1fr) 0; }
  body.ficha-collapsed .col-ficha { display: none; }
}

/* ==================== Compositor bloqueado no modo Agente Gaia ==================== */
.composer--locked #composerInput,
.composer--locked .composer-tools .icon-btn,
.composer--locked .composer-actions .icon-btn,
.composer--locked .send-btn { opacity: .4; cursor: not-allowed; }
.composer--locked #composerInput { background: var(--surface-2, #f1f5f9); }

/* ==================== Feedback de envio (spinner no botao) ==================== */
.send-btn { position: relative; }
.send-btn.is-sending svg { opacity: .15; }
.send-btn.is-sending::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: gaia-send-spin .7s linear infinite;
}
@keyframes gaia-send-spin { to { transform: rotate(360deg); } }

/* ==================== Zoom do avatar (nome do WhatsApp) ==================== */
.modal--info #modalCancel { display: none; }
.avatar--zoom { width: 124px; height: 124px; font-size: 46px; border-radius: 50%; }
.avatar-placeholder { width: 58%; height: 58%; color: rgba(255,255,255,.88); }
.avatar-zoom { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0 4px; }
.avatar-zoom-name { font-size: 18px; font-weight: 700; text-align: center; }
.avatar-zoom-sub { color: var(--faint); font-size: 13px; text-align: center; line-height: 1.6; }
.conv-head-id .avatar, #fichaHero .avatar { cursor: zoom-in; }

/* contato ainda sem nome salvo: dica discreta na lista */
.contact-hint { color: var(--faint); font-size: 12px; font-style: italic; }

@media (max-width: 420px) {
  .contact-form-row { grid-template-columns: 1fr; }
  .composer-review { flex-wrap: wrap; }
  .review-actions { width: 100%; margin-left: 0; }
  .review-btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
