:root {
  --bg: #ffffff;
  --text: #1f1f1f;
  --muted: #6e6e6e;
  --bubble: #f0f0f0;
  --border: #e3e3e3;
  --track: #ececec;
  --accent: #6b3fa0;
  --on-accent: #ffffff;
  --error: #b42318;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1c;
    --text: #ececec;
    --muted: #9b9b9b;
    --bubble: #2c2c2c;
    --border: #3a3a3a;
    --track: #333333;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: 100%;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Botoes */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn.secondary {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

.btn.large {
  min-height: 52px;
  padding: 14px 36px;
  font-size: 1.0625rem;
}

.btn.small {
  min-height: 36px;
  padding: 6px 16px;
  font-size: 0.875rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Tela inicial */
.start {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.start-inner {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.start h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.start .intro {
  margin: 0;
  font-size: 1.0625rem;
}

.start .note,
.start .signature {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.start .btn {
  margin-top: 8px;
}

/* Tela de chat */
.chat {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
}

.brand {
  font-weight: 650;
  min-width: 0;
  overflow-wrap: anywhere;
}

.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  font-size: 0.875rem;
  color: var(--muted);
}

.link-btn {
  padding: 4px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

.progress {
  height: 2px;
  background: var(--track);
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.3s ease;
}

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.thread {
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.msg.user {
  justify-content: flex-end;
}

.avatar {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.8125rem;
  font-weight: 650;
}

.text {
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 2px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble {
  max-width: 85%;
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--bubble);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dots {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
}

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

.dot + .dot {
  animation-delay: 0.2s;
}

.dot + .dot + .dot {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.msg-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  color: var(--error);
}

.msg-error p {
  flex: 1 1 200px;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

/* Cartao final */
.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  min-width: 0;
}

.card-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.card p {
  margin: 0;
  overflow-wrap: anywhere;
}

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

.card .instructions {
  white-space: pre-wrap;
}

.card .pdf-error {
  color: var(--error);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* Compositor */
.composer {
  flex-shrink: 0;
  padding: 8px 16px max(16px, env(safe-area-inset-bottom));
  background: var(--bg);
}

.composer-inner {
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 16px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--bubble);
}

.composer-inner:focus-within {
  border-color: var(--accent);
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 200px;
  margin: 0;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  resize: none;
}

.composer textarea:focus-visible {
  outline: none;
}

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

.send {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send svg {
  width: 18px;
  height: 18px;
}

@media (prefers-reduced-motion: reduce) {
  .dot {
    animation: none;
    opacity: 0.6;
  }

  .progress-bar {
    transition: none;
  }
}
