/* ============ 主题变量（支持换肤） ============ */
:root {
  --primary: #1677ff;
  --primary-deep: #0f5fd6;
  --primary-soft: #e8f1ff;
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #f2f5fa;
  --text: #1f2329;
  --text-soft: #86909c;
  --text-faint: #b0b8c4;
  --border: #e5e6eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --pill: 999px;

  --shadow-sm: 0 1px 2px rgba(31, 35, 41, 0.04);
  --shadow-md: 0 4px 16px rgba(22, 119, 255, 0.10);
  --shadow-lg: 0 12px 32px rgba(22, 119, 255, 0.14);

  --sidebar-w: 264px;
}

/* 深色主题 */
[data-theme="dark"] {
  --bg: #0f141b;
  --surface: #161c26;
  --surface-2: #1c2430;
  --text: #e6e9ee;
  --text-soft: #8a94a3;
  --text-faint: #5c6673;
  --border: #262e3a;
  --primary-soft: #16304f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* ============ 基础 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  /* 散点网格背景 */
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ============ 左侧边栏 ============ */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px 12px;
  gap: 12px;
  z-index: 10;
}

.logo { display: flex; align-items: center; gap: 10px; padding: 2px 8px; }
.logo-icon {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: linear-gradient(135deg, var(--primary), #4da0ff);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}
.logo-name { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }

.btn-new {
  padding: 11px 14px;
  border: none;
  border-radius: var(--pill);
  background: var(--primary);
  color: #fff;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: all .15s;
}
.btn-new:hover { background: var(--primary-deep); transform: translateY(-1px); }
.btn-new:active { transform: scale(0.97); }

/* 模块导航 */
.modules { display: flex; flex-direction: column; gap: 2px; }
.module {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border: none; border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-soft);
  font-size: 13.5px; font-weight: 500;
  text-align: left;
  transition: all .14s;
}
.module .mi { font-size: 16px; width: 20px; text-align: center; }
.module:hover { background: var(--surface-2); color: var(--text); }
.module.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* 会话列表 */
.session-box { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.session-search { padding: 0 4px 8px; }
.session-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.session-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.session-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background .12s;
}
.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--primary-soft); }
.session-item .si-icon { font-size: 15px; width: 18px; text-align: center; flex: none; }
.session-item .si-title {
  flex: 1; font-size: 13px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item .si-time { font-size: 11px; color: var(--text-faint); flex: none; }

.sidebar-foot {
  display: flex; gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.foot-btn {
  flex: 1; padding: 8px;
  border: none; border-radius: var(--radius-md);
  background: var(--surface-2);
  font-size: 15px;
  transition: background .12s;
}
.foot-btn:hover { background: var(--primary-soft); }

/* ============ 主区 ============ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.main-tabs {
  display: flex; gap: 4px;
  padding: 12px 20px 0;
}
.mtab {
  padding: 8px 18px;
  border: none; border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-soft);
  font-size: 14px; font-weight: 600;
  transition: all .14s;
}
.mtab:hover { color: var(--text); }
.mtab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

.content { flex: 1; min-height: 0; position: relative; }
.panel { display: none; position: absolute; inset: 0; flex-direction: column; }
.panel.active { display: flex; }

.panel-placeholder {
  margin: 20px;
  padding: 40px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-soft);
  font-size: 15px;
  text-align: center;
  flex: 1;
  display: flex; align-items: center; justify-content: center;
}

/* 消息流 */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { max-width: 78%; }
.msg.user { align-self: flex-end; }
.msg.ai { align-self: flex-start; }

.msg .bubble {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}
.msg.user .bubble {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 6px var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.msg.ai .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 6px;
  box-shadow: var(--shadow-sm);
}

/* 折叠块（Bash / Think / 工具调用） */
.fold { margin-top: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.fold-head {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 10px;
  background: var(--surface-2);
  font-size: 12px; font-weight: 600; color: var(--text-soft);
  cursor: pointer;
  user-select: none;
}
.fold-head .caret { transition: transform .15s; font-size: 10px; }
.fold.open .caret { transform: rotate(90deg); }
.fold-body {
  display: none;
  padding: 10px;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text;
  background: var(--surface-2);
}
.fold.open .fold-body { display: block; }

/* 轨迹 */
.trace {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.trace-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12.5px;
}
.trace-row .node { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.trace-row .tt { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.trace-row .tp { font-weight: 700; padding: 2px 9px; border-radius: var(--pill); font-size: 11px; }
.trace-row .td { color: var(--text-soft); word-break: break-all; }

/* 输入区 */
.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 20px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.composer-row { display: flex; gap: 10px; }
.composer-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--pill);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.composer-input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.btn-send {
  padding: 12px 26px;
  border: none; border-radius: var(--pill);
  background: var(--primary);
  color: #fff;
  font-size: 14px; font-weight: 700;
  box-shadow: var(--shadow-md);
  transition: all .15s;
}
.btn-send:hover { background: var(--primary-deep); }
.btn-send:active { transform: scale(0.96); }
.btn-send:disabled { opacity: .55; cursor: not-allowed; }

.composer-meta { display: flex; align-items: center; gap: 10px; }
.sel {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--pill);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 12.5px;
  outline: none;
}
.statusbar { margin-left: auto; display: flex; gap: 16px; }
.stat { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-soft); }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.warn { background: var(--warn); }

/* ============ 右侧悬浮按钮组 ============ */
.fab-group {
  position: fixed;
  right: 20px; top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 12px;
  z-index: 40;
}
.fab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 54px; padding: 10px 0;
  border: none; border-radius: var(--pill);
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  box-shadow: var(--shadow-lg);
  transition: all .15s;
}
.fab span { font-size: 10px; font-weight: 600; }
.fab:hover { background: var(--primary-deep); transform: translateY(-2px); }
.fab:active { transform: scale(0.95); }

/* ============ 鲸鱼娘桌宠 ============ */
.pet {
  position: fixed;
  right: 24px; bottom: 24px;
  z-index: 50;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.pet-img {
  width: 84px; height: 84px;
  object-fit: cover;
  background: linear-gradient(160deg, rgba(22,119,255,0.10), rgba(77,160,255,0.04));
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  animation: bob 3.2s ease-in-out infinite;
  transition: transform .15s;
}
.pet:hover .pet-img { transform: scale(1.06); }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
.pet-bubble {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translateY(4px);
  transition: all .2s;
  white-space: nowrap;
}
.pet.show .pet-bubble { opacity: 1; transform: translateY(0); }

/* ============ 滚动条 ============ */
.session-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.trace::-webkit-scrollbar { width: 6px; }
.session-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.trace::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ============ 模块面板 ============ */
.module-panel { flex: 1; display: flex; flex-direction: column; padding: 20px; gap: 14px; min-height: 0; }
.module-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.module-head h2 { font-size: 17px; font-weight: 700; margin-right: auto; }
.btn-pill {
  padding: 7px 16px;
  border: none; border-radius: var(--pill);
  background: var(--primary);
  color: #fff;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: all .14s;
}
.btn-pill:hover { background: var(--primary-deep); }
.btn-pill:active { transform: scale(0.96); }

.text-input {
  flex: 1; min-width: 160px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--pill);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.text-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.code-view {
  flex: 1;
  overflow: auto;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  color: var(--text);
  user-select: text;
}

/* 任务看板 */
.board-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.board-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.board-item .bi-icon { font-size: 20px; }
.board-item .bi-main { flex: 1; min-width: 0; }
.board-item .bi-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-item .bi-meta { font-size: 12px; color: var(--text-soft); }
.board-item .bi-del {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--pill);
  background: transparent;
  color: var(--text-soft);
  font-size: 12px;
}
.board-item .bi-del:hover { background: #fee2e2; color: var(--err); border-color: #fecaca; }

/* 文件预览 */
.files-body { flex: 1; display: flex; gap: 12px; min-height: 0; }
.file-list {
  width: 280px; flex: none;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px;
}
.file-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.file-item:hover { background: var(--surface-2); }
.file-item .fi-icon { font-size: 15px; }
.file-item .fi-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-item .fi-size { font-size: 11px; color: var(--text-faint); }
.file-item.dir { color: var(--primary); font-weight: 600; }

/* 移动控制 */
.remote-body { flex: 1; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.remote-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.rc-title { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; font-weight: 600; }
.rc-status { font-size: 20px; font-weight: 700; }
.rc-status.online { color: var(--ok); }
.rc-status.offline { color: var(--err); }
.rc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.rc-hint { font-size: 12.5px; color: var(--text-soft); line-height: 1.7; }

/* 登录遮罩（Web 版） */
.login-mask {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.login-box {
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 14px;
}
.login-box h2 { font-size: 18px; text-align: center; }
.login-box input {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--pill);
  font-size: 14px;
  outline: none;
}
.login-box input:focus { border-color: var(--primary); }
.login-box .btn-send { width: 100%; }

/* ============ 响应式（移动端） ============ */
@media (max-width: 720px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .fab-group { right: 12px; }
  .msg { max-width: 92%; }
  .statusbar { display: none; }
  .files-body { flex-direction: column; }
  .file-list { width: auto; flex: none; max-height: 40%; }
}
