:root {
  --bg: #ffffff;
  --fg: #1f1e1d;
  --muted: #6b6a67;
  --line: #e8e6e1;
  --user: #f2efe9;
  --accent: #d97757;
  --card: #faf9f7;
  --live: #2f9e52;
  --attn: #c78a1e;
  --accent-weak: rgba(217, 119, 87, 0.12);
  --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1e1d;
    --fg: #f5f4f2;
    --muted: #a3a09b;
    --line: #33312e;
    --user: #2a2724;
    --accent: #d97757;
    --card: #26241f;
    --live: #3fb950;
    --attn: #d29922;
    --accent-weak: rgba(217, 119, 87, 0.18);
  }
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
#app {
  max-width: 760px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  display: flex;
  gap: 10px;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}
.topbar .spacer {
  flex: 1;
}
/* Barra de uso da janela de 5h, logo acima do thread. */
.usage {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  font-size: 12px;
  color: var(--muted);
}
.usage.hidden {
  display: none;
}
.usage-tag {
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.usage-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.usage-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: #3fa45b;
  transition: width 0.4s ease;
}
.usage.warn .usage-fill {
  background: #d9a441;
}
.usage.high .usage-fill {
  background: #e07a34;
}
.usage.crit .usage-fill {
  background: #d24b3e;
}
.usage-pct {
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  font-weight: 600;
}
.usage-reset {
  font-variant-numeric: tabular-nums;
}
.usage.stale {
  opacity: 0.55;
}
.usage.stale .usage-fill {
  background: var(--muted);
}
.list {
  padding: 8px 12px;
  overflow-y: auto;
}
/* Card de sessao: espinha de status a esquerda (assinatura) + titulo + meta em mono. */
.session {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  align-items: baseline;
  padding: 13px 14px 13px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 8px 0;
  cursor: pointer;
  background: var(--card);
  transition: border-color 0.15s ease, transform 0.06s ease;
}
.session::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 13px;
  bottom: 13px;
  width: 3px;
  border-radius: 3px;
  background: var(--line);
}
.session:hover {
  border-color: var(--muted);
}
.session:active {
  transform: scale(0.992);
}
.session:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.session h3 {
  grid-column: 1;
  margin: 0 0 3px;
  font-size: 15px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session .s-meta {
  grid-column: 1;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session .s-when {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.session .s-state {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
  justify-self: end;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--muted);
}
/* Estados: a espinha e a palavra de estado carregam a cor. */
.session.is-current::before {
  background: var(--accent);
}
.session.is-current .s-state {
  color: var(--accent);
}
.session.is-working::before,
.session.is-attn::before {
  background: var(--attn);
}
.session.is-working .s-state,
.session.is-attn .s-state {
  color: var(--attn);
}
.session.is-live {
  border-color: color-mix(in srgb, var(--live) 45%, var(--line));
}
.session.is-live::before {
  background: var(--live);
  animation: sd-pulse 1.6s infinite;
}
.session.is-live .s-state {
  color: var(--live);
  font-weight: 700;
}
.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg > :first-child {
  margin-top: 0;
}
.msg > :last-child {
  margin-bottom: 0;
}
.msg.user {
  align-self: flex-end;
  background: var(--user);
  padding: 10px 14px;
  border-radius: 14px;
  max-width: 85%;
}
.msg.assistant {
  align-self: flex-start;
}
.msg pre {
  background: var(--card);
  padding: 12px;
  border-radius: 10px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
}
.msg code {
  font-family: var(--mono);
  font-size: 0.9em;
}
.tool {
  font-size: 13px;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding: 4px 10px;
  margin: 2px 0;
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}
.thinking {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}
.qcard {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--card);
  max-width: 100%;
}
.qtext {
  font-weight: 600;
  margin-bottom: 10px;
}
.qopt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  margin: 6px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.qopt:active {
  background: var(--user);
}
.qopt.chosen {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.qopt:disabled {
  opacity: 0.55;
}
/* Pergunta pendente vinda do hook: um bloco por pergunta, e um campo livre no fim. O livre
   nao e detalhe, e o caminho mais usado. */
.qblock {
  margin-bottom: 12px;
}
.qhead {
  font-size: 0.92rem;
  opacity: 0.85;
  margin-bottom: 6px;
}
.qfree {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  margin: 6px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
.qsend {
  display: block;
  width: 100%;
  padding: 11px 12px;
  margin-top: 6px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.qsend:disabled,
.qfree:disabled {
  opacity: 0.55;
}
.typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 8px 4px;
}
.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: sd-bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) {
  animation-delay: 0.18s;
}
.typing span:nth-child(3) {
  animation-delay: 0.36s;
}
@keyframes sd-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}
.settings {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.settings.hidden {
  display: none;
}
.settings label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  flex: 1;
}
.settings select {
  font: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}
.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  background: var(--bg);
  color: var(--fg);
  max-height: 40vh;
}
.composer button,
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}
.composer button:disabled {
  opacity: 0.5;
}
.perm {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 16px;
  max-width: 760px;
  margin: 0 auto;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.15);
  z-index: 10;
}
.perm pre {
  background: var(--bg);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  max-height: 30vh;
}
.perm .actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.perm .actions button {
  flex: 1;
}
.perm .deny {
  background: var(--line);
  color: var(--fg);
}
/* Tela de acesso: painel enxuto, wordmark em mono, passkey como acao principal. */
.login {
  margin: auto;
  padding: 24px;
  width: 100%;
  max-width: 380px;
}
.login-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  padding: 28px 24px 24px;
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}
.brand {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  color: var(--accent);
}
.tagline {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 22px;
}
.login .btn {
  width: 100%;
  margin-top: 10px;
}
.login input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: var(--mono);
  font-size: 14px;
  background: var(--bg);
  color: var(--fg);
}
.login input:focus {
  outline: none;
  border-color: var(--accent);
}
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.divider.hidden {
  display: none;
}
.btn.secondary {
  background: var(--accent-weak);
  color: var(--accent);
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.err {
  color: var(--accent);
  min-height: 1.2em;
  font-size: 13px;
  margin: 12px 0 0;
  text-align: center;
}
.status {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 16px;
}
.section-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 14px 4px 6px;
}
.newfolder {
  padding: 8px 4px;
}
.newfolder input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
.newfolder .btn {
  width: 100%;
  margin-top: 8px;
}
/* Wordmark na barra da lista. */
.topbar .brand {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar .brand .brand-mark {
  color: var(--accent);
  margin-right: 4px;
}
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  vertical-align: middle;
}
.badge.working {
  background: rgba(217, 119, 87, 0.2);
  color: var(--accent);
}
.badge.attn {
  background: rgba(210, 153, 34, 0.22);
  color: #d29922;
}
.badge.atual {
  background: rgba(63, 185, 80, 0.2);
  color: #3fb950;
}
.badge.live {
  background: rgba(63, 185, 80, 0.25);
  color: #3fb950;
  font-weight: 700;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3fb950;
  margin-right: 6px;
  vertical-align: middle;
  animation: sd-pulse 1.6s infinite;
}
@keyframes sd-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}
#termwrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: #000;
  padding: 6px;
}
.composer .iconbtn {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 10px 12px;
}
#term {
  width: max-content;
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
