:root {
  --bg: #F3F6F9; --card: #fff; --line: #E2E8EE; --text: #1E2A35; --sub: #6B7A88;
  --accent: #0F7C8C; --accent-dark: #0B5F6E; --accent-light: #E1F2F4; --bubble: #EEF2F5;
  --good: #22A05B; --bad: #D93F44;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 9px 16px; background: var(--accent); color: #fff; font-weight: 600; }
button:hover { background: var(--accent-dark); }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.secondary:hover { border-color: var(--accent); background: #F2F7F9; }
button.link { background: none; color: var(--accent); padding: 4px 6px; font-weight: 500; }
.muted { color: var(--sub); }
.pad { padding: 16px; margin: 0; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 17px; color: var(--accent-dark); }
.brand small { color: var(--sub); }
.logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-size: 20px;
        background: linear-gradient(135deg, #1A9AAA, #0B5F78); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.login-card .brand { margin-bottom: 6px; }
label { display: grid; gap: 4px; color: var(--sub); font-size: 13px; }
input, textarea { font: inherit; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; }
input:focus, textarea:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }

/* Layout */
.app { display: grid; grid-template-columns: 320px 1fr; height: 100%; }
.sidebar { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 18px 16px 10px; }
.me { display: flex; align-items: center; gap: 8px; padding: 6px 16px 10px; color: var(--sub); }
.me .link { margin-left: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.filters { display: flex; gap: 6px; padding: 0 16px 10px; border-bottom: 1px solid var(--line); }
.chip { background: none; color: var(--sub); border: 1px solid var(--line); padding: 4px 12px; border-radius: 99px; font-weight: 500; }
.chip:hover { background: var(--bg); }
.chip.active { background: var(--accent-light); color: var(--accent-dark); border-color: transparent; }
.sessions { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.sessions li { padding: 10px 12px; border-radius: 10px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.sessions li:hover { background: #F2F7F9; }
.sessions li.active { background: var(--accent-light); }
.sessions .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sessions .time { color: var(--sub); font-size: 12px; }
.sessions .preview { color: var(--sub); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; justify-self: end; }

.chat { min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.placeholder { margin: auto; color: var(--sub); }
.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.chat-head h2 { margin: 0; font-size: 17px; }
.chat-head > div { flex: 1; min-width: 0; }
.back { display: none; font-size: 20px; }
.chat-body { flex: 1; display: grid; grid-template-columns: 1fr 260px; min-height: 0; }
.messages { overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 70%; padding: 9px 13px; border-radius: 12px 12px 12px 3px; background: var(--card); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.agent { align-self: flex-end; background: var(--accent); color: #fff; border-color: var(--accent); border-radius: 12px 12px 3px 12px; }
.msg.system { align-self: center; background: none; border: 0; color: var(--sub); font-size: 12.5px; text-align: center; max-width: 90%; }
.msg .meta { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }
.context { border-left: 1px solid var(--line); background: var(--card); padding: 18px; overflow-y: auto; }
.context h3 { margin: 0 0 12px; font-size: 14px; }
.context dt { color: var(--sub); font-size: 12px; }
.context dd { margin: 0 0 10px; font-weight: 600; overflow-wrap: anywhere; }
.reply { display: flex; gap: 10px; padding: 14px 20px; background: var(--card); border-top: 1px solid var(--line); }
.reply textarea { flex: 1; resize: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: inline-block; }
  .chat-body { grid-template-columns: 1fr; }
  .context { display: none; }
  .msg { max-width: 88%; }
  .chat-head, .messages, .reply { padding-left: 16px; padding-right: 16px; }
}
