:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #e2e5e0;
  --text: #1b1f1c;
  --muted: #69716b;
  --accent: #1f8f5f;
  --accent-soft: #e3f3ea;
  --accent-text: #ffffff;
  --warn: #b26a00;
  --warn-soft: #fdf0dc;
  --danger: #c0392b;
  --danger-soft: #fbe6e3;
  --info: #2f6db5;
  --info-soft: #e5eef9;
  --bubble-in: #ffffff;
  --bubble-bot: #dcf3e6;
  --bubble-human: #e1ebf8;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413;
    --surface: #181c1a;
    --surface-2: #202522;
    --border: #2b312d;
    --text: #e8ece9;
    --muted: #97a09a;
    --accent: #3cbf86;
    --accent-soft: #173426;
    --accent-text: #08130d;
    --warn: #f0a940;
    --warn-soft: #3a2a12;
    --danger: #ef7466;
    --danger-soft: #3b1c18;
    --info: #78a9e6;
    --info-soft: #172638;
    --bubble-in: #202522;
    --bubble-bot: #1b3a2b;
    --bubble-human: #1c2b40;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
p { margin: 0; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 550; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

label { display: grid; gap: 6px; font-size: 14px; font-weight: 560; }
label .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px;
  padding: 1px 8px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--info-soft); color: var(--info); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; display: grid; gap: 16px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); position: relative; flex: none;
}
.logo::after {
  content: ""; position: absolute; left: 7px; top: 8px; width: 14px; height: 9px;
  background: var(--accent-text); border-radius: 3px 3px 3px 0;
}

/* ---------- Estrutura ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 0 8px; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; justify-content: space-between; text-decoration: none;
  color: var(--muted); padding: 8px 10px; border-radius: 8px; font-weight: 550;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; padding: 0 4px; }
.live { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live.on::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 560; grid-auto-flow: column; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 36px; height: 20px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.main { padding: 28px 32px 48px; min-width: 0; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Visão geral ---------- */
.progress-card { padding: 20px; display: grid; gap: 12px; margin-bottom: 16px; }
.progress-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.progress-top strong { font-size: 28px; font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .5s ease; }

.steps { list-style: none; margin: 0; padding: 0; }
.step { display: grid; grid-template-columns: 32px 1fr auto; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border); align-items: start; }
.step:first-child { border-top: 0; }
.step .dot {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted); margin-top: 1px;
}
.step.ok .dot { background: var(--accent); color: var(--accent-text); }
.step.current .dot { background: var(--warn-soft); color: var(--warn); }
.step h3 { font-size: 15px; font-weight: 600; }
.step p { font-size: 13.5px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.step .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.step-extra { grid-column: 2 / -1; margin-top: 8px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 16px 18px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat.attention strong { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.env-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.env-table td { padding: 8px 0; border-top: 1px solid var(--border); vertical-align: top; }
.env-table tr:first-child td { border-top: 0; }
.env-table td:first-child { width: 22px; }
.env-table code { font-size: 12px; }
.env-table .val { color: var(--muted); word-break: break-all; }
.copy-box { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: 9px; padding: 8px 10px; }
.copy-box code { background: none; padding: 0; flex: 1; word-break: break-all; }

/* ---------- Conversas ---------- */
.chat-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 140px); min-height: 480px; overflow: hidden; }
.conv-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 4px; padding: 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs button { border: 0; background: none; font: inherit; font-size: 13px; font-weight: 580; color: var(--muted); padding: 5px 10px; border-radius: 7px; cursor: pointer; }
.tabs button.active { background: var(--surface-2); color: var(--text); }
.conv-items { overflow-y: auto; overflow-x: hidden; flex: 1; }
.conv-item { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; background: none; border-left: 3px solid transparent; width: 100%; text-align: left; font: inherit; color: inherit; border-right: 0; border-top: 0; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.conv-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conv-item .name { min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .time { font-size: 12px; color: var(--muted); flex: none; }
.conv-item .preview { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); font-size: 14px; }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chat-head .who strong { display: block; }
.chat-head .who span { font-size: 13px; color: var(--muted); }
.handoff-banner { background: var(--warn-soft); color: var(--warn); font-size: 13.5px; padding: 8px 16px; }
.messages { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.msg { max-width: min(78%, 560px); padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); font-size: 14.5px; }
.msg .meta { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.msg.user { background: var(--bubble-in); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.assistant { background: var(--bubble-bot); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.human { background: var(--bubble-human); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.failed { outline: 1px solid var(--danger); }
.msg.system { align-self: center; background: var(--surface-2); color: var(--muted); box-shadow: none; font-size: 12.5px; border-radius: 999px; padding: 4px 12px; max-width: 90%; text-align: center; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { min-height: 44px; height: 44px; max-height: 160px; resize: none; line-height: 24px; padding: 9px 11px; overflow-y: hidden; }

/* ---------- Empresa ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.inline-check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.inline-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.save-bar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 0 0; background: linear-gradient(transparent, var(--bg) 40%); }
details summary { cursor: pointer; font-weight: 580; }
pre.prompt { white-space: pre-wrap; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 14px; border-radius: 9px; max-height: 420px; overflow: auto; margin: 12px 0 0; }

/* ---------- Simulador ---------- */
.sim { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 460px; overflow: hidden; }

/* ---------- Atividade ---------- */
.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 150px 70px 1fr; gap: 12px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 13.5px; align-items: start; }
.events li:first-child { border-top: 0; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; }
.events .msgtxt { word-break: break-word; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 10; max-width: calc(100% - 32px); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Celular ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar nav { display: flex; overflow-x: auto; order: 3; width: 100%; min-width: 0; scrollbar-width: none; }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar-foot .switch { font-size: 13px; }
  .sidebar nav a { white-space: nowrap; gap: 6px; }
  .sidebar-foot { margin: 0 0 0 auto; display: flex; align-items: center; }
  .sidebar-foot .live { display: none; }
  .main { padding: 20px 16px 40px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .chat-layout .conv-list { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--border); }
  .chat-layout .chat { height: 70vh; }
  .step { grid-template-columns: 28px 1fr; padding: 14px 16px; }
  .step .actions { grid-column: 2; justify-content: flex-start; }
  .events li { grid-template-columns: 1fr; gap: 2px; padding: 10px 16px; }
}

.test-note { margin: 12px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
