/* ======================= CHAT ======================= */
/* Extraído do index.html original. Só duas mudanças de layout:
   .chat-shell substitui a antiga .shell (a sidebar é assunto do chat, não do app)
   e as alturas 100dvh viram 100% porque agora existe a tab bar abaixo. */

.chat-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

/* ======================= SIDEBAR (conversas) ======================= */
.sidebar {
  flex: 0 0 248px;
  width: 248px;
  background: var(--bar-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(var(--safe-t) + 16px) 12px 14px 12px;
}
.sb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
}
.sb-head h2 {
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 17px;
  margin: 0;
  color: var(--ink);
}
.new-btn {
  border: 0;
  cursor: pointer;
  background: linear-gradient(135deg, #3aa0ff, #1565d8);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 13px;
  border-radius: 10px;
  padding: 8px 12px;
}
.new-btn:active {
  transform: scale(0.96);
}
.conv-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
}
.sb-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.logout-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--danger);
  font-weight: 600;
  font-size: 14px;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
}
.logout-btn:active {
  background: var(--field);
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px;
  font-size: 14px;
  color: var(--ink);
}
.conv-item:hover {
  background: var(--field);
}
.conv-item.active {
  background: var(--tint-blue);
  border-color: var(--tint-blue-line);
  font-weight: 600;
}
.conv-ic {
  font-size: 16px;
  flex: 0 0 auto;
}
.conv-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-pin {
  font-size: 10px;
  opacity: 0.55;
  flex: 0 0 auto;
}
.conv-del {
  flex: 0 0 auto;
  color: var(--tint-danger-ink);
  font-size: 18px;
  line-height: 1;
  padding: 0 5px;
  border-radius: 6px;
}
.conv-del:hover {
  background: var(--tint-danger);
}
.drawer-backdrop {
  display: none;
}
.drawer-toggle {
  background: transparent;
  border: 0;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.drawer-toggle:active {
  background: var(--field);
}
@media (min-width: 821px) {
  .drawer-toggle {
    display: none;
  }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--sh-lg);
    padding-bottom: calc(var(--safe-b) + 14px);
  }
  .sidebar.open {
    transform: none;
  }
  .drawer-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: var(--scrim);
  }
}

/* ======================= CARD DO CHAT ======================= */
.avatar,
.avatar-fallback {
  position: absolute;
  top: -26px;
  left: 16px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 4px solid var(--card-2);
  box-shadow: var(--sh-md);
  object-fit: cover;
  object-position: center top;
  background: var(--field);
}
.avatar-fallback {
  display: none;
  background: var(--accent);
  color: var(--on-warm);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 22px;
  align-items: center;
  justify-content: center;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 12px 88px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}
.card-header .htxt {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  min-width: 0;
}
.card-header .balloon {
  font-size: 16px;
}
.menu-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.menu-btn:active {
  background: var(--field);
}
/* posicionamento do menu dentro do card do chat (.menu genérico está em components.css) */
#chatMenu {
  top: 46px;
  right: 8px;
}

/* mensagens */
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  background: var(--field);
  border-radius: 14px;
  margin: 12px 0;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  margin: 0 0 11px;
  line-height: 1.5;
  font-size: 15px;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: rise 0.25s ease both;
}
.msg:last-child {
  margin-bottom: 0;
}
.msg .who {
  font-weight: 700;
  color: var(--ink);
}
.msg.user {
  margin-left: auto;
  width: fit-content;
  max-width: 85%;
  background: var(--tint-blue);
  border: 1px solid var(--tint-blue-line);
  border-radius: 14px;
  border-top-right-radius: 6px;
  padding: 9px 12px;
}
.msg.user .who {
  color: var(--blue-solid);
}

/* markdown renderizado (respostas do coach) */
.msg .md {
  white-space: normal;
}
.msg .md p {
  margin: 0 0 8px;
}
.msg .md > :last-child {
  margin-bottom: 0;
}
.msg .md ul,
.msg .md ol {
  margin: 6px 0;
  padding-left: 22px;
}
.msg .md li {
  margin: 2px 0;
}
.msg .md h1,
.msg .md h2,
.msg .md h3,
.msg .md h4 {
  margin: 10px 0 6px;
  line-height: 1.25;
  font-family: "Baloo 2", sans-serif;
  color: var(--ink);
}
.msg .md h1 {
  font-size: 20px;
}
.msg .md h2 {
  font-size: 18px;
}
.msg .md h3 {
  font-size: 16px;
}
.msg .md h4 {
  font-size: 15px;
}
.msg .md strong {
  font-weight: 700;
}
.msg .md em {
  font-style: italic;
}
.msg .md a {
  color: var(--blue-solid);
  text-decoration: underline;
}
.msg .md code {
  background: var(--field);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.msg .md pre {
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg .md pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.msg .md blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--tint-blue-line);
  color: var(--muted);
}
.msg.error {
  cursor: pointer;
  color: var(--danger);
}
.msg.error .retry {
  font-weight: 600;
  text-decoration: underline;
}

.typing {
  display: inline-flex;
  gap: 4px;
  vertical-align: middle;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.4s infinite both;
}
.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

/* composer */
.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  max-height: 120px;
  min-height: 48px;
  overflow-y: auto;
}
.composer textarea::placeholder {
  color: var(--muted);
}
.send-btn {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: linear-gradient(135deg, #3aa0ff, #1565d8);
  display: grid;
  place-items: center;
  transition:
    transform 0.08s ease,
    filter 0.15s ease;
}
.send-btn:active {
  transform: scale(0.94);
}
.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.send-btn svg {
  width: 22px;
  height: 22px;
  display: block;
}
