:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #1d2129; --muted: #5f6672; --line: #dfe2e7;
  --primary: #0b6b4f; --primary-bg: #0b6b4f; --on-primary: #fff;
  --red: #b42318; --red-bg: #fde8e7; --blue: #1f5fbf; --blue-bg: #e6eefb; --green: #0b6b4f; --green-bg: #e3f4ee;
  --bubble-in: #ffffff; --bubble-bot: #eef0f3; --bubble-admin: #d9f2e6; --focus: #1f5fbf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1a1e24; --text: #e6e8eb; --muted: #a1a8b3; --line: #2c323b;
    --primary: #4cc79b; --primary-bg: #13785a; --on-primary: #fff;
    --red: #ff8a80; --red-bg: #3a1d1b; --blue: #8ab4ff; --blue-bg: #1b2840; --green: #4cc79b; --green-bg: #15302a;
    --bubble-in: #20252c; --bubble-bot: #2a3038; --bubble-admin: #163b2f; --focus: #8ab4ff;
  }
}
* { 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; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .center { text-align: center; padding: 24px; }
.err { color: var(--red); min-height: 1em; margin: 6px 0 0; } .pad { padding: 0 12px; }
code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
input, textarea { width: 100%; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--on-primary); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 1px 8px; background: var(--bubble-bot); color: var(--muted); }
.pill.red { background: var(--red-bg); color: var(--red); } .pill.blue { background: var(--blue-bg); color: var(--blue); } .pill.green { background: var(--green-bg); color: var(--green); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row input { flex: 1; min-width: 120px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; } .login-card .btn { width: 100%; margin-top: 14px; }

/* app frame */
.app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { color: var(--primary); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab { font: inherit; background: none; border: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.tab.on { color: var(--text); background: var(--bg); font-weight: 600; }
.flag { font-size: 11px; font-weight: 700; color: var(--red); border: 1px solid var(--red); border-radius: 6px; padding: 1px 6px; }

/* inbox */
.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: 320px 1fr; }
.list-pane { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.filters { display: flex; gap: 6px; padding: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.chip { font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.chip.on { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--on-primary); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.conv:hover { background: var(--bg); } .conv.on { background: var(--blue-bg); }
.conv .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 12px; color: var(--muted); }
.conv .last { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv .tags { display: flex; gap: 4px; justify-content: flex-end; }
.unread { background: var(--primary-bg); color: var(--on-primary); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 0 7px; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; }
.grow { flex: 1; display: grid; place-items: center; }
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head .who { flex: 1; min-width: 0; } .chat-head .name { font-weight: 600; }
.chat-head .who > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.reason { background: var(--red-bg); color: var(--red); padding: 6px 12px; font-size: 13px; }
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(560px, 82%); padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--line); }
.msg.customer { align-self: flex-start; background: var(--bubble-in); }
.msg.bot { align-self: flex-end; background: var(--bubble-bot); }
.msg.admin { align-self: flex-end; background: var(--bubble-admin); }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg.failed { border-color: var(--red); }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: 999px; padding: 2px 10px; }
.note { background: var(--red-bg); color: var(--red); padding: 6px 12px; font-size: 13px; }
.composer { display: flex; gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea, .composer input { flex: 1; }

/* settings */
.settings { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 14px; max-width: 760px; width: 100%; margin: 0 auto; align-content: start; }
.switch { display: flex; gap: 8px; align-items: center; font-weight: 600; margin: 0; }
.switch input { width: auto; }
.status { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.status .ok { color: var(--green); font-weight: 700; } .status .no { color: var(--red); font-weight: 700; }
.test-msgs { min-height: 120px; max-height: 360px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.settings .composer { padding: 10px 0 0; background: none; border: none; }
.out { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; font-size: 12.5px; overflow-x: auto; }
details { margin-top: 12px; } summary { cursor: pointer; color: var(--muted); }

/* phone */
@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox.chat-open .list-pane { display: none; }
  .inbox:not(.chat-open) .chat-pane { display: none; }
  .back { display: inline-block; }
  .brand { display: none; }
  .chat-head { flex-wrap: wrap; }
  .settings { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
