:root {
  --ink: #1C2433;
  --ink-2: #4A5468;
  --muted: #7A8396;
  --line: #E1E5EC;
  --paper: #EEF1F5;
  --surface: #FFFFFF;
  --ai: #4F5BD5;
  --ai-soft: #ECEEFC;
  --you: #1F7A55;
  --you-soft: #E3F2EB;
  --sun: #E8A317;
  --sun-soft: #FFF4DC;
  --danger: #C2412D;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 18px;
  font-family: "Onest", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-size: 15px; line-height: 1.45; background: var(--paper); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ai); outline-offset: 2px; }

/* o sol do "raiar": a única marca da interface */
.sun { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--sun); box-shadow: 0 0 0 4px var(--sun-soft); margin-right: 10px; vertical-align: -1px; }
.sun.big { width: 22px; height: 22px; box-shadow: 0 0 0 6px rgba(232,163,23,.18); margin: 0; }

/* botões e campos */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 16px; border-radius: var(--radius-m); font-weight: 600; cursor: pointer; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2B3650; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
label { display: grid; gap: 6px; font-weight: 500; font-size: 14px; color: var(--ink-2); }
input, textarea, select { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-s); padding: 9px 11px; color: var(--ink); font-weight: 400; font-size: 15px; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--ai); outline: none; box-shadow: 0 0 0 3px var(--ai-soft); }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; }
.icon-btn { border: 0; background: transparent; width: 38px; height: 38px; border-radius: var(--radius-m); display: grid; place-items: center; cursor: pointer; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--paper); color: var(--ink); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 50% -20%, var(--sun-soft), transparent 55%), var(--paper); }
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: var(--radius-l); padding: 32px 28px; display: grid; gap: 16px; border: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 15px; color: var(--ink-2); }

/* estrutura */
.app { display: grid; grid-template-columns: 76px 1fr; height: 100dvh; }
.rail { background: var(--ink); color: #C9D0DD; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 0 14px; }
.rail .sun { margin-bottom: 18px; }
.rail-btn { width: 62px; border: 0; background: transparent; color: inherit; border-radius: var(--radius-m); padding: 9px 0 7px; display: grid; justify-items: center; gap: 3px; cursor: pointer; font-size: 11px; font-weight: 500; }
.rail-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.rail-btn.active { background: rgba(255,255,255,.12); color: #fff; }
.rail-spacer { flex: 1; }
.view { min-width: 0; min-height: 0; }

/* conversas */
.view-conversas { display: grid; grid-template-columns: 340px 1fr auto; height: 100dvh; }
.list-pane { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.pane-head { padding: 20px 20px 10px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 12px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; color: var(--ink-2); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 13px 20px 13px 17px; border-left: 3px solid transparent; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: #F7F8FA; }
.conv.selected { background: var(--paper); }
.conv.attention { border-left-color: var(--sun); background: linear-gradient(90deg, var(--sun-soft), transparent 70%); }
.conv .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 12px; color: var(--muted); }
.conv .preview { grid-column: 1 / -1; color: var(--ink-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .tag { grid-column: 1 / -1; font-size: 12px; font-weight: 600; justify-self: start; }
.tag.ai { color: var(--ai); }
.tag.human { color: var(--you); }
.tag.attention { color: #9A6A00; }
.tag.closed { color: var(--muted); }
.empty-list { padding: 40px 24px; color: var(--muted); text-align: center; }

.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.empty-chat { margin: auto; text-align: center; display: grid; gap: 10px; justify-items: center; padding: 24px; }
.empty-chat .sun { margin-bottom: 8px; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-head .back { display: none; }
.who { display: grid; min-width: 0; flex: 1; }
.who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* o seletor IA / Você: o coração do painel */
.mode { display: inline-flex; background: var(--paper); border-radius: 999px; padding: 3px; flex: none; }
.mode-btn { border: 0; background: transparent; padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.mode-btn.on[data-mode="ai"] { background: var(--ai); color: #fff; }
.mode-btn.on[data-mode="human"] { background: var(--you); color: #fff; }

.handoff { margin: 12px 16px 0; padding: 10px 14px; border-radius: var(--radius-m); background: var(--sun-soft); color: #6E4B00; font-size: 14px; border: 1px solid #F1D79A; }
.messages { list-style: none; margin: 0; padding: 18px 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(72ch, 78%); padding: 9px 13px 7px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg.customer { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.ai { align-self: flex-end; background: var(--ai-soft); border-color: #D5D9F7; border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-end; background: var(--you-soft); border-color: #C8E6D7; border-bottom-right-radius: 4px; }
.msg.system { align-self: center; background: transparent; border: 0; color: var(--muted); font-size: 13px; text-align: center; padding: 4px 8px; }
.msg.system .meta { display: none; }
.composer { display: flex; gap: 10px; padding: 12px 16px 6px; background: var(--surface); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { max-height: 160px; resize: none; }
.composer-hint { font-size: 12px; padding: 0 16px 10px; background: var(--surface); }

.info-pane { width: 300px; background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; }
.stack { display: grid; gap: 14px; padding: 4px 20px 20px; }

/* páginas */
.view-page { overflow-y: auto; height: 100dvh; }
.page { max-width: 820px; margin: 0 auto; padding: 32px 24px 64px; display: grid; gap: 20px; align-content: start; }
.page-head { display: grid; gap: 6px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.connect { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 22px; display: grid; gap: 14px; justify-items: start; }
.connect .row, .connect label { width: 100%; }
.channel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.channel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px 18px; display: flex; align-items: center; gap: 14px; }
.channel .ch-main { flex: 1; display: grid; min-width: 0; }
.status { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.connected { color: var(--you); } .status.connected::before { background: var(--you); }
.status.connecting, .status.pending { color: #9A6A00; } .status.connecting::before, .status.pending::before { background: var(--sun); }
.status.disconnected { color: var(--danger); } .status.disconnected::before { background: var(--danger); }
.qr-box { background: var(--surface); border: 2px solid var(--sun); border-radius: var(--radius-l); padding: 24px; display: grid; grid-template-columns: 1fr 260px; gap: 24px; align-items: center; }
.qr-box img { width: 260px; height: 260px; image-rendering: pixelated; background: #fff; border-radius: var(--radius-m); }
.qr-steps { display: grid; gap: 12px; }
.qr-steps ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; color: var(--ink-2); }
.pairing-code { font-size: 30px; font-weight: 700; letter-spacing: .12em; color: var(--ink); }
.qr-status { font-weight: 600; color: #9A6A00; }
.qr-status.ok { color: var(--you); }
.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--ai); }
.advanced { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px 16px; }
.advanced summary { cursor: pointer; font-weight: 600; }
.advanced[open] { display: grid; gap: 14px; }
.save-bar { display: flex; align-items: center; gap: 14px; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--paper) 30%); }
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius-m); overflow: hidden; border: 1px solid var(--line); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 500; }
tr:last-child td { border-bottom: 0; }
.usage { display: grid; gap: 10px; margin-top: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* celular */
@media (max-width: 1100px) {
  .info-pane { position: fixed; right: 0; top: 0; bottom: 0; z-index: 5; box-shadow: -8px 0 24px rgba(28,36,51,.12); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { flex-direction: row; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); order: 2; }
  .rail .sun, .rail-spacer { display: none; }
  .rail-btn { width: auto; flex: 1; }
  .view-conversas, .view-page { height: calc(100dvh - 64px); }
  .view-conversas { grid-template-columns: 1fr; }
  .view-conversas.in-chat .list-pane { display: none; }
  .view-conversas:not(.in-chat) .chat-pane { display: none; }
  .chat-head .back { display: grid; }
  .chat-head { flex-wrap: wrap; row-gap: 8px; padding: 10px 12px; }
  .chat-head .mode { order: 10; width: 100%; }
  .mode-btn { flex: 1; padding: 7px 9px; font-size: 13px; }
  .row, .qr-box { grid-template-columns: 1fr; }
  .qr-box img { justify-self: center; }
  .page { padding: 20px 16px 48px; }
  .msg { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
