:root {
  color-scheme: dark;
  --bg: #0c0d0f;
  --surface: #121417;
  --surface-2: #181b1f;
  --surface-3: #20242a;
  --line: #2a2e34;
  --line-soft: #202329;
  --text: #f4f4f2;
  --muted: #9b9da2;
  --faint: #656870;
  --accent: #e3362c;
  --accent-hover: #f04a40;
  --success: #3dc98b;
  --warning: #e2aa45;
  --radius: 12px;
  --sidebar: 278px;
  --queue: 340px;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Noto Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid #ff6b62; outline-offset: 2px; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: relative; z-index: 3; display: flex; flex-direction: column; min-width: 0; height: 100vh; padding: 18px 14px 14px; background: #0a0b0d; border-right: 1px solid var(--line-soft); }
.brand-block { display: flex; align-items: center; gap: 11px; padding: 2px 8px 18px; }
.brand-mark, .auth-brand > span { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #4c2322; border-radius: 9px; background: #1e1112; color: #ff6258; font-weight: 800; }
.brand-block div:last-child, .auth-brand div { display: flex; flex-direction: column; line-height: 1.05; }
.brand-block strong { letter-spacing: .01em; }
.brand-block span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.new-chat { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }
.new-chat:hover { background: var(--surface-2); }
.new-chat span:first-child { color: var(--accent-hover); font-size: 20px; }
.conversation-list { flex: 1; min-height: 0; margin: 14px 0; overflow: auto; }
.conversation-item { width: 100%; padding: 10px 11px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); text-align: left; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; }
.conversation-item:hover, .conversation-item.active { background: var(--surface-2); color: var(--text); }
.empty-list { margin: 14px 10px; color: var(--faint); font-size: 13px; line-height: 1.5; }
.sidebar-bottom { display: grid; gap: 10px; }
.download-link { display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 0 10px; border: 1px solid var(--line-soft); border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 12px; }
.download-link:hover { background: var(--surface-2); color: var(--text); }
.download-link > span:first-child { color: var(--accent-hover); font-size: 16px; }
.locale-switcher { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border: 1px solid var(--line-soft); border-radius: 9px; background: var(--surface); }
.locale-switcher button { min-height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--faint); font-size: 11px; cursor: pointer; }
.locale-switcher button.active { background: var(--surface-3); color: var(--text); }
.account-button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 9px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; text-align: left; }
.account-button:hover { background: var(--surface-2); }
.account-avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: #272b31; color: var(--muted); font-size: 12px; }
.account-copy { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.account-copy strong, .account-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: 13px; }
.account-copy small { margin-top: 3px; color: var(--faint); font-size: 11px; }

.workspace { min-width: 0; height: 100vh; background: var(--bg); }
.workspace-header { display: flex; align-items: center; justify-content: space-between; height: 62px; padding: 0 22px; border-bottom: 1px solid var(--line-soft); background: rgba(12, 13, 15, .96); }
.workspace-title { display: flex; flex-direction: column; }
.workspace-title strong { font-size: 14px; }
.workspace-title span { margin-top: 3px; color: var(--faint); font-size: 11px; }
.header-actions { display: flex; align-items: center; gap: 16px; }
.connection-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.connection-state.online i { background: var(--success); }
.queue-toggle { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; font-size: 12px; }
.queue-toggle b { display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #2a1a1b; color: #ff7b72; font-size: 10px; }
.chat-panel { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: calc(100vh - 62px); }
.messages { width: min(850px, 100%); margin: 0 auto; padding: 42px 28px 20px; overflow: auto; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; margin-bottom: 30px; }
.message.user-message { grid-template-columns: minmax(0, 1fr); }
.message.user-message .message-body { justify-self: end; max-width: 82%; padding: 10px 14px; border-radius: 14px 14px 3px 14px; background: var(--surface-3); }
.message-avatar { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid #492321; border-radius: 9px; background: #1c1112; color: #ff6b62; font-weight: 700; }
.message-author { margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.message-body p { margin: 0; color: #dededb; font-size: 15px; line-height: 1.72; white-space: pre-wrap; }
.message-meta { margin-top: 7px; color: var(--faint); font-size: 10px; }
.composer-wrap { width: min(850px, calc(100% - 42px)); margin: 0 auto; padding-bottom: 20px; }
.composer { display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; align-items: end; gap: 8px; padding: 9px; border: 1px solid #363a41; border-radius: 15px; background: #17191d; box-shadow: 0 12px 32px rgba(0,0,0,.24); }
.composer:focus-within { border-color: #555b65; }
.composer textarea { max-height: 180px; min-height: 34px; resize: none; padding: 7px 4px; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.45; }
.composer textarea::placeholder { color: #747780; }
.attach-button, .send-button, .icon-button { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; }
.attach-button { color: var(--muted); font-size: 22px; }
.attach-button:hover, .icon-button:hover { background: var(--surface-3); }
.send-button { background: var(--text); color: #111; font-size: 20px; font-weight: 700; }
.send-button:hover { background: white; }
.send-button:disabled { opacity: .35; cursor: not-allowed; }
.composer-note { margin: 8px 0 0; color: var(--faint); font-size: 10px; text-align: center; }

.task-panel { position: fixed; z-index: 5; top: 0; right: 0; width: min(var(--queue), 100vw); height: 100vh; padding: 18px; border-left: 1px solid var(--line); background: #101216; box-shadow: -20px 0 50px rgba(0,0,0,.32); transform: translateX(102%); transition: transform .18s ease; }
.task-panel.open { transform: translateX(0); }
.task-panel-header { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: 16px; border-bottom: 1px solid var(--line-soft); }
.task-panel-header div { display: flex; flex-direction: column; }
.task-panel-header span { margin-top: 4px; color: var(--faint); font-size: 11px; }
.scope-control { display: grid; gap: 7px; margin: 18px 0; }
.scope-control label { color: var(--muted); font-size: 12px; }
.scope-control select { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); }
.task-list { overflow: auto; max-height: calc(100vh - 170px); }
.task-item { padding: 12px; margin-bottom: 8px; border: 1px solid var(--line-soft); border-radius: 9px; background: var(--surface); }
.task-item strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; }
.task-item span { display: flex; justify-content: space-between; margin-top: 8px; color: var(--faint); font-size: 10px; }
.task-state { color: var(--warning); }

.auth-dialog { width: min(430px, calc(100vw - 30px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: #131519; color: var(--text); box-shadow: 0 32px 80px rgba(0,0,0,.55); }
.auth-dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(3px); }
.auth-card { position: relative; display: grid; gap: 10px; padding: 28px; }
.auth-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.auth-brand small { margin-top: 3px; color: var(--muted); }
.auth-card h2 { margin: 5px 0 0; font-size: 23px; }
.auth-card > p { margin: 0 0 10px; color: var(--muted); line-height: 1.5; }
.auth-card label { margin-top: 5px; color: var(--muted); font-size: 12px; }
.auth-card input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: #0d0f12; color: var(--text); }
.phone-row, .code-row { display: flex; gap: 8px; align-items: center; }
.phone-row > span { display: grid; place-items: center; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: #0d0f12; color: var(--muted); }
.code-row button { flex: 0 0 auto; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-3); cursor: pointer; }
.primary-button { min-height: 44px; margin-top: 10px; border: 0; border-radius: 9px; background: var(--accent); color: white; font-weight: 650; cursor: pointer; }
.primary-button:hover { background: var(--accent-hover); }
.primary-button:disabled, .code-row button:disabled { opacity: .45; cursor: not-allowed; }
.dialog-close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.auth-status { min-height: 20px; color: #ff8f87 !important; font-size: 12px; }
.toast { position: fixed; z-index: 10; bottom: 24px; left: 50%; max-width: calc(100vw - 30px); padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: #20242a; opacity: 0; transform: translate(-50%, 15px); transition: .18s ease; pointer-events: none; font-size: 12px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 88vw); transform: translateX(-102%); transition: transform .18s ease; box-shadow: 18px 0 50px rgba(0,0,0,.45); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: grid; }
  .workspace-header { padding: 0 13px; }
  .connection-state { display: none; }
  .messages { padding: 28px 16px 12px; }
  .composer-wrap { width: calc(100% - 24px); padding-bottom: 12px; }
  .queue-toggle > span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; }
}
