:root {
  color-scheme: light;
  --canvas: #ffffff;
  --canvas-soft: #fafafa;
  --canvas-hover: #f3f4f3;
  --ink: #171717;
  --ink-secondary: #363b38;
  --muted: #6a716d;
  --line: #e3e7e4;
  --line-strong: #c7ceca;
  --primary: #3ecf8e;
  --primary-hover: #31bf80;
  --green-ink: #12633f;
  --green-soft: #edf8f1;
  --outgoing: #e9f5ee;
  --warning-bg: #fff8e9;
  --warning-ink: #815411;
  --error: #a83530;
  --error-bg: #fff3f1;
  --radius: 6px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
button, a { touch-action: manipulation; }
button, input, textarea { transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease); }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--green-ink); outline-offset: 4px; }
input:focus, textarea:focus { outline: none; }
input:focus-visible { border-color: var(--green-ink); outline: 2px solid var(--green-soft); outline-offset: 2px; }
::selection { background: #c5efd8; color: var(--ink); }
input, textarea { caret-color: var(--green-ink); }
::placeholder { color: var(--muted); opacity: 1; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 500; text-wrap: balance; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -80px; left: 16px; z-index: 10; background: var(--ink); color: var(--canvas); padding: 12px; border-radius: var(--radius); }
.skip-link:focus { top: 12px; }

.topbar { height: 76px; border-bottom: 1px solid var(--line); }
.topbar-inner { height: 100%; max-width: 1376px; margin-inline: auto; padding-inline: 40px; display: flex; align-items: center; gap: 24px; }
.brand { color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 600; letter-spacing: -.04em; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; color: var(--ink); background: var(--primary); border-radius: 9px; }
.brand-mark .icon { width: 21px; height: 21px; stroke-width: 1.8; }
.nav-divider { width: 1px; height: 20px; background: var(--line); }
.nav-label { font-size: 13px; color: var(--ink-secondary); }
.server-chip { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; color: var(--muted); font-size: 12px; }
.server-chip .icon { width: 16px; height: 16px; }
#server-host { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-indicator { width: 6px; height: 6px; background: var(--line-strong); border-radius: 50%; margin-left: 3px; flex-shrink: 0; }
.server-indicator.connected { background: var(--green-ink); }
.icon-button { background: transparent; border: 0; color: var(--muted); width: 36px; height: 36px; padding: 8px; display: inline-grid; place-items: center; border-radius: var(--radius); flex-shrink: 0; }
.icon-button:hover { background: var(--canvas-hover); color: var(--ink); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 8px 13px; border-radius: var(--radius); border: 1px solid transparent; font-size: 13px; font-weight: 500; white-space: nowrap; }
.button .icon { width: 16px; height: 16px; }
.primary { background: var(--primary); color: var(--ink); }
.primary:hover:not(:disabled) { background: var(--primary-hover); }
.primary:active:not(:disabled) { background: #24b47e; }
.secondary { background: var(--canvas); border-color: var(--line); color: var(--ink-secondary); }
.secondary:hover { background: var(--canvas-soft); border-color: var(--line-strong); }
.text-button { background: transparent; border: 0; padding: 8px 0; color: var(--muted); font-size: 12px; text-align: left; border-radius: 3px; }
.text-button:hover:not(:disabled) { color: var(--green-ink); text-decoration: underline; text-underline-offset: 4px; }

.connect-view { max-width: 368px; margin: min(15vh, 136px) auto 64px; padding: 0 4px; }
.connect-symbol { margin-bottom: 24px; color: var(--green-ink); }
.connect-symbol .icon { width: 30px; height: 30px; }
.connect-view h1 { font-size: 26px; letter-spacing: -.02em; }
.connect-description { margin-top: 12px; color: var(--muted); line-height: 1.7; }
.connect-form { margin-top: 32px; }
.connect-form label { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 500; }
.connect-form input { display: block; width: 100%; height: 44px; padding: 10px 12px; background: var(--canvas); border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--ink); }
.field-hint { font-size: 12px; color: var(--muted); line-height: 1.7; margin-top: 10px; }
.error-text { color: var(--error); font-size: 12px; line-height: 1.7; margin-top: 12px; overflow-wrap: anywhere; }
.connect-button { width: 100%; justify-content: space-between; margin-top: 24px; min-height: 42px; }
.connect-footnote { border-top: 1px solid var(--line); margin-top: 32px; padding-top: 20px; font-size: 12px; color: var(--muted); }

.workspace { max-width: 1376px; margin-inline: auto; padding: 38px 40px 20px; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 28px; }
.page-heading h1 { font-size: 26px; line-height: 1.4; letter-spacing: -.02em; }
.page-heading p { color: var(--muted); font-size: 13px; margin-top: 10px; line-height: 1.6; }
.notice { padding: 12px 16px; border-radius: var(--radius); background: var(--warning-bg); color: var(--warning-ink); line-height: 1.6; font-size: 12px; margin-bottom: 16px; }
.conversation-shell { display: grid; grid-template-columns: 302px minmax(0, 1fr); border: 1px solid var(--line); border-radius: 12px; height: calc(100dvh - 268px); min-height: 480px; max-height: 820px; overflow: hidden; }
.account-pane { display: flex; flex-direction: column; background: var(--canvas-soft); border-right: 1px solid var(--line); min-height: 0; }
.account-pane-heading { padding: 25px 22px 21px; display: flex; align-items: center; gap: 9px; }
.account-pane-heading h2 { font-size: 12px; font-weight: 500; color: var(--muted); }
.count { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; min-width: 20px; text-align: center; line-height: 18px; font-variant-numeric: tabular-nums; }
.account-list { flex: 1; overflow-y: auto; padding: 0 10px 16px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.account-row { width: 100%; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 15px 11px; text-align: left; display: flex; align-items: flex-start; gap: 12px; margin-bottom: 5px; color: var(--ink); }
.account-row:hover { background: var(--canvas-hover); }
.account-row[aria-current="true"] { border-color: #d2e8da; background: var(--green-soft); }
.avatar { width: 40px; height: 40px; border-radius: 12px; background: #e7ece9; color: #42604d; font-size: 16px; display: grid; place-items: center; flex-shrink: 0; font-weight: 500; }
.account-row[aria-current="true"] .avatar { background: #d5ecde; color: var(--green-ink); }
.account-copy { flex: 1; min-width: 0; }
.account-name { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.5; }
.account-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); margin-top: 5px; }
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.account-status.ready { color: var(--green-ink); }
.account-status.warning { color: var(--warning-ink); }
.account-preview { margin-top: 10px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; line-height: 1.6; }
.account-row[aria-current="true"] .account-preview { color: #526c5e; }
.account-pane-footer { padding: 20px 22px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.account-pane-footer .icon { width: 14px; height: 14px; }
.accounts-empty { padding: 28px 14px; color: var(--muted); font-size: 12px; line-height: 1.9; }
.accounts-empty strong { display: block; font-size: 13px; font-weight: 500; color: var(--ink-secondary); margin-bottom: 6px; }
.welcome-pane { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; padding: 40px; }
.welcome-content { margin-top: -24px; text-align: center; }
.welcome-icon { width: 48px; height: 48px; stroke-width: 1; color: #84978b; margin-bottom: 24px; }
.welcome-content h2 { font-size: 21px; letter-spacing: -.01em; margin-bottom: 13px; }
.welcome-content p { color: var(--muted); font-size: 13px; line-height: 1.9; }
.message-path { margin: 32px auto 0; display: flex; align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-size: 11px; }
.path-line { width: 56px; height: 1px; background: var(--line-strong); position: relative; }
.path-line::before, .path-line::after { content: ""; position: absolute; top: -2px; width: 5px; height: 5px; border: 1px solid var(--line-strong); background: var(--canvas); border-radius: 50%; }
.path-line::before { left: 0; }
.path-line::after { right: 0; }
.welcome-footnote { position: absolute; bottom: 25px; color: var(--muted); font-size: 11px; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-header { min-height: 83px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; padding: 16px 26px; }
.chat-avatar { width: 36px; height: 36px; font-size: 14px; border-radius: 10px; }
.chat-heading { min-width: 0; flex: 1; }
.chat-heading h2 { font-size: 14px; line-height: 1.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-heading p { color: var(--muted); font-size: 11px; margin-top: 2px; line-height: 1.5; }
.back-button { display: none; }
.account-info { margin: 0; padding: 16px 26px; background: var(--canvas-soft); border-bottom: 1px solid var(--line); font-size: 12px; line-height: 1.7; }
.account-info div { display: flex; gap: 16px; }
.account-info div + div { margin-top: 7px; }
.account-info dt { color: var(--muted); width: 70px; flex-shrink: 0; }
.account-info dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
#mapping-account { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 11px; }
.chat-state-notice { padding: 11px 26px; background: var(--warning-bg); color: var(--warning-ink); font-size: 12px; line-height: 1.7; }
.history-region { flex: 1; min-height: 0; position: relative; }
.message-feed { height: 100%; padding: 24px 28px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; overscroll-behavior: contain; overflow-anchor: none; }
.messages { list-style: none; padding: 0; margin: 0; }
.message { display: flex; flex-direction: column; align-items: flex-start; margin-top: 22px; }
.message:first-child { margin-top: 0; }
.message.outgoing { align-items: flex-end; }
.message-meta { display: flex; align-items: center; gap: 9px; font-size: 11px; color: var(--muted); margin-bottom: 7px; font-variant-numeric: tabular-nums; }
.message-bubble { background: var(--canvas-soft); border: 1px solid var(--line); border-radius: 2px 12px 12px 12px; padding: 11px 15px; font-size: 13px; line-height: 1.85; max-width: min(82%, 66ch); white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.outgoing .message-bubble { color: #203f2e; background: var(--outgoing); border-color: transparent; border-radius: 12px 2px 12px 12px; }
.delivery-note { margin-top: 6px; color: var(--muted); font-size: 10px; display: flex; align-items: center; gap: 4px; }
.delivery-note .icon { width: 12px; height: 12px; }
.date-divider { display: flex; justify-content: center; color: var(--muted); font-size: 11px; padding: 10px 0 24px; }
.date-divider:not(:first-child) { padding-top: 28px; }
.chat-empty { height: 100%; min-height: 150px; display: flex; justify-content: center; flex-direction: column; align-items: center; text-align: center; color: var(--muted); }
.chat-empty h3 { color: var(--ink-secondary); font-size: 15px; margin-bottom: 10px; }
.chat-empty p { font-size: 12px; line-height: 1.9; }
.new-message-button { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); border-color: var(--line-strong); background: var(--canvas); color: var(--green-ink); font-size: 12px; }
.chat-footer { padding: 12px 24px 16px; }
.send-error { margin: 0 0 10px; }
.composer { border: 1px solid var(--line-strong); border-radius: 10px; background: var(--canvas); padding: 13px 14px 10px; }
.composer:focus-within { border-color: var(--green-ink); }
.composer textarea { width: 100%; resize: none; border: 0; padding: 0; background: transparent; color: var(--ink); display: block; line-height: 1.7; min-height: 70px; max-height: 160px; font-size: 13px; scrollbar-width: thin; }
.composer-toolbar { display: flex; align-items: center; gap: 14px; margin-top: 10px; }
.message-count { margin-left: auto; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.message-count.over-limit { color: var(--error); }
.send-button { min-height: 32px; padding: 6px 12px; }
.send-button .icon { width: 14px; height: 14px; }
.composer-hints { display: flex; justify-content: space-between; gap: 8px; margin-top: 11px; color: var(--muted); font-size: 10px; }
.hint-dot { padding-inline: 6px; }
.workspace-footer { display: flex; justify-content: space-between; gap: 16px; padding-top: 17px; font-size: 10px; color: var(--muted); }
.no-script { padding: 40px; text-align: center; }
.loading-placeholder { color: var(--muted); font-size: 12px; padding: 28px 0; }

@media (min-width: 1700px) {
  .workspace { padding-top: 52px; }
  .page-heading { margin-bottom: 36px; }
}
@media (max-width: 1050px) {
  .topbar-inner { padding-inline: 24px; }
  .workspace { padding-inline: 24px; }
  .conversation-shell { grid-template-columns: 258px minmax(0, 1fr); }
  .account-row { gap: 10px; padding-inline: 8px; }
  .avatar { width: 34px; height: 34px; font-size: 14px; border-radius: 10px; }
  .account-name { font-size: 12px; }
  .chat-header { padding-inline: 20px; }
  .message-feed { padding-inline: 20px; }
  .chat-footer { padding-inline: 18px; }
}
@media (max-width: 720px) {
  .topbar { height: 64px; }
  .topbar-inner { padding-inline: 20px; gap: 14px; }
  .brand { font-size: 20px; }
  .brand-mark { width: 29px; height: 29px; border-radius: 8px; }
  .nav-label, .nav-divider { display: none; }
  .server-chip { gap: 6px; font-size: 11px; }
  #server-host { max-width: 145px; }
  .server-chip .icon { display: none; }
  .icon-button { width: 40px; height: 40px; }
  #disconnect { margin-right: -8px; }
  .workspace { padding: 25px 18px 16px; }
  .page-heading { margin-bottom: 24px; gap: 12px; }
  .page-heading h1 { font-size: 24px; }
  .page-heading p { font-size: 12px; max-width: 24ch; }
  .page-heading .button { min-height: 40px; padding-inline: 10px; }
  .conversation-shell { display: block; min-height: 350px; height: calc(100dvh - 262px); border-radius: 10px; }
  .account-pane { height: 100%; border-right: 0; }
  .account-pane-heading { padding-top: 22px; }
  .account-row { padding: 18px 14px; gap: 14px; }
  .account-name { font-size: 14px; }
  .avatar { width: 42px; height: 42px; font-size: 16px; border-radius: 12px; }
  .account-status { font-size: 12px; }
  .account-preview { font-size: 12px; }
  .welcome-pane { display: none; }
  .workspace.has-selection { padding: 0; }
  .workspace.has-selection .page-heading, .workspace.has-selection .workspace-footer { display: none; }
  .workspace.has-selection .conversation-shell { height: calc(100dvh - 64px); min-height: 380px; max-height: none; border: 0; border-radius: 0; }
  .workspace.has-selection .account-pane { display: none; }
  .workspace.has-selection .notice { margin: 0; border-radius: 0; }
  .workspace.has-selection:has(.notice:not([hidden])) .conversation-shell { height: calc(100dvh - 120px); }
  .chat-pane { height: 100%; }
  .back-button { display: inline-grid; margin-left: -8px; }
  .chat-header { min-height: 76px; padding: 12px 16px; gap: 10px; }
  .chat-avatar { width: 34px; height: 34px; font-size: 14px; border-radius: 9px; }
  .chat-heading h2 { font-size: 13px; }
  .chat-heading p { font-size: 10px; }
  .chat-header > .icon-button:last-child { margin-right: -8px; }
  .chat-state-notice { padding-inline: 18px; }
  .message-feed { padding: 20px 18px; }
  .message-bubble { font-size: 14px; max-width: 88%; padding: 10px 13px; }
  .message-meta { font-size: 10px; }
  .chat-footer { padding: 10px 14px max(16px, env(safe-area-inset-bottom)); }
  .composer { padding: 12px; }
  .composer textarea { font-size: 16px; min-height: 66px; line-height: 1.6; }
  .composer-toolbar { gap: 10px; margin-top: 8px; }
  .text-button { min-height: 40px; }
  .send-button { min-height: 40px; padding-inline: 14px; }
  #composer-hint { display: none; }
  .composer-hints { justify-content: flex-end; margin-top: 8px; }
  .account-info { padding: 14px 18px; font-size: 11px; }
  .account-info dt { width: 60px; }
  .account-info div { gap: 10px; }
  .connect-view { margin: 64px auto 40px; max-width: 100%; width: 364px; padding-inline: 24px; }
  .connect-form input { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
