:root {
  --bg-base: #050f1f;
  --bg-deep: #030817;
  --bg-card: rgba(15, 30, 55, 0.65);
  --bg-card-solid: #0d1d36;
  --bg-card-hover: rgba(15, 30, 55, 0.85);
  --border: rgba(74, 222, 200, 0.18);
  --border-strong: rgba(74, 222, 200, 0.35);
  --green: #2be3a8;
  --green-bright: #4ff5c4;
  --cyan: #4dd0e1;
  --blue: #5b9fff;
  --green-glow: rgba(43, 227, 168, 0.4);
  --text: #e8f4ff;
  --text-dim: #a8c0d8;
  --text-muted: #6e859e;
  --danger: #ff6b6b;
  --warn: #ffb84d;
  --grad-main: linear-gradient(135deg, #2be3a8 0%, #4dd0e1 60%, #5b9fff 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  min-width: 320px;
  overflow: hidden;
  color: var(--text);
  background: var(--bg-base);
  font: 14px/1.5 "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea { font: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
[hidden] { display: none !important; }

.bg-layer {
  position: fixed;
  z-index: -2;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 1200px 800px at 80% 10%, rgba(43, 227, 168, 0.10) 0%, transparent 50%),
    radial-gradient(ellipse 1000px 600px at 10% 70%, rgba(91, 159, 255, 0.08) 0%, transparent 50%),
    var(--bg-base);
}
.bg-grid {
  position: fixed;
  z-index: -1;
  inset: 0;
  opacity: 0.3;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(74, 222, 200, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 222, 200, 0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
}

/* Portão de autenticação da POC; desaparece após o login. */
.login-gate {
  display: grid;
  min-height: 100%;
  padding: 28px;
  place-items: center;
}
.login-card {
  width: min(100%, 450px);
  padding: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: rgba(3, 8, 23, 0.88);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48), 0 0 50px rgba(43, 227, 168, 0.08);
  backdrop-filter: blur(20px);
}
.login-brand, .brand-logos { display: flex; align-items: center; gap: 10px; }
.login-brand { margin-bottom: 18px; }
.login-brand img, .brand-logos img { width: auto; height: 38px; object-fit: contain; }
.brand-sep {
  width: 1px;
  height: 28px;
  background: linear-gradient(180deg, transparent, var(--border-strong), transparent);
}
.brand-title {
  font: 700 18px "Sora", sans-serif;
  letter-spacing: -0.01em;
  background: var(--grad-main);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--text-muted);
  font: 10px "JetBrains Mono", monospace;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.brand-sub .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2s infinite;
}
.login-copy { margin: 22px 0; color: var(--text-dim); }
.login-card form { display: grid; gap: 10px; }
.login-card label { color: var(--text-dim); font-size: 12px; font-weight: 600; }
.login-card input {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: 0;
  background: var(--bg-card);
}
.login-card input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(43, 227, 168, 0.10); }
.login-card input::placeholder { color: var(--text-muted); }
.account-shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 3px 0 8px; }
.account-shortcuts > span {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font: 10px "JetBrains Mono", monospace;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.account-shortcuts button {
  min-width: 0;
  padding: 10px;
  color: var(--text);
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  cursor: pointer;
}
.account-shortcuts button:hover { border-color: var(--green); background: var(--bg-card-hover); }
.account-shortcuts strong, .account-shortcuts small { display: block; overflow: hidden; text-overflow: ellipsis; }
.account-shortcuts small { margin-top: 3px; color: var(--text-muted); font-size: 9px; white-space: nowrap; }
.login-submit {
  min-height: 44px;
  margin-top: 6px;
  padding: 10px 18px;
  color: var(--bg-deep);
  border: 0;
  border-radius: 10px;
  background: var(--grad-main);
  font-weight: 700;
  cursor: pointer;
}
.login-submit:hover { box-shadow: 0 6px 20px rgba(43, 227, 168, 0.4); }
.login-submit:disabled { opacity: 0.4; cursor: wait; }
.test-access {
  display: grid;
  gap: 2px;
  margin-top: 20px;
  padding: 13px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 30, 55, 0.42);
  font: 10px/1.5 "JetBrains Mono", monospace;
}
.test-access strong { color: var(--green); }

/* Estrutura original do Dr. Molécula. */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(3, 8, 23, 0.85);
  backdrop-filter: blur(20px);
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(74, 222, 200, 0.08);
}
.nav { flex: 1; padding: 14px 0; overflow: auto; }
.nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 22px;
  color: var(--text-dim);
  text-align: left;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  transition: all 0.2s;
}
.nav button:hover { color: var(--text); background: rgba(43, 227, 168, 0.05); }
.nav button:disabled { color: var(--text-muted); opacity: 0.55; cursor: not-allowed; }
.nav button:disabled:hover { color: var(--text-muted); background: transparent; }
.nav button.active {
  color: var(--green);
  border-left-color: var(--green);
  background: linear-gradient(90deg, rgba(43, 227, 168, 0.10), transparent);
  font-weight: 600;
}
.nav .ico { display: inline-flex; justify-content: center; width: 18px; font-size: 15px; }
.sidebar-foot {
  padding: 16px 22px;
  color: var(--text-muted);
  border-top: 1px solid rgba(74, 222, 200, 0.08);
  font: 10px "JetBrains Mono", monospace;
  letter-spacing: 0.8px;
}
.sidebar-foot .ver { margin-bottom: 4px; color: var(--green); font-weight: 600; }

.main { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 65px;
  padding: 16px 28px;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(5, 15, 31, 0.8);
  backdrop-filter: blur(20px);
}
.topbar h2 { color: var(--text); font: 600 17px "Sora", sans-serif; letter-spacing: -0.01em; }
#page-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: right;
  font: 10.5px "JetBrains Mono", monospace;
  letter-spacing: 0.3px;
}
#page-meta .ok { color: var(--green); }
#page-meta button {
  padding: 4px 9px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-card);
  cursor: pointer;
}
#page-meta button:hover { color: var(--green); border-color: var(--green); }
.panel { display: none; min-height: 0; animation: fade-up 0.4s both; }
.panel.active { display: block; flex: 1; }
.chat-wrap { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-msgs { flex: 1; min-height: 0; padding: 28px 32px; overflow: auto; }

.msg { display: flex; gap: 14px; max-width: 880px; margin: 0 auto 22px; animation: fade-up 0.3s both; }
.msg .avatar {
  display: flex;
  flex: 0 0 42px;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
}
.msg.user .avatar {
  color: var(--green);
  background: linear-gradient(135deg, rgba(43, 227, 168, 0.15), rgba(91, 159, 255, 0.10));
  font-family: "Sora", sans-serif;
}
.msg.bot .avatar { padding: 0; background: linear-gradient(135deg, var(--green), var(--blue)); box-shadow: 0 0 20px rgba(43, 227, 168, 0.3); }
.msg.bot .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.msg .bubble {
  flex: 1;
  padding: 16px 18px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  line-height: 1.6;
}
.msg.user .bubble { border-color: var(--border-strong); background: linear-gradient(135deg, rgba(43, 227, 168, 0.08), rgba(91, 159, 255, 0.04)); }
.answer-copy { margin: 0; white-space: pre-wrap; }
.answer-metrics { margin-top: 14px; padding-top: 10px; color: var(--text-muted); border-top: 1px solid var(--border); font: 10px "JetBrains Mono", monospace; }
.refs { margin-top: 16px; padding-top: 12px; color: var(--text-muted); border-top: 1px solid var(--border); font-size: 12px; }
.refs strong { color: var(--green-bright); font-family: "Sora", sans-serif; }
.refs ol { margin: 8px 0 0; padding-left: 24px; }
.refs li { margin-bottom: 4px; word-break: break-word; }
.source-id { color: var(--cyan); font-family: "JetBrains Mono", monospace; }

.chat-input {
  padding: 16px 32px;
  border-top: 1px solid var(--border);
  background: rgba(3, 8, 23, 0.6);
  backdrop-filter: blur(20px);
}
.chat-input .box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 880px;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: rgba(15, 30, 55, 0.5);
  transition: border-color 0.2s;
}
.chat-input .box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(43, 227, 168, 0.10); }
.chat-input textarea {
  flex: 1;
  min-height: 24px;
  max-height: 180px;
  padding: 8px 10px;
  resize: none;
  color: var(--text);
  border: 0;
  outline: 0;
  background: transparent;
}
.chat-input textarea::placeholder { color: var(--text-muted); }
.chat-input .box button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  color: var(--bg-deep);
  border: 0;
  border-radius: 10px;
  background: var(--grad-main);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-input .box button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(43, 227, 168, 0.4); }
.chat-input .box button:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-input-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 880px;
  margin: 6px auto 0;
  color: var(--text-muted);
  font-size: 10px;
}
.btn.ghost {
  padding: 4px 10px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  font-size: 11px;
}
.btn.ghost:disabled { opacity: 0.5; cursor: not-allowed; }
.typing { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); animation: typing 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
.feedback-row { display: flex; align-items: center; gap: 8px; max-width: 880px; margin: 8px auto 0; color: var(--text-dim); font-size: 11px; }
.feedback-row button { padding: 3px 10px; color: var(--text); border: 1px solid var(--border); border-radius: 7px; background: var(--bg-card); cursor: pointer; }
.feedback-row button:hover { border-color: var(--green); }

.empty-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
}
.empty-chat .hero-img { position: relative; width: 200px; height: 200px; margin-bottom: 24px; }
.empty-chat .hero-img::before {
  position: absolute;
  inset: -10%;
  content: "";
  background: radial-gradient(circle, rgba(43, 227, 168, 0.35) 0%, rgba(77, 208, 225, 0.15) 40%, transparent 70%);
  filter: blur(30px);
  animation: glow-pulse 4s ease-in-out infinite;
}
.empty-chat .hero-img img {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 30px rgba(43, 227, 168, 0.2));
  animation: float 6s ease-in-out infinite;
}
.empty-chat h3 { margin: 0 0 10px; color: var(--text); font: 700 28px "Sora", sans-serif; letter-spacing: -0.02em; }
.empty-chat h3 .gradient {
  background: var(--grad-main);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.empty-chat .tagline { margin-bottom: 12px; color: var(--cyan); font: 11px "JetBrains Mono", monospace; letter-spacing: 2px; text-transform: uppercase; }
.empty-chat p { max-width: 560px; margin-bottom: 30px; color: var(--text-dim); font-size: 15px; line-height: 1.6; }
.empty-chat .suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 700px; }
.empty-chat .suggest button {
  padding: 14px 16px;
  color: var(--text);
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  transition: all 0.2s;
}
.empty-chat .suggest button:hover { transform: translateY(-2px); border-color: var(--green); background: var(--bg-card-hover); box-shadow: 0 8px 24px rgba(43, 227, 168, 0.15); }

.status-message {
  position: fixed;
  z-index: 50;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 15px;
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.35);
  border-radius: 10px;
  background: rgba(43, 13, 24, 0.95);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.4);
}
.status-message[data-kind="success"] { color: var(--green); border-color: var(--border-strong); background: rgba(4, 30, 28, 0.95); }

@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.3); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes glow-pulse { 0%, 100% { opacity: 0.7; transform: scale(1); } 50% { opacity: 1; transform: scale(1.08); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes typing { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0) scale(0.9); } 40% { opacity: 1; transform: translateY(-5px) scale(1); } }

@media (max-width: 760px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: 100svh; }
  .sidebar { display: none; }
  .topbar { min-height: 58px; padding: 12px 16px; }
  #user-email, #page-meta .ok { display: none; }
  .chat-msgs { padding: 20px 16px; }
  .chat-input { padding: 12px 14px; }
  .empty-chat { justify-content: flex-start; padding-top: 8px; }
  .empty-chat .hero-img { width: 150px; height: 150px; margin-bottom: 16px; }
  .empty-chat .suggest { grid-template-columns: 1fr; }
  .chat-input-meta > span:first-child, .btn.ghost { display: none; }
  .account-shortcuts { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
