:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #f7f9fb;
  --line: #e2e7ee;
  --text: #17212b;
  --muted: #637083;
  --brand: #0b4f8a;
  --brand-2: #0d66b3;
  --brand-soft: #e6f0fa;
  --ok: #188a4b;
  --ok-soft: #e3f5ea;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --bad: #c0392b;
  --bad-soft: #fde8e6;
  --in: #ffffff;
  --out: #dcf3e4;
  --chat-bg: #eef1f4;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --panel: #161d24; --panel-2: #1b232c; --line: #26313c;
    --text: #e6ebf0; --muted: #94a2b2; --brand: #4ea1e8; --brand-2: #6db3f0; --brand-soft: #16304a;
    --ok: #4cc17f; --ok-soft: #173326; --warn: #f0b14a; --warn-soft: #3a2d14; --bad: #f07466; --bad-soft: #3d1f1c;
    --in: #1f2830; --out: #1d3b2b; --chat-bg: #12181e; --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Botões e campos ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
input[type=text], input[type=password], input[type=tel], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

/* ---------- Telas de acesso ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p { color: var(--muted); margin: 0 0 20px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--brand); }
.logo img { width: 34px; height: 34px; border-radius: 8px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 6px 0; }

/* ---------- Estrutura ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; }
.side .logo { padding: 4px 8px 16px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); border: 0; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.side .spacer { flex: 1; }
.side .me { font-size: 12.5px; color: var(--muted); padding: 8px 10px; border-top: 1px solid var(--line); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.page { padding: 20px 24px; overflow: auto; height: 100%; }
.page h2 { margin: 0 0 16px; font-size: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card h3 small { font-weight: 400; color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }

/* ---------- Conversas ---------- */
.chat-layout { display: grid; grid-template-columns: 330px 1fr; height: 100%; min-height: 0; }
.conv-list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.conv-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.chip.on { background: var(--brand-soft); color: var(--brand); border-color: transparent; font-weight: 600; }
.conv-items { overflow: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--brand-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.conv .body { min-width: 0; flex: 1; }
.conv .top { display: flex; gap: 6px; align-items: baseline; }
.conv .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { margin-left: auto; font-size: 11.5px; color: var(--muted); flex: none; }
.conv .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .tags { display: flex; gap: 4px; margin-top: 3px; }
.tag { white-space: nowrap; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag.att { background: var(--warn-soft); color: var(--warn); border-color: transparent; font-weight: 600; }
.tag.bot { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.human { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.unread { background: var(--ok); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; margin-left: 4px; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

.chat { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.chat-top { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-top .who { min-width: 0; flex: 1; }
.chat-top .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-top .who b { display: block; }
.chat-top .who small { color: var(--muted); }
.banner { padding: 8px 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
.banner.att { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--brand-soft); color: var(--brand); }
.msgs { flex: 1; overflow: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 2px 10px; border-radius: 99px; margin: 8px 0; box-shadow: var(--shadow); }
.bubble { max-width: min(560px, 82%); padding: 7px 10px 5px; border-radius: 10px; box-shadow: var(--shadow); overflow-wrap: anywhere; }
.bubble .txt { white-space: pre-wrap; }
.bubble.in { align-self: flex-start; background: var(--in); border-top-left-radius: 3px; }
.bubble.out { align-self: flex-end; background: var(--out); border-top-right-radius: 3px; }
.bubble .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; }
.bubble .who-tag { font-size: 11px; font-weight: 600; color: var(--brand); margin-bottom: 2px; }
.bubble .fail { color: var(--bad); font-size: 12px; margin-top: 3px; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; resize: none; }
.closed-note { background: var(--panel); border-top: 1px solid var(--line); padding: 12px 14px; color: var(--muted); font-size: 13px; }
.chat-side { display: none; }

/* ---------- Agenda ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 180px; display: flex; flex-direction: column; }
.day.today { border-color: var(--brand-2); box-shadow: 0 0 0 1px var(--brand-2) inset; }
.day-h { padding: 8px 10px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.day-h b { font-size: 15px; }
.day-h .add { opacity: .6; }
.day-b { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.appt { border-left: 3px solid var(--brand-2); background: var(--panel-2); border-radius: 6px; padding: 6px 8px; cursor: pointer; font-size: 12.5px; }
.appt:hover { filter: brightness(.97); }
.appt b { display: block; font-size: 13px; }
.appt .t { color: var(--muted); }
.appt.k-suporte_remoto { border-color: #2f80ed; }
.appt.k-manutencao { border-color: #e67e22; }
.appt.k-visita { border-color: #8e44ad; }
.appt.k-implantacao { border-color: #16a085; }
.appt.s-concluido { opacity: .6; }
.appt.s-cancelado, .appt.s-faltou { opacity: .5; text-decoration: line-through; }
.st { display: inline-block; font-size: 10.5px; padding: 0 6px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); margin-top: 3px; }
.st.confirmado { color: var(--ok); border-color: var(--ok); }
.st.concluido { color: var(--muted); }
.st.cancelado, .st.faltou { color: var(--bad); border-color: var(--bad); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,15,20,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-h { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-h h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-b { padding: 16px 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--panel); }
.modal-f .grow { flex: 1; }

/* ---------- Status ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
table.log { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.log td { border-bottom: 1px solid var(--line); padding: 6px 8px 6px 0; vertical-align: top; }
table.log td.d { white-space: nowrap; color: var(--muted); }
table.log td.k { white-space: nowrap; font-weight: 600; }
table.log td.x { word-break: break-word; }
.copy { display: flex; gap: 6px; }
.copy input { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.hours { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; align-items: center; }

/* ---------- Avisos ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- Celular ---------- */
.mobile-nav { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { display: none; }
  .mobile-nav { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav .nav-item { flex-direction: column; gap: 2px; font-size: 11px; justify-content: center; align-items: center; padding: 8px 4px; border-radius: 0; position: relative; }
  .mobile-nav .badge { position: absolute; top: 4px; left: 55%; margin: 0; }
  .page { padding: 16px; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-layout.has-chat .conv-list { display: none; }
  .chat-layout:not(.has-chat) .chat { display: none; }
  .msgs { padding: 12px; }
  .chat-top .acts { width: 100%; }
  .chat-top .acts .btn { flex: 1; justify-content: center; }
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .day-b:empty::after { content: "Livre"; color: var(--muted); font-size: 12px; padding: 4px; }
  .only-desktop { display: none !important; }
}
@media (min-width: 861px) { .only-mobile { display: none !important; } }
