:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1d2330;
  --muted: #6b7280;
  --primary: #0f6e56;
  --primary-soft: #e6f2ee;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warning-soft: #fff6e0;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { opacity: .8; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); margin-top: 0; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: #14211d; color: #dfe9e5;
  padding: 1.25rem .75rem; display: flex; flex-direction: column; gap: .15rem;
}
.sidebar a { color: #dfe9e5; text-decoration: none; padding: .45rem .75rem; border-radius: 6px; }
.sidebar a:hover, .sidebar a.active { background: #22352f; color: #fff; }
.brand { font-weight: 600; padding: 0 .75rem 1rem; display: flex; flex-direction: column; }
.brand span { font-weight: 400; font-size: .8rem; color: #8fb3a6; }
.logout { margin-top: auto; padding: .75rem; font-size: .85rem; display: flex; flex-direction: column; gap: .25rem; }
.content { flex: 1; padding: 1.5rem 2rem; max-width: 1200px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat span { color: var(--muted); font-size: .85rem; display: block; }
.stat strong { font-size: 1.6rem; }

label { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; font-size: .9rem; }
input, select, textarea {
  font: inherit; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text);
}
textarea { min-height: 7rem; resize: vertical; }
button, .button {
  font: inherit; background: var(--primary); color: #fff; border: 0; border-radius: 6px;
  padding: .5rem 1rem; cursor: pointer; text-decoration: none; display: inline-block;
}
button.secondary { background: #e8ebef; color: var(--text); }
button.danger { background: var(--danger); }
button.link { background: none; color: inherit; padding: 0; text-decoration: none; text-align: left; }
button:disabled { opacity: .5; cursor: default; }

.alert { background: var(--danger-soft); color: var(--danger); padding: .6rem .8rem; border-radius: 6px; }
.notice { background: var(--primary-soft); color: var(--primary); padding: .6rem .8rem; border-radius: 6px; }
.warning { background: var(--warning-soft); padding: .6rem .8rem; border-radius: 6px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.badge { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: #e8ebef; white-space: nowrap; }
.badge.ok { background: var(--primary-soft); color: var(--primary); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

.login { min-height: 100vh; display: grid; place-items: center; }
.login .card { width: 360px; }
.login button { width: 100%; }

.customers { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.customer { flex-direction: row; align-items: flex-start; gap: .6rem; border: 1px solid var(--border); border-radius: 6px; padding: .6rem .75rem; margin: 0; cursor: pointer; }
.customer input { margin-top: .3rem; }

.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 190px); min-height: 420px; padding: 0; }
.turns { flex: 1; overflow-y: auto; padding: 1rem; background: #efeae2; border-radius: var(--radius) var(--radius) 0 0; }
.turn { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.bubble { max-width: 78%; padding: .5rem .75rem; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble.client { align-self: flex-end; background: #d9fdd3; }
.bubble.agent { align-self: flex-start; background: #fff; }
.bubble.attachment { font-style: italic; }
.handoff { align-self: stretch; background: var(--warning-soft); border-radius: 6px; padding: .5rem .75rem; font-size: .9rem; }
.handoff pre { white-space: pre-wrap; font-size: .8rem; margin: .5rem 0 0; }
#composer { padding: .75rem; border-top: 1px solid var(--border); }
.composer { display: flex; gap: .5rem; }
.composer input { flex: 1; }
.htmx-indicator { display: none; margin: .4rem 0 0; font-size: .85rem; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: block; }

.feedback { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .8rem; align-self: flex-start; max-width: 78%; }
.feedback input { flex: 1; min-width: 180px; padding: .25rem .5rem; font-size: .8rem; }
.chip { background: #fff; color: var(--text); border: 1px solid var(--border); padding: .15rem .6rem; font-size: .8rem; border-radius: 999px; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip.bad.on { background: var(--danger); border-color: var(--danger); }

.debug { position: sticky; top: 1rem; font-size: .88rem; }
.debug h2 { font-size: .95rem; margin-top: .5rem; }
.step { padding: .4rem 0; border-bottom: 1px dashed var(--border); display: flex; flex-direction: column; }
.step .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.step.code strong { font-size: 1.3rem; letter-spacing: .15em; color: var(--primary); }
a.card.stat { text-decoration: none; color: inherit; }

.filters { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.filters label { margin-bottom: 0; }
.cards.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat small { display: block; margin-top: .2rem; }
.bar { height: .6rem; background: var(--primary); border-radius: 999px; min-width: 2px; }
.pager { display: flex; gap: 1rem; align-items: center; }
.turns.readonly { max-height: none; background: #efeae2; border-radius: var(--radius); padding: 1rem; }

label.inline { flex-direction: row; align-items: center; gap: .5rem; }
.checks { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; margin-bottom: .75rem; }
.hours input[type=time] { width: 8rem; }
code.preview { font-size: .75rem; white-space: pre-wrap; word-break: break-word; color: var(--muted); }

.options { display: flex; flex-direction: column; gap: .3rem; margin-top: .6rem; }
.options.buttons { flex-direction: row; flex-wrap: wrap; }
.option { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: .1rem;
  background: #f0f7f4; color: var(--primary); border: 1px solid #cfe5dc; border-radius: 6px;
  padding: .4rem .7rem; font-size: .88rem; }
.options.buttons .option { align-items: center; }
.option small { color: var(--muted); font-weight: 400; }
button.option:hover { background: var(--primary-soft); }

/* Chat de treinamento e validação */
.chat-header h1 { margin-bottom: .1rem; }
.chat-header p { margin-top: 0; }
.bubble { position: relative; padding: .45rem .75rem 1.15rem; min-width: 90px; line-height: 1.45; }
.bubble.client { border-bottom-right-radius: 2px; }
.bubble.agent { border-bottom-left-radius: 2px; }
.bubble .sender { display: block; font-size: .72rem; font-weight: 600; color: var(--primary); margin-bottom: .15rem; }
.bubble .meta { position: absolute; right: .55rem; bottom: .25rem; font-size: .68rem; color: var(--muted); }
.bubble.attachment { padding-bottom: .45rem; }
.turn.pending .bubble { opacity: .65; padding-bottom: .45rem; }
.typing { display: none; align-items: center; gap: .5rem; padding: .4rem 1rem; font-size: .85rem;
  color: var(--muted); background: #efeae2; }
.typing.htmx-request { display: flex; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.feedback { font-size: .78rem; margin-top: -.1rem; }
.feedback .chip { font-size: .76rem; padding: .1rem .55rem; }

@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .6rem; }
  .brand { padding: 0 .75rem 0 .25rem; }
  .logout { margin: 0 0 0 auto; padding: .25rem .5rem; flex-direction: row; align-items: center; gap: .6rem; }
  .content { padding: 1rem; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat { height: 70vh; }
  .debug { position: static; }
  .bubble, .feedback { max-width: 92%; }
}

.bubble.client, .bubble .text { white-space: pre-wrap; }
.bubble .options { white-space: normal; margin-top: .5rem; }

.composer { align-items: center; }
.composer-main { flex: 1; display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.composer-main input[type=text] { width: 100%; }
.attach { position: relative; cursor: pointer; font-size: .85rem; color: var(--primary); padding: .5rem .6rem;
  border: 1px solid var(--border, #d5dbe1); border-radius: 8px; background: #fff; white-space: nowrap; }
.attach input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-chip { align-self: flex-start; font-size: .78rem; background: #e7f3ef; color: var(--primary);
  border-radius: 999px; padding: .1rem .6rem; }
