/* Condlink AI: página inteira, coluna central de 768px (chat moderno), cores do avatar
   (verde-água e limão). Tema claro e escuro por prefers-color-scheme. */

:root {
  --bg: #ffffff;
  --surface: #f5f7f6;
  --surface-hover: #ecf0ee;
  --text: #0f1a17;
  --muted: #5c6b66;
  --border: #dbe3e0;
  --brand: #17a583;
  --brand-ink: #0a7560;
  --lime: #a4d630;
  --on-brand: #04201a;
  --user-bubble: #e3f3ec;
  --danger: #c62828;
  --shadow: 0 2px 16px rgb(15 26 23 / 9%);
  --column: 768px;
  --radius-pill: 28px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1320;
    --surface: #141f31;
    --surface-hover: #1b2a42;
    --text: #e8f0ed;
    --muted: #9db1aa;
    --border: #26364f;
    --brand: #2fcba2;
    --brand-ink: #5fe0bb;
    --user-bubble: #173a34;
    --danger: #ff8a80;
    --shadow: 0 2px 18px rgb(0 0 0 / 35%);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

h1,
h2 {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex: none;
}

.avatar-sm {
  width: 28px;
  height: 28px;
}

.avatar-lg {
  width: 88px;
  height: 88px;
}

/* --- Controles ------------------------------------------------------------------ */

button {
  font: inherit;
  color: var(--text);
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 16px;
}

button:hover:not(:disabled) {
  background: var(--surface-hover);
}

button:disabled {
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent);
  outline-offset: 2px;
}

button.ghost {
  background: transparent;
}

button.primary {
  background: linear-gradient(135deg, var(--brand), var(--lime));
  color: var(--on-brand);
  border-color: transparent;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand), var(--lime));
  filter: brightness(1.06);
}

button.primary:disabled {
  opacity: 0.6;
}

button.round {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: none;
}

input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  width: 100%;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

/* --- Login ---------------------------------------------------------------------- */

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login {
  width: 100%;
  max-width: 380px;
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.login h1 {
  font-size: 1.7rem;
  margin-top: 8px;
}

.login p {
  margin: 0;
}

.login form {
  width: 100%;
  display: grid;
  gap: 14px;
  margin-top: 18px;
  text-align: left;
}

.login button.primary {
  padding: 13px 16px;
}

/* --- Chat: página inteira ---------------------------------------------------------- */

.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.topbar .avatar {
  width: 36px;
  height: 36px;
}

.topbar-title {
  display: grid;
  line-height: 1.25;
  flex: 1;
  min-width: 0;
}

.topbar-title span {
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

.empty {
  flex: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px 20px 32px;
  text-align: center;
  max-width: var(--column);
  width: 100%;
  margin: 0 auto;
}

.empty h2 {
  font-size: clamp(1.5rem, 4.5vw, 2rem);
  font-weight: 650;
  margin-top: 8px;
}

.empty p {
  margin: 0;
  max-width: 34em;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.suggestions button {
  background: var(--surface);
  font-size: 0.93rem;
}

/* --- Mensagens ------------------------------------------------------------------ */

.messages {
  width: 100%;
  max-width: var(--column);
  margin: 0 auto;
  padding: 24px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.messages:empty {
  display: none;
}

.msg {
  overflow-wrap: anywhere;
}

.msg-user {
  align-self: flex-end;
  max-width: min(82%, 560px);
  background: var(--user-bubble);
  padding: 10px 18px;
  border-radius: 22px;
  white-space: pre-wrap;
}

.msg-assistant {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.msg-assistant .avatar-sm {
  margin-top: 2px;
}

.md {
  flex: 1;
  min-width: 0;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 0.75em;
}

.md ul,
.md ol {
  margin: 0 0 0.75em;
  padding-left: 1.5em;
}

.md li > p {
  margin: 0;
}

.md li > ul,
.md li > ol {
  margin: 0.25em 0 0;
}

.md li + li {
  margin-top: 0.25em;
}

.md h3,
.md h4,
.md h5 {
  margin: 1em 0 0.4em;
  line-height: 1.3;
}

.md h3 {
  font-size: 1.1rem;
}

.md h4,
.md h5 {
  font-size: 1rem;
}

.md a {
  color: var(--brand-ink);
  text-underline-offset: 2px;
}

.md code {
  font: 0.9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface);
  border-radius: 6px;
  padding: 0.1em 0.35em;
}

.md pre {
  margin: 0 0 0.75em;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 12px;
  overflow-x: auto;
}

.md pre code {
  background: none;
  padding: 0;
}

.msg-status {
  align-self: flex-start;
  color: var(--muted);
  font-size: 0.9rem;
  padding-left: 40px;
}

.msg-erro {
  color: var(--danger);
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 28px;
}

.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: digitando 1.2s ease-in-out infinite;
}

.typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes digitando {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* --- Campo de entrada fixo embaixo ------------------------------------------------- */

.dock {
  width: 100%;
  max-width: var(--column);
  margin: 0 auto;
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
  padding: 8px 8px 8px 20px;
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--brand) 70%, var(--border));
}

.composer textarea {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  padding: 8px 0;
  max-height: 160px;
  line-height: 1.45;
}

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

.composer textarea:disabled {
  opacity: 0.7;
}

button.round.voice {
  background: linear-gradient(135deg, var(--brand), var(--lime));
  color: var(--on-brand);
  border-color: transparent;
}

button.round.voice:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand), var(--lime));
  filter: brightness(1.07);
}

button.round.send {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

button.round.send:hover:not(:disabled) {
  background: var(--text);
  opacity: 0.85;
}

button.round.send:disabled {
  background: var(--border);
  color: var(--muted);
}

.disclaimer {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}

/* --- Conversa por voz (tela cheia) ------------------------------------------------- */

dialog.voice {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--text);
  background:
    radial-gradient(60% 45% at 50% 38%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 70%),
    var(--bg);
}

dialog.voice[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: max(24px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
}

.voice-stage {
  flex: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 22px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.orb {
  --nivel: 0;
  position: relative;
  width: 232px;
  height: 232px;
  display: grid;
  place-items: center;
}

.orb::before,
.orb::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

/* Anel interno e externo crescem com o nível de áudio. */
.orb::before {
  inset: 18px;
  background: radial-gradient(circle, color-mix(in srgb, var(--brand) 55%, transparent), transparent 72%);
  transform: scale(calc(1 + var(--nivel) * 0.55));
  opacity: 0.85;
}

.orb::after {
  inset: 0;
  border: 2px solid color-mix(in srgb, var(--lime) 70%, transparent);
  transform: scale(calc(0.9 + var(--nivel) * 0.2));
  opacity: calc(0.35 + var(--nivel) * 0.65);
}

.orb-avatar {
  position: relative;
  z-index: 1;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 8px 40px color-mix(in srgb, var(--brand) 35%, transparent);
  transform: scale(calc(1 + var(--nivel) * 0.1));
}

.orb[data-state='connecting']::before,
.orb[data-state='working']::before {
  animation: respirar 1.6s ease-in-out infinite;
}

.orb[data-state='speaking']::after {
  border-color: var(--lime);
}

.orb[data-state='error']::before,
.orb[data-state='error']::after {
  opacity: 0.2;
}

@keyframes respirar {
  50% {
    transform: scale(1.22);
    opacity: 0.5;
  }
}

.voice-label {
  margin: 0;
  min-height: 1.6em;
  font-size: 1.25rem;
  font-weight: 600;
}

.voice-error {
  margin: 0;
  color: var(--danger);
  max-width: 28em;
}

/* Aviso do guarda de honestidade: a fala do modelo foi interrompida e nada foi feito. */
.voice-notice {
  margin: 0;
  max-width: 28em;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-weight: 600;
  text-align: center;
}

.voice-controls {
  display: flex;
  gap: 40px;
  justify-content: center;
}

.voice-control {
  display: grid;
  justify-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

button.round-lg {
  width: 68px;
  height: 68px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
}

button.round-lg[aria-pressed='true'] {
  background: var(--text);
  color: var(--bg);
}

button.round-lg .slash {
  display: none;
}

button.round-lg[aria-pressed='true'] .slash {
  display: inline;
}

button.round-lg.end {
  background: #e5393f;
  border-color: transparent;
  color: #fff;
}

button.round-lg.end:hover:not(:disabled) {
  background: #cf2c32;
}

/* --- Confirmação ------------------------------------------------------------------ */

dialog.confirm {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  max-width: 420px;
  width: calc(100% - 32px);
  padding: 22px;
}

dialog.confirm::backdrop {
  background: rgb(5 10 20 / 55%);
}

dialog.confirm h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

dialog.confirm dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 12px 0 0;
}

dialog.confirm dt {
  color: var(--muted);
  text-transform: capitalize;
}

dialog.confirm dd {
  margin: 0;
  overflow-wrap: anywhere;
}

dialog.confirm .voice-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

dialog.confirm .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* --- Resultado de ação -------------------------------------------------------------- */

.msg-resultado {
  align-self: flex-start;
  max-width: min(560px, 100%);
  border: 1px solid var(--border);
  border-left: 4px solid #1f9d55;
  border-radius: 14px;
  background: var(--bg-soft, var(--bg));
  padding: 12px 14px;
}

.msg-resultado .resultado-titulo {
  margin: 0 0 6px;
  font-weight: 600;
}

.msg-resultado dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 0;
}

.msg-resultado dt {
  color: var(--muted);
}

.msg-resultado dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.msg-resultado a {
  color: inherit;
  text-decoration: underline;
}

.msg-resultado .copiar {
  margin-left: 8px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

/* --- Celular ---------------------------------------------------------------------- */

@media (max-width: 520px) {
  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .messages {
    padding: 18px 12px 6px;
    gap: 18px;
  }

  .msg-user {
    max-width: 88%;
  }

  .dock {
    padding-left: 10px;
    padding-right: 10px;
  }

  .disclaimer {
    font-size: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .typing i,
  .orb::before {
    animation: none !important;
    opacity: 0.6;
  }

  .orb::before,
  .orb::after,
  .orb-avatar {
    transform: none !important;
  }
}
