/* Assistente AGM · design ferramenta operacional
   Base clara + acento AGM rosa; identidade visual dupla (CI cliente · AGM autor). */

:root {
  /* Neutros */
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-alt: #faf8f5;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --text-subtle: #999;
  --border: #e8e5e0;
  --border-strong: #d8d4cd;

  /* Acentos AGM */
  --agm-pink: #ED2E7E;
  --agm-pink-dark: #C6206A;
  --agm-yellow: #F5C518;

  /* Marca CI (leão vermelho) */
  --ci-red: #E20613;

  /* Bolhas */
  --user-bubble: #FEF0F5;
  --user-bubble-border: #F8D0DF;
  --ia-bubble: #ffffff;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);

  /* Layout */
  --sidebar-w: 280px;
  --header-h: 68px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f;
    --surface: #1c1917;
    --surface-alt: #22201d;
    --text: #f5f2ed;
    --text-muted: #a8a29e;
    --text-subtle: #78716c;
    --border: #2d2a26;
    --border-strong: #3d3a35;
    --user-bubble: #3d1c2c;
    --user-bubble-border: #5a2b40;
    --ia-bubble: #22201d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Instrument Sans', 'Segoe UI', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== Layout principal ========== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
}

/* ========== Sidebar ========== */
.sidebar {
  background: var(--surface-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.btn-nova {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  background: var(--agm-pink);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  box-shadow: var(--shadow-sm);
}
.btn-nova:hover { background: var(--agm-pink-dark); }
.btn-nova:active { transform: scale(0.98); }
.btn-nova .plus {
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
}

.sidebar-filtro {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.filtro-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  font-weight: 600;
}
.filtro-select {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.filtro-select:focus { outline: none; border-color: var(--agm-pink); }

.sidebar-conversas {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  min-height: 0;
}
.sidebar-titulo {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  padding: 8px 12px 6px;
  font-weight: 600;
}
.lista-conversas {
  list-style: none;
}
.conversa-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.1s;
  position: relative;
}
.conversa-item:hover { background: var(--surface); }
.conversa-item.ativa {
  background: var(--surface);
  border-left: 3px solid var(--agm-pink);
  padding-left: 9px;
}
.conversa-titulo {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 20px;
}
.conversa-data {
  font-size: 11px;
  color: var(--text-subtle);
  margin-top: 2px;
}
.conversa-delete {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.1s;
  padding: 4px 8px;
  border-radius: 4px;
}
.conversa-item:hover .conversa-delete { opacity: 1; }
.conversa-delete:hover { color: var(--agm-pink); background: rgba(237, 46, 126, 0.08); }
.sem-conversas {
  padding: 16px 12px;
  color: var(--text-subtle);
  font-size: 12px;
  font-style: italic;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-agm-side {
  width: 32px;
  height: 32px;
  object-fit: contain;
}
.assinatura {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.assinatura span {
  font-size: 10px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.assinatura strong {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

/* ========== Header ========== */
.site-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  flex-shrink: 0;
}
.btn-sidebar {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
}
.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}
.logo-ci {
  height: 40px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.header-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  font-weight: 600;
}
.unidade-atual {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-spacer { display: none; }

/* ========== Chat ========== */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.msg {
  max-width: min(85%, 760px);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
  animation: msgIn 0.2s ease-out;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user {
  background: var(--user-bubble);
  border: 1px solid var(--user-bubble-border);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg.ia {
  background: var(--ia-bubble);
  align-self: flex-start;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg img {
  max-width: 100%;
  border-radius: 10px;
  margin-top: 10px;
  display: block;
}
.msg .msg-card {
  max-width: 320px;
  margin-top: 12px;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  pointer-events: none;
  user-select: none;
}
.msg strong { font-weight: 700; }
.msg em { font-style: italic; color: var(--text-muted); }
.msg .typing { color: var(--text-muted); font-style: italic; }
.msg .typing::after {
  content: '…';
  display: inline-block;
  animation: dots 1.4s infinite;
}
@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '…'; }
}
.msg.erro {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  align-self: center;
  text-align: center;
  max-width: 90%;
  font-size: 14px;
}

/* ========== Onboarding (form estruturado) ========== */
.onboarding {
  padding: 24px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.onboarding[hidden] { display: none; }
.onb-inner {
  max-width: 560px;
  width: 100%;
}
.onb-titulo {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}
.onb-sub {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 24px;
  line-height: 1.5;
}
.onb-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--surface);
  padding: 24px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.onb-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: none;
  padding: 0;
}
.onb-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.onb-field input[type="text"] {
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s;
}
.onb-field input[type="text"]:focus {
  outline: none;
  border-color: var(--agm-pink);
  background: var(--surface);
}
.onb-radios legend { padding: 0; }
.onb-radios-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.onb-radios label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  transition: all 0.12s;
}
.onb-radios label:hover { border-color: var(--agm-pink); }
.onb-radios input[type="radio"] {
  accent-color: var(--agm-pink);
  width: 16px;
  height: 16px;
}
.onb-radios input[type="radio"]:checked + span { font-weight: 600; color: var(--agm-pink); }
.onb-radios label:has(input:checked) {
  border-color: var(--agm-pink);
  background: rgba(237, 46, 126, 0.06);
}
.onb-btn {
  background: var(--agm-pink);
  color: white;
  border: none;
  padding: 14px 20px;
  border-radius: 10px;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s;
}
.onb-btn:hover { background: var(--agm-pink-dark); }
.onb-btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 600px) {
  .onb-radios-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ========== Botões dos modos (após onboarding) ========== */
.modos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 8px 20px 12px;
  flex-shrink: 0;
}
.modos[hidden] { display: none; }
.modo-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
}
.modo-btn:hover {
  border-color: var(--agm-pink);
  background: var(--surface-alt);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.modo-emoji { font-size: 22px; }
.modo-titulo {
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 14px;
}
.modo-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}

@media (max-width: 700px) {
  .modos { grid-template-columns: 1fr; }
  .modo-btn { flex-direction: row; align-items: center; gap: 12px; }
  .modo-emoji { font-size: 20px; }
}

/* ========== Preview de imagem ========== */
.preview-imagem {
  padding: 10px 20px;
  background: var(--surface-alt);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.preview-imagem img { height: 60px; border-radius: 8px; }
.preview-imagem button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 22px;
  padding: 4px 8px;
  margin-left: auto;
  line-height: 1;
  border-radius: 4px;
}
.preview-imagem button:hover { color: var(--agm-pink); background: rgba(237, 46, 126, 0.08); }

/* ========== Input bar ========== */
.input-bar {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  align-items: flex-end;
  flex-shrink: 0;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.btn-imagem, .btn-enviar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-imagem:hover { color: var(--agm-pink); border-color: var(--agm-pink); }
.btn-enviar {
  background: var(--agm-pink);
  color: white;
  border-color: var(--agm-pink);
}
.btn-enviar:hover { background: var(--agm-pink-dark); border-color: var(--agm-pink-dark); }
.btn-enviar:disabled { opacity: 0.5; cursor: not-allowed; }

#textInput {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  resize: none;
  max-height: 140px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  transition: border-color 0.15s;
}
#textInput:focus { outline: none; border-color: var(--agm-pink); background: var(--surface); }
#textInput::placeholder { color: var(--text-subtle); }

/* ========== Backdrop mobile ========== */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

/* ========== Responsivo ========== */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
  .btn-sidebar { display: block; }
  .site-header { padding: 12px 16px; }
  .logo-ci { height: 32px; }
  .unidade-atual { font-size: 16px; }
  .chat { padding: 16px; }
  .input-bar { padding: 12px 16px; }
}
