    #doc-refresh-btn:hover:not(:disabled),
    #doc-edit-btn:hover:not(:disabled) {
      border-color: var(--border-strong);
      background: var(--bg2);
    }


    #doc-preview-content {
      flex: 1;
      min-height: 0;
      overflow-y: auto;
      padding: 14px 14px 18px;
      font-family: var(--md-font-family);
      font-size: var(--md-font-size);
      line-height: 1.65;
      white-space: pre-wrap;
    }

    #doc-preview-content.unsupported {
      color: var(--muted);
    }


    #doc-preview-content.image-preview {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 12px;
      user-select: none;
      white-space: normal;
    }


    .doc-preview-image {
      max-width: 100%;
      max-height: 100%;
      object-fit: contain;
      border-radius: 8px;
      box-shadow: 0 8px 24px rgba(7, 54, 66, 0.12);
    }


    #doc-preview-content .doc-edit-textarea {
      /* textarea 默认为 inline-block，基线对齐会把它向下推、底部超出容器，
         导致预览容器和 textarea 出现双滚动条；块级化后高度正好填满内容区。 */
      display: block;
      width: 100%;
      height: 100%;
      border: none;
      outline: none;
      resize: none;
      padding: 14px 14px 18px;
      font-family: var(--md-font-family);
      font-size: var(--md-font-size);
      line-height: 1.65;
      color: var(--text1);
      background: var(--bg);
      white-space: pre-wrap;
      tab-size: 2;
    }


    #messages {
      flex: 1;
      overflow-y: auto;
      padding: 22px;
      display: flex;
      flex-direction: column;
      gap: 18px;
      min-height: 0;
      align-items: center;
      scrollbar-gutter: stable both-edges;
      scrollbar-width: thin;
      scrollbar-color: transparent transparent;
    }

    #messages:hover {
      scrollbar-color: var(--border-strong) transparent;
    }


    #messages::-webkit-scrollbar { width: 10px; }

    #messages::-webkit-scrollbar-track { background: transparent; }

    #messages::-webkit-scrollbar-thumb {
      background: transparent;
      border: 3px solid var(--bg);
      border-radius: 999px;
    }

    #messages:hover::-webkit-scrollbar-thumb {
      background: rgba(147, 161, 161, 0.45);
    }

    /* Reserve enough trailing space for the active user message to align with
       the top of the viewport while its reply grows below it. */
    #messages.round-anchor-active::after {
      content: "";
      flex: 0 0 calc(100% - 44px);
      pointer-events: none;
    }


    #empty-state {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: var(--text2);
      gap: 8px;
    }

    #empty-state .icon {
      width: 48px;
      height: 48px;
      color: var(--border-strong);
    }

    #empty-state .icon svg {
      width: 48px;
      height: 48px;
      display: block;
      stroke: currentColor;
      fill: none;
      stroke-width: 1.5;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    #empty-state p { font-size: 14px; }


    .message {
      display: flex;
      flex-direction: column;
      max-width: min(82%, 920px);
      width: 100%;
    }

    .message.user {
      width: min(82%, 920px);
      position: relative;
    }

    .restart-round-btn {
      position: absolute;
      top: 6px;
      right: -36px;
      width: 28px;
      height: 28px;
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--bg);
      color: var(--text3);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.15s, border-color 0.15s, color 0.15s;
      z-index: 1;
    }

    .restart-round-btn:hover {
      border-color: var(--danger);
      color: var(--danger);
    }

    .message.user:hover .restart-round-btn {
      opacity: 1;
    }

    .message.assistant { }


    .message-role {
      display: none;
    }


    .message-bubble {
      padding: 12px 15px;
      border-radius: 14px;
      font-size: 14px;
      line-height: 1.66;
      word-break: break-word;
      box-shadow: 0 1px 0 rgba(88, 110, 117, 0.08);
    }

    .message.user .message-bubble {
      background: var(--user-bg);
      border: 1px solid rgba(185, 173, 143, 0.42);
      border-bottom-right-radius: 5px;
      white-space: pre-wrap;
      width: 100%;
    }

    .message.assistant .message-bubble {
      background: transparent;
      border: none;
      border-radius: 0;
      box-shadow: none;
      padding: 4px 2px;
    }

    /* Text segments sit between reasoning/tool blocks in chronological order.
       Keep them flowing naturally without extra gaps. */
    .text-segment {
      margin: 0;
      line-height: inherit;
      font-family: var(--md-font-family);
      font-size: var(--md-font-size);
    }


    .markdown-body {
      font-family: var(--md-font-family);
      font-size: var(--md-font-size);
      white-space: normal;
    }


    .markdown-body > *:first-child { margin-top: 0; }

    .markdown-body > *:last-child { margin-bottom: 0; }


    .markdown-body h1,
    .markdown-body h2,
    .markdown-body h3,
    .markdown-body h4 {
      line-height: 1.35;
      margin: 0.95em 0 0.45em;
    }


    .markdown-body h1 {
      font-size: 1.5em;
      font-weight: 800;
      color: var(--text1);
    }

    .markdown-body h2 {
      font-size: 1.2em;
      font-weight: 750;
      color: var(--text1);
      padding-bottom: 0.25em;
      border-bottom: 1px solid var(--border);
    }

    .markdown-body h3 {
      font-size: 1.05em;
      font-weight: 700;
      color: var(--text2);
    }

    .markdown-body h4 {
      font-size: 1em;
      font-weight: 700;
      color: var(--text2);
      font-style: italic;
    }


    .markdown-body p { margin: 0.58em 0; }

    .markdown-body strong { color: var(--text2); font-weight: 750; }

    .markdown-body em { color: var(--text2); }


    .markdown-body ul,
    .markdown-body ol {
      margin: 0.58em 0 0.58em 1.45em;
      padding-left: 0.35em;
    }


    .markdown-body li {
      margin: 0.25em 0;
      padding-left: 0.1em;
    }


    .markdown-body blockquote {
      margin: 0.75em 0;
      padding: 0.65em 0.9em;
      border-left: 4px solid var(--accent);
      background: var(--md-blockquote-bg);
      color: var(--text2);
      border-radius: 0 10px 10px 0;
    }


    .markdown-body code {
      font-family: inherit;
      font-size: 0.92em;
      background: var(--md-code-inline-bg);
      color: var(--code-color);
      border: 1px solid var(--border);
      border-radius: 5px;
      padding: 0.12em 0.36em;
    }


    .markdown-body pre {
      margin: 0.8em 0;
      padding: 12px 14px;
      overflow-x: auto;
      background: var(--code-bg);
      border: 1px solid var(--border);
      border-radius: 10px;
    }


    .markdown-body pre code {
      display: block;
      background: transparent;
      border: none;
      padding: 0;
      white-space: pre;
      color: var(--text2);
    }


    .markdown-body table {
      width: 100%;
      border-collapse: collapse;
      margin: 0.8em 0;
      font-size: 13px;
      overflow: hidden;
      border-radius: 10px;
      border: 1px solid var(--border);
    }


    .markdown-body th,
    .markdown-body td {
      padding: 8px 10px;
      border-bottom: 1px solid var(--border);
      text-align: left;
      vertical-align: top;
    }


    .markdown-body th {
      background: var(--md-th-bg);
      color: var(--text2);
      font-weight: 700;
    }


    .markdown-body tr:last-child td { border-bottom: none; }


    .markdown-body hr {
      border: none;
      border-top: 1px solid var(--border);
      margin: 1em 0;
    }

    .markdown-body .katex {
      color: var(--text2);
    }

    .markdown-body .katex-display {
      margin: 0.85em 0;
      overflow-x: auto;
      overflow-y: hidden;
      padding: 4px 0;
    }

    .markdown-body img {
      max-width: 100%;
      height: auto;
      border-radius: 8px;
      margin: 0.5em 0;
      display: block;
    }


    .cursor {
      display: inline-block;
      width: 2px;
      height: 1em;
      background: var(--accent);
      margin-left: 2px;
      vertical-align: text-bottom;
      animation: blink 0.8s step-end infinite;
    }

    @keyframes blink { 50% { opacity: 0; } }


    #input-area {
      padding: 16px 20px;
      border-top: none;
      background: var(--bg);
      display: flex;
      justify-content: center;
      flex-shrink: 0;
    }


    #composer {
      width: min(810px, calc(100vw - 300px));
      background: var(--composer-bg);
      border: 1px solid var(--border);
      border-radius: 12px;
      overflow: visible;
      position: relative;
      box-shadow: inset 0 1px 0 rgba(88, 110, 117, 0.04), 0 4px 16px rgba(88, 110, 117, 0.08);
    }


    #pending-images {
      display: none;
      gap: 8px;
      padding: 10px 12px 0;
      flex-direction: column;
    }


    .pending-image-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      padding: 8px 10px;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: var(--pending-image-bg);
      font-size: 12px;
      color: var(--text2);
    }


    .pending-image-path {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }


    .pending-image-remove {
      border: 1px solid var(--border);
      background: var(--image-btn-bg);
      color: var(--text2);
      border-radius: 9px;
      cursor: pointer;
      transition: background 0.15s, border-color 0.15s, color 0.15s;
      width: 26px;
      height: 26px;
      flex-shrink: 0;
    }


    .pending-image-remove:hover {
      border-color: var(--border-strong);
      background: var(--bg2);
      color: var(--text2);
    }


    #message-input {
      width: 100%;
      background: var(--composer-bg);
      border: none;
      border-radius: 12px 12px 0 0;
      padding: 15px 18px;
      color: var(--text);
      font-size: 15px;
      font-family: inherit;
      resize: none;
      min-height: 60px;
      max-height: 200px;
      outline: none;
      line-height: 1.5;
      display: block;
    }

    #message-input:focus { box-shadow: none; }

    #message-input::placeholder { color: var(--text2); }


    #composer-toolbar {
      min-height: 44px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 7px 8px 7px 10px;
      background: var(--composer-bg);
      border-top: 1px solid rgba(185, 173, 143, 0.42);
      border-radius: 0 0 12px 12px;
    }
