:root{
  --bg:#f4f6fb; --card:#fff; --ink:#0f172a; --muted:#64748b;
  --brand:#2563eb; --brand-2:#1d4ed8; --line:#e5e7eb;
  --bubble-visitor:#e9efff; --bubble-agent:#f1f5f9;
}
*{box-sizing:border-box}
html,body{margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;background:var(--bg);color:var(--ink)}
button{cursor:pointer;border:0;border-radius:8px;padding:10px 14px;background:var(--brand);color:#fff;font-weight:600}
button:hover{background:var(--brand-2)}
input[type=text],input[type=password]{width:100%;padding:10px 12px;border:1px solid var(--line);border-radius:8px;font:inherit;background:#fff}
.muted{color:var(--muted);font-size:12px}
.error{background:#fee2e2;color:#991b1b;padding:8px 10px;border-radius:8px;margin-bottom:10px;font-size:14px}

/* ===== Visitor chat ===== */
.chat-page{display:flex;align-items:center;justify-content:center;min-height:100vh;padding:16px}
.chat-card{background:var(--card);width:100%;max-width:440px;height:80vh;max-height:720px;border-radius:16px;box-shadow:0 12px 40px rgba(15,23,42,.12);display:flex;flex-direction:column;overflow:hidden}
.chat-header{display:flex;align-items:center;gap:12px;padding:14px 16px;border-bottom:1px solid var(--line);background:linear-gradient(135deg,var(--brand),var(--brand-2));color:#fff}
.chat-header .name{color:#fff;font-weight:700;display:flex;align-items:center;gap:6px}
.chat-header .sub{color:rgba(255,255,255,.85);font-size:12px}
.avatar-wrap{position:relative;width:42px;height:42px;flex-shrink:0}
.avatar-wrap img,.avatar-fallback{width:42px;height:42px;border-radius:50%;object-fit:cover;background:#cbd5e1;display:flex;align-items:center;justify-content:center;font-weight:700;color:#fff}
.status-dot{position:absolute;right:0;bottom:0;width:11px;height:11px;background:#22c55e;border:2px solid #fff;border-radius:50%}
.verified{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border-radius:50%;background:#1d9bf0;color:#fff;font-size:11px;line-height:1;font-weight:900}

.name-gate{padding:24px;display:flex;flex-direction:column;gap:10px;margin:auto;width:100%;max-width:320px}
.name-gate label{font-weight:600}

.messages{flex:1;overflow-y:auto;padding:14px;display:flex;flex-direction:column;gap:8px;background:#fafbff}
.bubble{max-width:78%;padding:8px 12px;border-radius:14px;font-size:14px;line-height:1.35;word-wrap:break-word;white-space:pre-wrap}
.bubble.visitor{align-self:flex-end;background:var(--brand);color:#fff;border-bottom-right-radius:4px}
.bubble.agent{align-self:flex-start;background:var(--bubble-agent);color:var(--ink);border-bottom-left-radius:4px}
.bubble .meta{display:block;font-size:11px;opacity:.7;margin-bottom:2px}
.bubble.agent .meta{display:flex;align-items:center;gap:4px;color:var(--muted)}

.composer{display:flex;gap:8px;padding:10px;border-top:1px solid var(--line);background:#fff}
.composer input{flex:1}

/* ===== Agent ===== */
.agent-page{min-height:100vh}
.login-card{max-width:360px;margin:80px auto;background:#fff;padding:28px;border-radius:14px;box-shadow:0 12px 40px rgba(15,23,42,.08)}
.login-card h1{margin:0 0 16px;font-size:20px}
.login-card label{display:block;margin:10px 0 6px;font-weight:600;font-size:14px}
.login-card button{width:100%;margin-top:14px}

.agent-shell{display:grid;grid-template-columns:320px 1fr;height:100vh}
.agent-sidebar{border-right:1px solid var(--line);padding:14px;display:flex;flex-direction:column;background:#fff;overflow-y:auto}
.agent-me{display:flex;align-items:center;gap:10px;margin-bottom:10px}
.me-info .name{font-weight:700;display:flex;align-items:center;gap:6px}
.me-info .sub{font-size:12px;color:var(--muted)}
.avatar-form{display:flex;align-items:center;gap:10px;margin:6px 0 16px}
.upload-btn{background:#eef2ff;color:var(--brand-2);padding:6px 10px;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer}
.upload-btn:hover{background:#e0e7ff}
.agent-sidebar h3{margin:8px 0;font-size:13px;text-transform:uppercase;color:var(--muted);letter-spacing:.06em}
.conv-list{list-style:none;margin:0;padding:0;flex:1}
.conv-list li{padding:10px;border-radius:10px;cursor:pointer;margin-bottom:4px}
.conv-list li:hover{background:#f1f5f9}
.conv-list li.active{background:#eef2ff}
.conv-list .ttl{font-weight:600;font-size:14px;display:flex;justify-content:space-between}
.conv-list .prev{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.logout{display:block;margin-top:12px;text-align:center;color:var(--muted);text-decoration:none;font-size:13px}

.agent-main{display:flex;flex-direction:column;background:var(--bg)}
.empty{margin:auto;color:var(--muted)}
#agent-chat{display:flex;flex-direction:column;height:100%}
.chat-sub-header{padding:12px 16px;background:#fff;border-bottom:1px solid var(--line);font-weight:700}

@media (max-width:760px){
  .agent-shell{grid-template-columns:1fr}
  .agent-sidebar{height:auto;max-height:45vh}
}
