:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #eef3f8;
  color: #172b4d;
  --ink: #172b4d;
  --muted: #64748b;
  --line: #d9e2ec;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --danger-bg: #fff1f0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { width: 100%; max-width: 100vw; margin: 0; min-width: 320px; overflow-x: hidden; background: #eef3f8; }
button, input, textarea, select { font: inherit; }
button { border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.danger { color: var(--danger); border-color: #f0b5ae; background: var(--danger-bg); }
input, textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 6px; padding: 10px 12px; background: #fff; color: var(--ink); }
.dialog-form select { width: 100%; border: 1px solid #cbd5e1; border-radius: 6px; padding: 10px 12px; background: #fff; color: var(--ink); }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(15, 118, 110, .18); border-color: var(--accent); }

.app-shell { max-width: 1440px; margin: 0 auto; padding: 24px; }
.topbar, .panel-heading, .detail-heading, .composer-footer, .inline-form, .dialog-heading, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.detail-actions { display: flex; align-items: center; gap: 8px; }
.topbar { margin-bottom: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.server-tools { display: flex; align-items: center; gap: 10px; min-height: 42px; margin: -8px 0 14px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.provider-control { display: inline-flex; min-width: 0; flex: 1 1 auto; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.provider-control span { flex: 0 0 auto; white-space: nowrap; }
.provider-control select { min-width: 0; flex: 1 1 auto; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; }
.compact-action { flex: 0 0 auto; border-radius: 6px; padding: 6px 10px; font-size: 12px; }
.server-tools > .muted { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-control { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.target-control select { min-width: 118px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; }
h1, h2, p { margin: 0; }
h1 { font-size: 25px; letter-spacing: 0; }
h2 { font-size: 18px; letter-spacing: 0; }
.eyebrow { color: #7c3aed; font-size: 10px; font-weight: 700; letter-spacing: 1px; }
.muted, .hint { color: var(--muted); font-size: 12px; }
.status-pill { border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 600; }
.status-online { background: #dcfce7; color: #166534; }
.status-offline { background: #e2e8f0; color: #475569; }
.auth-panel { display: grid; gap: 8px; max-width: 560px; margin-bottom: 18px; padding: 14px 16px; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; }
.remember-code { display: inline-flex; align-items: center; gap: 7px; width: fit-content; color: var(--muted); font-size: 12px; cursor: pointer; }
.remember-code input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.inline-form { align-items: stretch; }
.inline-form button { min-width: 78px; border-radius: 6px; }
.workspace { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 18px; min-height: 660px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.thread-panel { display: flex; flex-direction: column; }
.panel-heading, .detail-heading { padding: 17px 18px; border-bottom: 1px solid var(--line); }
.heading-actions { display: flex; gap: 6px; }
.icon-button { width: 34px; height: 34px; border-radius: 6px; font-size: 20px; line-height: 1; }
.thread-list { overflow: auto; }
.project-section { display: flex; min-height: 0; height: 250px; max-height: 250px; flex: 0 0 250px; flex-direction: column; padding: 8px 10px 0; border-bottom: 1px solid #edf2f7; }
.project-row { display: flex; width: 100%; flex: none; align-items: center; gap: 8px; min-height: 30px; padding: 5px 8px; border: 0; border-radius: 5px; background: transparent; text-align: left; font-size: 12px; }
.project-row:hover, .project-row.selected { background: #f0fdfa; color: var(--accent-dark); }
.project-mark { color: #7c3aed; font-size: 11px; }
.project-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-count { color: var(--muted); font-size: 11px; }
.project-list { display: grid; min-height: 0; flex: 1 1 auto; gap: 2px; margin-top: 2px; overflow-y: auto; padding-bottom: 7px; }
.section-label { padding: 12px 18px 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.thread-search { padding: 10px 12px 2px; }
.thread-search input { padding: 8px 10px; font-size: 12px; }
.thread-card { width: 100%; text-align: left; padding: 14px 16px; border: 0; border-bottom: 1px solid #edf2f7; background: #fff; }
.thread-card:hover, .thread-card.selected { background: #f0fdfa; }
.thread-card.selected { box-shadow: inset 3px 0 0 var(--accent); }
.thread-name { display: block; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-preview { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thread-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; color: #829ab1; font-size: 11px; }
.thread-source { color: #7c3aed; }
.detail-panel { display: flex; min-width: 0; flex-direction: column; }
.detail-heading { align-items: flex-start; }
.detail-heading > div:first-child { min-width: 0; }
.sidebar-toggle { display: none; margin-bottom: 8px; }
.detail-heading .danger { border-radius: 6px; padding: 8px 12px; }
.goal-summary { max-width: min(760px, 100%); margin-top: 4px; overflow: hidden; color: #0f766e; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.event-strip { min-height: 31px; padding: 8px 18px; color: #52606d; background: #f8fafc; border-bottom: 1px solid #edf2f7; font-size: 12px; }
.conversation-body { display: grid; min-height: 0; flex: 1; grid-template-columns: 52px minmax(0, 1fr); }
.message-nav { min-height: 0; overflow-y: auto; padding: 12px 8px; border-right: 1px solid #edf2f7; background: #fbfdff; }
.message-nav-list { display: grid; gap: 6px; justify-items: center; }
.message-nav-button { width: 30px; min-height: 28px; padding: 3px; border: 1px solid #d9e2ec; border-radius: 5px; background: #fff; color: #64748b; font-size: 10px; }
.message-nav-button:hover { border-color: var(--accent); color: var(--accent-dark); background: #f0fdfa; }
.message-list { min-width: 0; min-height: 0; overflow: auto; padding: 20px; display: grid; align-content: start; gap: 12px; overscroll-behavior: contain; overflow-anchor: none; }
.message { min-width: 0; max-width: min(860px, 92%); padding: 11px 13px; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; line-height: 1.55; font-size: 14px; }
.message.user { justify-self: end; background: #e6fffa; border-color: #99f6e4; }
.message.agent { justify-self: start; background: #f8fafc; }
.message.system { justify-self: start; color: var(--muted); background: #fff; font-size: 12px; }
.message-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.message-body { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-body p { margin: 8px 0; }
.message-body ul, .message-body ol { margin: 8px 0; padding-left: 22px; }
.message-body li + li { margin-top: 4px; }
.message-body h1, .message-body h2, .message-body h3, .message-body h4 { margin: 13px 0 7px; font-size: 1.05em; }
.message-body blockquote { margin: 9px 0; padding: 5px 12px; border-left: 3px solid #a7f3d0; color: #52606d; background: #f1f5f9; }
.message-body code { padding: 2px 5px; border-radius: 4px; background: #e2e8f0; font-family: Consolas, monospace; font-size: .9em; }
.message-body pre { margin: 10px 0; padding: 11px 12px; overflow: auto; border-radius: 6px; background: #102a43; color: #e6fffa; }
.message-body pre code { padding: 0; background: transparent; color: inherit; }
.message-body a { color: #0f766e; text-decoration: underline; text-underline-offset: 2px; }
.message-body img { display: block; max-width: 100%; height: auto; }
.message-body table { display: block; max-width: 100%; margin: 10px 0; overflow-x: auto; border-collapse: collapse; font-size: .92em; }
.message-body th, .message-body td { padding: 6px 8px; border: 1px solid #cbd5e1; text-align: left; vertical-align: top; }
.message-body th { background: #e2e8f0; font-weight: 650; }
.task-end-marker { display: flex; align-items: center; gap: 8px; margin: 2px 0; color: #64748b; font-size: 11px; white-space: nowrap; }
.task-end-marker::before, .task-end-marker::after { flex: 1; border-top: 1px solid #d9e2ec; content: ""; }
.composer { position: relative; padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.composer textarea { resize: vertical; min-height: 78px; }
.skill-suggestions { position: absolute; z-index: 8; right: 18px; bottom: calc(100% - 1px); left: 18px; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: 0 -8px 24px rgba(15, 23, 42, .14); }
.skill-suggestion { display: grid; width: 100%; min-width: 0; grid-template-columns: 26px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 8px 10px; border: 0; border-bottom: 1px solid #edf2f7; border-radius: 0; text-align: left; }
.skill-suggestion:last-child { border-bottom: 0; }
.skill-suggestion:hover, .skill-suggestion.selected { background: #f0fdfa; }
.skill-mark { display: inline-grid; width: 24px; height: 24px; place-items: center; border: 1px solid #99f6e4; border-radius: 5px; color: var(--accent-dark); background: #e6fffa; font-weight: 700; }
.skill-copy { display: flex; min-width: 0; align-items: baseline; gap: 8px; }
.skill-copy strong { flex: 0 0 auto; font-size: 12px; }
.skill-copy > span { min-width: 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.skill-scope { color: var(--muted); font-size: 10px; white-space: nowrap; }
.composer-error { margin-top: 7px; padding: 7px 9px; border: 1px solid #f0b5ae; border-radius: 6px; color: var(--danger); background: var(--danger-bg); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.composer-footer { margin-top: 9px; }
.composer-tools, .composer-actions { display: flex; min-width: 0; align-items: center; gap: 8px; }
.composer-actions { flex: 1; justify-content: flex-end; }
#selected-cwd { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-select { min-width: 0; height: 30px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px; background: #fff; color: var(--ink); font-size: 11px; text-overflow: ellipsis; }
.turn-model { width: min(150px, 22vw); }
.turn-reasoning { width: 94px; }
.image-button { display: inline-flex; align-items: center; justify-content: center; }
.image-preview { position: relative; display: inline-flex; width: 44px; height: 44px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #f8fafc; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.remove-image { position: absolute; top: 1px; right: 1px; width: 17px; height: 17px; padding: 0; border: 0; border-radius: 50%; background: rgba(15, 23, 42, .72); color: #fff; font-size: 13px; line-height: 17px; }
.image-upload-state { display: inline-flex; min-width: 0; max-width: 210px; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.image-upload-state.error { color: var(--danger); }
.image-upload-state.success { color: #166534; }
.image-progress { width: 42px; height: 6px; flex: 0 0 auto; accent-color: var(--accent); }
#image-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bottom-button { width: 30px; height: 30px; padding: 0; font-size: 16px; line-height: 1; }
.queue-toggle { min-width: 52px; height: 30px; padding: 0 8px; border-radius: 6px; color: var(--muted); background: #f8fafc; font-size: 11px; white-space: nowrap; }
.queue-toggle.active { border-color: #99f6e4; background: #e6fffa; color: var(--accent-dark); }
.composer-footer button { min-width: 76px; border-radius: 6px; padding: 8px 14px; }
.composer-footer .queue-toggle { min-width: 52px; padding: 0 8px; }
.composer-footer .bottom-button { width: 30px; min-width: 30px; padding: 0; }
.empty-state { padding: 28px 18px; color: var(--muted); text-align: center; font-size: 13px; }
dialog { width: min(520px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 8px; padding: 0; color: var(--ink); box-shadow: 0 20px 55px rgba(15, 23, 42, .2); }
dialog::backdrop { background: rgba(15, 23, 42, .35); }
.dialog-form { display: grid; gap: 9px; padding: 20px; }
.dialog-heading { margin-bottom: 6px; }
.dialog-actions { justify-content: flex-end; margin-top: 10px; }
.dialog-actions button { border-radius: 6px; padding: 8px 14px; }
.approval-details { max-height: 300px; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafc; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }

@media (max-width: 760px) {
  .app-shell { width: 100%; max-width: 100vw; padding: 6px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left)); }
  .topbar { min-height: 38px; margin-bottom: 6px; }
  .topbar > div:first-child { min-width: 0; flex: 1 1 auto; }
  .topbar .eyebrow { display: none; }
  .topbar-actions { min-width: 0; flex: 0 0 auto; align-items: center; flex-direction: row; gap: 6px; }
  .target-control { flex: 0 0 auto; gap: 3px; font-size: 10px; white-space: nowrap; }
  .target-control select { min-width: 94px; padding: 4px 5px; font-size: 11px; }
  .status-pill { flex: 0 0 auto; white-space: nowrap; }
  .server-tools { gap: 6px; min-height: 34px; margin: -2px 0 7px; padding: 4px 6px; }
  .provider-control { gap: 4px; font-size: 10px; }
  .provider-control select { padding: 4px 5px; font-size: 10px; }
  .compact-action { padding: 5px 8px; font-size: 11px; }
  h1 { overflow: hidden; font-size: 18px; text-overflow: ellipsis; white-space: nowrap; }
  .workspace { display: block; position: relative; min-height: 0; }
  .thread-panel { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(86vw, 340px); max-height: none; border-radius: 0 8px 8px 0; transform: translateX(-105%); transition: transform .18s ease; box-shadow: 18px 0 40px rgba(15, 23, 42, .2); }
  .thread-panel.open { transform: translateX(0); }
  .project-section { height: 220px; max-height: 220px; flex-basis: 220px; }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar-backdrop { display: none; position: fixed; z-index: 20; inset: 0; border: 0; border-radius: 0; background: rgba(15, 23, 42, .32); }
  .sidebar-backdrop.open { display: block; }
  .detail-panel { height: calc(100vh - 64px); max-height: calc(100vh - 64px); min-height: 560px; }
  @supports (height: 100dvh) {
    .detail-panel { height: calc(100dvh - 64px); max-height: calc(100dvh - 64px); }
  }
  .detail-heading { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; grid-template-rows: auto auto; align-items: center; padding: 7px 9px; column-gap: 7px; row-gap: 1px; }
  .detail-heading > div:first-child { display: contents; }
  .detail-heading .sidebar-toggle { grid-column: 1; grid-row: 1; margin: 0; }
  .detail-heading .eyebrow { display: none; }
  .detail-heading h2 { grid-column: 2; grid-row: 1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; line-height: 1.25; }
  .detail-heading .muted { grid-column: 2; grid-row: 2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; line-height: 1.25; }
  .detail-heading .goal-summary { grid-column: 2; grid-row: 3; }
  .detail-heading .danger { grid-column: 3; grid-row: 1; align-self: center; }
  .detail-actions { grid-column: 3; grid-row: 1 / span 2; align-self: center; flex-direction: row; gap: 4px; }
  .detail-heading .danger { padding: 6px 9px; font-size: 12px; }
  .detail-heading .compact-action { padding: 5px 8px; font-size: 11px; }
  .goal-summary { max-width: 100%; margin-top: 2px; font-size: 9px; }
  .message { max-width: 99%; padding: 8px 10px; font-size: 13px; line-height: 1.48; }
  .message-label { margin-bottom: 3px; font-size: 9px; }
  .message-list { padding: 9px; gap: 8px; }
  .message-list { min-height: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
  .conversation-body { display: flex; flex-direction: column; }
  .message-nav { flex: 0 0 auto; max-height: 26px; overflow-x: auto; overflow-y: hidden; padding: 2px 6px; border-right: 0; border-bottom: 1px solid #edf2f7; }
  .message-nav-list { display: flex; gap: 6px; justify-items: initial; }
  .message-nav-button { width: 24px; min-height: 22px; padding: 1px; font-size: 9px; }
  .event-strip { min-height: 21px; padding: 3px 9px; font-size: 10px; }
}

@media (max-width: 760px) {
  body.connected { overflow: hidden; }
  body.connected .app-shell { height: 100vh; min-height: 100vh; display: flex; flex-direction: column; }
  body.connected .topbar { flex: 0 0 auto; }
  body.connected .workspace { flex: 1 1 auto; min-height: 0; }
  body.connected .detail-panel { height: 100%; max-height: none; min-height: 0; }
  body.connected .composer { padding: 5px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); }
  body.connected .skill-suggestions { right: 8px; left: 8px; max-height: min(176px, 32dvh); }
  body.connected .skill-suggestion { padding: 6px 8px; }
  body.connected .composer textarea { min-height: 46px; max-height: 86px; padding: 6px 9px; font-size: 13px; }
  body.connected .composer-footer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px; margin-top: 5px; }
  body.connected .composer-tools, body.connected .composer-actions { gap: 4px; }
  body.connected #selected-cwd { display: none; }
  body.connected .image-button { width: 28px; height: 28px; font-size: 16px; }
  body.connected .turn-select { height: 28px; padding: 3px 4px; font-size: 10px; }
  body.connected .turn-model { width: auto; flex: 1 1 68px; }
  body.connected .turn-reasoning { width: 44px; flex: 0 0 44px; }
  body.connected .image-upload-state { max-width: 120px; font-size: 10px; }
  body.connected .image-progress { width: 30px; }
  body.connected .bottom-button { width: 26px; height: 28px; font-size: 15px; }
  body.connected .queue-toggle { min-width: 42px; height: 28px; padding: 0 4px; font-size: 10px; }
  body.connected .composer-footer button { min-width: 52px; padding: 6px 7px; font-size: 12px; }
  body.connected .composer-footer .queue-toggle { min-width: 42px; padding: 0 4px; }
  body.connected .composer-footer .bottom-button { width: 26px; min-width: 26px; padding: 0; }
  @supports (height: 100dvh) {
    body.connected .app-shell { height: 100dvh; min-height: 100dvh; }
  }
}
