:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dfe3e8;
  --accent: #ce1f2e; /* vermelho CDI */
  --accent-text: #ffffff;
  --user-bubble: #fbe8ea;
  --error: #b42318;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e6eaef;
    --muted: #9aa5b3;
    --border: #2c3440;
    --accent: #f0525e;
    --accent-text: #1a0507;
    --user-bubble: #3a1d21;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.brand-logo { display: block; height: 30px; width: auto; }
.brand-divider { width: 1px; height: 24px; background: var(--border); }
.user { display: flex; gap: 16px; align-items: center; font-size: 14px; color: var(--muted); }
.user a { color: var(--accent); text-decoration: none; }
.user a:hover { text-decoration: underline; }

/* Layout: barra lateral de conversas + área do chat */
.layout { flex: 1; display: flex; min-height: 0; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.sidebar {
  width: 270px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px;
  padding: 16px 12px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.new-chat {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px dashed var(--accent);
  background: transparent; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
.new-chat:hover { background: var(--user-bubble); }
.sidebar-title {
  margin: 12px 8px 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.sidebar-empty { margin: 4px 8px; font-size: 13px; color: var(--muted); }
.sidebar-admin {
  display: none; margin-top: auto; padding: 10px; border-top: 1px solid var(--border);
  color: var(--accent); text-decoration: none; font-size: 14px;
}
.brand-name { white-space: nowrap; }
.conversation-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.conversation-list button {
  width: 100%; display: flex; align-items: baseline; gap: 8px; padding: 8px 10px; border-radius: 8px;
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px;
  text-align: left; cursor: pointer;
}
.conversation-list button:hover { background: var(--bg); }
.conversation-list button.active { background: var(--user-bubble); }
.conversation-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-date { flex-shrink: 0; font-size: 12px; color: var(--muted); }

.menu-button {
  display: none; border: 0; background: transparent; color: var(--text);
  font-size: 22px; line-height: 1; padding: 4px 6px; cursor: pointer;
}
.sidebar-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 9; }

.chat {
  flex: 1; overflow-y: auto; padding: 24px max(16px, calc((100% - 820px) / 2));
  display: flex; flex-direction: column; gap: 14px;
}

.welcome { margin: auto 0; text-align: center; color: var(--muted); }
.welcome h1 { color: var(--text); font-size: 26px; margin-bottom: 8px; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; }
.suggestion {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 14px; cursor: pointer; font: inherit; font-size: 14px;
}
.suggestion:hover { border-color: var(--accent); }

.message {
  max-width: 85%; padding: 12px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); overflow-wrap: anywhere;
}
.message.user { align-self: flex-end; background: var(--user-bubble); border-color: transparent; white-space: pre-wrap; }
.message.assistant { align-self: flex-start; }
.message.error { color: var(--error); }
.message p { margin: 0 0 8px; }
.message p:last-child { margin-bottom: 0; }
.message ul, .message ol { margin: 4px 0 8px; padding-left: 22px; }

.dots { letter-spacing: 3px; color: var(--muted); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.sources { font-size: 13px; color: var(--muted); margin-top: 10px !important; }

.fallback {
  margin-top: 12px; padding: 12px; border-radius: 10px;
  border: 1px dashed var(--accent); color: var(--text);
}
.fallback p { margin: 0 0 8px; }

.button, .composer button {
  display: inline-block; background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.composer button:disabled { opacity: 0.5; cursor: wait; }

.feedback { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.feedback button {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: 8px; padding: 2px 8px; cursor: pointer; font: inherit;
}
.feedback button:disabled { opacity: 0.5; cursor: default; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  width: 100%; max-width: 820px; margin: 0 auto; padding: 12px 16px 20px;
}
.composer textarea {
  flex: 1; resize: none; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; min-height: 44px;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Painel de revisão */
.admin { max-width: 1100px; margin: 0 auto; padding: 24px 16px; width: 100%; }
.admin table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; }
.admin th, .admin td { text-align: left; vertical-align: top; padding: 10px; border-bottom: 1px solid var(--border); }
.admin th { color: var(--muted); font-weight: 600; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); }

/* Login e acesso negado */
.login-page { align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 440px; padding: 40px 32px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  border-top: 4px solid var(--accent);
}
.login-logo img { display: block; height: 43px; width: auto; margin: 0 auto 24px; }
.login-card h1 { font-size: 24px; margin: 0 0 12px; }
.login-lead { color: var(--muted); margin: 0 0 20px; }
.login-points {
  text-align: left; margin: 0 0 28px; padding: 16px 16px 16px 36px;
  background: var(--bg); border-radius: 10px; font-size: 14px;
}
.login-points li + li { margin-top: 6px; }
.login-points li::marker { color: var(--accent); }
.google-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none;
}
.google-button:hover { border-color: var(--accent); }
.google-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.login-note { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

@media (max-width: 800px) {
  .menu-button { display: block; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 10; width: min(300px, 85vw);
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 24px rgb(0 0 0 / 0.25); }
}

@media (max-width: 600px) {
  .brand { gap: 8px; }
  .brand-divider { display: none; }
  .user #admin-link { display: none; }
  .sidebar-admin:not([hidden]) { display: block; }
  .topbar { padding: 10px 16px; }
  .user span { display: none; }
  .brand-logo { height: 24px; }
  .login-card { padding: 32px 20px; }
  .message { max-width: 100%; }
}
