.topbar {
  height: 66px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 20, 37, 0.88);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .agent-name { font-weight: 650; font-size: 15px; }
.topbar .agent-sub { font-size: 12px; color: var(--muted); }
.topbar .status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  display: inline-block; margin-right: 6px;
  box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.15);
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 999px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 750; font-size: 13px; color: #fff;
}
.user-chip .name { font-size: 13px; font-weight: 650; line-height: 1.1; }
.user-chip .role { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
  height: calc(100vh - 66px);
  overflow: hidden;
}
.conv-sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.conv-sidebar .side-head { padding: 16px; border-bottom: 1px solid var(--line); }
.conv-list { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.conv-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 11px;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  font: inherit;
}
.conv-item:hover { background: var(--panel); }
.conv-item.active { background: var(--panel-2); border-color: var(--line); }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conv-item .conv-count { font-size: 11px; color: var(--muted); }
.conv-item .del {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 6px; opacity: 0;
}
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--danger); background: rgba(239, 83, 80, 0.12); }
.side-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

.chat-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-head {
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
}
.chat-head h2 { font-size: 16px; margin: 0; }
.chat-head .sub { font-size: 12px; color: var(--muted); }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.msg { display: flex; gap: 10px; max-width: 86%; }
.msg .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px;
  padding: 11px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.55;
}
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800; font-size: 13px;
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .bubble {
  background: linear-gradient(135deg, rgba(230, 0, 126, 0.22), rgba(123, 92, 255, 0.24));
  border-color: rgba(123, 92, 255, 0.35);
  border-radius: 14px 14px 4px 14px;
}
.msg.user .msg-avatar { background: var(--panel-3); color: var(--text); }
.msg.error .bubble { border-color: rgba(239, 83, 80, 0.45); background: rgba(239, 83, 80, 0.08); }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: bounce 1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.12s; }
.typing span:nth-child(3) { animation-delay: 0.24s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-4px); opacity: 1; } }
.delta-cursor::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.action-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 22px 10px; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.chip:hover { background: var(--panel-2); border-color: var(--accent-2); }

.composer {
  border-top: 1px solid var(--line);
  padding: 14px 18px 18px;
  background: var(--bg);
}
.composer-inner {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s ease;
}
.composer-inner:focus-within { border-color: var(--accent-2); }
.composer textarea {
  border: 0; background: transparent; box-shadow: none; padding: 6px 0;
  min-height: 24px; max-height: 160px; resize: none;
}
.composer textarea:focus { box-shadow: none; }
.composer .hint { padding: 6px 4px 0; }

.account-panel {
  border-left: 1px solid var(--line);
  background: var(--bg-2);
  overflow-y: auto;
  padding: 18px;
  min-height: 0;
}
.account-panel h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 10px; }
.acct-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.acct-plan { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.acct-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13.5px; border-bottom: 1px dashed rgba(255,255,255,0.05); }
.acct-row:last-child { border-bottom: 0; }
.acct-row .k { color: var(--muted); }
.acct-row .v { font-weight: 600; text-align: right; }
.acct-list { display: flex; flex-direction: column; gap: 8px; }
.acct-item { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.acct-item .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 650; }
.acct-item .bot { color: var(--muted); font-size: 12px; margin-top: 3px; display: flex; justify-content: space-between; gap: 8px; }
.debt-big { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.section-label { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .account-panel { display: none; }
  .account-panel.open {
    display: block;
    position: fixed;
    top: 66px; right: 0; bottom: 0;
    width: min(360px, 92vw);
    z-index: 30;
    box-shadow: -20px 0 50px rgba(0,0,0,0.4);
  }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .conv-sidebar {
    position: fixed;
    top: 66px; bottom: 0; left: 0;
    width: min(300px, 86vw);
    z-index: 30;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: 20px 0 50px rgba(0,0,0,0.4);
  }
  .conv-sidebar.open { transform: none; }
  .msg { max-width: 94%; }
  .messages { padding: 16px; }
  .topbar { padding: 0 14px; }
  .topbar .agent-name { display: none; }
  .composer { padding: 10px 12px 14px; }
  .action-chips { padding: 0 12px 8px; }
  #menuToggle { display: inline-flex !important; }
  #accountToggle { display: inline-flex !important; }
}

/* ---------- guest / public demo ---------- */
.guest-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  height: calc(100vh - 66px);
  overflow: hidden;
}
.guest-banner {
  margin: 14px 22px 0;
  border: 1px solid rgba(123, 92, 255, 0.35);
  background: linear-gradient(135deg, rgba(230, 0, 126, 0.12), rgba(123, 92, 255, 0.12));
  border-radius: 12px;
  padding: 12px 14px;
}
.guest-banner .title { font-weight: 650; font-size: 13px; margin-bottom: 4px; }
.demo-codes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.demo-code {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
}
.demo-code:hover { border-color: var(--accent-2); }
.demo-code b { display: block; font-size: 13px; }
.demo-code span { color: var(--muted); font-size: 11.5px; }
.guest-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.guest-body { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.guest-body .messages { padding-top: 16px; }
.guest-account .acct-card { margin-bottom: 12px; }
.guest-verify { border: 1px dashed var(--line); border-radius: 12px; padding: 14px; color: var(--muted); font-size: 13px; line-height: 1.6; }
@media (max-width: 1180px) {
  .guest-shell { grid-template-columns: minmax(0, 1fr); }
  .guest-shell .account-panel { display: none; }
  .guest-shell .account-panel.open {
    display: block;
    position: fixed;
    top: 66px; right: 0; bottom: 0;
    width: min(360px, 92vw);
    z-index: 30;
    box-shadow: -20px 0 50px rgba(0,0,0,0.4);
  }
}
@media (max-width: 760px) {
  .guest-banner { margin: 10px 12px 0; }
  .guest-shell { height: calc(100vh - 66px); }
  #guestAccountToggle { display: inline-flex !important; }
}
