:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-2: #f9fafa;
  --line: #e4e8e6;
  --text: #17201c;
  --muted: #66736d;
  --brand: #00a86b;
  --brand-ink: #ffffff;
  --brand-soft: #e3f6ee;
  --accent: #ffcc33;
  --danger: #d6453d;
  --note: #fff6d6;
  --note-line: #f0d77a;
  --in: #ffffff;
  --out: #dcf6e9;
  --bot: #eef1f0;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --panel: #161d1a;
    --panel-2: #1b2420;
    --line: #26312c;
    --text: #e6ece9;
    --muted: #8d9a94;
    --brand: #19c483;
    --brand-ink: #062015;
    --brand-soft: #143127;
    --note: #3a3218;
    --note-line: #6b5a1f;
    --in: #1f2925;
    --out: #164233;
    --bot: #202a26;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 24px 0 8px; }
.mt { margin-top: 40px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); }

input, textarea, select {
  font: inherit; color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }

.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); }
.btn.full { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: default; }
select.btn { padding-right: 28px; max-width: 170px; }
.icon-btn { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--text); padding: 4px 8px; }

.brand { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.brand .bolt {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--brand); color: #fff; font-size: 18px;
}
.brand.big { font-size: 24px; margin-bottom: 4px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 15px; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card p { margin: 0; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 76px 360px 1fr; height: 100vh; height: 100dvh; }
.rail {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px;
}
.rail .brand { margin-bottom: 12px; }
.rail-btn {
  width: 64px; border: 0; background: none; cursor: pointer; color: var(--muted);
  border-radius: 10px; padding: 8px 2px; font-size: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.rail-btn span { font-size: 11px; font-weight: 500; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-btn:hover { background: var(--panel-2); color: var(--text); }
.rail-btn.active { background: var(--brand-soft); color: var(--text); }
.rail-spacer { flex: 1; }

/* ---------- Lista ---------- */
.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.list-head { padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.list-title { display: flex; align-items: center; justify-content: space-between; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.conn.on { background: var(--brand); }
.stats { display: flex; gap: 6px; flex-wrap: wrap; }
.stat { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; color: var(--muted); }
.stat b { color: var(--text); }
.search { width: 100%; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button {
  flex: 1; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 7px 4px; border-radius: 7px; cursor: pointer;
}
.tabs button b { font-weight: 600; font-size: 11px; background: var(--line); border-radius: 999px; padding: 1px 6px; margin-left: 2px; }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.tabs button.active b { background: var(--brand); color: var(--brand-ink); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.chip.active { border-color: var(--brand); background: var(--brand-soft); color: var(--text); }

.conv-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
.conv {
  display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 16px; cursor: pointer; border-left: 3px solid transparent;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--brand-soft); border-left-color: var(--brand); }
.conv .avatar { width: 42px; height: 42px; font-size: 15px; }
.conv .mid { min-width: 0; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tag.queue { background: #fff2cc; border-color: #f2d47a; color: #7a5b00; }
.tag.active { background: var(--brand-soft); border-color: transparent; color: var(--text); }
.tag.menu { background: #e8eefc; border-color: #c6d4f5; color: #2f4a8a; }
@media (prefers-color-scheme: dark) {
  .tag.queue { background: #3b3112; border-color: #6b5a1f; color: #f5d66c; }
  .tag.menu { background: #1c2740; border-color: #2f4170; color: #a9bff2; }
}
.conv .right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 12px; color: var(--muted); }
.badge { background: var(--brand); color: var(--brand-ink); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; }
.list-empty { padding: 32px 16px; text-align: center; color: var(--muted); }

.avatar {
  border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  font-weight: 700; color: #fff; width: 40px; height: 40px;
}

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.empty { margin: auto; text-align: center; padding: 24px; }
.empty-icon { font-size: 40px; width: 72px; height: 72px; margin: 0 auto 12px; display: grid; place-items: center; background: var(--brand-soft); border-radius: 20px; }
.empty h2 { margin: 0 0 4px; }
.chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.chat-head .who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-head .who strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who span { font-size: 12px; }
.chat-head .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.back { display: none; }
.window-warn { background: #fff2cc; color: #6b5000; padding: 8px 16px; font-size: 13px; border-bottom: 1px solid #f2d47a; }
@media (prefers-color-scheme: dark) { .window-warn { background: #3b3112; color: #f5d66c; border-color: #6b5a1f; } }

.messages { flex: 1; overflow-y: auto; padding: 16px clamp(12px, 4vw, 48px); display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(560px, 82%); padding: 8px 11px 6px; border-radius: 12px; box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.msg.in { background: var(--in); align-self: flex-start; border-top-left-radius: 4px; }
.msg.out { background: var(--out); align-self: flex-end; border-top-right-radius: 4px; }
.msg.bot { background: var(--bot); align-self: flex-end; border-top-right-radius: 4px; color: var(--muted); font-size: 13px; }
.msg.note { background: var(--note); border: 1px dashed var(--note-line); align-self: center; box-shadow: none; font-size: 13px; max-width: 90%; }
.msg .meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg .author { font-size: 12px; font-weight: 600; color: var(--brand); margin-bottom: 2px; }
.msg.failed { outline: 1px solid var(--danger); }
.msg .err { color: var(--danger); font-size: 12px; margin-top: 4px; white-space: normal; }
.msg img.media, .msg video.media { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; margin-bottom: 4px; cursor: zoom-in; }
.msg audio { max-width: 100%; }
.msg a { color: var(--brand); }
.tick { font-size: 12px; letter-spacing: -3px; }
.tick.read { color: #2b8cff; }
.day-sep, .conv-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; margin: 10px 0 4px; }
.conv-sep { background: var(--panel-2); }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px 12px; }
.composer .mode { display: flex; gap: 4px; margin-bottom: 6px; }
.composer .mode button { border: 0; background: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.composer .mode button.active { background: var(--brand-soft); color: var(--text); }
.composer.note-mode .mode button[data-mode="note"].active { background: var(--note); }
.composer.note-mode textarea { background: var(--note); border-color: var(--note-line); }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea { flex: 1; resize: none; max-height: 180px; line-height: 1.4; }
.send { height: 40px; }
.closed-bar { background: var(--panel); border-top: 1px solid var(--line); padding: 14px 16px; color: var(--muted); text-align: center; }

/* ---------- Páginas admin ---------- */
.page { overflow-y: auto; grid-column: 2 / 4; }
.page-inner { max-width: 860px; padding: 28px 24px 64px; margin: 0 auto; }
.page-inner > p { margin: 6px 0 16px; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); }
.table tr:last-child td { border-bottom: 0; }
.table .sec-list { display: flex; gap: 4px; flex-wrap: wrap; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid-form .sectors-pick, .grid-form button { grid-column: 1 / -1; }
.grid-form button { justify-self: start; }
.sectors-pick { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 12px; }
.sectors-pick legend { font-weight: 500; padding: 0 4px; }
.sectors-pick label, label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; max-width: 320px; }
.settings-form { display: flex; flex-direction: column; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.settings-form button { align-self: flex-start; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 16, 13, .45); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- Celular ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail {
    grid-row: 2; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
  }
  .rail .brand, .rail-spacer { display: none; }
  .rail-btn { width: auto; flex: 1; }
  .list, .chat, .page { grid-row: 1; grid-column: 1; }
  .app.chat-open .list { display: none; }
  .app:not(.chat-open) .chat { display: none; }
  .back { display: block; }
  .chat-head .actions { width: 100%; }
  .chat-head .actions > * { flex: 1; max-width: none; }
  .grid-form { grid-template-columns: 1fr; }
  .table { font-size: 13px; }
}

/* ===================== v2: dono do cliente, avisos, alarmes ===================== */
.small { font-size: 12px; }
.btn.big { padding: 12px 20px; font-size: 15px; }
.btn.danger-soft { color: var(--muted); }
.settings-form h2 { margin: 12px 0 0; font-size: 15px; }
.settings-form h2:first-child { margin-top: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 860px) { .two { grid-template-columns: 1fr; } }

.push-banner {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--brand-soft); border: 1px solid var(--brand); border-radius: 10px; padding: 10px 12px; font-size: 13px;
}
.install-tip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; }

.team { display: flex; gap: 6px; flex-wrap: wrap; }
.person {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 3px 9px 3px 7px; color: var(--muted);
}
.person i { width: 7px; height: 7px; border-radius: 50%; background: #b9c2be; }
.person.on { color: var(--text); }
.person.on i { background: var(--brand); }
.person b { background: var(--line); color: var(--text); border-radius: 999px; padding: 0 6px; font-size: 11px; }
.person.late { border-color: var(--danger); }
.person.late b { background: var(--danger); color: #fff; }

.tabs button.alert b { background: var(--danger) !important; color: #fff !important; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.tag.mine { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.wait { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.wait.warn { background: #fff2cc; border-color: #f2d47a; color: #7a5b00; }
.wait.late { background: var(--danger); border-color: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .wait.warn { background: #3b3112; border-color: #6b5a1f; color: #f5d66c; } }

.conv.locked .preview { font-style: italic; }
.conv.locked .avatar { opacity: .75; }
.conv-list .group { padding: 12px 16px 4px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.claim-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--panel); border-top: 1px solid var(--line); padding: 14px 16px;
}
.locked-view { margin: auto; text-align: center; padding: 24px; max-width: 420px; position: relative; }
.locked-view .lock-icon { font-size: 36px; width: 72px; height: 72px; margin: 0 auto 12px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px; }
.locked-view h2 { margin: 0 0 6px; }
.locked-view .back { position: fixed; top: 12px; left: 8px; }
.msg.note { text-align: center; }

@media (max-width: 860px) {
  .app:not(.chat-open) .chat { display: none; }
  .claim-bar .btn { width: 100%; }
}

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.notify-log { font-size: 12px; display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; }
.notify-log .ok { color: var(--brand); }
.notify-log .bad { color: var(--danger); }
