/* 深色主题（默认） */
:root, body.dark {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1f2430;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #5b8cff;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --gray: #6e7681;
  --overlay: rgba(0, 0, 0, .6);
  --codebg: #0b0d11;
  --hover: #2a3040;
  --active: #243049;
}

/* 浅色主题 */
body.light {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel2: #eef1f7;
  --border: #d8dee9;
  --text: #1b2230;
  --muted: #65718a;
  --accent: #2f6fed;
  --green: #1a7f37;
  --yellow: #9a6700;
  --red: #cf222e;
  --gray: #8b94a6;
  --overlay: rgba(20, 28, 46, .35);
  --codebg: #f0f3f9;
  --hover: #e2e7f0;
  --active: #dbe6ff;
}
body.light .plog.thinking { color: #6f42c1; }
body.light .plog.tool { color: #1a7f8c; }
body.light .plog.output { color: #1a7f37; }
body { transition: background .2s, color .2s; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ── 侧边栏 ── */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.sidebar header h1 { font-size: 16px; margin: 0; }
.section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.section h2 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; letter-spacing: .5px; }

select, input, textarea, button {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
select, input, textarea { width: 100%; }
input::placeholder, textarea::placeholder { color: var(--muted); }

button { cursor: pointer; background: var(--panel2); transition: background .15s; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--red); }
button.warn { color: var(--yellow); }
button:disabled { opacity: .4; cursor: not-allowed; }

.row { display: flex; gap: 8px; margin-top: 8px; }
.row > * { flex: 1; }

/* 根目录选择行：下拉占满 + 紧凑方形图标按钮 */
.root-row { display: flex; gap: 6px; align-items: center; }
.root-row select { flex: 1; min-width: 0; }
.icon-square {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

/* 根目录备注 + 链接 */
.root-meta { margin-top: 10px; }
.meta-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.meta-head .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.meta-edit { flex: none; padding: 2px 8px; font-size: 12px; background: transparent; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); }
.meta-empty { width: 100%; text-align: left; font-size: 12px; color: var(--muted); background: transparent; border: 1px dashed var(--border); border-radius: 8px; padding: 7px 10px; }
.meta-empty:hover { background: var(--hover); }
.root-meta .note { font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-word; margin-bottom: 8px; }
.root-meta .links { display: flex; flex-wrap: wrap; gap: 6px; }
.root-meta .links a {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.root-meta .links a:hover { background: var(--hover); }

/* 编辑根目录弹窗字段 */
.fld-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.fld-row { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 8px; }
.link-row { display: flex; gap: 6px; margin-bottom: 6px; }
.link-row .lbl { flex: 0 0 34%; }
.link-row .url { flex: 1; }
.link-row .del { flex: none; padding: 6px 10px; }

.session-list { flex: 1; overflow-y: auto; }
.session-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.session-item:hover { background: var(--panel2); }
.session-item.active { background: var(--active); border-left: 3px solid var(--accent); }
.session-item .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .meta { font-size: 11px; color: var(--muted); }
.session-item .del { color: var(--gray); font-size: 12px; opacity: 0; }
.session-item:hover .del { opacity: 1; }
.empty { color: var(--muted); font-size: 13px; padding: 16px 14px; }

/* ── 主区 ── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.main-header .title { font-weight: 600; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.badge.paused { background: #3a2f12; color: var(--yellow); }
body.light .badge.paused { background: #fbf0d0; }
.spacer { flex: 1; }

.content { flex: 1; display: flex; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.assistant { align-self: flex-start; background: var(--panel2); border-bottom-left-radius: 3px; }
.msg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 0; }
.msg.user .who { color: #dce7ff; }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.copy-btn {
  flex: none; border: none; background: transparent; cursor: pointer;
  font-size: 12px; line-height: 1; padding: 2px 5px; border-radius: 6px;
  color: inherit; opacity: .5; transition: opacity .15s, background .15s;
}
.copy-btn:hover { opacity: 1; background: rgba(127, 127, 127, .18); }
.copy-btn.copied { opacity: 1; color: #16a34a; }
.msg.user .copy-btn.copied { color: #d1ffe0; }

/* 过程面板 */
.process-panel {
  width: 38%;
  min-width: 280px;
  border-left: 1px solid var(--border);
  background: var(--codebg, #0b0d11);
  display: flex;
  flex-direction: column;
}
.process-panel header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}
.process-log { flex: 1; overflow-y: auto; padding: 10px 12px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; line-height: 1.5; }
.plog { margin-bottom: 6px; white-space: pre-wrap; word-break: break-word; }
.plog.thinking { color: #b794f6; }
.plog.tool { color: #56b6c2; }
.plog.output { color: #98c379; }
.plog .tag { opacity: .6; margin-right: 6px; }

/* 任务队列 + 输入 */
.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 12px 16px; }
.queue-bar { display: flex; align-items: center; margin-bottom: 8px; }
.queue-toggle {
  flex: none;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel2);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.queue-toggle:hover { background: var(--hover); }
.queue { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; max-height: 78px; overflow-y: auto; }
/* 展开：纵向完整清单，可看到全部任务与完整文本 */
.queue.expanded {
  flex-direction: column;
  flex-wrap: nowrap;
  max-height: 46vh;
  gap: 4px;
  padding-right: 4px;
}
.queue.expanded .qtask {
  width: 100%;
  border-radius: 8px;
  align-items: flex-start;
  padding: 7px 10px;
}
.queue.expanded .qtask .qtext { white-space: normal; word-break: break-word; flex: 1; }
.queue .qtask .qidx { display: none; }
.queue.expanded .qtask .qidx { display: inline; color: var(--muted); margin-right: 2px; }
.queue-empty { color: var(--muted); font-size: 12px; padding: 4px 2px; }
.qtask { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); display: flex; gap: 6px; align-items: center; }
.qtask .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.pending { background: var(--gray); }
.dot.running { background: var(--accent); animation: pulse 1s infinite; }
.dot.done { background: var(--green); }
.dot.stopped { background: var(--yellow); }
.dot.error { background: var(--red); }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.3;} }

.composer textarea { resize: vertical; min-height: 56px; }
.controls { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.controls button { flex: none; }
/* 紧凑按钮 */
button.sm { padding: 6px 12px; font-size: 13px; border-radius: 7px; }
#addTasksBtn.sm { padding: 4px 11px; font-size: 12px; border-radius: 999px; }
.tasks-hint { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.tasks-count { color: var(--muted); font-size: 13px; }
#tasksInput { font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.5; }

/* ── 登录遮罩 ── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.login-overlay[hidden] { display: none; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px;
  width: 320px;
  max-width: 90vw;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.login-card h2 { margin: 0 0 18px; font-size: 18px; }
.login-card input { margin-bottom: 12px; }
.login-card button { width: 100%; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ── 目录选择器 ── */
.picker-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 560px;
  max-width: 94vw;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
  overflow: hidden;
}
.picker-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.picker-bar { padding: 8px 14px 0; display: flex; gap: 8px; align-items: center; }
.picker-card > #pickerSearch { margin: 8px 14px 0; width: auto; }
.drives { display: flex; gap: 6px; flex-wrap: wrap; overflow-x: auto; }
.drives button { flex: none; padding: 5px 10px; }
.picker-list { flex: 1; overflow-y: auto; margin: 10px 0; padding: 0 8px; min-height: 180px; }
.dir-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.dir-row:hover { background: var(--panel2); }
.dir-row .ico { opacity: .8; }
.dir-row .sub { color: var(--muted); font-size: 11px; margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 50%; }
.picker-foot { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.picker-foot input { flex: 1; }
.picker-empty { color: var(--muted); padding: 24px; text-align: center; }
#pickerPath { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* 图标按钮（抽屉 / 过程切换），桌面端隐藏 */
.icon-btn {
  display: none;
  flex: none;
  font-size: 18px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
}
.icon-btn:hover { background: var(--panel2); }
.scrim { display: none; }
.proc-close { display: none; }

/* ── 移动端适配：抽屉式侧栏 + ChatGPT 风格对话 ── */
@media (max-width: 860px) {
  .icon-btn { display: inline-flex; align-items: center; }

  /* 侧栏变为左侧抽屉，默认滑出屏幕 */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 84vw;
    max-width: 330px;
    height: 100vh;
    max-height: none;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 24px rgba(0, 0, 0, .35);
  }
  body.drawer-open .sidebar { transform: none; }

  /* 抽屉背景遮罩 */
  body.drawer-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 50;
  }

  .main { width: 100%; height: 100vh; }
  .main-header { padding: 10px 12px; }
  .main-header .title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* 对话区：消息占满，输入框沉底（类似 ChatGPT） */
  .content { flex-direction: column; min-height: 0; }
  .messages { padding: 14px 12px 4px; }
  .msg { max-width: 88%; }

  /* 过程面板：移动端作为覆盖层，由 ⚙ 切换 */
  .process-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    min-width: 0;
    z-index: 70;
    border-left: none;
    display: none;
  }
  .proc-close { display: inline-flex; }
  body.show-process .process-panel { display: flex; }

  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .composer textarea { min-height: 44px; }
  .controls button { padding: 9px 12px; }
}
