* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #1a1a1a; color: #e5e5e5;
}
.muted { color: #888; font-size: 13px; }
.spacer { flex: 1; }
button {
  background: #2d2d2d; color: #e5e5e5; border: 1px solid #3d3d3d;
  padding: 6px 14px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
button:hover { background: #3d3d3d; }
button.tiny { padding: 2px 8px; font-size: 12px; }
button.ghost { background: transparent; }
button.danger:hover { background: #5c2222; border-color: #8c3333; }

/* ── 登录页 ─────────────────────────────── */
.login-body {
  display: flex; align-items: center; justify-content: center; height: 100vh;
  background: linear-gradient(135deg, #1a1a1a 0%, #2a2a3a 100%);
}
.login-card {
  background: #222; padding: 40px; border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5); width: 320px;
}
.login-card h1 { margin: 0 0 4px 0; font-size: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-card input {
  background: #1a1a1a; color: #e5e5e5; border: 1px solid #3d3d3d;
  padding: 10px 14px; border-radius: 4px; font-size: 14px;
}
.login-card input:focus { border-color: #4d7dff; outline: none; }
.login-card button { padding: 10px; font-size: 14px; }
.err { color: #ff6b6b; font-size: 13px; min-height: 18px; margin: 8px 0 0 0; }

/* ── 主布局 ─────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: #222; border-bottom: 1px solid #333;
  height: 44px;
}
.brand { font-weight: 600; letter-spacing: 0.5px; flex-shrink: 0; }

/* ── 标签栏 ─────────────────────────────── */
.tab-bar {
  flex: 1; min-width: 0; list-style: none; margin: 0; padding: 0;
  display: flex; gap: 4px; overflow-x: auto;
}
.tab-bar::-webkit-scrollbar { height: 4px; }
.tab-bar::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }
.tab-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 10px; background: #2a2a2a; border: 1px solid #333;
  border-radius: 4px; font-size: 12px; cursor: pointer; color: #ccc;
  white-space: nowrap; max-width: 220px; flex-shrink: 0;
}
.tab-item:hover { background: #333; }
.tab-item.active { background: #2a3a5a; border-color: #4d7dff; color: #fff; }
.tab-item .icon { font-size: 11px; opacity: 0.85; }
.tab-item .label { overflow: hidden; text-overflow: ellipsis; }
.tab-item .close {
  background: transparent; border: none; color: #888;
  font-size: 14px; padding: 0 2px; cursor: pointer; line-height: 1;
}
.tab-item .close:hover { color: #ff6b6b; }
.layout {
  display: flex; height: calc(100vh - 44px);
}
.sidebar {
  width: 240px; background: #1f1f1f; border-right: 1px solid #333;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 10px 14px; font-size: 12px; color: #888;
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid #2a2a2a;
}
.section-title.collapsible { cursor: pointer; user-select: none; }
.section-title.collapsible:hover { background: #232323; }
.section-title .collapse-chevron {
  display: inline-block; font-size: 10px; transition: transform 0.15s;
  width: 10px; text-align: center;
}
.section-title.collapsed .collapse-chevron { transform: rotate(-90deg); }
.section-title.collapsed + .spec-list,
.section-title.collapsed + .session-list { display: none; }
.session-list { list-style: none; margin: 0; padding: 4px 0; }
.session-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; cursor: pointer;
  border-left: 3px solid transparent;
}
.session-item:hover { background: #2a2a2a; }
.session-item.active { background: #2a3a5a; border-left-color: #4d7dff; }
.session-item .name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .meta { font-size: 11px; color: #777; }
.session-item .kill-btn {
  opacity: 0; background: transparent; border: none; color: #888;
  font-size: 14px; padding: 2px 6px; cursor: pointer;
}
.session-item:hover .kill-btn { opacity: 1; }
.session-item .kill-btn:hover { color: #ff6b6b; }
.attached-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: #4dff7d; margin-right: 4px;
}

/* ── 终端区 ─────────────────────────────── */
.terminal-pane {
  flex: 1; position: relative; background: #000;
}
.term-container {
  width: 100%; height: 100%; position: relative;
}
.term-container iframe {
  position: absolute; inset: 0;
  width: 100%; height: 100%; border: none; display: none;
}
.term-container iframe.active { display: block; }
.empty-state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #555; font-size: 14px; pointer-events: none;
}

/* SPEC 列表 */
.spec-list { list-style: none; margin: 0; padding: 4px 0; }
.spec-item {
  padding: 8px 14px; cursor: pointer; font-size: 13px;
  border-left: 3px solid transparent;
  position: relative;
}
.spec-item:hover { background: #2a2a2a; }
.spec-item .title {
  color: #e5e5e5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.spec-item .meta { color: #777; font-size: 11px; margin-top: 2px; }
.spec-item .spec-kill {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  opacity: 0; background: transparent; border: none; color: #888;
  font-size: 14px; padding: 2px 6px; cursor: pointer;
}
.spec-item:hover .spec-kill { opacity: 1; }
.spec-item .spec-kill:hover { color: #ff6b6b; }

/* 状态徽章 */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px;
  font-size: 11px; border-radius: 8px; line-height: 1;
  flex-shrink: 0;
}
.badge-done      { background: #2e6b3e; color: #bfe9c5; }
.badge-running   { background: #2a4a7a; color: #b7d0ff; animation: pulse 1.6s infinite; }
.badge-interrupt { background: #6b5722; color: #f0d78a; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* SPEC 内嵌预览（覆盖终端区） */
.spec-view {
  position: absolute; inset: 0; z-index: 5;
  background: #1a1a1a;
  display: none; flex-direction: column;
}
.spec-view.active { display: flex; }
.spec-view-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid #333; background: #222;
}
.spec-view-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.spec-view-header .muted { font-size: 12px; }
.spec-view-header button { font-size: 18px; padding: 0 8px; }
.spec-view-body {
  flex: 1; overflow: auto; margin: 0; padding: 14px 18px;
  font-family: "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  color: #d4d4d4; background: #1a1a1a;
}
.spec-view-footer {
  padding: 10px 16px; border-top: 1px solid #333; background: #1f1f1f;
  display: flex; align-items: center; gap: 10px; justify-content: flex-end;
}
.spec-view-footer .muted { margin-right: auto; }
.spec-item.active { background: #2a3a5a; border-left-color: #4d7dff; }

/* 剪贴板复制 toast */
.clip-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: #2e6b3e; color: #e8f5e9; padding: 8px 16px;
  border-radius: 6px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; z-index: 200;
}
.clip-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.clip-toast.err { background: #8c3333; color: #ffdede; }

/* 桌面端不需要菜单按钮 */
.menu-btn { display: none; font-size: 18px; padding: 4px 10px; }

.sidebar-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
  display: none;
}
.layout { position: relative; }

/* ── 移动端适配 ─────────────────────────── */
@media (max-width: 768px) {
  .topbar {
    height: 44px; padding: 4px 8px; gap: 6px;
  }
  .menu-btn { display: inline-flex; align-items: center; }
  .brand { font-size: 13px; }

  .sidebar {
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 78%; max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
    box-shadow: 2px 0 16px rgba(0,0,0,0.5);
  }
  .layout.sidebar-open .sidebar { transform: translateX(0); }
  .layout.sidebar-open .sidebar-backdrop { display: block; }

  /* 让终端区占满，sidebar 浮在上层 */
  .terminal-pane { width: 100%; }

  /* 移动端隐藏标签栏，仅靠侧栏切换 */
  .tab-bar { display: none; }

  /* 退出按钮顶到右上角 */
  #logout-btn { margin-left: auto; }

  /* 触控目标加大 */
  .session-item, .spec-item { padding: 12px 14px; }
  .session-item .kill-btn, .spec-item .spec-kill { opacity: 1; }

  /* SPEC 视图按钮在窄屏换行 */
  .spec-view-header { padding: 8px 12px; }
  .spec-view-header h3 { font-size: 14px; }
  .spec-view-header .muted { display: none; }
  .spec-view-body { padding: 10px 12px; font-size: 11px; }
  .spec-view-footer {
    flex-wrap: wrap; gap: 6px; padding: 8px 10px;
  }
  .spec-view-footer .muted {
    width: 100%; margin: 0 0 2px 0; font-size: 11px;
  }
  .spec-view-footer button {
    flex: 1 1 auto; min-width: 0; padding: 8px 10px; font-size: 12px;
  }
}

/* 桌面端隐藏 backdrop */
@media (min-width: 769px) {
  .sidebar-backdrop { display: none !important; }
}
