:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --blue: #0071e3;
  --blue-soft: #e8f1fc;
  --green: #1f9d55;
  --green-soft: #e6f6ec;
  --amber: #b25e00;
  --amber-soft: #fff3e0;
  --red: #d70015;
  --red-soft: #fdecee;
  --violet: #6e3ad8;
  --violet-soft: #f1ebfd;
  --bubble-in: #ffffff;
  --bubble-ia: #e8f1fc;
  --bubble-human: #dcf8c6;
  --bubble-sys: #f2f2f7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { -webkit-font-smoothing: antialiased; font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; height: 100dvh; }
.side { background: #0b0b0f; color: #f5f5f7; display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 600; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand small { display: block; font-weight: 400; color: #a1a1a6; font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: #d2d2d7; font-size: 14px; }
.nav a:hover { background: #1c1c22; color: #fff; }
.nav a.on { background: #26262e; color: #fff; }
.nav .badge { margin-left: auto; }
.side .foot { margin-top: auto; padding: 10px 12px; font-size: 12px; color: #a1a1a6; }
.side .foot button { background: none; border: 0; color: #a1a1a6; padding: 0; cursor: pointer; text-decoration: underline; }
.main { overflow: auto; height: 100dvh; }
.page { padding: 28px 32px 60px; max-width: 1180px; }
.page h1 { font-size: 28px; letter-spacing: -.02em; margin: 0 0 4px; }
.page .sub { color: var(--muted); margin: 0 0 22px; }
.icon { width: 18px; height: 18px; flex: none; }

/* Cards & forms */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -.01em; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,113,227,.15); }
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
.btn { border: 0; border-radius: 980px; padding: 9px 18px; background: var(--blue); color: #fff; cursor: pointer; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.soft { background: var(--blue-soft); color: var(--blue); }
.btn.red { background: var(--red); }
.btn.green { background: var(--green); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.icon-only { padding: 8px; border-radius: 50%; }
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 980px; padding: 3px 10px; font-size: 12px; font-weight: 500; background: var(--bubble-sys); color: var(--muted); white-space: nowrap; }
.chip.ia { background: var(--blue-soft); color: var(--blue); }
.chip.aguardando { background: var(--amber-soft); color: var(--amber); }
.chip.humano { background: var(--green-soft); color: var(--green); }
.chip.encerrada { background: #ececf0; color: var(--muted); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.violet { background: var(--violet-soft); color: var(--violet); }
.badge { background: var(--red); color: #fff; border-radius: 980px; font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tabs { display: inline-flex; background: #e8e8ed; border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 500; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.off td { opacity: .45; }
td input, td select { padding: 6px 8px; font-size: 14px; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 26px; letter-spacing: -.02em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stats .card { margin: 0; }
.switch { position: relative; width: 42px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d1d1d6; border-radius: 26px; transition: .2s; cursor: pointer; }
.switch span:before { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span:before { transform: translateX(16px); }
.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.alert.warn { background: var(--amber-soft); color: #7a4100; }
.alert.info { background: var(--blue-soft); color: #0a4a8f; }
.alert.err { background: var(--red-soft); color: #8e0010; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, #2a2a33, #0b0b0f); }
.login .box { width: min(380px, 92vw); background: #fff; border-radius: 20px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login h1 { font-size: 24px; margin: 14px 0 4px; letter-spacing: -.02em; }
.login img { width: 48px; height: 48px; border-radius: 12px; }
.login .btn { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; }

/* Conversas */
.inbox { display: grid; grid-template-columns: 360px 1fr; height: 100dvh; }
.list { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.list .top { padding: 18px 16px 10px; border-bottom: 1px solid var(--line); }
.list .top h1 { font-size: 22px; margin: 0 0 10px; letter-spacing: -.02em; }
.list .filters { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.list .filters button { border: 1px solid var(--line); background: #fff; border-radius: 980px; padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.list .filters button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.list .items { overflow-y: auto; flex: 1; }
.item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #f0f0f3; cursor: pointer; align-items: flex-start; }
.item:hover { background: #fafafc; }
.item.on { background: var(--blue-soft); }
.item.wait { box-shadow: inset 3px 0 0 var(--amber); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #cfd3dc, #a7adba); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.item .meta { flex: 1; min-width: 0; }
.item .name { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.item .name time { font-weight: 400; color: var(--muted); font-size: 12px; }
.item .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item .tags { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.chat { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.chat .head { background: #fff; padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.chat .head .who { flex: 1; min-width: 0; }
.chat .head .who b { display: block; }
.chat .head .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chat .banner { padding: 8px 18px; font-size: 13px; background: var(--amber-soft); color: #7a4100; border-bottom: 1px solid #f3dfbf; }
.chat .banner.sum { background: #fff; color: var(--ink); }
.chat .msgs { flex: 1; overflow-y: auto; padding: 18px 6% 10px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: min(560px, 80%); padding: 8px 12px 6px; border-radius: 12px; box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; position: relative; }
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 4px; }
.bubble.out { align-self: flex-end; border-top-right-radius: 4px; }
.bubble.ia { background: var(--bubble-ia); }
.bubble.humano { background: var(--bubble-human); }
.bubble.sistema { background: var(--bubble-sys); }
.bubble .by { font-size: 11px; font-weight: 600; margin-bottom: 2px; }
.bubble.ia .by { color: var(--blue); }
.bubble.humano .by { color: var(--green); }
.bubble.sistema .by { color: var(--muted); }
.bubble .foot { display: flex; justify-content: flex-end; gap: 6px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble .foot button { border: 0; background: none; color: var(--blue); font-size: 11px; cursor: pointer; padding: 0; }
.bubble img { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; }
.bubble audio { width: 240px; max-width: 100%; }
.bubble.failed { outline: 2px solid var(--red); }
.day-sep { align-self: center; background: #e1f2fb; color: #54656f; font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 8px 0; }
.composer { background: #f0f2f5; padding: 10px 14px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; border-radius: 20px; padding: 10px 14px; flex: 1; }
.composer .btn.icon-only { width: 42px; height: 42px; justify-content: center; }
.rec { background: var(--red) !important; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.placeholder { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 20px; background: var(--bg); }
.back { display: none; }

/* Regras */
.rule { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.rule:last-child { border-bottom: 0; }
.rule .num { width: 28px; height: 28px; border-radius: 50%; background: var(--bubble-sys); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; color: var(--muted); }
.rule .txt { flex: 1; min-width: 0; }
.rule .txt b { display: block; margin-bottom: 2px; }
.rule .txt p { margin: 0; color: #3a3a3c; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.rule.off { opacity: .45; }
.rule .ops { display: flex; gap: 6px; align-items: center; }

/* Simulador */
.sim { display: grid; grid-template-columns: 1fr 340px; gap: 16px; }
.phone { background: #efeae2; border-radius: 22px; height: 70vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); }
.phone .msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.log { font-size: 13px; max-height: 70vh; overflow-y: auto; }
.log .ev { border-left: 3px solid var(--line); padding: 6px 10px; margin-bottom: 8px; background: #fff; border-radius: 0 8px 8px 0; }
.log .ev.trava { border-color: var(--red); }
.log .ev.tool { border-color: var(--blue); }
.log .ev.handoff { border-color: var(--amber); }
.log pre { white-space: pre-wrap; margin: 4px 0 0; font-size: 12px; color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 18px; width: min(560px, 100%); max-height: 90dvh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal .row.end { justify-content: flex-end; margin-top: 8px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #1d1d1f; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 99; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Mobile */
.bottom-nav { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { display: none; }
  .main { height: calc(100dvh - 62px - env(safe-area-inset-bottom)); }
  .bottom-nav { display: flex; background: #fff; border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--muted); padding: 4px 6px; position: relative; }
  .bottom-nav a.on { color: var(--blue); }
  .bottom-nav .badge { position: absolute; top: -2px; right: 0; }
  .page { padding: 18px 14px 40px; }
  .inbox { grid-template-columns: 1fr; height: 100%; }
  .inbox.has-chat .list { display: none; }
  .inbox:not(.has-chat) .chat { display: none; }
  .back { display: inline-flex; }
  .chat .msgs { padding: 14px 10px; }
  .bubble { max-width: 88%; }
  .sim { grid-template-columns: 1fr; }
  .phone { height: 60vh; }
  .chat .head { padding: 10px 12px; }
  .chat .head .actions .btn { padding: 6px 10px; font-size: 12px; }
}
