/* ============================================
   移动端样式

   ── 断点体系（全站统一，避免碎片化）──
     ≤768px  平板竖屏 / 桌面窄窗口 —— 主断点
     ≤640px  宽对话框收窄（目录浏览器等，局部补充）
     ≤480px  手机竖屏 —— 主断点
     ≤375px  超窄屏（小屏手机）
   另一处 ≤600px 仅用于消息聚合信息行的字号降档（task.css），
   新增断点前请先评估能否归入上述档位。
   ============================================ */

@media (max-width: 768px) {
    .message .alert {
        padding: 10px 14px;
        margin: 10px 0;
        font-size:  var(--fs-md-lg);
    }
    .message .alert .alert-title {
        font-size:  var(--fs-md-lg);
    }
    .mermaid-wrapper {
        padding: 10px;
        margin: 10px 0;
    }
}
@media (max-width: 640px) {
    .dir-browser-dialog {
        width: 94vw;
        max-width: 94vw;
        height: auto;
        max-height: 88dvh;
        border-radius: 12px;
        margin: 16px;
    }
    .dir-browser-header {
        padding: 12px 14px;
        flex-shrink: 0;
    }
    .dir-browser-header h3 {
        font-size:  var(--fs-base);
    }
    .dir-browser-close {
        width: 44px;
        height: 44px;
        font-size:  var(--fs-2xl);
    }
    
    .dir-browser-nav {
        gap: 4px;
        padding: 6px 10px 0;
    }
    .dir-browser-nav-btn {
        width: 40px;
        height: 40px;
        border-radius: 8px;
        font-size:  var(--fs-base);
    }
    .dir-browser-breadcrumb {
        min-height: 40px;
        align-items: center;
        -webkit-overflow-scrolling: touch;
    }
    .dir-browser-crumb {
        padding: 8px 6px;
        font-size:  var(--fs-sm);
        min-height: 36px;
    }
    .dir-browser-crumb-sep {
        font-size:  var(--fs-md);
    }
    .dir-browser-current {
        padding: 8px 12px;
        font-size:  var(--fs-md);
        min-height: 44px;
        margin: 4px 10px 0;
        flex-shrink: 0;
    }
    .dir-browser-path-input {
        font-size:  var(--fs-md);
        min-height: 40px;
    }
    .dir-browser-list {
        flex: 1 1 auto;
        max-height: none;
        min-height: 80px;
        margin: 4px 10px;
    }
    .dir-browser-item {
        padding: 12px 14px;
        font-size:  var(--fs-base);
        min-height: 44px;
        gap: 12px;
        touch-action: manipulation;
    }
    .dir-browser-footer {
        justify-content: stretch;
        padding: 8px 14px 12px;
        gap: 10px;
        flex-shrink: 0;
    }
    .dir-browser-footer .settings-btn {
        flex: 1;
        text-align: center;
        padding: 10px 20px;
        font-size:  var(--fs-md-lg);
        min-height: 44px;
    }
    
    .security-dir-row {
        align-items: center;
        gap: 6px;
        padding: 6px 10px;
    }
    .security-dir-row .sec-path-display {
        flex: 1 1 0%;
        min-width: 0;
        font-size:  var(--fs-md);
    }
    .security-dir-row .sec-desc-display {
        flex: 0 1 auto;
        min-width: 0;
        max-width: 300px;
        font-size:  var(--fs-sm);
        color: var(--text-muted);
    }
    .sec-remove-btn {
        position: relative;
        width: 32px;
        height: 32px;
        font-size:  var(--fs-lg);
        flex-shrink: 0;
    }
    .sec-remove-btn::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 40px;
        height: 40px;
    }

    
    .security-add-dir-form {
        padding: 10px 12px;
    }
    .sec-add-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .security-add-dir-form .sec-add-path {
        flex: 1 1 auto;
        min-width: 0;
        gap: 6px;
    }
    .security-add-dir-form .sec-path-input {
        min-height: 44px;
        padding: 8px 10px;
        font-size:  var(--fs-base);
    }
    .sec-browse-btn {
        width: 44px;
        height: 44px;
        font-size:  var(--fs-xl);
        flex-shrink: 0;
    }
    .security-add-dir-form .sec-desc-input {
        flex: 0 0 100%;
        order: 2;
    }
    .sec-desc-input {
        min-height: 44px;
        padding: 8px 10px;
        font-size:  var(--fs-base);
    }
    .security-add-dir-form .sec-add-btn {
        flex: 0 0 100%;
        order: 3;
        justify-content: center;
    }
    .sec-add-btn {
        width: 100%;
        white-space: nowrap;
        text-align: center;
        padding: 10px 16px;
        font-size:  var(--fs-md-lg);
        min-height: 44px;
    }

    
    .security-dir-header {
        display: none;
    }

    .capability-item {
        gap: 6px 10px;
        padding: 10px 6px;
    }
    .capability-info {
        flex: 1 1 auto;
        min-width: 0;
    }
    .capability-desc {
        font-size:  var(--fs-sm);
    }
    .switch {
        flex-shrink: 0;
    }
}
@media (max-width: 768px) {
    :root {
        --toolbar-height: 36px;
        --titlebar-height: 36px;
        --inputbar-height: 60px;
        --statusbar-height: 24px;
        /* 消息标题阶梯随终端整体降档（桌面值见 base.css --fs-h*）：
           组件只写 var(--fs-hN)，不在此重复声明字号 */
        --fs-h1: 1.6em;
        --fs-h2: 1.3em;
        --fs-h3: 1.1em;
        --fs-h4: 1em;
        --fs-h5: .9em;
        --fs-h6: .8em;
    }

    #toolbar {
        padding: 0 8px;
        gap: 6px;
    }
    #minimized-icons {
        gap: 4px;
        padding: 2px 0;
    }
    .minimized-icon {
        padding: 3px 6px;
        font-size:  var(--fs-xs);
        max-width: 120px;
        gap: 3px;
    }
    .minimized-icon .dot {
        width: 5px;
        height: 5px;
    }
    #toolbar .actions {
        gap: 4px;
    }
    #toolbar button {
        padding: 4px 8px;
        font-size:  var(--fs-sm);
    }
    
    #toolbar #btn-main-menu,
    #toolbar #btn-arrange,
    #toolbar #btn-settings {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 26px;
        height: 26px;
        padding: 0;
    }
    #new-agent-dropdown #btn-new-agent {
        width: 26px;
        height: 26px;
        padding: 0;
    }
    #new-agent-dropdown #btn-new-agent svg {
        width: 14px;
        height: 14px;
    }
    #new-agent-dropdown #btn-new-agent-toggle {
        width: 20px;
        height: 20px;
        padding: 0;
        min-width: 20px;
        font-size:  var(--fs-2xs);
    }

    
    #new-agent-menu {
        right: 0;
        left: auto;
        max-width: calc(100vw - 16px);
    }

    .agent-window {
        min-width: 200px;
        min-height: 150px;
        border-radius: var(--window-radius, 12px);
        box-shadow: var(--window-shadow);
    }
    .agent-window.active {
        box-shadow: var(--window-shadow-active);
    }
    .window-titlebar {
        height: var(--titlebar-height);
        padding: 0 8px;
    }
    .window-titlebar .title {
        font-size:  var(--fs-md-lg);
    }
    .window-controls {
        gap: 4px;
    }
    .window-controls button {
        width: 28px;
        height: 28px;
        font-size:  var(--fs-sm);
        border-radius: 6px;
        touch-action: manipulation;
    }
    .window-controls button svg {
        width: 14px;
        height: 14px;
    }
    .window-content {
        padding: 8px 6px;
    }

    .messages-container {
        gap: 12px;
    }
    .message {
        font-size:  var(--fs-md-lg);
        max-width: 95%;
        line-height: 1.55;
    }
    .message.user {
        padding: 6px 12px;
        border-radius: 14px 14px 4px 14px;
        font-size:  var(--fs-md-lg);
    }
    
    .msg-emoji {
        font-size: var(--fs-em-xs);
    }
    .message.agent.streaming {
        padding-left: 8px;
        border-left-width: 2px;
    }

    .message pre {
        padding: 8px 10px;
        font-size:  var(--fs-sm);
        border-radius: 6px;
    }
    .code-toolbar {
        padding: 2px 8px;
        font-size:  var(--fs-2xs);
    }

    .thinking-content {
        padding: 6px 0 6px 12px;
        font-size:  var(--fs-sm);
    }
    .thinking-content::before {
        width: 5px;
        height: 5px;
        top: 12px;
    }
    .thinking-content::after {
        top: 24px;
        bottom: 6px;
    }

    .scroll-to-bottom {
        width: 28px;
        height: 28px;
        font-size:  var(--fs-sm);
        bottom: 10px;
        right: 10px;
    }
    .transfers-container {
        max-height: 120px;
    }
    .transfer-row {
        padding: 4px 10px;
        gap: 6px;
    }
    .transfer-label {
        font-size:  var(--fs-xs);
    }
    .transfer-bar-outer {
        height: 3px;
    }
    .transfer-pct {
        font-size:  var(--fs-xs);
        min-width: 30px;
    }

    #input-bar {
        padding: 0 8px 2px;
        min-height: 44px;
    }
    #global-input {
        padding: 8px 10px;
        border-radius: 8px;
        font-size:  var(--fs-md);
        min-height: 34px;
        max-height: none;
    }
    .input-row {
        gap: 6px;
    }
    #input-bar > button,
    .input-row button {
        border-radius: 8px;
        height: 30px;
        padding: 0 10px;
        font-size:  var(--fs-sm);
    }

    .attachment-card {
        width: 64px;
        padding: 3px;
    }
    .attach-thumb {
        width: 34px;
        height: 34px;
        font-size:  var(--fs-3xs);
    }

    #status-bar {
        padding: 0 8px;
        gap: 8px;
        font-size:  var(--fs-xs);
    }
    #status-bar .status-item {
        gap: 4px;
    }
    #status-bar .status-dot {
        width: 6px;
        height: 6px;
    }

    .confirm-dialog {
        min-width: 260px;
        padding: 16px;
        max-width: 90vw;
    }
    .confirm-btn-cancel,
    .confirm-btn-ok {
        padding: 8px 18px;
        font-size:  var(--fs-md-lg);
    }
    .confirm-actions {
        gap: 10px;
    }

    .input-dialog {
        max-width: 95vw;
        margin: 8px;
    }
    .input-dialog-title {
        padding: 16px 16px 4px;
        font-size:  var(--fs-base);
    }
    .input-dialog-prompt {
        padding: 8px 16px 0;
        font-size:  var(--fs-md);
    }
    .input-dialog-body {
        padding: 12px 16px 4px;
    }
    .input-dialog-input,
    .input-dialog-textarea {
        padding: 8px 10px;
        font-size:  var(--fs-md);
    }
    .input-dialog-footer {
        padding: 4px 16px 16px;
        gap: 8px;
    }
    .input-dialog-btn,
    .dialog-btn, 
    .change-pwd-btn {
        padding: 8px 16px;
        font-size:  var(--fs-md);
    }

    .settings-dialog {
        border-radius: 12px;
        flex-direction: column;
        max-width: 94vw;
        max-height: 88dvh;
        margin: 16px;
    }
    .settings-tabs {
        flex-direction: row;
        width: 100%;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-light);
        /* 压缩顶部区域占用：底部不留 padding，让选中背景贴底 */
        padding: 8px 8px 0;
        gap: 4px;
        /* 滚动条默认隐藏，拖动/触摸滚动时由系统 overlay 呈现 */
        scrollbar-width: none;
    }
    .settings-tabs::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }
    .settings-tab-btn {
        position: relative;
        border: 0;
        border-radius: 8px 8px 0 0; /* 顶部圆角、底部直角 */
        padding: 8px 12px;
        white-space: nowrap;
        /* 选中状态平滑过渡，点击无高亮闪烁 */
        transition: background .18s ease, color .18s ease;
        -webkit-tap-highlight-color: transparent;
    }
    .settings-tab-btn:hover {
        background: var(--bg-hover);
    }
    
    .settings-tab-btn::after {
        content: '';
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 2px;
        border-radius: 1px 1px 0 0;
        background: var(--accent);
        opacity: 0;
        transform: scaleX(0);
        transition: opacity .18s ease, transform .22s ease;
        pointer-events: none;
    }
    .settings-tab-btn.active::after {
        opacity: 1;
        transform: scaleX(1);
    }
    .settings-tab-btn.active {
        background: var(--accent-soft);
        color: var(--accent);
        font-weight: 600;
    }
    .settings-content {
        padding: 12px 12px 24px;
        gap: 12px;
        overscroll-behavior: contain;
    }
    
    .settings-panel-title {
        display: none;
    }
    .settings-section h4 {
        font-size:  var(--fs-md-lg);
    }
    .settings-field label {
        font-size:  var(--fs-sm);
    }
    .settings-field input,
    .settings-field select {
        padding: 6px 10px;
        font-size:  var(--fs-md);
    }
    .settings-btn {
        padding: 8px 18px;
        font-size:  var(--fs-md-lg);
    }
    .settings-btn-outline {
        padding: 8px 18px;
        font-size:  var(--fs-md-lg);
    }

    .toast {
        bottom: 60px;
        padding: 6px 16px;
        font-size:  var(--fs-sm);
    }

    .change-pwd-dialog {
        max-width: 95vw;
    }
    .change-pwd-title {
        padding: 16px 16px 4px;
        font-size:  var(--fs-base);
    }
    .change-pwd-body {
        padding: 12px 16px 4px;
    }
    .change-pwd-footer {
        padding: 4px 16px 16px;
    }
    .change-pwd-btn {
        padding: 8px 16px;
        font-size:  var(--fs-md);
    }

    .shortcut-popup {
        min-width: 140px;
        right: 8px;
    }
    .shortcut-popup .item {
        padding: 6px 10px;
        font-size:  var(--fs-sm);
    }

    .phrase-manager-dialog {
        min-width: auto;
        width: 95vw;
        padding: 12px;
        max-height: 90vh;
    }
    .phrase-manager-dialog h3 {
        font-size:  var(--fs-base);
    }
    .phrase-edit-row input {
        padding: 4px 6px;
        font-size:  var(--fs-sm);
    }
    .phrase-edit-row .icon-input {
        width: 34px;
        text-align: center;
        font-size: var(--fs-sm);
    }
    .add-phrase-btn {
        font-size: var(--fs-sm);
    }
    .cancel-btn,
    .reset-btn,
    .save-btn {
        padding: 8px 16px;
        font-size:  var(--fs-md);
    }

    .msg-tool-execution {
        margin: 8px 0;
        border-left-width: 2px;
        border-radius: 6px;
        font-size:  var(--fs-sm);
    }
    .tool-toggle {
        padding: 6px 10px;
        font-size:  var(--fs-sm);
        gap: 6px;
    }
    .tool-content {
        padding: 4px 10px 6px;
    }
    .tool-item {
        padding: 5px 0;
        font-size:  var(--fs-sm);
    }
    .tool-item + .tool-item {
        margin-top: 3px;
        padding-top: 6px;
    }
    .tool-item-header {
        gap: 6px;
    }
    .tool-status-icon {
        width: 16px;
        height: 16px;
    }
    .tool-name {
        max-width: 140px;
    }
    .tool-args {
        font-size:  var(--fs-sm);
    }
    .tool-result {
        font-size:  var(--fs-sm);
        padding: 3px 0 1px 24px;
    }

    .login-card {
        padding: 24px 20px;
        width: 320px;
    }
    .login-card h2 {
        font-size:  var(--fs-xl);
        margin-bottom: 16px;
    }
    .login-card input {
        padding: 8px 10px;
        font-size:  var(--fs-md-lg);
        margin: 8px 0;
    }
    .login-card button {
        padding: 9px;
        font-size:  var(--fs-md-lg);
    }

    .config-card .card-name-inline {
        font-size:  var(--fs-md-lg);
        max-width: 120px;
        min-width: 60px;
    }
    .config-card .card-body {
        padding: 12px;
    }
    .config-card .card-row-2col {
        flex-direction: column;
        /* 同一行两列在窄屏纵向堆叠，间距改由 gap 提供（.card-field 底边距已归零） */
        gap: 12px;
        margin-bottom: 12px;
    }

    .sig-key-row {
        flex-wrap: wrap;
        gap: 6px;
        padding: 6px 8px;
    }
    .sig-key-row input {
        min-width: 0;
        flex: 1 1 100px;
        padding: 4px 8px;
        font-size:  var(--fs-sm);
    }

    .msg-thinking {
        font-size:  var(--fs-sm);
    }
    .msg-tool-execution {
        margin: 6px 0;
    }
    .message table td,
    .message table th {
        padding: 4px 8px;
        font-size:  var(--fs-sm);
    }
    .config-card .card-field input {
        padding: 4px 8px;
        font-size:  var(--fs-sm);
    }
    
    .config-card .card-field select {
        padding: 4px 26px 4px 8px;
        font-size:  var(--fs-sm);
        background-position: right 8px center;
    }
    .config-card .card-temp-value {
        font-size:  var(--fs-md);
    }
    .settings-btn-icon {
        font-size:  var(--fs-base);
    }

    
    .agent-window .resize-n {
        top: 0;
        height: 8px;
        left: 0;
        right: 0;
    }
    .agent-window .resize-s {
        bottom: 0;
        height: 20px;
        left: 0;
        right: 0;
    }
    .agent-window .resize-e {
        right: 0;
        width: 16px;
        top: 0;
        bottom: 0;
    }
    .agent-window .resize-w {
        left: 0;
        width: 16px;
        top: 0;
        bottom: 0;
    }

    
    .agent-window .resize-ne {
        top: 0;
        right: 0;
        width: 36px;
        height: 36px;
    }
    .agent-window .resize-nw {
        top: 0;
        left: 0;
        width: 36px;
        height: 36px;
    }
    .agent-window .resize-se {
        bottom: 0;
        right: 0;
        width: 40px;
        height: 40px;
    }
    .agent-window .resize-sw {
        bottom: 0;
        left: 0;
        width: 40px;
        height: 40px;
    }

    
    .code-block-wrapper {
        border-radius: 6px;
    }
    .code-toolbar {
        border-radius: 6px 6px 0 0;
    }
}
@media (max-width: 480px) {
    :root {
        --toolbar-height: 32px;
        --titlebar-height: 32px;
        --inputbar-height: 50px;
        --statusbar-height: 22px;
        /* 标题阶梯再降一档（h4~h6 沿用 768 档） */
        --fs-h1: 1.3em;
        --fs-h2: 1.1em;
        --fs-h3: 1em;
    }
    #toolbar button {
        padding: 3px 6px;
        font-size:  var(--fs-xs);
    }
    
    #toolbar #btn-main-menu,
    #toolbar #btn-arrange,
    #toolbar #btn-settings {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 24px;
        height: 24px;
        padding: 0;
    }
    #new-agent-dropdown #btn-new-agent {
        width: 24px;
        height: 24px;
        padding: 0;
    }
    #new-agent-dropdown #btn-new-agent svg {
        width: 13px;
        height: 13px;
    }
    #new-agent-dropdown #btn-new-agent-toggle {
        width: 18px;
        height: 18px;
        padding: 0;
        min-width: 18px;
        font-size:  var(--fs-3xs);
    }
    .minimized-icon {
        padding: 2px 5px;
        font-size:  var(--fs-2xs);
        max-width: 96px;
    }
    #toolbar .actions {
        gap: 3px;
    }

    .agent-window {
        min-width: 160px;
        min-height: 120px;
        border-radius: var(--window-radius, 12px);
    }
    .window-titlebar {
        height: var(--titlebar-height);
        padding: 0 6px;
    }
    .window-titlebar .title {
        font-size:  var(--fs-md);
    }
    .window-controls {
        gap: 3px;
    }
    .window-controls button {
        width: 26px;
        height: 26px;
        font-size:  var(--fs-xs);
        border-radius: 5px;
        touch-action: manipulation;
    }
    .window-controls button svg {
        width: 13px;
        height: 13px;
    }
    .window-content {
        padding: 6px 4px;
    }
    .transfers-container {
        max-height: 100px;
    }
    .transfer-row {
        padding: 3px 8px;
        gap: 4px;
    }
    .transfer-icon {
        font-size:  var(--fs-md);
        width: 16px;
    }
    .transfer-pct {
        font-size:  var(--fs-2xs);
        min-width: 28px;
    }

    .messages-container {
        gap: 8px;
    }
    .message {
        font-size:  var(--fs-md);
        max-width: 98%;
        line-height: 1.45;
    }
    .message.user {
        padding: 5px 10px;
        border-radius: 12px 12px 3px 12px;
        font-size:  var(--fs-md);
    }
    .message.agent.streaming {
        padding-left: 6px;
        border-left-width: 2px;
    }
    .message pre {
        padding: 6px 8px;
        font-size:  var(--fs-xs);
        border-radius: 5px;
    }
    .code-toolbar {
        padding: 2px 6px;
        font-size:  var(--fs-3xs);
    }
    .code-block-wrapper {
        border-radius: 5px;
    }
    .code-toolbar {
        border-radius: 5px 5px 0 0;
    }

    .thinking-content {
        padding: 4px 0 4px 10px;
        font-size:  var(--fs-xs);
    }
    .thinking-content::before {
        width: 4px;
        height: 4px;
        top: 10px;
    }
    .thinking-content::after {
        top: 20px;
        bottom: 4px;
    }

    #input-bar {
        min-height: 40px;
        padding: 0 6px 2px;
    }
    #global-input {
        padding: 6px 8px;
        font-size:  var(--fs-sm);
        min-height: 30px;
        max-height: none;
    }
    #input-bar > button,
    .input-row button {
        height: 28px;
        padding: 0 8px;
        font-size:  var(--fs-xs);
    }
    .attachment-card {
        width: 56px;
        padding: 2px;
    }
    .attach-thumb {
        width: 28px;
        height: 28px;
        font-size:  var(--fs-4xs);
    }
    #status-bar {
        font-size:  var(--fs-2xs);
        padding: 0 6px;
        gap: 6px;
    }
    #status-bar .status-dot {
        width: 5px;
        height: 5px;
    }
    .confirm-dialog {
        min-width: 220px;
        padding: 12px;
    }
    .confirm-btn-cancel,
    .confirm-btn-ok {
        padding: 6px 14px;
        font-size:  var(--fs-md);
    }
    .confirm-actions {
        gap: 8px;
    }
    .input-dialog-title {
        padding: 12px 12px 4px;
        font-size:  var(--fs-md-lg);
    }
    .input-dialog-prompt {
        padding: 6px 12px 0;
        font-size:  var(--fs-sm);
    }
    .input-dialog-body {
        padding: 8px 12px 4px;
    }
    .input-dialog-input,
    .input-dialog-textarea {
        padding: 6px 8px;
        font-size:  var(--fs-sm);
    }
    .input-dialog-footer {
        padding: 4px 12px 12px;
        gap: 6px;
    }
    .input-dialog-btn,
    .dialog-btn, 
    .change-pwd-btn {
        padding: 6px 12px;
        font-size:  var(--fs-sm);
    }
    .settings-content {
        padding: 8px;
        gap: 8px;
    }
    .settings-section h4 {
        font-size:  var(--fs-md);
    }
    .settings-field label {
        font-size:  var(--fs-xs);
    }
    .settings-field input,
    .settings-field select {
        padding: 5px 8px;
        font-size:  var(--fs-sm);
    }
    .settings-btn {
        padding: 7px 18px;
        font-size:  var(--fs-md-lg);
    }
    .settings-btn-outline {
        padding: 7px 18px;
        font-size:  var(--fs-md-lg);
    }

    
    .sec-path-display {
        font-size:  var(--fs-sm);
    }
    .sec-desc-display {
        font-size:  var(--fs-md);
    }
    .security-dir-row {
        padding: 10px 10px;
    }
    .security-dir-header {
        padding: 6px 10px;
    }

    .toast {
        bottom: 50px;
        padding: 5px 12px;
        font-size:  var(--fs-xs);
    }
    .change-pwd-title {
        padding: 12px 12px 4px;
        font-size:  var(--fs-md-lg);
    }
    .change-pwd-body {
        padding: 8px 12px 4px;
    }
    .change-pwd-footer {
        padding: 4px 12px 12px;
    }
    .change-pwd-btn {
        padding: 6px 12px;
        font-size:  var(--fs-sm);
    }
    .shortcut-popup {
        min-width: 120px;
        right: 4px;
    }
    .shortcut-popup .item {
        padding: 5px 8px;
        font-size:  var(--fs-xs);
    }
    .phrase-manager-dialog {
        padding: 8px;
        width: 98vw;
    }
    .phrase-manager-dialog h3 {
        font-size:  var(--fs-md-lg);
    }
    .phrase-edit-row input {
        padding: 3px 5px;
        font-size:  var(--fs-xs);
    }
    .cancel-btn,
    .reset-btn,
    .save-btn {
        padding: 6px 12px;
        font-size:  var(--fs-sm);
    }
    .scroll-to-bottom {
        width: 24px;
        height: 24px;
        font-size:  var(--fs-xs);
        bottom: 6px;
        right: 6px;
    }
    .login-card {
        padding: 20px 16px;
        width: 280px;
    }
    .login-card h2 {
        font-size:  var(--fs-lg);
        margin-bottom: 12px;
    }
    .login-card input {
        padding: 6px 8px;
        font-size:  var(--fs-md);
        margin: 6px 0;
    }
    .login-card button {
        padding: 8px;
        font-size:  var(--fs-md-lg);
    }
    .msg-tool-execution {
        margin: 6px 0;
        border-left-width: 2px;
        border-radius: 5px;
        font-size:  var(--fs-xs);
    }
    .tool-toggle {
        padding: 4px 8px;
        font-size:  var(--fs-xs);
        gap: 4px;
    }
    .tool-content {
        padding: 3px 8px 5px;
    }
    .tool-item {
        padding: 4px 0;
        font-size:  var(--fs-xs);
    }
    .tool-item + .tool-item {
        margin-top: 2px;
        padding-top: 5px;
    }
    .tool-item-header {
        gap: 4px;
    }
    .tool-status-icon {
        width: 14px;
        height: 14px;
    }
    .tool-name {
        max-width: 100px;
    }
    .tool-args {
        font-size:  var(--fs-xs);
    }
    .tool-result {
        font-size:  var(--fs-xs);
        padding: 2px 0 1px 22px;
    }
    .msg-thinking {
        font-size:  var(--fs-xs);
    }
}
@media (max-width: 375px) {
    :root {
        --toolbar-height: 28px;
        --titlebar-height: 28px;
        --inputbar-height: 44px;
        --statusbar-height: 20px;
    }

    #toolbar {
        padding: 0 4px;
        gap: 3px;
    }
    #toolbar button {
        padding: 3px 5px;
        font-size:  var(--fs-xs);
    }
    
    #toolbar #btn-main-menu,
    #toolbar #btn-arrange,
    #toolbar #btn-settings {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 22px;
        height: 22px;
        padding: 0;
    }
    #new-agent-dropdown #btn-new-agent {
        width: 22px;
        height: 22px;
        padding: 0;
    }
    #new-agent-dropdown #btn-new-agent svg {
        width: 12px;
        height: 12px;
    }
    #new-agent-dropdown #btn-new-agent-toggle {
        width: 16px;
        height: 16px;
        padding: 0;
        min-width: 16px;
        font-size:  var(--fs-4xs);
    }
    .minimized-icon {
        padding: 2px 4px;
        font-size:  var(--fs-3xs);
        max-width: 72px;
    }
    .window-titlebar {
        height: var(--titlebar-height);
        padding: 0 4px;
    }
    .window-titlebar .title {
        font-size:  var(--fs-sm);
    }
    .window-controls {
        gap: 2px;
    }
    .window-controls button {
        width: 24px;
        height: 24px;
        font-size:  var(--fs-2xs);
        border-radius: 5px;
        touch-action: manipulation;
    }
    .window-controls button svg {
        width: 12px;
        height: 12px;
    }
    .window-content {
        padding: 4px 3px;
    }
    .transfers-container {
        max-height: 80px;
    }
    .transfer-row {
        padding: 2px 6px;
        gap: 3px;
    }
    .transfer-icon {
        font-size:  var(--fs-xs);
        width: 14px;
    }
    .transfer-label {
        font-size:  var(--fs-2xs);
    }
    .transfer-bar-outer {
        height: 2px;
    }
    .transfer-pct {
        font-size:  var(--fs-3xs);
        min-width: 24px;
    }

    .message {
        font-size:  var(--fs-sm);
        line-height: 1.4;
    }
    .message.user {
        padding: 4px 8px;
        font-size:  var(--fs-sm);
    }
    .message pre {
        padding: 5px 6px;
        font-size:  var(--fs-xs);
    }
    .code-toolbar {
        padding: 1px 5px;
        font-size:  var(--fs-4xs);
    }
    #input-bar {
        min-height: 36px;
        padding: 0 4px 2px;
    }
    #global-input {
        padding: 5px 6px;
        font-size:  var(--fs-xs);
        min-height: 26px;
        max-height: none;
    }
    #input-bar > button,
    .input-row button {
        height: 26px;
        padding: 0 6px;
        font-size:  var(--fs-xs);
        border-radius: 6px;
    }
    .attachment-card {
        width: 48px;
        padding: 2px;
    }
    .attach-thumb {
        width: 24px;
        height: 24px;
        font-size: var(--fs-3xs);
    }
    #status-bar {
        font-size:  var(--fs-3xs);
        padding: 0 4px;
        gap: 4px;
    }
    .login-card {
        padding: 16px 12px;
        width: 260px;
    }
    .confirm-dialog {
        min-width: 200px;
    }
}
@media (max-width: 768px) {
    .window-titlebar .status-badge {
        font-size:  var(--fs-2xs);
        padding: 1px 6px;
        gap: 3px;
    }
    .status-badge .status-dot {
        width: 5px;
        height: 5px;
    }
    .messages-container .empty-placeholder {
        min-height: 120px;
        padding: 24px 16px;
    }
    .messages-container .empty-placeholder .placeholder-icon {
        font-size: var(--fs-icon-md);
    }
}
@media (max-width: 375px) {
    .input-dialog {
        margin: 4px;
    }
    .settings-content {
        padding: 6px;
        gap: 6px;
    }
    .phrase-manager-dialog {
        padding: 6px;
    }
    .scroll-to-bottom {
        width: 22px;
        height: 22px;
        font-size:  var(--fs-3xs);
        bottom: 4px;
        right: 4px;
    }
}


/* ═══════════════════════════════════════════
   移动端设置对话框：浮层化（不占满全屏），点击背景即可关闭
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    .settings-dialog {
        position: relative;
    }


    
    .window-controls button,
    .toolbar-btn,
    .sched-action-btn {
        position: relative;
    }
    .window-controls button::before,
    .scroll-to-bottom::before,
    .toolbar-btn::before,
    .sched-action-btn::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 44px;
        height: 44px;
    }
}

/* ═══════════════════════════════════════════
   移动端触控目标优化
   通过透明伪元素把命中热区扩展到 ≥44px，
   视觉尺寸保持不变，不破坏既有布局。
   ═══════════════════════════════════════════ */

/* ═══════════════════════════════════════════
   窄屏工具栏折叠
   ≤375px 时隐藏顶部「排列」按钮（折叠进主菜单操作项）；
   工作区**不折叠**：代理菜单与工作区菜单各用各的下拉、各用各的滚动区，
   两者内容不混放（窄屏下工作区按钮只显图标，省出宽度）。
   ═══════════════════════════════════════════ */
@media (max-width: 375px) {
    #arrange-dropdown {
        display: none !important;
    }
    #main-menu-dropdown .main-menu-action[data-action="arrange"] {
        display: block !important;
    }
    /* 窄屏宽度紧：工作区按钮只留图标 + 展开箭头，文字标签隐藏（title 仍可悬停查看） */
    #workspace-btn-label {
        display: none;
    }

    /* 窄屏纵向空间更紧：压缩常驻动作区，把高度让给代理列表
       （优先级特意写到 2 个 id + 2 个 class，以胜过 layout.css 的
       #toolbar #main-menu-dropdown .main-menu-action） */
    #toolbar #main-menu-dropdown .main-menu-footer .main-menu-action {
        padding: 6px 12px;
    }
    #toolbar #main-menu-dropdown .main-menu-footer .main-menu-divider {
        margin: 2px 0;
    }
}

/* ═══════════════════════════════════════════
   状态栏信息降载（窄屏）
   优先保留连接状态与活跃代理，隐藏次要汇总，
   避免信息过载与溢出。
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    #status-bar #usage-summary {
        display: none !important;
    }
}
@media (max-width: 480px) {
    #status-bar #workspace-status {
        display: none !important;
    }
    #status-bar #active-agent-label-prefix {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════
   移动端：活动窗口左侧装饰条收窄
   窄屏下 3px 竖条仍显粗，收窄至 2px 并去掉发光阴影（窄条+辉光在低分辨率下易糊）
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    .agent-window.active .window-titlebar::before {
        width: 2px;
        top: 0;
        bottom: 0;
        border-radius: 0 2px 2px 0;
        box-shadow: none;
    }


    .window-titlebar .title .session-title-chip {
        max-width: 96px;
        padding: 1px 2px;
        gap: 0;
    }
    .window-titlebar .title .session-title-chip::before {
        content: '';
    }
}

/* ═══════════════════════════════════════════
   移动端：标题栏空间有限，会话标题 chip 紧凑显示
   隐藏 [page] 图标、收窄宽度，超长省略号截断；字号继承 .title 与代理名一致
   ═══════════════════════════════════════════ */
/* 超窄屏（≤375px）进一步收窄 */
@media (max-width: 375px) {
    .window-titlebar .title .session-title-chip {
        max-width: 64px;
    }
}

/* ═══════════════════════════════════════════
   内嵌面板（Todo/计划任务/任务队列）浮动定位微调
   面板为 absolute 浮层，不占用/影响消息区布局；
   此处按 window-content 的 padding 同步收窄边距，保持视觉一致。
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    .todo-panel, .sched-panel { top: 8px; left: 6px; right: 18px; }
    .queue-panel { bottom: 6px; left: 6px; right: 18px; }
}
@media (max-width: 480px) {
    .todo-panel, .sched-panel { top: 6px; left: 4px; right: 16px; }
    .queue-panel { bottom: 4px; left: 4px; right: 16px; }
}
@media (max-width: 375px) {
    .todo-panel, .sched-panel { top: 4px; left: 3px; right: 15px; }
    .queue-panel { bottom: 3px; left: 3px; right: 15px; }
}

/* ═══════════════════════════════════════════
   标题栏徽标（Todo / 计划任务）移动端统一尺寸
   与状态徽标（.status-badge）保持一致：≤768px 同步缩小，480px 不再额外缩小
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
    .todo-badge, .sched-badge {
        padding: 1px 6px;
        font-size:  var(--fs-2xs);
        gap: 3px;
    }
    .todo-badge .badge-icon, .sched-badge .badge-icon {
        font-size:  var(--fs-sm);
    }
}

/* ── 桌面端保险：JS 滚动条指示器仅移动端创建，桌面端用原生滚动条 ──
   （原分散在 window.css / todo.css / scheduled-task.css 三处完全相同的规则，
     2026-09-29 审查时合并至此，避免同一保险规则三份漂移） */
@media (min-width: 769px) {
    .panel-scrollbar-indicator {
        display: none;
    }
}

/* ── 触屏设备：取消「粘滞 hover」 ──
   触屏没有真实悬停，:hover 会停留在最后一次点击的元素上，表现为「某个按钮一直
   高亮/放大」的假状态；此处把移动端主要接触面的悬停反馈交还给「按下」。

   三条硬约定：
   1. 选择器必须 ≥ 原 :hover 规则的特异性（同特异性靠「排在 mobile.css 末尾」胜出），
      否则容器内更具体的专属 :hover 会压过通用选择器 → 轻触后一直高亮不恢复
      （用户报告：「单击标题栏最小化/还原/关闭按钮后按钮状态没有恢复」）。
   2. 统一带 `:not(:active):not(.is-pressed)`：按住期间让位给按下态——浏览器原生
      :active，以及全局 JS 维护的 .is-pressed（touchActivate.js；触屏上 :active 时机
      不可靠，需要它兜底）。否则按住期间连按下反馈都被中和，观感就是「按住没反应、
      松开才有动静」（用户报告）。
   3. 中和值必须等于元素「常态值」：常态不是透明底的（工具条胶囊底 8% 白、主题色
      主按钮、滚动到底圆底…），必须还原到常态值而不是抹成 transparent。
   4. 「按住期间的样子」= 各按钮族原本的 :hover / :active 观感，CSS 侧按
      `X:hover, X.is-pressed { … }` 成对书写（见 layout/window/dialog/settings/todo/
      message/scheduled-task），这样触屏上即便 :active 不成立，按下也不会没反馈。 */
@media (hover: none), (pointer: coarse) {
    #toolbar .dropdown-menu button:hover:not(:active):not(.is-pressed),
    #toolbar #main-menu-dropdown .main-menu-item:hover:not(:active):not(.is-pressed),
    #toolbar #main-menu-dropdown .main-menu-action:hover:not(:active):not(.is-pressed),
    #toolbar .workspace-menu button:hover:not(:active):not(.is-pressed),
    .window-controls button:hover:not(:active):not(.is-pressed),
    .window-toolbar button:hover:not(:active):not(.is-pressed),
    .settings-btn:hover:not(:active):not(.is-pressed),
    .settings-btn-icon:hover:not(:active):not(.is-pressed),
    .sig-key-row .settings-btn-icon:hover:not(:active):not(.is-pressed),
    .dialog-btn:hover:not(:active):not(.is-pressed),
    .todo-action-btn:hover:not(:active):not(.is-pressed),
    .todo-panel-list .todo-item:hover:not(:active):not(.is-pressed),
    .todo-item:hover:not(:active):not(.is-pressed),
    .sched-panel-list .sched-item:hover:not(:active):not(.is-pressed),
    .sched-item:hover:not(:active):not(.is-pressed),
    .queue-item:hover:not(:active):not(.is-pressed),
    .shortcut-popup .item:hover:not(:active):not(.is-pressed),
    .msg-copy-icon:hover:not(:active):not(.is-pressed),
    .code-toolbar button:hover:not(:active):not(.is-pressed) {
        background-color: transparent;
    }
    /* 实心/彩色按钮例外：其底色就是常态底色，粘滞 hover 绝不能把它抹成透明——
       否则移动端 tap「保存 AI 配置 / 保存信令配置 / 保存安全设置 / 保存语言」等按钮后，
       按钮会变成对话框底色（看起来「变白」）且因 hover 粘滞而不恢复。
       这里把底色/阴影还原为各自的常态值，等于「触屏悬停无变化」。
       特异性高于上面的 .settings-btn:hover / .dialog-btn:hover，故不受其影响。 */
    .settings-btn.dialog-btn-primary:hover:not(:active):not(.is-pressed),
    .dialog-btn.dialog-btn-primary:hover:not(:active):not(.is-pressed),
    .dialog-btn-primary:hover:not(:active):not(.is-pressed) {
        background-color: var(--accent);
        box-shadow: none;
    }
    .settings-btn.settings-btn-danger:hover:not(:active):not(.is-pressed) {
        background-color: var(--danger);
    }
    .dialog-btn.dialog-btn-cancel:hover:not(:active):not(.is-pressed) {
        background-color: var(--dialog-btn-cancel-bg);
    }

    /* ── 自带「专属 :hover」的按钮：底色/图标色是常态之外的另一套配色，
       上面的通用规则特异性不够（0,2,1 压不住 0,3,0），必须按元素常态值逐条抹平。
       保留 :not(:active)：按住那一刻让位给按钮自身的 :active 按下反馈。 ── */
    /* 标题栏控制按钮（最小化/还原/关闭）：常态 = 透明底 + 常态图标色
       `:not(.is-pressed)`：按住期间由 JS 维护的按下态（见 touchActivate.js）不被中和，
       否则触屏上 :active 不成立时会连「按下反馈」一并被抹掉 → 观感「按住没反应」。 */
    .window-controls .btn-minimize:hover:not(:active):not(.is-pressed),
    .window-controls .btn-maximize:hover:not(:active):not(.is-pressed),
    .window-controls .btn-close:hover:not(:active):not(.is-pressed) {
        background-color: transparent;
        color: var(--text-muted);
    }
    /* 窗口工具条按钮（暂停/保存/任务队列）：同上 */
    .window-toolbar .toolbar-btn:hover:not(:active):not(.is-pressed) {
        background-color: transparent;
        color: var(--text-muted);
    }
    /* 工具条按钮（主菜单/排列/设置/工作区…）：常态底色是白色 8% 的胶囊底
       （layout.css 的 #toolbar button），中和悬停必须还原到该常态值——
       抹成透明会让按钮轻触后「掉底」，同样表现为「状态没有恢复」。 */
    #toolbar button:hover:not(:active):not(.is-pressed) {
        background-color: rgba(255,255,255,.08);
    }
    /* 工具条主按钮（新建代理 ＋ / 类型切换）：底色本就是主题色，粘滞 hover 绝不能
       把它抹成透明，故还原为常态底色并去掉悬停光晕 */
    #toolbar button.primary:hover:not(:active):not(.is-pressed) {
        background-color: var(--accent);
        box-shadow: none;
    }
    /* 滚动到底按钮：其 :hover 只改 filter / transform / box-shadow（不动底色），
       故不能把常态底（var(--toolbar-bg) 圆底）抹成透明，也不能漏掉放大态；
       阴影须还原到常态值（0 2px 8px）而非 none。 */
    .scroll-to-bottom:hover:not(:active):not(.is-pressed) {
        filter: none;
        transform: none;
        box-shadow: 0 2px 8px rgba(0,0,0,.15);
    }
    /* 输入栏按钮（发送 / 附件 / 快捷短语）：与工具条同理——常态底色不是透明，
       中和必须还原常态值（否则 tap「发送」后按钮掉底/掉光晕）；
       按下态见 layout.css 中与之配对的 `:hover, .is-pressed` 规则。 */
    #btn-send:hover:not(:active):not(.is-pressed) {
        background: var(--accent);
        box-shadow: none;
    }
    #btn-attach:hover:not(:active):not(.is-pressed),
    #btn-shortcut:hover:not(:active):not(.is-pressed) {
        background: var(--bg-hover);
    }
    /* 窗口标题栏徽标（待办 / 计划任务）：与工具条按钮同理——常态有底色与常态阴影，
       中和必须逐项还原常态值（抹成透明/去掉阴影同样表现为「状态没恢复」）。
       但两个徽标的**常态底色随状态而变**（计划任务：橙=暂停 / 绿=运行中 / 灰=终态与无任务；
       待办：主题色 / 灰=全部完成），所以中和必须按状态分别还原到各自的常态值——
       否则绿/灰徽标一被轻触就会被抹成默认橙/主题色（同样是「状态没恢复」）。
       面板打开时（.active）保留「打开中高亮」，故这些都排除 .active。 */
    .todo-badge:not(.active):hover:not(:active):not(.is-pressed) {
        background: var(--accent);
        transform: none;
        box-shadow: 0 1px 4px color-mix(in srgb, var(--accent) 25%, transparent);
    }
    .todo-badge:not(.active)[data-status="done"]:hover:not(:active):not(.is-pressed) {
        background: var(--todo-done-bg);
        box-shadow: inset 0 0 0 1px var(--todo-done-border);
    }
    .sched-badge:not(.active):hover:not(:active):not(.is-pressed) {
        background: var(--sched-color);
        transform: none;
        box-shadow: 0 1px 4px color-mix(in srgb, var(--sched-color) 25%, transparent);
    }
    .sched-badge:not(.active)[data-status="active"]:hover:not(:active):not(.is-pressed) {
        background: var(--sched-active);
        box-shadow: 0 1px 4px color-mix(in srgb, var(--sched-active) 25%, transparent);
    }
    .sched-badge:not(.active)[data-status="done"]:hover:not(:active):not(.is-pressed),
    .sched-badge:not(.active)[data-status="idle"]:hover:not(:active):not(.is-pressed) {
        background: var(--sched-done);
        box-shadow: 0 1px 4px color-mix(in srgb, var(--sched-done) 25%, transparent);
    }

    /* 空桌面引导按钮（文字链接观感）：常态 = 主题色文字 + 无下划线，
       粘滞 hover 必须还原到这两个常态值，否则轻触后一直挂着下划线
       （按下态见 layout.css 中与之配对的 `:hover, .is-pressed` 规则）。 */
    #empty-desk-hint .empty-desk-create-btn:hover:not(:active):not(.is-pressed) {
        color: var(--accent);
        text-decoration: none;
    }

    /* 通用兜底按下反馈：任何按钮在按住期间至少有「轻微缩小」的即时反馈
       （:where() 保持最低特异性，不覆盖各族自己的 :active / :hover 专属观感）。 */
    :where(button.is-pressed):not(:active) {
        transform: scale(.97);
    }
}

/* ========== 系统「减少透明度」偏好 ==========
   已开启时，弹窗遮罩的毛玻璃降级为不透明暗色（遮罩定义分散在 dialog/layout.css，
   本文件加载顺序最后，非 !important 即可覆盖它们的同特异性声明） */
@media (prefers-reduced-transparency: reduce) {
    .phrase-manager-overlay,
    .confirm-overlay,
    .change-pwd-overlay,
    .session-dialog-overlay {
        backdrop-filter: none;
    }
}

/* ========== 矮视口兜底：菜单列表区上限收一档 ==========
   手机横屏、小尺寸笔电等场景纵向空间极少。此时主菜单/工作区菜单的
   固定动作区本身就能占掉大半屏，若列表区上限仍按 36vh 算，列表只能
   剩一两行。这里把列表上限压到 30vh/200px，优先保证底部动作项可用。
   （变量定义在 base.css :root，此处按视口高度覆盖即可） */
@media (max-height: 620px) {
    :root {
        --main-menu-list-max-h: min(30vh, 200px);
        --workspace-menu-list-max-h: min(30vh, 200px);
    }
}
