/* GWIA — gwia.busiabr.com
   Identidade AlfabetizIA (navy #0a1730 + azul elétrico #2f6bff) com
   acabamento premium: tipografia Sora/Inter, superfícies em vidro,
   gradientes discretos, movimento suave. Ícones sempre SVG. */

:root {
  --bg: #f4f6fb;
  --bg-soft: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef2fa;
  --text: #10203c;
  --text-dim: #5a6b8a;
  --line: rgba(16, 32, 60, .10);
  --accent: #2f6bff;
  --accent-2: #4f86ff;
  --accent-grad: linear-gradient(135deg, #4f86ff 0%, #2f6bff 100%);
  --bubble-user: linear-gradient(135deg, #4f86ff 0%, #2f6bff 100%);
  --bubble-user-text: #ffffff;
  --bubble-agent: #ffffff;
  --bubble-agent-text: #10203c;
  --ok: #12b76a;
  --alert: #ef3e46;
  --shadow: 0 12px 40px rgba(10, 23, 48, .10);
  --shadow-soft: 0 4px 18px rgba(10, 23, 48, .07);
}

[data-theme="dark"] {
  --bg: #0a1730;
  --bg-soft: #0d1f3f;
  --surface: #0f2244;
  --surface-2: #13284f;
  --text: #eaf0fb;
  --text-dim: #8fa3c8;
  --line: rgba(234, 240, 251, .09);
  --bubble-agent: #13284f;
  --bubble-agent-text: #eaf0fb;
  --shadow: 0 12px 40px rgba(0, 0, 0, .35);
  --shadow-soft: 0 4px 18px rgba(0, 0, 0, .25);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .35s ease, color .35s ease;
  -webkit-font-smoothing: antialiased;
}
h1, h2, .brand-name, .agent-id strong { font-family: 'Sora', 'Inter', sans-serif; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.view { min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ══════════ LOGIN ══════════ */
#view-login { align-items: center; justify-content: center; position: relative; overflow: hidden; }

.login-bg { position: absolute; inset: 0; pointer-events: none; }
.orb {
  position: absolute; border-radius: 50%; filter: blur(90px); opacity: .5;
  animation: drift 18s ease-in-out infinite alternate;
}
.orb-a { width: 480px; height: 480px; background: #2f6bff; top: -160px; right: -120px; }
.orb-b { width: 420px; height: 420px; background: #4f86ff; bottom: -180px; left: -140px; animation-delay: -9s; opacity: .35; }
[data-theme="light"] .orb { opacity: .22; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-40px, 36px, 0) scale(1.12); }
}
.grid-lines {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 20%, transparent 75%);
}

.login-card {
  position: relative; z-index: 1;
  width: min(420px, calc(100vw - 40px));
  padding: 44px 40px 32px;
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise .6s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.brand { text-align: center; margin-bottom: 30px; }
.brand-mark { width: 66px; height: 66px; filter: drop-shadow(0 10px 24px rgba(47, 107, 255, .45)); }
.brand-name { font-size: 34px; font-weight: 700; letter-spacing: .14em; margin-top: 14px; }
.brand-name span { background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-tag { color: var(--text-dim); font-size: 13.5px; margin-top: 6px; line-height: 1.5; }

.field { display: block; margin-bottom: 16px; }
.field span {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 7px;
}
.field input {
  width: 100%; padding: 13px 16px; font-size: 15px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.btn-primary {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px; margin-top: 8px;
  font-size: 15px; font-weight: 600; color: #fff;
  background: var(--accent-grad); border-radius: 12px;
  box-shadow: 0 10px 26px rgba(47, 107, 255, .38);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-primary svg { width: 18px; height: 18px; }

.login-error {
  color: var(--alert); font-size: 13.5px; margin: -4px 0 12px; text-align: center;
}
.login-foot {
  margin-top: 26px; text-align: center; font-size: 11.5px;
  color: var(--text-dim); letter-spacing: .04em;
}

/* ══════════ TOPBAR ══════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px clamp(16px, 4vw, 32px);
  background: color-mix(in srgb, var(--bg-soft) 78%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.mini-mark { width: 40px; height: 40px; border-radius: 12px; }
.agent-id { display: flex; flex-direction: column; line-height: 1.25; }
.agent-id strong { font-size: 16px; letter-spacing: .1em; }
.agent-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.agent-status em { font-style: normal; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--alert); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.off { background: #c7cede; }

.topbar-right { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 11px; color: var(--text-dim);
  transition: background .18s, color .18s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
[data-theme="dark"] .ic-moon { display: none; }
[data-theme="light"] .ic-sun { display: none; }

/* ══════════ CHAT ══════════ */
.chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.chat-list {
  max-width: 820px; margin: 0 auto; padding: 28px clamp(14px, 4vw, 24px) 8px;
  display: flex; flex-direction: column; gap: 14px;
}
.chat-hello { text-align: center; padding: 48px 20px 34px; color: var(--text-dim); }
.chat-hello svg { width: 58px; height: 58px; border-radius: 16px; }
.chat-hello h2 { color: var(--text); font-size: 21px; margin: 16px 0 8px; }
.chat-hello p { font-size: 14px; max-width: 440px; margin: 0 auto; line-height: 1.6; }

.msg { display: flex; animation: msgIn .3s cubic-bezier(.2, .8, .2, 1); }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 620px);
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px; line-height: 1.55;
  word-wrap: break-word; overflow-wrap: break-word;
  box-shadow: var(--shadow-soft);
}
.msg.user .bubble {
  background: var(--bubble-user); color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}
.msg.agent .bubble {
  background: var(--bubble-agent); color: var(--bubble-agent-text);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.bubble .t {
  display: block; font-size: 10.5px; opacity: .62; margin-top: 6px; text-align: right;
}
.bubble code {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 13px; padding: 1.5px 6px; border-radius: 6px;
  background: color-mix(in srgb, currentColor 12%, transparent);
}
.bubble pre {
  margin: 8px 0; padding: 12px 14px; border-radius: 12px; overflow-x: auto;
  background: rgba(6, 14, 30, .92); color: #dbe6ff;
}
.bubble pre code { background: none; padding: 0; color: inherit; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg.agent .bubble a { color: var(--accent-2); }

.typing {
  max-width: 820px; margin: 0 auto; padding: 4px clamp(14px, 4vw, 24px) 16px;
  display: flex; align-items: center; gap: 10px;
}
.typing-avatar {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent-grad); color: #fff; font-family: 'Sora'; font-weight: 700; font-size: 9.5px; letter-spacing: .04em;
}
.typing-dots { display: flex; gap: 5px; padding: 12px 16px; background: var(--bubble-agent); border: 1px solid var(--line); border-radius: 16px; }
.typing-dots i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: .18s; }
.typing-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

/* ══════════ COMPOSER ══════════ */
.composer-wrap {
  padding: 10px clamp(14px, 4vw, 24px) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.composer {
  max-width: 820px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 10px 10px 10px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.composer textarea {
  flex: 1; resize: none; border: none; outline: none; background: none;
  color: var(--text); font-family: inherit; font-size: 15px; line-height: 1.5;
  max-height: 160px; padding: 8px 0;
}
.composer textarea::placeholder { color: var(--text-dim); }
.send-btn {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 14px; color: #fff;
  background: var(--accent-grad);
  box-shadow: 0 6px 16px rgba(47, 107, 255, .38);
  transition: transform .15s, filter .15s, opacity .15s;
}
.send-btn:hover { transform: translateY(-1px); filter: brightness(1.07); }
.send-btn:disabled { opacity: .45; transform: none; cursor: default; }
.send-btn svg { width: 19px; height: 19px; }
.composer-hint {
  max-width: 820px; margin: 8px auto 0; text-align: center;
  font-size: 11px; color: var(--text-dim); letter-spacing: .05em;
}

/* ══════════ APP SHELL (rail + tabs) ══════════ */
.app { flex-direction: row; }
.rail {
  width: 84px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 0 14px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100dvh; z-index: 20;
}
.rail-mark { width: 44px; height: 44px; border-radius: 13px; margin-bottom: 14px; }
.rail-btn {
  width: 64px; padding: 9px 0 7px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border-radius: 13px; color: var(--text-dim);
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  transition: background .18s, color .18s;
}
.rail-btn svg { width: 21px; height: 21px; }
.rail-btn:hover { background: var(--surface-2); color: var(--text); }
.rail-btn.active {
  color: #fff; background: var(--accent-grad);
  box-shadow: 0 8px 18px rgba(47, 107, 255, .35);
}
.rail-spacer { flex: 1; }
[data-theme="dark"] .rail .ic-moon { display: none; }
[data-theme="light"] .rail .ic-sun { display: none; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.tab { display: none; flex-direction: column; flex: 1; min-height: 0; }
.tab.active { display: flex; }
#tab-chat.active { height: 100%; }
.page-scroll { flex: 1; overflow-y: auto; padding: 26px clamp(16px, 4vw, 36px); }

/* ══════════ CARDS (projetos + integrações) ══════════ */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; max-width: 1080px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 18px 20px; box-shadow: var(--shadow-soft);
  display: flex; flex-direction: column; gap: 8px;
  animation: msgIn .3s cubic-bezier(.2,.8,.2,1);
}
.card-head { display: flex; align-items: center; gap: 10px; }
.card-ic {
  width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center;
  border-radius: 11px; background: var(--surface-2); color: var(--accent-2);
}
.card-ic svg { width: 20px; height: 20px; }
.card-head strong { font-family: 'Sora'; font-size: 15px; flex: 1; }
.card p { font-size: 13px; color: var(--text-dim); line-height: 1.55; }
.card .st {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}
.st .dot { width: 7px; height: 7px; }
.st.ok { color: var(--ok); }
.st.off { color: var(--text-dim); }
.st.wait { color: #e8a13c; }
.st.wait .dot { background: #e8a13c; }
.card-actions { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.btn-slim {
  width: auto; padding: 9px 16px; margin: 0; font-size: 13.5px;
  border-radius: 10px; box-shadow: 0 6px 14px rgba(47,107,255,.3);
}
.btn-ghost {
  padding: 9px 16px; font-size: 13.5px; font-weight: 600;
  border-radius: 10px; border: 1px solid var(--line); color: var(--text-dim);
  transition: background .18s, color .18s;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.card .meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 14px; }
.card a.dlink { color: var(--accent-2); font-size: 13px; text-decoration: none; font-weight: 600; }
.card a.dlink:hover { text-decoration: underline; }

.proj-new { display: flex; gap: 10px; max-width: 560px; margin-bottom: 22px; }
.proj-new input {
  flex: 1; padding: 12px 16px; font-size: 14.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.proj-new input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* seletor de projeto no composer */
.composer-meta { max-width: 820px; margin: 0 auto 6px; display: flex; }
.proj-label {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-dim); font-size: 12.5px;
}
.proj-label svg { width: 15px; height: 15px; }
.proj-label select {
  border: none; background: none; color: var(--text); font-family: inherit;
  font-size: 12.5px; font-weight: 600; outline: none; cursor: pointer; max-width: 200px;
}
.proj-label select option { background: var(--surface); color: var(--text); }

/* ══════════ MODAL ══════════ */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6, 13, 28, .6); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(440px, 100%); background: var(--surface);
  border: 1px solid var(--line); border-radius: 22px;
  padding: 30px 28px 24px; box-shadow: var(--shadow);
  animation: rise .45s cubic-bezier(.2,.8,.2,1);
}
.modal-ic { width: 44px; height: 44px; margin-bottom: 12px; }
.modal h3 { font-family: 'Sora'; font-size: 19px; margin-bottom: 10px; }
.modal p { font-size: 14px; color: var(--text-dim); line-height: 1.6; }
.modal ol { margin: 12px 0 0 20px; font-size: 14px; line-height: 2; color: var(--text); }
.modal-note { font-size: 12.5px !important; margin-top: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* creds + CRM */
.creds-code {
  display: inline-block; margin-top: 4px; padding: 6px 10px; border-radius: 8px;
  background: var(--surface-2); font-size: 12px; word-break: break-all;
  user-select: all;
}
.crm-convo { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.crm-convo-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--line); background: var(--bg-soft);
}
.msg.out { justify-content: flex-end; }
.msg.out .bubble { background: var(--bubble-user); color: #fff; border-bottom-right-radius: 6px; }
.msg.in .bubble { background: var(--bubble-agent); color: var(--bubble-agent-text); border: 1px solid var(--line); border-bottom-left-radius: 6px; }

/* QR + Master */
.modal-center { text-align: center; }
.qr-box {
  width: 232px; height: 232px; margin: 16px auto 8px;
  display: grid; place-items: center;
  background: #fff; border-radius: 16px; overflow: hidden;
  border: 1px solid var(--line);
}
.qr-box img { width: 100%; height: 100%; object-fit: contain; }
.modal-wide { width: min(560px, 100%); max-height: 90dvh; overflow-y: auto; }
.modal ol li { margin-bottom: 4px; }
#creds-help ol { line-height: 1.7; }
.master-badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; vertical-align: middle;
  padding: 3px 9px; margin-left: 8px; border-radius: 20px;
  background: var(--accent-grad); color: #fff;
}
.master-log {
  max-height: 260px; overflow-y: auto; margin: 14px 0 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.master-log .mlog {
  font-size: 13.5px; line-height: 1.5; padding: 9px 13px; border-radius: 12px;
  max-width: 92%;
}
.master-log .mlog.user { align-self: flex-end; background: var(--bubble-user); color: #fff; }
.master-log .mlog.master { align-self: flex-start; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.master-log .mlog.info { align-self: center; color: var(--text-dim); font-size: 12px; background: none; }
.master-composer { margin: 0; }

/* scrollbar discreta */
.chat-scroll::-webkit-scrollbar { width: 9px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

@media (max-width: 640px) {
  .bubble { max-width: 88%; }
  .login-card { padding: 36px 24px 26px; }
  /* rail vira barra inferior */
  .app { flex-direction: column-reverse; }
  .rail {
    width: 100%; height: auto; flex-direction: row; justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--line);
    position: sticky; bottom: 0; top: auto;
    overflow-x: auto; gap: 2px;
  }
  .rail-btn { flex-shrink: 0; }
  .rail-mark { display: none; }
  .rail-spacer { display: none; }
  .rail-btn { width: auto; padding: 7px 12px 5px; }
  .content { height: auto; flex: 1; min-height: 0; }
  .cards { grid-template-columns: 1fr; }
}
