:root {
  --bg: #eae6df;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --line: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --accent: #00a884;
  --accent-ink: #ffffff;
  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --notice: #fff3c4;
  --notice-ink: #54470a;
  --human: #e9573f;
  --human-soft: #fde4df;
  --bot-soft: #d8f3ec;
  --bot-ink: #00775c;
  --selected: #f0f2f5;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b141a;
    --panel: #111b21;
    --panel-2: #202c33;
    --line: #222d34;
    --text: #e9edef;
    --muted: #8696a0;
    --accent: #00a884;
    --accent-ink: #0b141a;
    --chat-bg: #0b141a;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --notice: #3b3517;
    --notice-ink: #f3e3a0;
    --human: #ff7a63;
    --human-soft: #4a2620;
    --bot-soft: #103a31;
    --bot-ink: #5fd3b5;
    --selected: #2a3942;
  }
}
:root[data-theme="dark"] {
  --bg: #0b141a; --panel: #111b21; --panel-2: #202c33; --line: #222d34; --text: #e9edef; --muted: #8696a0;
  --accent: #00a884; --accent-ink: #0b141a; --chat-bg: #0b141a; --bubble-in: #202c33; --bubble-out: #005c4b;
  --notice: #3b3517; --notice-ink: #f3e3a0; --human: #ff7a63; --human-soft: #4a2620; --bot-soft: #103a31;
  --bot-ink: #5fd3b5; --selected: #2a3942;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border-radius: 12px; padding: 28px 24px;
  display: grid; gap: 14px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.btn-primary {
  padding: 11px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 0; font-size: 13px; }
.login-msg { font-size: 13px; min-height: 1em; color: var(--muted); }
.login-msg.err { color: var(--human); }

/* Layout */
.app {
  height: 100dvh; display: grid; grid-template-columns: minmax(300px, 400px) 1fr;
  max-width: 1600px; margin: 0 auto; background: var(--panel);
}
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; background: var(--panel); }
.side-head {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; background: var(--panel-2);
  font-size: 16px;
}
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 50%; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--line); }
.side-tools { padding: 8px 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.side-tools input {
  width: 100%; padding: 8px 12px; border-radius: 8px; border: 0; background: var(--panel-2); outline: none;
}
.filters { display: flex; gap: 6px; }
.chip {
  border: 0; border-radius: 999px; padding: 5px 12px; background: var(--panel-2); color: var(--muted); font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--bot-soft); color: var(--bot-ink); font-weight: 600; }
.count { background: var(--human); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; font-weight: 700; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.item {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center; padding: 10px 14px;
  cursor: pointer; border-bottom: 1px solid var(--line);
}
.item:hover { background: var(--panel-2); }
.item.selected { background: var(--selected); }
.item .meta { min-width: 0; }
.item .row1, .item .row2 { display: flex; align-items: center; gap: 6px; min-width: 0; }
.item .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.item .reason { color: var(--human); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .side { display: grid; justify-items: end; gap: 4px; align-self: start; padding-top: 2px; }
.item .time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.avatar {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 600;
  background: var(--panel-2); color: var(--muted); flex: none; font-size: 16px;
}
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; vertical-align: middle;
  white-space: nowrap;
}
.badge.bot { background: var(--bot-soft); color: var(--bot-ink); }
.badge.human { background: var(--human-soft); color: var(--human); }

/* Chat */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); position: relative; }
.placeholder { margin: auto; text-align: center; padding: 24px; }
.placeholder p { margin: 4px 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel-2); min-height: 60px;
}
.chat-head .avatar { width: 40px; height: 40px; font-size: 14px; }
.chat-title { min-width: 0; }
.chat-title > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.handoff-bar {
  background: var(--human-soft); color: var(--human); padding: 8px 16px; font-size: 13px; border-bottom: 1px solid var(--line);
}
.messages { flex: 1; overflow-y: auto; padding: 16px 6% 24px; display: flex; flex-direction: column; gap: 3px; }
.day {
  align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 8px;
  margin: 10px 0 6px; box-shadow: var(--shadow); text-transform: uppercase; letter-spacing: .02em;
}
.bubble {
  max-width: min(78%, 560px); padding: 6px 8px 6px 9px; border-radius: 8px; box-shadow: var(--shadow);
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; position: relative;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); }
.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble.first.in { border-top-left-radius: 0; margin-top: 6px; }
.bubble.first.out { border-top-right-radius: 0; margin-top: 6px; }
.bubble .stamp { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--muted); }
.bubble a { color: #027eb5; }
.bubble .who { display: block; font-size: 11.5px; font-weight: 600; color: var(--bot-ink); margin-bottom: 1px; }
.media {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-style: italic;
}
.media svg { flex: none; }
.notice {
  align-self: center; background: var(--notice); color: var(--notice-ink); font-size: 12.5px; padding: 5px 12px;
  border-radius: 8px; margin: 6px 0; box-shadow: var(--shadow); text-align: center; max-width: 90%;
}
.notice strong { font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--panel);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 10; max-width: calc(100% - 32px);
}

/* Celular */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .chat { display: none; }
  .app.open .sidebar { display: none; }
  .app.open .chat { display: flex; height: 100dvh; }
  .back { display: grid; margin-left: -8px; }
  .messages { padding: 12px 10px 20px; }
  .bubble { max-width: 88%; }
  .chat-head { padding: 8px 10px; }
  .side-head { padding-top: max(14px, env(safe-area-inset-top)); }
}
