:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef2f7;
  color: #172033;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: #eef2f7;
}

button, input, textarea { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.chat-card {
  width: min(820px, 100%);
  height: min(860px, calc(100vh - 40px));
  min-height: 560px;
  background: #fff;
  border: 1px solid #dde3ec;
  border-radius: 22px;
  box-shadow: 0 18px 60px rgba(22, 34, 52, .12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #e6eaf0;
}

.chat-header h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #677184;
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
}

.status-dot.online { background: #22a06b; }
.status-dot.offline { background: #c93756; }

.secondary-btn {
  border: 1px solid #d7dde8;
  background: #fff;
  color: #263248;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

.service-panel {
  padding: 12px 16px;
  border-bottom: 1px solid #e6eaf0;
  background: #f8fafc;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.start-form {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 280px;
}

.start-form input {
  min-width: 0;
  flex: 1;
  border: 1px solid #d7dde8;
  border-radius: 10px;
  padding: 10px 12px;
}

.service-panel button,
.composer button {
  border: 0;
  border-radius: 10px;
  background: #2947d9;
  color: white;
  padding: 10px 16px;
  cursor: pointer;
}

.service-panel button:disabled,
.composer button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f5f7fb;
}

.message {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.sent { align-self: flex-end; align-items: flex-end; }
.message.received { align-self: flex-start; align-items: flex-start; }

.message-meta {
  font-size: 11px;
  color: #7a8598;
  padding-inline: 5px;
}

.message-bubble {
  padding: 10px 13px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(20, 35, 60, .05);
}

.message.sent .message-bubble {
  background: #2947d9;
  color: #fff;
  border-bottom-right-radius: 5px;
}

.message.received .message-bubble {
  background: #fff;
  color: #172033;
  border: 1px solid #e0e5ed;
  border-bottom-left-radius: 5px;
}

.composer {
  padding: 12px;
  display: flex;
  gap: 10px;
  border-top: 1px solid #e6eaf0;
  background: #fff;
}

.composer textarea {
  min-width: 0;
  flex: 1;
  resize: none;
  border: 1px solid #d7dde8;
  border-radius: 12px;
  padding: 11px 13px;
  outline: none;
}

.composer textarea:focus {
  border-color: #2947d9;
  box-shadow: 0 0 0 3px rgba(41, 71, 217, .10);
}


.hidden { display: none !important; }

@media (max-width: 700px) {
  .app-shell { padding: 0; }
  .chat-card {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }
  .message { max-width: 88%; }
  .start-form { min-width: 100%; }
}

/* Menu interativo do OPA */
.message-bubble.has-menu {
  padding: 0;
  overflow: hidden;
  min-width: min(420px, 72vw);
}

.interactive-menu-title {
  padding: 12px 14px;
  line-height: 1.45;
}

.interactive-menu-options {
  display: flex;
  flex-direction: column;
  border-top: 1px solid #e0e5ed;
}

.interactive-menu-option {
  appearance: none;
  width: 100%;
  border: 0;
  border-top: 1px solid #e0e5ed;
  background: #fff;
  color: #263248;
  padding: 11px 14px;
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background .15s ease;
}

.interactive-menu-option:first-child {
  border-top: 0;
}

.interactive-menu-option:hover:not(:disabled) {
  background: #f1f4fa;
}

.interactive-menu-option:focus-visible {
  outline: 2px solid #2947d9;
  outline-offset: -2px;
}

.interactive-menu-option:disabled {
  opacity: .55;
  cursor: wait;
}

.interactive-menu-option-text {
  font-weight: 650;
}

.interactive-menu-option-description {
  font-size: 12px;
  color: #7a8598;
  font-weight: 400;
}

.message-bubble a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

@media (max-width: 700px) {
  .message-bubble.has-menu {
    min-width: min(340px, 84vw);
  }
}

/* Ações rápidas: anexo, câmera e localização */
.composer {
  align-items: flex-end;
}

.composer-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.composer .icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  flex: 0 0 42px;
  border: 1px solid #d7dde8;
  background: #f7f9fc;
  color: #263248;
  font-size: 20px;
  line-height: 1;
}

.composer .icon-btn:hover:not(:disabled) {
  background: #eef2f8;
}

.composer .send-btn {
  height: 42px;
}

.action-status {
  padding: 7px 14px;
  border-top: 1px solid #e6eaf0;
  background: #f8fafc;
  color: #536075;
  font-size: 12px;
}

.action-status[data-tone="success"] {
  color: #147a51;
  background: #eefaf5;
}

.action-status[data-tone="error"] {
  color: #b4233e;
  background: #fff1f3;
}

.attachment {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: min(300px, 62vw);
}

.attachment-image-link {
  display: block;
  margin: -10px -13px 0;
  overflow: hidden;
  border-radius: 14px 14px 8px 8px;
}

.attachment-image {
  display: block;
  width: 100%;
  max-width: 420px;
  max-height: 340px;
  object-fit: cover;
  background: #e7ebf2;
}

.attachment-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.14);
  color: inherit;
  text-decoration: none !important;
}

.message.received .attachment-file {
  background: #f2f5fa;
}

.attachment-file-icon {
  font-size: 24px;
}

.attachment-file-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.attachment-file-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-file-info small {
  opacity: .72;
}

.attachment-description,
.attachment-extra-text {
  line-height: 1.4;
}

@media (max-width: 700px) {
  .composer {
    gap: 7px;
    padding: 8px;
  }

  .composer-actions {
    gap: 3px;
  }

  .composer .icon-btn {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    font-size: 18px;
  }

  .composer .send-btn {
    height: 38px;
    padding-inline: 12px;
  }

  .attachment {
    min-width: min(260px, 72vw);
  }
}

/* V4: links visíveis + câmera real via getUserMedia */
.message-bubble a {
  color: #1b63d9;
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

.message.sent .message-bubble a {
  color: #ffffff;
  font-weight: 600;
}

.camera-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
}

.camera-modal.hidden {
  display: none;
}

.camera-panel {
  width: min(720px, 96vw);
  overflow: hidden;
  border-radius: 18px;
  background: #111827;
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
}

.camera-video {
  display: block;
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  background: #000;
}

.camera-controls {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px;
  background: #ffffff;
}

.camera-capture-btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: #2f4be0;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

/* V5: notificações, som e contador de não lidas */
.brand-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.unread-badge {
  min-width: 21px;
  height: 21px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #d92d4f;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid #d7dde8;
  border-radius: 10px;
  background: #fff;
  color: #263248;
  cursor: pointer;
  font-size: 18px;
}

.header-icon-btn:hover:not(:disabled) {
  background: #f4f6fa;
}

.header-icon-btn[aria-pressed="true"] {
  background: #eef2ff;
  border-color: #b8c3ff;
}

.header-icon-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .chat-header {
    padding: 12px 14px;
  }

  .header-actions {
    gap: 5px;
  }

  .header-icon-btn {
    width: 36px;
    height: 36px;
    font-size: 17px;
  }

  .chat-header .secondary-btn {
    padding: 8px 10px;
  }
}


/* V6: tema escuro */
body.dark-theme {
  background: #141922;
  color: #e7ebf3;
}

body.dark-theme .app-shell {
  background: #141922;
}

body.dark-theme .chat-card {
  background: #1e2430;
  border-color: #30394a;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .38);
}

body.dark-theme .chat-header {
  border-bottom-color: #30394a;
  background: #1e2430;
}

body.dark-theme .chat-header h1 {
  color: #f4f6fa;
}

body.dark-theme .status-row,
body.dark-theme .message-meta {
  color: #9aa6b7;
}

body.dark-theme .secondary-btn,
body.dark-theme .header-icon-btn {
  border-color: #3b4659;
  background: #293140;
  color: #edf1f7;
}

body.dark-theme .secondary-btn:hover,
body.dark-theme .header-icon-btn:hover:not(:disabled) {
  background: #343e50;
}

body.dark-theme .header-icon-btn[aria-pressed="true"] {
  background: #303a68;
  border-color: #5869ba;
}

body.dark-theme .service-panel {
  border-bottom-color: #30394a;
  background: #232a36;
  color: #e7ebf3;
}

body.dark-theme .start-form input,
body.dark-theme .composer textarea {
  border-color: #3b4659;
  background: #171c25;
  color: #edf1f7;
}

body.dark-theme .start-form input::placeholder,
body.dark-theme .composer textarea::placeholder {
  color: #8591a3;
}

body.dark-theme .composer textarea:focus {
  border-color: #6f82ff;
  box-shadow: 0 0 0 3px rgba(111, 130, 255, .16);
}

body.dark-theme .messages {
  background: #181e28;
}

body.dark-theme .message.received .message-bubble {
  background: #293140;
  color: #edf1f7;
  border-color: #3b4659;
}

body.dark-theme .message.sent .message-bubble {
  background: #3c57e8;
  color: #fff;
}

body.dark-theme .interactive-menu-options,
body.dark-theme .interactive-menu-option {
  border-color: #3b4659;
}

body.dark-theme .interactive-menu-option {
  background: #293140;
  color: #edf1f7;
}

body.dark-theme .interactive-menu-option:hover:not(:disabled) {
  background: #343e50;
}

body.dark-theme .interactive-menu-option-description {
  color: #a2adbd;
}

body.dark-theme .composer {
  border-top-color: #30394a;
  background: #1e2430;
}

body.dark-theme .composer .icon-btn {
  border-color: #3b4659;
  background: #293140;
  color: #edf1f7;
}

body.dark-theme .composer .icon-btn:hover:not(:disabled) {
  background: #343e50;
}

body.dark-theme .action-status {
  border-top-color: #30394a;
  background: #232a36;
  color: #b3bdcb;
}

body.dark-theme .action-status[data-tone="success"] {
  color: #6fd6aa;
  background: #17332a;
}

body.dark-theme .action-status[data-tone="error"] {
  color: #ff9bad;
  background: #3b1f27;
}

body.dark-theme .message.received .attachment-file {
  background: #202733;
}

body.dark-theme .attachment-image {
  background: #202733;
}

body.dark-theme .message-bubble a {
  color: #77aaff;
}

body.dark-theme .message.sent .message-bubble a {
  color: #ffffff;
}

body.dark-theme .camera-controls {
  background: #1e2430;
}


/* ============================================================
   V7 - Interface moderna
   ============================================================ */

:root {
  --chat-accent: #2947d9;
  --chat-accent-2: #2039b8;
  --chat-surface: #ffffff;
  --chat-bg: #f3f6fb;
  --chat-border: #e2e7ef;
  --chat-muted: #748096;
  --chat-danger: #d9344f;
}

.chat-card {
  border-radius: 26px;
  box-shadow: 0 22px 70px rgba(25, 39, 64, .14);
}

.chat-header {
  min-height: 76px;
  padding: 14px 18px;
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #2947d9, #5672ff);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  box-shadow: 0 7px 20px rgba(41, 71, 217, .24);
}

.brand-copy {
  min-width: 0;
}

.brand-title-row h1 {
  font-size: 18px;
  line-height: 1.1;
}

.protocol-mini {
  margin-left: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4b5fbd;
  font-size: 10px;
  font-weight: 700;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-icon-btn.danger {
  color: #c52d49;
  border-color: #f1c5ce;
  background: #fff5f7;
}

.header-icon-btn.danger:hover:not(:disabled) {
  background: #ffe8ed;
}

.messages-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  background: #f5f7fb;
}

.messages {
  width: 100%;
  min-height: 0;
  padding: 22px 24px 26px;
  gap: 7px;
  scroll-behavior: smooth;
}

.message {
  gap: 5px;
  margin-top: 7px;
}

.message.grouped {
  margin-top: 1px;
}

.message.grouped .message-sender {
  display: none;
}

.message.grouped .message-meta {
  justify-content: flex-end;
  min-height: 0;
}

.message.received.grouped .message-meta {
  justify-content: flex-start;
}

.message-meta {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  padding-inline: 7px;
}

.message.received .message-meta {
  justify-content: flex-start;
}

.message-sender {
  font-weight: 600;
}

.message-time {
  opacity: .76;
  font-variant-numeric: tabular-nums;
}

.message-bubble {
  border-radius: 18px;
  padding: 10px 13px;
  line-height: 1.46;
}

.message.sent .message-bubble {
  border-bottom-right-radius: 6px;
  box-shadow: 0 5px 16px rgba(41, 71, 217, .14);
}

.message.received .message-bubble {
  border-bottom-left-radius: 6px;
  box-shadow: 0 4px 16px rgba(31, 47, 74, .06);
}

.day-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 13px 0 7px;
  user-select: none;
}

.day-separator span {
  padding: 5px 10px;
  border: 1px solid #e3e8f0;
  border-radius: 999px;
  background: rgba(255,255,255,.88);
  color: #738096;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(31,47,74,.04);
}

.scroll-bottom-btn {
  position: absolute;
  right: 18px;
  bottom: 16px;
  z-index: 8;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #dce3ed;
  border-radius: 50%;
  background: #fff;
  color: #2947d9;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 9px 28px rgba(28, 43, 68, .16);
}

.scroll-bottom-btn:hover {
  transform: translateY(-1px);
  background: #f7f9ff;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(238, 243, 252, .88);
  backdrop-filter: blur(5px);
  pointer-events: none;
}

.drop-overlay-card {
  min-width: min(330px, 90%);
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  border: 2px dashed #8194ed;
  border-radius: 20px;
  background: #fff;
  color: #29334a;
  box-shadow: 0 20px 55px rgba(36, 55, 91, .15);
}

.drop-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 5px;
  border-radius: 14px;
  background: #eef2ff;
  color: #2947d9;
  font-size: 24px;
}

.drop-overlay-card small {
  color: #78849a;
}

.composer {
  position: relative;
  gap: 8px;
  padding: 10px 12px 12px;
  align-items: flex-end;
  box-shadow: 0 -8px 24px rgba(34, 49, 73, .035);
}

.composer-actions {
  align-self: flex-end;
}

.composer textarea {
  min-height: 42px;
  max-height: 128px;
  overflow-y: auto;
  border-radius: 16px;
  padding: 10px 13px;
  line-height: 1.4;
}

.composer .icon-btn,
.composer .send-btn {
  border-radius: 13px;
}

.composer .send-btn {
  width: 44px;
  min-width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(145deg, #2947d9, #405fe6);
  box-shadow: 0 7px 18px rgba(41, 71, 217, .20);
}

.emoji-panel {
  position: absolute;
  z-index: 30;
  left: 18px;
  bottom: 76px;
  width: min(340px, calc(100% - 36px));
  padding: 10px;
  border: 1px solid #dde3ec;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 16px 50px rgba(29, 45, 73, .18);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}

.emoji-option {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
}

.emoji-option:hover {
  background: #f0f3f8;
  transform: scale(1.06);
}

.image-modal,
.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(7, 11, 19, .82);
  backdrop-filter: blur(7px);
}

.image-modal img {
  max-width: min(1100px, 94vw);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 28px 90px rgba(0,0,0,.42);
}

.image-modal-close {
  position: fixed;
  top: 20px;
  right: 22px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 50%;
  background: rgba(20,25,34,.78);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
}

.confirm-card {
  width: min(420px, 94vw);
  padding: 26px;
  border-radius: 22px;
  background: #fff;
  color: #1f2937;
  text-align: center;
  box-shadow: 0 28px 90px rgba(0,0,0,.28);
}

.confirm-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff0f3;
  color: #d9344f;
  font-size: 25px;
  font-weight: 800;
}

.confirm-card h2 {
  margin: 0 0 8px;
  font-size: 21px;
}

.confirm-card p {
  margin: 0;
  color: #657186;
  line-height: 1.5;
}

.confirm-actions {
  margin-top: 22px;
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.danger-btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  background: #d9344f;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.attachment-image-link {
  cursor: zoom-in;
}

/* Dark mode V7 */
body.dark-theme .brand-avatar {
  box-shadow: 0 7px 20px rgba(41, 71, 217, .17);
}

body.dark-theme .protocol-mini {
  background: #303a68;
  color: #c6d0ff;
}

body.dark-theme .messages-wrap,
body.dark-theme .messages {
  background: #181e28;
}

body.dark-theme .day-separator span {
  border-color: #384356;
  background: #232b38;
  color: #aab5c5;
  box-shadow: none;
}

body.dark-theme .scroll-bottom-btn {
  border-color: #3a4658;
  background: #293140;
  color: #9db0ff;
  box-shadow: 0 9px 28px rgba(0,0,0,.28);
}

body.dark-theme .drop-overlay {
  background: rgba(18, 24, 33, .88);
}

body.dark-theme .drop-overlay-card,
body.dark-theme .emoji-panel,
body.dark-theme .confirm-card {
  border-color: #3b4659;
  background: #252d3a;
  color: #edf1f7;
}

body.dark-theme .drop-icon {
  background: #303a68;
  color: #bac6ff;
}

body.dark-theme .drop-overlay-card small,
body.dark-theme .confirm-card p {
  color: #9da9ba;
}

body.dark-theme .emoji-option:hover {
  background: #343e50;
}

body.dark-theme .confirm-icon {
  background: #44232c;
  color: #ff91a5;
}

body.dark-theme .header-icon-btn.danger {
  border-color: #613541;
  background: #3b2229;
  color: #ff9aae;
}

@media (max-width: 700px) {
  .chat-header {
    min-height: 68px;
    gap: 8px;
  }

  .brand-avatar {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    border-radius: 12px;
    font-size: 17px;
  }

  .reconnect-label {
    width: 36px;
    height: 36px;
    overflow: hidden;
    padding: 0;
    font-size: 0;
    display: grid;
    place-items: center;
  }

  .reconnect-label::before {
    content: "↻";
    font-size: 18px;
  }

  .messages {
    padding: 15px 12px 20px;
  }

  .message {
    max-width: 90%;
  }

  .composer {
    padding-bottom: max(9px, env(safe-area-inset-bottom));
  }

  .composer-actions {
    gap: 2px;
  }

  .composer .icon-btn {
    width: 35px;
    height: 38px;
    flex-basis: 35px;
    font-size: 17px;
  }

  .composer .send-btn {
    width: 40px;
    min-width: 40px;
  }

  .emoji-panel {
    left: 8px;
    bottom: 70px;
    width: calc(100% - 16px);
  }

  .emoji-grid {
    grid-template-columns: repeat(8, 1fr);
  }

  .emoji-option {
    font-size: 19px;
  }

  .protocol-mini {
    display: none !important;
  }
}

.chat-card { position: relative; }

/* =========================================================
   V7 — interface moderna
   ========================================================= */

:root {
  --brand: #2947d9;
  --brand-strong: #213bc0;
  --brand-soft: #eef2ff;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --chat-bg: #f1f4f9;
  --line: #e2e7ef;
  --text: #172033;
  --muted: #6f7b8f;
  --danger: #d92d4f;
}

.chat-card {
  position: relative;
  width: min(920px, 100%);
  height: min(900px, calc(100vh - 32px));
  border-radius: 26px;
  box-shadow: 0 24px 70px rgba(31, 45, 72, .14);
}

.chat-header {
  min-height: 76px;
  padding: 14px 18px;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(14px);
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(145deg, #3958e8, #213bc0);
  color: #fff;
  font-size: 20px;
  font-weight: 850;
  box-shadow: 0 7px 18px rgba(41,71,217,.25);
}

.brand-copy { min-width: 0; }
.brand-title-row h1 { font-size: 18px; letter-spacing: -.2px; }

.status-row {
  min-width: 0;
  gap: 6px;
  line-height: 1.2;
}

.protocol-mini {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: 3px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: #455cc9;
  font-size: 10px;
  font-weight: 750;
}

.header-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.header-icon-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.finish-btn {
  height: 38px;
  border: 1px solid #ffd2da;
  border-radius: 12px;
  padding: 0 13px;
  background: #fff5f7;
  color: #c71f42;
  font: inherit;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.finish-btn:hover { background: #ffe9ee; }

.service-panel {
  gap: 12px;
  padding: 12px 18px;
  background: #fbfcfe;
}

.service-text {
  color: #536075;
  font-size: 13px;
}

.start-form input {
  min-height: 42px;
  border-radius: 13px;
}

.service-panel button {
  min-height: 42px;
  border-radius: 13px;
  font-weight: 700;
}

.messages-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 18%, rgba(41,71,217,.035), transparent 24%),
    radial-gradient(circle at 90% 84%, rgba(41,71,217,.03), transparent 25%),
    var(--chat-bg);
}

.messages {
  height: 100%;
  min-height: 0;
  padding: 22px 24px 30px;
  gap: 8px;
  background: transparent;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: #ccd3df; border-radius: 999px; }
.messages::-webkit-scrollbar-track { background: transparent; }

.day-separator {
  align-self: center;
  display: flex;
  justify-content: center;
  width: 100%;
  margin: 8px 0 12px;
}

.day-separator span {
  padding: 5px 10px;
  border: 1px solid #e3e8f0;
  border-radius: 999px;
  background: rgba(255,255,255,.88);
  color: #7a8598;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(23,32,51,.04);
}

.message {
  max-width: min(74%, 590px);
  gap: 4px;
}

.message-meta {
  display: flex;
  gap: 5px;
  align-items: center;
  font-size: 10.5px;
  opacity: .86;
}

.message-time::before {
  content: "·";
  margin-right: 5px;
}

.message.grouped { margin-top: -3px; }
.message.grouped .message-meta { display: none; }
.message.grouped.sent .message-bubble { border-top-right-radius: 8px; }
.message.grouped.received .message-bubble { border-top-left-radius: 8px; }

.message-bubble {
  padding: 11px 14px;
  border-radius: 18px;
  line-height: 1.45;
  font-size: 14px;
  box-shadow: 0 2px 7px rgba(28,42,67,.05);
}

.message.sent .message-bubble {
  border-bottom-right-radius: 6px;
  background: linear-gradient(145deg, #3654e4, #2947d9);
  box-shadow: 0 5px 14px rgba(41,71,217,.16);
}

.message.received .message-bubble {
  border-color: #e0e5ed;
  border-bottom-left-radius: 6px;
}

.message-bubble.has-menu {
  min-width: min(440px, 70vw);
  border-radius: 18px;
}

.interactive-menu-title { padding: 14px 15px; }

.interactive-menu-option {
  padding: 12px 14px;
  transition: background .15s ease, color .15s ease;
}

.interactive-menu-option:hover:not(:disabled) {
  background: #f1f4fb;
  color: #253fc7;
}

.attachment-image-link {
  cursor: zoom-in;
}

.attachment-image {
  border-radius: 13px;
  transition: transform .18s ease;
}

.attachment-image-link:hover .attachment-image {
  transform: scale(1.01);
}

.scroll-bottom-btn {
  position: absolute;
  z-index: 7;
  right: 18px;
  bottom: 16px;
  width: 40px;
  height: 40px;
  border: 1px solid #d8deea;
  border-radius: 50%;
  background: rgba(255,255,255,.95);
  color: #31405a;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 8px 25px rgba(27,40,64,.18);
  cursor: pointer;
}

.scroll-bottom-btn:hover { background: #fff; transform: translateY(-1px); }

.drop-overlay {
  position: absolute;
  z-index: 15;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 2px dashed #7387ef;
  border-radius: 22px;
  background: rgba(238,242,255,.94);
  backdrop-filter: blur(8px);
}

.drop-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: #3348b8;
}

.drop-overlay-icon { font-size: 30px; }
.drop-overlay-card small { color: #6f7b8f; }

.action-status {
  min-height: 30px;
  padding: 7px 18px;
}

.composer-shell {
  position: relative;
  z-index: 20;
  border-top: 1px solid #e5e9f0;
  background: rgba(255,255,255,.98);
}

.composer {
  border-top: 0;
  padding: 10px 12px 6px;
  align-items: flex-end;
  gap: 6px;
}

.composer-input-wrap {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: flex-end;
  border: 1px solid #d8deea;
  border-radius: 18px;
  background: #f8fafc;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.composer-input-wrap:focus-within {
  border-color: #8090ef;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(41,71,217,.08);
}

.composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 128px;
  border: 0 !important;
  border-radius: 18px;
  background: transparent !important;
  padding: 10px 13px;
  box-shadow: none !important;
  line-height: 21px;
  overflow-y: auto;
}

.composer .icon-btn,
.composer .send-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 14px;
  padding: 0;
}

.composer .icon-btn {
  font-size: 18px;
  border-color: transparent;
  background: transparent;
}

.composer .icon-btn:hover:not(:disabled) {
  background: #eff2f7;
}

.composer .send-btn {
  display: grid;
  place-items: center;
  font-size: 18px;
  box-shadow: 0 5px 14px rgba(41,71,217,.22);
}

.composer-hint {
  padding: 0 16px 7px;
  text-align: center;
  color: #9aa3b2;
  font-size: 10px;
}

.emoji-panel {
  position: absolute;
  z-index: 40;
  left: 10px;
  bottom: calc(100% - 1px);
  width: min(330px, calc(100vw - 28px));
  padding: 10px;
  border: 1px solid #dfe4ed;
  border-radius: 18px;
  background: rgba(255,255,255,.98);
  box-shadow: 0 18px 55px rgba(26,39,63,.20);
  backdrop-filter: blur(15px);
}

.emoji-panel-title {
  padding: 2px 5px 8px;
  color: #7a8598;
  font-size: 11px;
  font-weight: 750;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}

.emoji-option {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

.emoji-option:hover { background: #eef2f7; }

.confirm-modal,
.image-modal {
  position: fixed;
  z-index: 1200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10,15,25,.68);
  backdrop-filter: blur(5px);
}

.confirm-card {
  width: min(420px, 94vw);
  padding: 24px;
  border-radius: 22px;
  background: #fff;
  color: #172033;
  text-align: center;
  box-shadow: 0 28px 80px rgba(0,0,0,.30);
}

.confirm-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff0f3;
  color: #cc2345;
  font-size: 23px;
  font-weight: 900;
}

.confirm-card h2 { margin: 0 0 8px; font-size: 19px; }
.confirm-card p { margin: 0; color: #6f7b8f; line-height: 1.5; font-size: 13px; }

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.danger-btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 13px;
  background: #d92d4f;
  color: #fff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.image-modal {
  align-content: center;
}

.image-modal img {
  max-width: min(1100px, 94vw);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 15px;
  box-shadow: 0 24px 80px rgba(0,0,0,.42);
}

.image-modal-close {
  position: fixed;
  top: 18px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 50%;
  background: rgba(0,0,0,.32);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
}


/* Tema escuro — V7 */
body.dark-theme .chat-header,
body.dark-theme .composer-shell {
  background: rgba(30,36,48,.98);
}

body.dark-theme .brand-avatar {
  background: linear-gradient(145deg, #667cff, #3c57e8);
}

body.dark-theme .protocol-mini {
  background: #303a68;
  color: #c8d0ff;
}

body.dark-theme .finish-btn {
  border-color: #63303d;
  background: #3b1f27;
  color: #ff9bad;
}

body.dark-theme .messages-wrap {
  background:
    radial-gradient(circle at 15% 18%, rgba(111,130,255,.05), transparent 24%),
    radial-gradient(circle at 90% 84%, rgba(111,130,255,.04), transparent 25%),
    #181e28;
}

body.dark-theme .messages { background: transparent; }
body.dark-theme .messages::-webkit-scrollbar-thumb { background: #3b4659; }

body.dark-theme .day-separator span {
  border-color: #354052;
  background: rgba(37,45,58,.94);
  color: #a5b0bf;
}

body.dark-theme .scroll-bottom-btn {
  border-color: #435067;
  background: rgba(41,49,64,.96);
  color: #eef2f8;
}

body.dark-theme .drop-overlay {
  border-color: #7d8fff;
  background: rgba(35,42,54,.96);
}

body.dark-theme .drop-overlay-card { color: #b8c2ff; }
body.dark-theme .drop-overlay-card small { color: #9aa6b7; }

body.dark-theme .composer-shell { border-top-color: #30394a; }

body.dark-theme .composer-input-wrap {
  border-color: #3b4659;
  background: #171c25;
}

body.dark-theme .composer-input-wrap:focus-within {
  border-color: #6f82ff;
  background: #171c25;
  box-shadow: 0 0 0 3px rgba(111,130,255,.13);
}

body.dark-theme .composer .icon-btn {
  border-color: transparent;
  background: transparent;
}

body.dark-theme .composer .icon-btn:hover:not(:disabled) { background: #303847; }
body.dark-theme .composer-hint { color: #687486; }

body.dark-theme .emoji-panel {
  border-color: #3b4659;
  background: rgba(34,41,54,.98);
}

body.dark-theme .emoji-option:hover { background: #343e50; }

body.dark-theme .confirm-card {
  background: #242c39;
  color: #edf1f7;
}

body.dark-theme .confirm-card p { color: #a6b0bf; }
body.dark-theme .confirm-icon { background: #3b1f27; color: #ff9bad; }

@media (max-width: 760px) {
  .app-shell { padding: 0; }
  .chat-card {
    height: 100dvh;
    min-height: 100dvh;
    border-radius: 0;
  }

  .chat-header {
    min-height: 66px;
    padding: max(10px, env(safe-area-inset-top)) 10px 10px;
  }

  .brand-avatar {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    border-radius: 12px;
    font-size: 17px;
  }

  .brand-title-row h1 { font-size: 16px; }
  .status-row { font-size: 11px; }
  .protocol-mini { max-width: 130px; }

  .header-actions { gap: 3px; }
  .header-icon-btn { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
  .finish-btn { height: 34px; padding: 0 8px; font-size: 11px; }

  .messages { padding: 14px 12px 24px; }
  .message { max-width: 88%; }
  .message-bubble { font-size: 14px; }
  .message-bubble.has-menu { min-width: min(350px, 84vw); }

  .composer {
    padding: 7px 7px max(5px, env(safe-area-inset-bottom));
    gap: 2px;
  }

  .composer .icon-btn,
  .composer .send-btn {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    border-radius: 12px;
    font-size: 16px;
  }

  .composer-input-wrap { border-radius: 16px; }
  .composer textarea { min-height: 38px; padding: 8px 10px; }
  .composer-hint { display: none; }

  .emoji-panel {
    left: 7px;
    bottom: calc(100% + 2px);
    width: min(320px, calc(100vw - 14px));
  }

  .emoji-grid { grid-template-columns: repeat(8, 1fr); }
  .emoji-option { width: 32px; height: 32px; font-size: 19px; }

}

@media (max-width: 520px) {
  .header-actions #soundBtn { display: none; }
  .header-actions #reconnectBtn { display: none; }
  .composer #locationBtn { display: inline-grid; }
  .emoji-grid { grid-template-columns: repeat(7, 1fr); }
}


/* =========================================================
   V9 — composer único, alinhado e mobile-first
   ========================================================= */
.composer-shell {
  padding: 0;
}

.composer {
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  flex-wrap: nowrap;
}

.composer-bar {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  padding: 4px 5px;
  border: 1px solid #d9e0eb;
  border-radius: 20px;
  background: #fff;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.composer-bar:focus-within {
  border-color: #5d72ef;
  box-shadow: 0 0 0 3px rgba(66, 88, 224, .10);
}

.composer-input-wrap {
  min-width: 80px;
  flex: 1 1 auto;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.composer-input-wrap:focus-within {
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
}

.composer textarea {
  width: 100%;
  min-height: 38px;
  max-height: 110px;
  padding: 8px 7px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  line-height: 1.35;
}

.composer .icon-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  margin: 1px 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-size: 17px;
}

.composer .icon-btn:hover:not(:disabled) {
  background: #eef2f8;
}

.composer .send-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  margin: 0;
  border-radius: 15px;
  font-size: 19px;
  box-shadow: 0 7px 18px rgba(54, 78, 224, .22);
}

.composer-hint { display: none !important; }

body.dark-theme .composer-bar {
  border-color: #3b4659;
  background: #171c25;
}

body.dark-theme .composer-bar:focus-within {
  border-color: #6f82ff;
  box-shadow: 0 0 0 3px rgba(111, 130, 255, .12);
}

body.dark-theme .composer-input-wrap,
body.dark-theme .composer-input-wrap:focus-within {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

body.dark-theme .composer .icon-btn {
  background: transparent;
  border: 0;
}

body.dark-theme .composer .icon-btn:hover:not(:disabled) {
  background: #2c3544;
}

@media (max-width: 760px) {
  .composer {
    gap: 6px;
    padding: 7px 8px max(8px, env(safe-area-inset-bottom));
  }

  .composer-bar {
    gap: 1px;
    padding: 3px 4px;
    border-radius: 18px;
  }

  .composer .icon-btn {
    width: 34px;
    height: 36px;
    min-width: 34px;
    flex-basis: 34px;
    border-radius: 11px;
    font-size: 16px;
  }

  .composer textarea {
    min-height: 36px;
    padding: 8px 5px;
    font-size: 14px;
  }

  .composer .send-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    flex-basis: 42px;
    border-radius: 14px;
  }
}

@media (max-width: 420px) {
  .composer {
    gap: 4px;
    padding-inline: 5px;
  }

  .composer-bar {
    padding-inline: 2px;
  }

  .composer .icon-btn {
    width: 31px;
    min-width: 31px;
    flex-basis: 31px;
    font-size: 15px;
  }

  .composer textarea {
    min-width: 70px;
    padding-inline: 4px;
  }

  .composer .send-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    flex-basis: 40px;
  }
}


/* =========================================================
   V10 — gravação de áudio
   ========================================================= */
.composer .send-btn.mic-mode {
  font-size: 18px;
}

.audio-recorder {
  min-width: 0;
  flex: 1 1 auto;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 8px;
  border: 1px solid #d9e0eb;
  border-radius: 20px;
  background: #fff;
}

.audio-recorder.hidden { display: none !important; }

.composer.recording-audio .composer-bar,
.composer.recording-audio > .send-btn {
  display: none !important;
}

.audio-recorder-status {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #58647a;
}

.audio-recording-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, .4);
  animation: audio-pulse 1.35s infinite;
}

.audio-recorder.paused .audio-recording-dot {
  animation: none;
  opacity: .45;
}

@keyframes audio-pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .38); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.audio-timer {
  min-width: 38px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #1d2939;
}

.audio-recorder-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
}

.audio-recorder-btn,
.audio-recorder-send {
  width: 36px;
  height: 36px;
  min-width: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
}

.audio-recorder-btn {
  background: #eef2f8;
  color: #253047;
}

.audio-recorder-btn:hover { background: #e3e8f1; }

.audio-discard-btn { color: #dc2626; }

.audio-recorder-send {
  background: #3650e6;
  color: #fff;
  box-shadow: 0 5px 14px rgba(54, 80, 230, .22);
}

.audio-recorder-send:hover { background: #2d45cf; }

.attachment-audio {
  min-width: min(320px, 70vw);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.attachment-audio-player {
  display: block;
  width: 100%;
  max-width: 330px;
  height: 38px;
}

.attachment-audio-info {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
}

.attachment-audio-info strong {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.attachment-audio-info small { opacity: .72; }

body.dark-theme .audio-recorder {
  border-color: #3b4659;
  background: #171c25;
}

body.dark-theme .audio-recorder-status { color: #a6b0c1; }
body.dark-theme .audio-timer { color: #f0f3f8; }
body.dark-theme .audio-recorder-btn { background: #2c3544; color: #dbe1eb; }
body.dark-theme .audio-recorder-btn:hover { background: #354052; }
body.dark-theme .audio-discard-btn { color: #fb7185; }

@media (max-width: 520px) {
  .audio-recorder {
    height: 44px;
    gap: 5px;
    padding: 4px 5px;
    border-radius: 17px;
  }
  .audio-recorder-btn,
  .audio-recorder-send {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 11px;
  }
  .audio-recorder-text { display: none; }
  .attachment-audio { min-width: min(260px, 74vw); }
}


/* =========================================================
   V11 — áudio mais moderno + player dentro do chat
   ========================================================= */
.composer .send-btn svg,
.audio-recorder-btn svg,
.audio-recorder-send svg,
.chat-audio-play svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
  display: block;
}

.composer .send-btn.mic-mode {
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(54, 78, 224, .22);
}

.audio-recorder {
  min-height: 50px;
  height: auto;
  padding: 6px 7px;
  gap: 9px;
  border-radius: 18px;
}

.audio-recorder-center {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.audio-recorder-status {
  flex: 0 0 auto;
  gap: 7px;
}

.audio-waveform {
  min-width: 80px;
  flex: 1 1 auto;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  overflow: hidden;
}

.audio-waveform span {
  width: 3px;
  height: 7px;
  flex: 0 0 3px;
  border-radius: 999px;
  background: #7180a1;
  opacity: .75;
  animation: recorder-wave 1.05s ease-in-out infinite alternate;
  transform-origin: center;
}
.audio-waveform span:nth-child(3n+1) { animation-delay: -.15s; }
.audio-waveform span:nth-child(3n+2) { animation-delay: -.42s; }
.audio-waveform span:nth-child(4n) { animation-delay: -.68s; }
.audio-waveform span:nth-child(5n) { animation-delay: -.28s; }

.audio-recorder.paused .audio-waveform span {
  animation-play-state: paused;
  height: 5px;
  opacity: .42;
}

@keyframes recorder-wave {
  from { height: 5px; }
  to { height: 23px; }
}

.audio-recorder-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.audio-recorder-btn,
.audio-recorder-send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 13px;
}

.audio-discard-btn {
  flex: 0 0 38px;
}

.audio-recorder-send {
  border-radius: 50%;
}

.attachment-audio-wrap {
  min-width: min(360px, 72vw);
}

.chat-audio-player {
  width: min(350px, 68vw);
  min-width: 240px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 7px;
  border-radius: 14px;
  background: rgba(255,255,255,.16);
}

.message.received .chat-audio-player {
  background: #f3f6fa;
}

.chat-audio-element {
  display: none;
}

.chat-audio-play {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255,255,255,.92);
  color: #3650e6;
  box-shadow: 0 3px 10px rgba(20,32,60,.10);
}

.message.received .chat-audio-play {
  background: #3650e6;
  color: #fff;
}

.chat-audio-center {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chat-audio-progress {
  width: 100%;
  height: 4px;
  margin: 0;
  accent-color: currentColor;
  cursor: pointer;
}

.chat-audio-meta {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto auto;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  opacity: .82;
  font-variant-numeric: tabular-nums;
}

.chat-audio-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.chat-audio-size {
  white-space: nowrap;
  font-size: 10px;
  opacity: .72;
}

.chat-audio-speed {
  min-width: 34px;
  height: 24px;
  padding: 0 7px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  background: rgba(255,255,255,.16);
  color: inherit;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.message.received .chat-audio-speed {
  border-color: #d4dbe8;
  background: #e7ebf3;
  color: #34415b;
}

.chat-audio-speed:hover {
  filter: brightness(.97);
}

body.dark-theme .message.received .chat-audio-speed {
  border-color: #455168;
  background: #303a4b;
  color: #eef3ff;
}

body.dark-theme .audio-waveform span { background: #8f9ab0; }
body.dark-theme .message.received .chat-audio-player { background: #232b38; }
body.dark-theme .message.received .chat-audio-play { background: #556df3; }

@media (max-width: 600px) {
  .audio-recorder { gap: 6px; padding: 5px; }
  .audio-recorder-center { gap: 7px; }
  .audio-recorder-text { display: none; }
  .audio-waveform { min-width: 42px; gap: 2px; }
  .audio-waveform span { width: 2px; flex-basis: 2px; }
  .audio-waveform span:nth-child(n+14) { display: none; }
  .audio-recorder-btn, .audio-recorder-send {
    width: 36px; height: 36px; min-width: 36px;
  }
  .chat-audio-player {
    width: min(300px, 74vw);
    min-width: 215px;
    grid-template-columns: 40px minmax(0,1fr);
  }
  .chat-audio-size { display: none; }
  .chat-audio-play { width: 38px; height: 38px; }
  .chat-audio-meta { grid-template-columns: auto minmax(0,1fr) auto auto; gap: 5px; }
  .chat-audio-speed { min-width: 31px; height: 22px; padding: 0 6px; }
}

@media (max-width: 400px) {
  .audio-recorder-center { gap: 5px; }
  .audio-waveform span:nth-child(n+10) { display: none; }
  .audio-timer { min-width: 34px; font-size: 12px; }
  .chat-audio-player { width: min(270px, 78vw); min-width: 190px; }
}


/* =========================================================
   V13 — recorder alinhado, velocidade real e vídeo da câmera
   ========================================================= */

/* Recorder: 5 zonas fixas e alinhadas, sem elementos "soltos". */
.audio-recorder {
  display: grid;
  grid-template-columns: 40px auto minmax(90px, 1fr) 40px 42px;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 6px 7px;
}

.audio-recorder-center,
.audio-recorder-actions {
  display: contents;
}

.audio-recorder-status {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  min-width: 62px;
}

.audio-recorder-text {
  display: none !important;
}

.audio-waveform {
  grid-column: 3;
  width: 100%;
  min-width: 90px;
  justify-content: center;
  padding: 0 6px;
}

.audio-discard-btn {
  grid-column: 1;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
}

.audio-pause-btn {
  grid-column: 4;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
}

.audio-recorder-send {
  grid-column: 5;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
}

.audio-timer {
  min-width: 38px;
  text-align: left;
  font-size: 13px;
}

/* Modal da câmera com foto + vídeo. */
.camera-panel {
  position: relative;
}

.camera-video-badge {
  position: absolute;
  z-index: 2;
  top: 14px;
  left: 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(17, 24, 39, .82);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px);
}

.camera-video-badge.hidden { display: none !important; }

.camera-video-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239,68,68,.45);
  animation: audio-pulse 1.25s infinite;
}

.camera-controls {
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.camera-video-btn,
.camera-capture-btn {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 800;
  cursor: pointer;
}

.camera-video-btn {
  background: #eef2f8;
  color: #253047;
}

.camera-video-btn:hover { background: #e1e7f0; }
.camera-video-btn.recording {
  background: #dc2626;
  color: #fff;
}
.camera-video-btn.recording:hover { background: #b91c1c; }
.camera-capture-btn:disabled { opacity: .45; cursor: not-allowed; }

body.dark-theme .camera-video-btn {
  background: #2b3545;
  color: #edf2fb;
}
body.dark-theme .camera-video-btn:hover { background: #354155; }
body.dark-theme .camera-video-btn.recording { background: #b91c1c; color: #fff; }

/* Vídeos recebidos ficam reproduzíveis dentro do chat. */
.attachment-video-wrap {
  width: min(420px, 72vw);
}

.attachment-video {
  display: block;
  width: 100%;
  max-height: 420px;
  border-radius: 12px;
  background: #000;
}

@media (max-width: 600px) {
  .audio-recorder {
    grid-template-columns: 36px auto minmax(42px, 1fr) 36px 40px;
    gap: 6px;
    min-height: 48px;
    padding: 5px 6px;
  }
  .audio-discard-btn,
  .audio-pause-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }
  .audio-recorder-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }
  .audio-recorder-status { min-width: 57px; gap: 5px; }
  .audio-waveform { min-width: 42px; padding: 0 2px; }

  .camera-controls {
    padding: 10px;
    gap: 8px;
  }
  .camera-controls .secondary-btn,
  .camera-video-btn,
  .camera-capture-btn {
    flex: 1 1 auto;
    min-width: 100px;
    padding: 9px 11px;
  }
  .attachment-video-wrap { width: min(330px, 78vw); }
}

@media (max-width: 400px) {
  .audio-recorder {
    grid-template-columns: 34px auto minmax(26px, 1fr) 34px 38px;
    gap: 5px;
  }
  .audio-discard-btn,
  .audio-pause-btn { width: 34px; height: 34px; min-width: 34px; }
  .audio-recorder-send { width: 38px; height: 38px; min-width: 38px; }
  .audio-waveform span:nth-child(n+8) { display: none; }
  .camera-controls { flex-direction: column-reverse; }
  .camera-controls .secondary-btn,
  .camera-video-btn,
  .camera-capture-btn { width: 100%; }
}

/* ============================================================
   V15 — conexão, recuperação de sessão e PWA
   ============================================================ */
.status-dot.reconnecting {
  background: #e8a317;
  box-shadow: 0 0 0 3px rgba(232, 163, 23, .12);
  animation: connectionPulse 1.25s ease-in-out infinite;
}

@keyframes connectionPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .55; transform: scale(.82); }
}

.connection-banner {
  min-height: 42px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid #e6eaf0;
  font-size: 13px;
  line-height: 1.35;
}

.connection-banner.is-reconnecting {
  background: #fff8e7;
  color: #76530a;
  border-bottom-color: #f0dfb7;
}

.connection-banner.is-offline {
  background: #fff0f3;
  color: #8e2d43;
  border-bottom-color: #f1c9d2;
}

.connection-banner-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: rgba(255,255,255,.65);
}

.connection-banner.is-reconnecting .connection-banner-icon {
  animation: connectionSpin 1.2s linear infinite;
}

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

.connection-banner-text {
  flex: 1;
  min-width: 0;
}

.connection-retry-btn {
  flex: 0 0 auto;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

body.dark-theme .connection-banner.is-reconnecting {
  background: #2a2418;
  color: #f4cf77;
  border-bottom-color: #46391e;
}

body.dark-theme .connection-banner.is-offline {
  background: #2a1b20;
  color: #f0a5b7;
  border-bottom-color: #4b2630;
}

body.dark-theme .connection-banner-icon {
  background: rgba(0,0,0,.18);
}

@media (max-width: 700px) {
  .connection-banner {
    padding: 7px 10px;
    font-size: 12px;
  }
  .connection-retry-btn {
    padding: 5px 8px;
  }
  .header-actions #installBtn {
    display: inline-grid;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot.reconnecting,
  .connection-banner.is-reconnecting .connection-banner-icon {
    animation: none;
  }
}
