:root {
  --bg-primary: #08090a;
  --bg-panel: #0f1011;
  --bg-elevated: #191a1b;
  --bg-surface: #28282c;
  --accent: #08CAE8;
  --accent-hover: #33D6ED;
  --text-primary: #f7f8f8;
  --text-secondary: #d0d6e0;
  --text-muted: #8a8f98;
  --border: rgba(255, 255, 255, 0.08);
  --error: #F04438;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, sans-serif;
  font-feature-settings: "cv01", "ss03";
  font-weight: 400;
}

button { font-family: inherit; }

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ================================================================== */
/* SIDEBAR — estado aberto (260px) / recolhido (regua 64px)            */
/* ================================================================== */

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.18s ease;
}

.sidebar.expanded .only-collapsed { display: none !important; }
.sidebar:not(.expanded) .only-open { display: none !important; }

@media (min-width: 761px) {
  .sidebar:not(.expanded) { width: 64px; }
}

/* -- Regua recolhida: logo + 3 icones de acao -------------------------- */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 10px;
  height: 100%;
}

.rail-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.rail-logo img { width: 24px; height: 24px; object-fit: contain; }
.rail-logo:hover { background: var(--bg-elevated); }

.rail-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.rail-btn svg { width: 20px; height: 20px; }
.rail-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

.rail-avatar {
  margin-top: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(8, 202, 232, 0.16);
  color: var(--accent);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 590;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: default;
}

/* -- Estado aberto: header, novo chat, nav, recentes, perfil ----------- */

.sb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
  flex-shrink: 0;
}

.sb-logo { height: 20px; width: auto; object-fit: contain; }

.sb-header-actions { display: flex; gap: 2px; flex-shrink: 0; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

.sb-newchat {
  margin: 6px 12px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 8px;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 510;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
  transition: background 0.15s;
}

.sb-newchat:hover { background: var(--bg-surface); }
.sb-newchat-icon { width: 18px; height: 18px; display: flex; color: var(--text-secondary); flex-shrink: 0; }
.sb-newchat-icon svg { width: 18px; height: 18px; }

.sb-recents {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  padding-top: 2px;
  margin-top: 6px;
}

.sb-recents-header {
  display: flex;
  align-items: center;
  padding: 10px 16px 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 510;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-list {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  /* rolagem funcional, barra invisivel */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar-list::-webkit-scrollbar { display: none; }

.session-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.3;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

/* Truncamento vive num <span> interno, nao no <button> em si: em
   engines WebKit/Safari, text-overflow:ellipsis aplicado direto num
   <button> nao e confiavel (o botao tem uma caixa flex interna da UA
   que ignora a regra) -- so funciona de forma consistente num elemento
   de bloco simples. min-width:0 garante que o span pode encolher abaixo
   da largura intrinseca do texto dentro do flex item pai. */
.session-item-text {
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.session-item:hover {
  background: rgba(8, 202, 232, 0.08);
  color: var(--text-primary);
}

.session-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: inset 2px 0 0 var(--accent);
}

.session-empty {
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.sb-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(8, 202, 232, 0.16);
  color: var(--accent);
  font-size: 12px;
  font-weight: 590;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sb-profile-text { flex: 1; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.sb-profile-text strong { font-size: 13.5px; font-weight: 510; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-profile-text span { font-size: 11.5px; color: var(--text-muted); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
}

/* ================================================================== */
/* AREA PRINCIPAL                                                       */
/* ================================================================== */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.topbar {
  position: relative;
  min-height: 58px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: none;
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mobile-menu-btn svg { width: 18px; height: 18px; }

/* -- Hero (estado vazio, sem mensagens) --------------------------------- */

.hero {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 20px;
}

.main.chatting .hero { display: none; }

.hero-title {
  margin: 0;
  font-size: 32px;
  font-weight: 510;
  letter-spacing: -0.704px;
  color: var(--text-primary);
  text-align: center;
}

.composer-wrap {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.hero-suggestion {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13.5px;
  cursor: pointer;
  padding: 4px 6px;
  align-self: flex-start;
}

.hero-suggestion:hover { color: var(--text-secondary); }

.hero-suggestion-orb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  background: radial-gradient(circle at 32% 30%, var(--accent-hover), var(--accent) 55%, #062229 100%);
  box-shadow: 0 0 10px rgba(8, 202, 232, 0.45);
}

/* -- Composer (pilula) compartilhado entre hero e docked ---------------- */

.composer-pill {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 8px 8px 8px 18px;
}

.composer-round {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.composer-round svg { width: 18px; height: 18px; }
.composer-round:hover { background: var(--bg-panel); color: var(--text-primary); }

.composer-round.is-recording {
  background: var(--accent);
  color: var(--bg-primary);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

.composer-round.is-transcribing {
  background: var(--bg-panel);
  color: var(--accent);
  cursor: wait;
  animation: mic-fade 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(8, 202, 232, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(8, 202, 232, 0); }
}

@keyframes mic-fade {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.composer-input {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 140px;
  background: transparent;
  border: none;
  outline: none;
  padding: 9px 4px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  /* rolagem funcional, barra invisivel (textarea pode rolar internamente perto do max-height) */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.composer-input::-webkit-scrollbar { display: none; }

.composer-input::placeholder { color: var(--text-muted); }

.composer-send {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.composer-send svg { width: 17px; height: 17px; }
.composer-send:hover:not(:disabled) { background: var(--accent-hover); }
.composer-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* -- Conversa (estado com mensagens) ------------------------------------ */

.conversation {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.main.chatting .conversation { display: flex; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  /* rolagem funcional, barra invisivel */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chat::-webkit-scrollbar { display: none; }

.msg-row {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
}

.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }

.bubble-user {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 14.5px;
  line-height: 1.55;
  max-width: 82%;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-bot {
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.65;
  max-width: 100%;
  word-break: break-word;
}

.bubble-bot p { margin: 0 0 10px; }
.bubble-bot p:last-child { margin-bottom: 0; }
.bubble-bot strong { font-weight: 590; }
.bubble-bot em { color: var(--text-secondary); }
.bubble-bot code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}
.bubble-bot ul, .bubble-bot ol { margin: 6px 0; padding-left: 22px; }
.bubble-bot li { margin-bottom: 4px; }
.bubble-bot a { color: var(--accent); text-decoration: underline; }

.typing, .error-banner {
  max-width: 760px;
  width: 100%;
  margin: 0 auto 10px;
  padding: 0 20px;
}

.typing.hidden, .error-banner.hidden { display: none; }

.typing-bubble {
  display: inline-flex;
  gap: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  padding: 14px 16px;
}

.typing-bubble span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: blink 1.2s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.error-banner {
  box-sizing: border-box;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(240, 68, 56, 0.12);
  border: 1px solid var(--error);
  color: #ffb4ac;
  font-size: 13px;
}

.composer-docked {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  flex-shrink: 0;
}

.conversation > .composer-docked {
  margin-bottom: 20px;
}

/* ================================================================== */
/* RESPONSIVO — mobile: sidebar vira drawer off-canvas                  */
/* ================================================================== */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 84%;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 30;
  }

  .sidebar.expanded {
    transform: translateX(0);
    width: 84%;
    max-width: 300px;
  }

  .sidebar-overlay.open { display: block; }

  .mobile-menu-btn { display: flex; }

  .topbar { padding: 14px 60px; }
  .hero-title { font-size: 26px; }
  .msg-row { padding: 0 14px; }
  .bubble-user { max-width: 90%; }
  .composer-wrap, .composer-docked { padding: 0 14px; }
}
