/* CoGraph interface tokens. The workbench owns all application geometry. */
:root {
    color-scheme: dark;
    --bg: #111110; --surface: #ffffff0d; --surface-2: #1919189c; --surface-3: #ffffff12; --surface-sunken: #10100f;
    --overlay: #08080780; --hover: #ffffff0a; --hover-strong: #ffffff15;
    --border: #ffffff12; --border-strong: #ffffff29;
    --text: #f5f3ef; --text-muted: #b7b2aa; --text-faint: #a29c93;
    --accent: #ff9b50; --accent-hover: #ffb573; --accent-ink: #231307; --accent-soft: #ff94251c; --accent-border: #ff9b504d;
    --action-bg: #ff9b50; --action-hover: #ffb573; --action-ink: #231307;
    --danger: #ff8c82; --danger-soft: #ff8c8218; --ok: #91c6a2;
    --shadow-sm: 0 2px 8px #0003; --shadow-md: 0 8px 28px #0004; --shadow-lg: 0 24px 70px #0006;
    --ct-accent: var(--accent); --ct-border: var(--border); --ct-head: var(--surface); --ct-badge-bg: var(--accent-soft); --ct-badge-fg: var(--accent);
}
html[data-theme="light"] {
    color-scheme: light;
    --bg: #eeece7; --surface: #ffffffad; --surface-2: #ffffff70; --surface-3: #dfdad34d; --surface-sunken: #e8e5de;
    --overlay: #35302630; --hover: #44332208; --hover-strong: #44332212;
    --border: #322b2014; --border-strong: #322b2029;
    --text: #25231f; --text-muted: #686158; --text-faint: #766e64;
    --accent: #a7440b; --accent-hover: #853307; --accent-ink: #ffffff; --accent-soft: #ed8b2814; --accent-border: #c86c234d;
    --action-bg: #282622; --action-hover: #454039; --action-ink: #fffdf9;
    --danger: #bb4035; --danger-soft: #bb403514; --ok: #33734a;
    --shadow-sm: 0 2px 8px #47361e0a; --shadow-md: 0 8px 28px #47361e12; --shadow-lg: 0 24px 70px #47361e24;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    overflow: hidden;
    background: var(--bg);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--text);
    user-select: none;
    /* Native-app feel on touch devices: disable the browser's double-tap-to-zoom
       gesture (e.g. double-tapping a node to rename) and the 300ms tap delay.
       Panning/scrolling inside scrollable panels still works. */
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

/* ===== Login Modal ===== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 40px;
    min-width: 360px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text);
}

.modal-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.modal .input-group {
    margin-bottom: 20px;
    text-align: left;
}

.modal .input-group label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

#login-userid,
#login-password {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 13px;
    outline: none;
}
#login-userid:focus,
#login-password:focus {
    border-color: var(--accent);
}

/* 设置弹窗「切换项目」列表 */
#settings-projects-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}
.settings-project-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 3px;
    transition: all 0.15s;
}
.settings-project-row:hover { border-color: var(--accent-border); background: var(--hover); }
.settings-project-row.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}
.settings-project-open {
    flex: 1;
    min-width: 0;
    border: none;
    background: none;
    color: inherit;
    padding: 7px 8px;
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.settings-project-row.active .settings-project-open { font-weight: 650; }
.settings-project-pin {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-faint);
    padding: 6px 7px;
    font-size: 11px;
    cursor: pointer;
}
.settings-project-pin:hover {
    background: var(--surface-3);
    color: var(--text);
}
.settings-project-pin.active {
    background: var(--accent-soft);
    color: var(--accent);
}
.settings-project-pin:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}
.settings-system-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.settings-theme-control {
    display: flex;
    gap: 3px;
    padding: 3px;
    border-radius: 9px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.settings-theme-control button {
    flex: 1;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    padding: 7px 10px;
    font-size: 12px;
    cursor: pointer;
}
.settings-theme-control button:hover {
    color: var(--text);
    background: var(--hover);
}
.settings-theme-control button.active {
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    font-weight: 650;
}
.input-error {
    font-size: 11px;
    color: var(--danger);
    margin-top: 6px;
}

#login-confirm {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
    color: var(--accent-ink);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.15s;
}

#login-confirm:hover {
    background: var(--accent-hover);
}

/* ===== Top Bar ===== */

#topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

/* 顶部常驻项目：最多六个紧凑标签，在固定主栏宽度内均分并省略长名称。 */
#pinned-projects {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.pinned-project-chip {
    position: relative;
    isolation: isolate;
    flex: 1 1 64px;
    min-width: 38px;
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 7px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 550;
    transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.pinned-project-chip:hover {
    color: var(--text);
    background: var(--hover);
}
.pinned-project-chip.active {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent-border);
    font-weight: 650;
}
.pinned-project-chip.working {
    color: var(--ct-badge-fg);
    border-color: var(--ct-border);
    background: var(--ct-badge-bg);
}
.pinned-project-chip.working::before {
    content: '';
    position: absolute;
    z-index: -1;
    inset: 0 auto 0 0;
    width: 48%;
    pointer-events: none;
    background: linear-gradient(100deg, transparent 0%, rgba(132, 199, 159, 0.3) 50%, transparent 100%);
    transform: translateX(-160%);
    animation: pinned-project-sweep 2.8s ease-in-out infinite;
}
@keyframes pinned-project-sweep {
    0%   { transform: translateX(-160%); }
    58%  { transform: translateX(310%); }
    100% { transform: translateX(310%); }
}
.pinned-project-chip.temporary {
    max-width: 140px;
}

/* 独立的系统设置入口。 */
#project-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
#project-btn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}
#project-btn:active { transform: translateY(0.5px); }

#topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    transition: box-shadow 0.15s;
}
/* 头像作为退出按钮：裸按钮包住头像，hover 时加一圈强调环 */
#logout-btn {
    background: none;
    border: none;
    padding: 0;
    margin-left: 2px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    line-height: 0;
}
#logout-btn:hover .topbar-avatar {
    box-shadow: 0 0 0 2px var(--accent-border);
}

/* ===== Context Menu ===== */
#context-menu {
    position: fixed;
    z-index: 10000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    min-width: 180px;
    box-shadow: var(--shadow-lg);
}
.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s;
}
.ctx-item:hover {
    background: var(--hover);
}
.ctx-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}
.ctx-item-danger {
    color: var(--danger);
}
.ctx-item-danger:hover {
    background: var(--danger-soft);
}

/* ===== Editor navigation ===== */
#sidebar-close {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    margin-right: 2px;
    border-radius: 6px;
    flex-shrink: 0;
}
#sidebar-close:hover {
    background: var(--hover);
    color: var(--text);
}

/* ===== Chat Messages ===== */
#chat-messages {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    user-select: text;
}

#chat-messages > * {
    margin-bottom: 12px;
}

.chat-msg {
    max-width: 100%;
    font-size: 13.5px;
    line-height: 1.65;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-msg .bubble {
    padding: 10px 14px;
    border-radius: 12px;
}

.chat-msg.user {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.bubble-images {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
    width: 100%;
    max-width: 80%;
    margin-left: auto;
}

.bubble-img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    border: 1px solid var(--border);
}

.chat-msg.user .bubble {
    background: var(--sidebar-accent, var(--accent));
    color: var(--accent-ink);
    border-radius: 14px 14px 4px 14px;
    max-width: 80%;
    font-size: 13px;
}

.chat-msg.user .msg-side {
    justify-content: flex-end; /* 时间靠近头像 */
}
.chat-msg.user .msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.agent-card-wrap {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
}

/* 头像竖排列（用户消息: .msg-side，AI消息: .msg-avatar-col）*/
.msg-side, .msg-avatar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.chat-time-divider {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 10px 0 4px;
    user-select: none;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}
.agent-card-wrap .msg-avatar-col {
    margin-top: 10px;
}
.agent-card-wrap .msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-card-wrap .msg-avatar svg {
    width: 16px;
    height: 16px;
    color: var(--accent);
}

.agent-card-wrap .agent-card {
    flex: 1;
    min-width: 0;
}

/* Agent activity card */
.agent-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
    animation: fadeInUp 0.25s ease;
}

.agent-card-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.agent-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ok);
    flex-shrink: 0;
    animation: pulse 1.5s infinite;
}
.agent-pulse.done {
    background: var(--ok);
    animation: none;
}
.agent-pulse.error {
    background: var(--danger);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(62, 157, 91, 0.5); }
    50% { opacity: 0.7; box-shadow: 0 0 0 4px rgba(62, 157, 91, 0); }
}

.agent-status-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-card.done .agent-card-status {
    color: var(--text-faint);
}

.agent-card-body {
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
}
.agent-card-body:empty {
    display: none;
}
.agent-card-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.agent-card-body a:hover { color: var(--accent-hover); }

/* 加载动效：三点跳动 */
.loading-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 20px 0;
}
.loading-dots span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-faint);
    animation: loading-bounce 1.2s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes loading-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%            { transform: translateY(-6px); opacity: 1; }
}


@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Code blocks in messages */
.chat-msg .bubble pre {
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12px;
    line-height: 1.5;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.chat-msg .bubble code {
    background: var(--surface-3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.chat-msg .bubble pre code {
    background: none;
    padding: 0;
}

.chat-msg .bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chat-msg .bubble a:hover {
    color: var(--accent-hover);
}

/* ===== Chat Input ===== */
#chat-input-area {
    padding: 12px 16px;
    flex-shrink: 0;
}

#chat-status {
    font-size: 11px;
    color: var(--text-faint);
    margin-bottom: 6px;
    min-height: 16px;
}

#chat-status.running {
    color: var(--sidebar-accent, var(--accent));
}
#chat-status.ctx-locked {
    color: #c74040;
    font-weight: 500;
}

#image-preview-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 0 6px 0;
}

.img-preview-thumb {
    position: relative;
    display: inline-flex;
}

.img-preview-thumb.uploading img {
    opacity: .55;
}

.img-preview-state {
    display: none;
    position: absolute;
    inset: 0;
    margin: auto;
    width: 18px;
    height: 18px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.img-preview-thumb.uploading .img-preview-state {
    display: block;
    border: 2px solid rgba(255, 255, 255, .65);
    border-top-color: var(--sidebar-accent, var(--accent));
    animation: prompt-image-spin .8s linear infinite;
}

@keyframes prompt-image-spin {
    to { transform: rotate(360deg); }
}

.img-preview-thumb.error .img-preview-state {
    display: flex;
    background: var(--danger);
}

#chat-status.upload-error {
    color: var(--danger);
}

.img-preview-thumb img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.img-preview-remove {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: none;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

#image-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: color 0.15s, background 0.15s;
}

#image-upload-btn:hover {
    color: var(--text);
    background: var(--surface-3);
}

#chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    scrollbar-width: none;
    min-height: 20px;
    white-space: pre-wrap;
    word-break: break-word;
}
#chat-input:empty::before {
    content: attr(data-placeholder);
    color: var(--text-faint);
    pointer-events: none;
}
#chat-input::-webkit-scrollbar {
    display: none;
}

#chat-input:focus {
    border-color: var(--sidebar-accent, var(--accent));
}

#chat-input.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

#chat-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#chat-send, #chat-stop {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-send {
    background: var(--sidebar-accent, var(--accent));
    color: var(--accent-ink);
}
#chat-send:hover {
    filter: brightness(1.08);
}
#chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#chat-stop {
    background: var(--danger-soft);
    color: var(--danger);
}
#chat-stop:hover {
    background: rgba(199, 73, 58, 0.18);
}

.compact-summary-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--sidebar-accent, var(--accent));
    border-radius: 10px;
    padding: 10px 14px;
    margin: 6px 0 12px;
    font-size: 13px;
    overflow-x: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
}
.compact-summary-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--sidebar-accent, var(--accent));
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.compact-summary-body {
    color: var(--text-faint);
    line-height: 1.55;
    font-size: 12.5px;
    overflow-x: hidden;
}
.compact-summary-body p { margin: 0 0 4px; }
.compact-summary-body p:last-child { margin-bottom: 0; }

/* ===== 自定义滚动条：对话与文件面板，统一贴合主题 =====
   细、透明轨道、圆角拇指，两侧留 2px 透明边做内缩感，hover 提亮。 */
#chat-messages::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}
#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
#chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
#chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
    background-clip: padding-box;
}
/* Firefox */
#chat-messages {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

/* ===== Settings Modal ===== */
#settings-modal {
    z-index: 2000;
}
.settings-modal-content {
    width: min(880px, calc(100vw - 32px));
    min-width: 0;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    text-align: left;
    padding: 22px 24px 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
/* Mobile tab switcher — hidden on desktop */
.settings-mobile-tabs {
    display: none;
}
.settings-body {
    display: flex;
    gap: 0;
    align-items: flex-start;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.settings-col {
    flex: 1;
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    align-self: stretch;
    padding: 0 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.settings-col:first-child { padding-left: 0; }
.settings-col:last-child { padding-right: 0; }
.settings-col-divider {
    width: 1px;
    align-self: stretch;
    background: var(--border);
    flex-shrink: 0;
}
.settings-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    margin-bottom: 18px;
}
.settings-modal-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}
.settings-modal-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
}
.settings-modal-header button:hover {
    background: var(--hover);
    color: var(--text);
}
/* ===== Settings: 分区 ===== */
.settings-section-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 6px;
}
/* ===== Settings: Target Applications ===== */
#settings-apps-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.settings-app-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.settings-app-icon {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--ct-badge-bg);
    color: var(--ct-badge-fg);
}
.settings-app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.settings-app-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.settings-app-tag {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-3);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 4px;
    vertical-align: middle;
}
.settings-app-port {
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--accent);
    text-decoration: none;
}
.settings-app-port:hover { text-decoration: underline; }
/* 每个应用一行里的「AGENTS.md」按钮 —— 编辑该应用工作目录下的 AGENTS.md */
.settings-app-md, .settings-app-build, .settings-app-publish, .settings-app-deploy-logs {
    flex-shrink: 0;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    padding: 5px 9px;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.settings-app-md:hover {
    background: var(--accent-soft);
    border-color: var(--accent-border);
}
.settings-app-https,
.settings-app-start {
    flex-shrink: 0;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    padding: 5px 7px;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.settings-app-https.active,
.settings-app-start.active {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent);
}
.settings-app-https:hover,
.settings-app-start:hover { background: var(--hover); }

/* app status dot */
.app-status-dot {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background 0.2s;
}
.app-status-dot.running { background: #34c759; }
.app-status-dot.degraded { background: #ff9f0a; cursor: pointer; }
.app-status-dot.stopped { background: #ff3b30; cursor: pointer; }
.app-status-dot.stopped:hover { background: #ff6b61; }
.app-status-dot.starting {
    background: #ff9f0a;
    animation: dot-pulse 0.8s ease-in-out infinite alternate;
}
@keyframes dot-pulse { from { opacity: 0.5; } to { opacity: 1; } }

/* ===== Confirm Dialog ===== */
#confirm-dialog { z-index: 3000; }
.confirm-dialog-content {
    max-width: 340px;
    padding: 28px 32px 24px;
}
.confirm-dialog-icon {
    margin-bottom: 12px;
}
.confirm-dialog-content p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 20px;
}
.confirm-dialog-buttons {
    display: flex;
    gap: 10px;
}
.confirm-btn-cancel, .confirm-btn-ok {
    flex: 1;
    padding: 9px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.confirm-btn-cancel {
    background: var(--surface-3);
    color: var(--text-muted);
}
.confirm-btn-cancel:hover {
    background: var(--hover-strong);
    color: var(--text);
}
.confirm-btn-ok {
    background: var(--danger);
    color: #fff;
}
.confirm-btn-ok:hover {
    background: #b03e30;
}

/* ===== Input Dialog (custom prompt) ===== */
#input-dialog { z-index: 3000; }
.input-dialog-content {
    max-width: 340px;
    padding: 24px 24px 20px;
    text-align: left;
}
.input-dialog-content h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
}
#input-dialog-field {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
}
#input-dialog-field:focus { border-color: var(--accent); }
.input-dialog-buttons {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}
.input-dialog-buttons button {
    flex: 1;
    padding: 9px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.input-dialog-ok {
    background: var(--accent);
    color: var(--accent-ink);
}
.input-dialog-ok:hover { background: var(--accent-hover); }

/* ===== AGENTS.md Editor Sidebar ===== */
.agentsmd-editor {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 0;
    resize: none;
    outline: none;
}
.agentsmd-editor::placeholder {
    color: var(--text-faint);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .settings-app-https,
    .settings-app-start { display: none; }
    /* Settings modal: single-panel + tab switcher */
    .settings-modal-content {
        width: calc(100vw - 24px);
        padding: 16px 14px 18px;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        overflow: hidden;
    }
    .settings-mobile-tabs {
        display: flex;
        flex-shrink: 0;
        gap: 0;
        background: var(--surface-2);
        border-radius: 10px;
        padding: 3px;
        margin-bottom: 14px;
    }
    .settings-mobile-tab {
        flex: 1;
        border: none;
        background: none;
        color: var(--text-muted);
        font-size: 13px;
        font-weight: 500;
        padding: 8px 0;
        border-radius: 8px;
        cursor: pointer;
        transition: background 0.15s, color 0.15s;
    }
    .settings-mobile-tab.active {
        background: var(--surface);
        color: var(--text);
        font-weight: 600;
        box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    }
    .settings-body {
        display: block;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .settings-col-divider {
        display: none;
    }
    .settings-col {
        padding: 0;
        display: none;
        max-height: none;
        overflow: visible;
    }
    .settings-col.active {
        display: block;
    }

    /* Top bar */
    #topbar-left { gap: 4px; }
    #topbar-right { gap: 4px; }
    #topbar-left button { padding: 4px; }
    #project-name-display { font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    /* Workspace full width, leave room for bottom nav (+ iPhone home indicator) */



    /* Mobile Chrome/Safari auto-zoom the page layer when a focused text field has
       font-size < 16px. Force >= 16px on focusable text surfaces so focusing them
       (e.g. tapping the rename pencil to edit a title) doesn't zoom the page. */
    #chat-input, .agentsmd-editor,
    input, textarea, select, [contenteditable="true"] {
        font-size: 16px;
    }
    /* These selectors carry higher specificity than the generic `input` rule above,
       so override them explicitly to prevent browser auto-zoom on focus. */
    #login-userid, #login-password {
        font-size: 16px;
    }

    /* Sidebar fullscreen on mobile.
       Height tracks the visual viewport (--app-height, set by JS) so the bottom
       input area stays visible above the on-screen keyboard; falls back to dvh. */
    /* Back chevron: a touch more tap area on mobile */
    #sidebar-close {
        padding: 6px 8px;
    }
    /* Fullscreen sidebar: keep the chat input clear of the iPhone home indicator */
    #chat-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Login modal */
    .modal-content {
        min-width: unset;
        width: 90vw;
        padding: 24px 20px;
    }

}

@media (prefers-reduced-motion: reduce) {
    .pinned-project-chip.working::before { animation: none; }
}

/* Markdown in streamed replies and conversation history. */
:is(.agent-card-body, .compact-summary-body) { white-space: normal; overflow-wrap: anywhere; }
:is(.agent-card-body, .compact-summary-body) > :first-child { margin-top: 0; }
:is(.agent-card-body, .compact-summary-body) > :last-child { margin-bottom: 0; }
:is(.agent-card-body, .compact-summary-body) p { margin: 0 0 12px; }
:is(.agent-card-body, .compact-summary-body) :is(h1, h2, h3, h4, h5, h6) { margin: 22px 0 10px; line-height: 1.4; font-weight: 650; }
:is(.agent-card-body, .compact-summary-body) h1 { font-size: 1.6em; }
:is(.agent-card-body, .compact-summary-body) h2 { font-size: 1.35em; }
:is(.agent-card-body, .compact-summary-body) h3 { font-size: 1.15em; }
:is(.agent-card-body, .compact-summary-body) :is(ul, ol) { margin: 10px 0 14px; padding-left: 24px; }
:is(.agent-card-body, .compact-summary-body) li { margin: 5px 0; }
:is(.agent-card-body, .compact-summary-body) li > :is(ul, ol, p) { margin-block: 5px; }
:is(.agent-card-body, .compact-summary-body) blockquote { margin: 14px 0; padding: 2px 14px; border-left: 3px solid var(--border-strong); color: var(--text-muted); }
:is(.agent-card-body, .compact-summary-body) blockquote p:last-child { margin-bottom: 0; }
:is(.agent-card-body, .compact-summary-body) hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
:is(.agent-card-body, .compact-summary-body) code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; background: var(--surface-3); padding: 2px 5px; border-radius: 4px; }
:is(.agent-card-body, .compact-summary-body) pre { max-width: 100%; overflow-x: auto; white-space: pre; overflow-wrap: normal; margin: 14px 0; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); line-height: 1.6; }
:is(.agent-card-body, .compact-summary-body) pre code { padding: 0; background: none; border-radius: 0; white-space: pre; }
:is(.agent-card-body, .compact-summary-body) .markdown-table { max-width: 100%; overflow-x: auto; margin: 14px 0; }
:is(.agent-card-body, .compact-summary-body) table { border-collapse: collapse; font-size: .95em; min-width: 100%; }
:is(.agent-card-body, .compact-summary-body) :is(th, td) { padding: 8px 12px; border: 1px solid var(--border); text-align: left; min-width: 90px; }
:is(.agent-card-body, .compact-summary-body) th { background: var(--surface-2); font-weight: 600; }
:is(.agent-card-body, .compact-summary-body) img { display: block; max-width: 100%; height: auto; border-radius: 8px; margin-block: 12px; }
