    :root {
      --bg: #f4f7fb;
      --panel: #ffffff;
      --border: #e5eaf2;
      --text: #1f2937;
      --muted: #6b7280;
      --me: #2563eb;
      --me-text: #ffffff;
      --other: #eef2ff;
      --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    }

    * {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      min-height: 100vh;
      min-height: 100dvh;
      display: block;
      background:
        radial-gradient(circle at 10% 10%, #dbeafe 0, transparent 45%),
        radial-gradient(circle at 90% 90%, #e0e7ff 0, transparent 45%),
        var(--bg);
      font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
      color: var(--text);
      padding: 0;
    }

    .chat-app {
      position: relative;
      width: 100%;
      height: 100vh;
      height: 100dvh;
      background: var(--panel);
      border: none;
      border-radius: 0;
      box-shadow: none;
      display: grid;
      grid-template-rows: 64px 1fr auto;
      overflow: hidden;
    }

    .chat-header {
      position: relative;
      z-index: 30;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: max(10px, env(safe-area-inset-top)) 14px 10px;
      border-bottom: 1px solid var(--border);
      background: rgba(255, 255, 255, 0.9);
      backdrop-filter: blur(8px);
    }

    .chat-title {
      display: flex;
      align-items: center;
      gap: 12px;
      font-weight: 700;
      position: relative;
    }

    .avatar {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      display: grid;
      place-items: center;
      color: #fff;
      background: linear-gradient(135deg, #3b82f6, #1d4ed8);
      font-size: 14px;
      flex: 0 0 auto;
    }

    .menu-trigger {
      border: none;
      background: none;
      padding: 0;
      margin: 0;
      border-radius: 999px;
      cursor: pointer;
      display: inline-grid;
      place-items: center;
      -webkit-tap-highlight-color: transparent;
    }

    .menu-trigger:focus-visible {
      outline: 2px solid #93c5fd;
      outline-offset: 2px;
    }

    .header-menu {
      position: absolute;
      top: calc(100% + 8px);
      left: 0;
      min-width: 150px;
      background: rgba(255, 255, 255, 0.92);
      border: 1px solid rgba(226, 232, 240, 0.95);
      border-radius: 14px;
      box-shadow: 0 16px 32px rgba(15, 23, 42, 0.12);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      padding: 6px;
      display: grid;
      gap: 4px;
      z-index: 100;
    }

    .header-menu[hidden] {
      display: none;
    }

    .menu-item {
      width: 100%;
      border: none;
      background: transparent;
      text-align: left;
      border-radius: 10px;
      padding: 10px 12px;
      font: inherit;
      font-size: 14px;
      color: var(--text);
      cursor: pointer;
    }

    .menu-item:hover,
    .menu-item:focus-visible {
      background: rgba(59, 130, 246, 0.08);
      outline: none;
    }

    .menu-item.danger {
      color: #b91c1c;
    }

    .menu-item.danger:hover,
    .menu-item.danger:focus-visible {
      background: rgba(239, 68, 68, 0.08);
    }

    .status {
      font-size: 12px;
      color: var(--muted);
      font-weight: 500;
    }

    .chat-body {
      position: relative;
      z-index: 1;
      padding: 14px 12px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 12px;
      background: linear-gradient(180deg, #fbfcff 0%, #f8fbff 100%);
    }

    .day-divider {
      align-self: center;
      font-size: 12px;
      color: var(--muted);
      background: rgba(255, 255, 255, 0.85);
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 4px 10px;
    }

    .empty-state {
      margin: auto 0;
      align-self: center;
      text-align: center;
      color: var(--muted);
      font-size: 13px;
      padding: 14px 16px;
      border-radius: 12px;
      background: rgba(255, 255, 255, 0.68);
      border: 1px solid var(--border);
      box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
    }

    .empty-state[hidden] {
      display: none;
    }

    .msg-row {
      display: flex;
      gap: 10px;
      align-items: flex-end;
      max-width: 88%;
    }

    .msg-row.me {
      align-self: flex-end;
      flex-direction: row-reverse;
    }

    .msg-bubble {
      position: relative;
      max-width: 100%;
      padding: 10px 12px;
      border-radius: 16px;
      line-height: 1.45;
      font-size: 14px;
      white-space: pre-wrap;
      overflow-wrap: anywhere;
      box-shadow:
        0 10px 24px rgba(15, 23, 42, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.28);
      word-break: break-word;
      border: 1px solid rgba(255, 255, 255, 0.28);
      backdrop-filter: blur(12px) saturate(135%);
      -webkit-backdrop-filter: blur(12px) saturate(135%);
      overflow: hidden;
    }

    .msg-code-block {
      position: relative;
      z-index: 1;
      max-width: 100%;
      margin: 8px 0;
      padding: 10px 12px;
      border-radius: 12px;
      overflow-x: auto;
      white-space: pre;
      word-break: normal;
      overflow-wrap: normal;
      border: 1px solid rgba(148, 163, 184, 0.22);
      background: rgba(15, 23, 42, 0.82);
      color: #e2e8f0;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    }

    .msg-code-block code {
      display: block;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
      font-size: 12px;
      line-height: 1.5;
      white-space: inherit;
    }

    .msg-row.me .msg-code-block {
      background: rgba(15, 23, 42, 0.68);
      border-color: rgba(191, 219, 254, 0.18);
      color: #eff6ff;
    }

    .msg-row.other .msg-bubble {
      background: rgba(99, 102, 241, 0.24);
      color: #0f172a;
      border-top-left-radius: 6px;
      border-color: rgba(129, 140, 248, 0.38);
      box-shadow:
        0 10px 22px rgba(79, 70, 229, 0.10),
        inset 0 1px 0 rgba(255, 255, 255, 0.24);
    }

    .msg-row.me .msg-bubble {
      background: rgba(29, 78, 216, 0.62);
      border-top-right-radius: 6px;
      color: var(--me-text);
      border-color: rgba(96, 165, 250, 0.58);
      box-shadow:
        0 14px 28px rgba(29, 78, 216, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
    }

    .msg-bubble::before {
      content: "";
      position: absolute;
      inset: 0;
      background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.26) 0%,
        rgba(255, 255, 255, 0.10) 34%,
        rgba(255, 255, 255, 0) 100%
      );
      pointer-events: none;
    }

    .msg-bubble::after {
      content: "";
      position: absolute;
      left: 8px;
      right: 8px;
      top: 5px;
      height: 10px;
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.22);
      filter: blur(2px);
      pointer-events: none;
    }

    .msg-bubble.is-pressing {
      transform: scale(0.985);
      transition: transform 0.12s ease;
    }

    .msg-bubble.is-copied {
      box-shadow:
        0 0 0 2px rgba(16, 185, 129, 0.28),
        0 12px 24px rgba(16, 185, 129, 0.16);
    }

    .msg-meta {
      font-size: 11px;
      color: var(--muted);
      margin-top: 4px;
      padding: 0 2px;
    }

    .msg-device-tag {
      align-self: flex-start;
      margin-top: 5px;
      padding: 3px 8px;
      border-radius: 999px;
      font-size: 11px;
      line-height: 1;
      color: #475569;
      background: rgba(255, 255, 255, 0.72);
      border: 1px solid rgba(226, 232, 240, 0.9);
      backdrop-filter: blur(6px);
      -webkit-backdrop-filter: blur(6px);
    }

    .msg-row.me .msg-device-tag {
      align-self: flex-end;
      color: #dbeafe;
      background: rgba(30, 41, 59, 0.20);
      border-color: rgba(191, 219, 254, 0.18);
    }

    .msg-stack {
      display: flex;
      flex-direction: column;
      min-width: 0;
      max-width: 100%;
    }

    .msg-row.me[data-local-status="sending"] .msg-bubble,
    .msg-row.me[data-local-status="queued"] .msg-bubble {
      opacity: 0.86;
    }

    .msg-row.me[data-local-status="failed"] .msg-bubble {
      border-color: rgba(239, 68, 68, 0.55);
      box-shadow:
        0 12px 22px rgba(239, 68, 68, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.16);
    }

    .msg-meta.is-error {
      color: #dc2626;
    }

    .chat-input {
      border-top: 1px solid var(--border);
      padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
      background: #fff;
    }

    .input-wrap {
      display: grid;
      grid-template-columns: auto auto 1fr auto;
      gap: 8px;
      align-items: stretch;
    }

    .attach-btn {
      border: 1px solid var(--border);
      border-radius: 14px;
      min-width: 46px;
      min-height: 46px;
      display: grid;
      place-items: center;
      font-size: 22px;
      font-weight: 600;
      color: #1d4ed8;
      background: #eff6ff;
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    }

    .attach-btn:active {
      transform: scale(0.98);
    }

    .attach-btn:disabled {
      cursor: not-allowed;
      opacity: 0.6;
    }

    .file-input {
      display: none;
    }

    .mode-toggle {
      border: 1px solid rgba(191, 219, 254, 0.9);
      border-radius: 14px;
      min-width: 56px;
      min-height: 46px;
      padding: 0 12px;
      font: inherit;
      font-size: 13px;
      font-weight: 700;
      color: #1d4ed8;
      background: #f8fbff;
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
      box-shadow: 0 8px 18px rgba(37, 99, 235, 0.08);
    }

    .mode-toggle.is-agent {
      color: #fff;
      background: linear-gradient(135deg, #0f766e, #0f766e 45%, #155e75);
      border-color: rgba(15, 118, 110, 0.9);
      box-shadow: 0 10px 20px rgba(15, 118, 110, 0.24);
    }

    .mode-toggle:active {
      transform: scale(0.98);
    }

    .input-box {
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 12px 14px;
      min-height: 46px;
      max-height: 120px;
      resize: none;
      font: inherit;
      font-size: 16px;
      color: inherit;
      outline: none;
      background: #fbfdff;
      transition: border-color 0.15s ease, box-shadow 0.15s ease;
    }

    .input-box:focus {
      border-color: #93c5fd;
      box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
    }

    .send-btn {
      border: none;
      border-radius: 14px;
      padding: 0 14px;
      min-width: 68px;
      min-height: 46px;
      height: auto;
      font: inherit;
      font-weight: 700;
      color: #fff;
      background: linear-gradient(135deg, #2563eb, #1d4ed8);
      cursor: pointer;
      box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
      align-self: stretch;
    }

    .msg-image {
      display: block;
      max-width: 240px;
      max-height: 240px;
      border-radius: 12px;
      object-fit: cover;
    }

    .msg-video {
      display: block;
      max-width: 260px;
      max-height: 260px;
      border-radius: 12px;
      background: #0f172a;
    }

    .msg-file {
      display: block;
      color: inherit;
      text-decoration: none;
      font-weight: 600;
      margin-bottom: 6px;
    }

    .msg-file-size {
      font-size: 12px;
      color: var(--muted);
    }

    .msg-bubble.typing {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      min-width: 52px;
      justify-content: center;
    }

    .typing-dot {
      width: 6px;
      height: 6px;
      border-radius: 999px;
      background: rgba(100, 116, 139, 0.7);
      animation: typingPulse 1.2s infinite ease-in-out;
    }

    .typing-dot:nth-child(2) {
      animation-delay: 0.2s;
    }

    .typing-dot:nth-child(3) {
      animation-delay: 0.4s;
    }

    @keyframes typingPulse {
      0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.6;
      }
      40% {
        transform: scale(1.2);
        opacity: 1;
      }
    }

    .send-btn:active {
      transform: translateY(1px);
    }

    .send-btn:disabled {
      cursor: not-allowed;
      opacity: 0.55;
      box-shadow: none;
      background: linear-gradient(135deg, #93c5fd, #60a5fa);
    }

    .hint {
      margin-top: 6px;
      font-size: 12px;
      color: var(--muted);
      text-align: right;
    }

    .hint.state-ok {
      color: #15803d;
    }

    .hint.state-warn {
      color: #b45309;
    }

    .hint.state-error {
      color: #b91c1c;
    }

    .copy-toast {
      position: absolute;
      left: 50%;
      bottom: calc(86px + env(safe-area-inset-bottom));
      transform: translate(-50%, 10px);
      background: rgba(17, 24, 39, 0.88);
      color: #fff;
      border-radius: 999px;
      padding: 8px 12px;
      font-size: 12px;
      line-height: 1;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.18s ease, transform 0.18s ease;
      box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
      z-index: 5;
      max-width: calc(100% - 32px);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .copy-toast.show {
      opacity: 1;
      transform: translate(-50%, 0);
    }

    .login-overlay {
      position: fixed;
      inset: 0;
      display: grid;
      place-items: center;
      background: rgba(15, 23, 42, 0.45);
      backdrop-filter: blur(6px);
      z-index: 80;
      padding: 18px;
    }

    .login-overlay[hidden] {
      display: none;
    }

    .login-card {
      width: min(360px, 92vw);
      background: #fff;
      border-radius: 18px;
      padding: 20px;
      border: 1px solid rgba(226, 232, 240, 0.9);
      box-shadow: 0 24px 40px rgba(15, 23, 42, 0.2);
      display: grid;
      gap: 14px;
      text-align: center;
    }

    .login-title {
      font-weight: 700;
      font-size: 18px;
    }

    .login-desc {
      font-size: 13px;
      color: var(--muted);
    }

    .login-input {
      width: 100%;
      border-radius: 12px;
      border: 1px solid var(--border);
      padding: 10px 12px;
      font-size: 14px;
      outline: none;
      transition: border 0.2s ease, box-shadow 0.2s ease;
    }

    .login-input:focus {
      border-color: #60a5fa;
      box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.25);
    }

    .login-actions {
      display: grid;
      gap: 8px;
    }

    .login-btn {
      border: none;
      border-radius: 12px;
      background: linear-gradient(135deg, #2563eb, #1d4ed8);
      color: #fff;
      padding: 10px 12px;
      font-weight: 600;
      cursor: pointer;
    }

    .login-btn:disabled {
      opacity: 0.6;
      cursor: default;
    }

    .login-error {
      font-size: 12px;
      color: #dc2626;
      min-height: 16px;
    }

    @media (min-width: 768px) {
      body {
        display: grid;
        place-items: center;
        padding: 20px;
      }

      .chat-app {
        width: calc(100vw - 40px);
        height: calc(100vh - 40px);
        height: calc(100dvh - 40px);
        border: 1px solid var(--border);
        border-radius: 24px;
        box-shadow: var(--shadow);
      }

      .msg-row {
        max-width: 86%;
      }
    }
  
