/* ============================================================
   GoodHand · 对话端样式（自包含，不依赖任何共享样式文件）
   区块：令牌 / 深色 / 基础 / 布局 / 侧栏 / 模型 / 顶栏 /
         消息 / 空状态 / 输入区 / Toast / 响应式 / 动效降级
   ============================================================ */

/* ---------------- 设计令牌 ---------------- */
:root {
  color-scheme: light;

  /* 字体 */
  --font-sans: "Inter", "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;

  /* 颜色 */
  --bg: #f5f6fb;
  --bg-soft: #eceff9;
  --surface: #ffffff;
  --surface-2: #fafbff;
  --border: #e5e8f1;
  --border-strong: #cbd2e2;
  --text: #161922;
  --text-2: #454b5c;
  --muted: #656c88;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef0ff;
  --brand-ring: rgba(79, 70, 229, .16);
  --success: #0f9d76;
  --danger: #e5484d;
  --warning: #b7791f;
  /* Anthropic 协议标签的暖色（与客户端控制台保持一致） */
  --warm: #a05a2c;
  --warm-soft: #f5efe7;
  --warm-border: #ecdcc9;

  /* 圆角 / 阴影 / 动效 */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 2px 8px rgba(16, 24, 40, .06);
  --shadow-md: 0 10px 30px rgba(16, 24, 40, .08);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, .16);
  --ease: cubic-bezier(.22, .61, .36, 1);
  --dur: .18s;

  /* 补充令牌：只为深色模式下「仅覆盖变量」而存在，避免重复写规则 */
  --brand-grad: linear-gradient(135deg, var(--brand), var(--brand-2));
  --on-brand: #ffffff;
  --user-code-bg: rgba(255, 255, 255, .2);
  --user-link-underline: rgba(255, 255, 255, .7);
  --brand-border: #c9cdf7;
  --user-text: #ffffff;
  --code-bg: rgba(22, 25, 34, .06);
  --code-block-bg: #f2f4fa;
  --danger-soft: #fdf2f2;
  --danger-border: #f3c9ca;
  --danger-text: #b42326;
  --toast-bg: #1f2330;
  --toast-text: #ffffff;
  --scroll-thumb: #c9cfdd;
}

/* ---------------- 深色模式：只覆盖变量 ---------------- */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0e1016;
    --bg-soft: #141823;
    --surface: #171a24;
    --surface-2: #1d2130;
    --border: #262b3a;
    --border-strong: #3a4258;
    --text: #eef1f8;
    --text-2: #c3c9d8;
    --muted: #8b93a8;
    --brand: #8189ff;
    --brand-2: #a78bfa;
    --brand-soft: #232a4d;
    --brand-ring: rgba(129, 137, 255, .22);
    --warm: #e8b57a;
    --warm-soft: rgba(224, 166, 74, .14);
    --warm-border: rgba(224, 166, 74, .3);

    /* 阴影加深 */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .40);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, .45);
    --shadow-md: 0 12px 34px rgba(0, 0, 0, .50);
    --shadow-lg: 0 26px 64px rgba(0, 0, 0, .60);

    --brand-border: #3f4785;
    /* 深色下品牌色变浅，实心底改用更深的渐变以保证白字对比度 */
    --brand-grad: linear-gradient(135deg, #4f46e5, #7c3aed);
    --user-text: #ffffff;
    --code-bg: rgba(255, 255, 255, .08);
    --code-block-bg: #10131c;
    --danger-soft: #2a1518;
    --danger-border: #5d2429;
    --danger-text: #ffb4b6;
    --toast-bg: #eef1f8;
    --toast-text: #12141c;
    --scroll-thumb: #3a4258;
  }
}

/* ---------------- 基础重置 ---------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

svg {
  display: block;
}

a {
  color: var(--brand);
  text-decoration: none;
}

.is-hidden {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

::selection {
  background: var(--brand-ring);
}

/* ---------------- 滚动条（webkit 细样式） ---------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  background-clip: content-box;
  border: 3px solid transparent;
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
  background-clip: content-box;
}

/* ---------------- 整体布局 ---------------- */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------------- 侧栏 ---------------- */
.sidebar {
  display: flex;
  flex: 0 0 264px;
  flex-direction: column;
  gap: 14px;
  width: 264px;
  min-height: 0;
  padding: 18px 14px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-head {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--brand-grad);
  color: var(--on-brand);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .2px;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .2px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

/* ---------------- 当前用户（租户） ---------------- */
.user-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.user-avatar {
  display: grid;
  flex: 0 0 30px;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-grad);
  color: var(--on-brand);
  font-size: 14px;
  font-weight: 700;
}

.user-meta {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.user-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-sub {
  color: var(--muted);
  font-size: 11px;
}

.user-logout {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.user-logout:hover {
  border-color: var(--danger-border, #f3c9ca);
  background: var(--danger-soft, #fdf2f2);
  color: var(--danger);
}

.model-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.sidebar-label {
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.sidebar-foot {
  padding: 8px 4px 2px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

/* ---------------- 模型列表（仅选择，增删在客户端） ---------------- */
.model-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  margin: -2px;
  padding: 2px;
  overflow-y: auto;
}

.model-item {
  position: relative;
  display: block;
  width: 100%;
  padding: 10px 12px 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  color: inherit;
  text-align: left;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.model-item:hover {
  background: var(--bg-soft);
  box-shadow: var(--shadow-sm);
}

.model-item.is-active {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  box-shadow: var(--shadow-xs);
}

.model-item.is-active::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 3px;
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
}

.model-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.model-name-text {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  flex: 0 0 auto;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.6;
}

.tag-anthropic {
  border-color: var(--warm-border);
  background: var(--warm-soft);
  color: var(--warm);
}

.tag-openai {
  color: var(--text-2);
}

.model-id {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-meta {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-2);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--muted);
}

.model-empty-text {
  font-size: 12.5px;
}

.skill-empty {
  padding: 8px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ---------------- 事件执行（侧栏折叠区，定时任务即事件） ---------------- */
.evt-panel {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.evt-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
}

.evt-toggle {
  display: inline-flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-align: left;
  transition: color var(--dur) var(--ease);
}

.evt-toggle:hover {
  color: var(--brand);
}

.evt-chevron {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  transition: transform var(--dur) var(--ease);
}

.evt-toggle.is-open .evt-chevron {
  transform: rotate(90deg);
}

.evt-count {
  flex: 0 0 auto;
  min-width: 16px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0;
  text-align: center;
}

.evt-count:empty {
  display: none;
}

.evt-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.evt-hint {
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.evt-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(300px, 40vh);
  margin: -2px;
  padding: 2px;
  overflow-y: auto;
}

.evt-item {
  display: flex;
  align-items: stretch;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.evt-item:hover {
  border-color: var(--border);
  background: var(--bg-soft);
}

.evt-item.is-paused .evt-item-name,
.evt-item.is-paused .evt-item-summary {
  color: var(--muted);
}

.evt-item-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  text-align: left;
}

.evt-item-name {
  overflow: hidden;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evt-item-summary {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evt-item-run {
  flex: 0 0 auto;
  align-self: center;
  margin-right: 6px;
  padding: 4px 12px;
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11.5px;
  font-weight: 700;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}

.evt-item-run:hover:not(:disabled) {
  background: var(--brand);
  color: var(--on-brand);
}

.evt-item-run:disabled {
  cursor: not-allowed;
  opacity: .5;
}

/* ---------------- 定时任务（侧栏折叠区，位于 Skill 管理上方） ---------------- */
.task-panel {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.task-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
}

.task-toggle {
  display: inline-flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-align: left;
  transition: color var(--dur) var(--ease);
}

.task-toggle:hover {
  color: var(--brand);
}

.task-chevron {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  transition: transform var(--dur) var(--ease);
}

.task-toggle.is-open .task-chevron {
  transform: rotate(90deg);
}

.task-count {
  flex: 0 0 auto;
  min-width: 16px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0;
  text-align: center;
}

.task-count:empty {
  display: none;
}

.task-add {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  line-height: 1;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.task-add:hover {
  border-color: var(--brand-border);
  background: var(--brand-soft);
  color: var(--brand);
}

.task-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.task-hint {
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(300px, 40vh);
  margin: -2px;
  padding: 2px;
  overflow-y: auto;
}

.task-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.task-item:hover {
  border-color: var(--border);
  background: var(--bg-soft);
}

.task-item.is-paused .task-item-name,
.task-item.is-paused .task-item-summary {
  color: var(--muted);
}

.task-item-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  text-align: left;
}

.task-item-name {
  overflow: hidden;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-item-summary {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-item-del {
  flex: 0 0 auto;
  width: 24px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  opacity: .6;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}

.task-item-del:hover {
  background: var(--danger-soft);
  color: var(--danger);
  opacity: 1;
}

/* 任务弹窗：频率条件字段 / 启用行 / 执行记录 */
.task-schedule-row {
  flex-direction: row;
  gap: 10px;
}

.field-inner {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
}

.field-inner label {
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 4px;
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
}

.check-row input {
  accent-color: var(--brand);
}

.modal-spacer {
  flex: 1;
}

.task-runs {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.task-runs-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.task-runs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-run {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.task-run.is-error {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.task-run.is-running {
  border-color: var(--brand-border);
  background: var(--brand-soft);
}

.task-run-head {
  margin: 0 0 4px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.task-run-output {
  margin: 0;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.task-run-file {
  display: inline-block;
  margin-top: 6px;
  color: var(--brand);
  font-size: 12px;
  text-decoration: none;
}

.task-run-file:hover {
  text-decoration: underline;
}

.task-run-empty,
.task-run-next {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    filter var(--dur) var(--ease),
    transform var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .45;
  transform: none;
}

.btn-primary {
  background: var(--brand-grad);
  color: var(--on-brand);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  filter: none;
  transform: none;
}

.btn-primary.is-stop {
  background: var(--danger);
}

.btn-secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.btn-sm {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

/* ---------------- 主区 / 顶栏 ---------------- */
.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

/* ---------------- 右侧半屏抽屉（事件执行 / 定时任务） ----------------
   打开时与 .chat 平分侧栏之外的剩余空间：对话窗口缩为原来的一半。 */
.drawer {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.drawer-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.drawer-tab {
  padding: 6px 16px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.drawer-tab:hover {
  color: var(--brand);
}

.drawer-tab.is-on {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-xs);
}

.drawer-search {
  flex: 0 0 auto;
  padding: 10px 16px 0;
}

.drawer-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-family: inherit;
  font-size: 13px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.drawer-search input::placeholder {
  color: var(--muted);
}

.drawer-search input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.drawer-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 14px 16px 16px;
}

.drawer-hint {
  flex: 0 0 auto;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.drawer-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  margin: -2px;
  padding: 2px;
}

.drawer-list .evt-item,
.drawer-list .task-item {
  flex: 0 0 auto;
  padding: 2px;
}

.drawer-list .evt-item-main,
.drawer-list .task-item-main {
  padding: 9px 10px;
}

.drawer-list .evt-item-summary,
.drawer-list .task-item-summary {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.drawer-list .evt-item-run {
  margin-right: 8px;
  padding: 6px 16px;
  font-size: 12px;
}

.drawer-list .skill-empty {
  padding: 18px 12px;
  text-align: center;
}

.chat-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.chat-head-main {
  min-width: 0;
}

.current-model {
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .1px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current-model-sub {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.head-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

/* ---------------- 历史对话面板（顶栏「历史对话」弹出） ---------------- */
.hist-wrap {
  position: relative;
}

.hist-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  width: 304px;
  max-height: min(440px, calc(100vh - 150px));
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 8px;
}

.hist-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .4px;
}

.hist-new {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  transition:
    box-shadow var(--dur) var(--ease),
    filter var(--dur) var(--ease);
}

.hist-new:hover {
  box-shadow: var(--shadow-sm);
  filter: brightness(1.03);
}

.hist-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.hist-empty {
  margin: 0;
  padding: 18px 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.hist-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.hist-item:hover {
  border-color: var(--border);
  background: var(--bg-soft);
}

.hist-item.is-active {
  border-color: var(--brand-border);
  background: var(--brand-soft);
}

.hist-item-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  text-align: left;
}

.hist-item-name {
  overflow: hidden;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hist-item-summary {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hist-item-del {
  flex: 0 0 auto;
  width: 24px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  opacity: .6;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}

.hist-item-del:hover {
  background: var(--danger-soft);
  color: var(--danger);
  opacity: 1;
}

/* ---------------- 消息区 ---------------- */
.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 28px 20px 10px;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.messages-inner {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

.message-list {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 22px;
}

.msg {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

.msg.user {
  align-items: flex-end;
}

.msg.assistant {
  align-items: flex-start;
}

.msg .who {
  margin-bottom: 5px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .02em;
}

.msg.user .who {
  padding-right: 6px;
}

.bubble {
  max-width: 86%;
  padding: 11px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  border-bottom-right-radius: var(--radius-sm);
  background: var(--brand-grad);
  color: var(--user-text);
  box-shadow: var(--shadow-sm);
}

.msg.assistant .bubble {
  border-color: var(--border);
  border-bottom-left-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.msg.is-error .bubble {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger-text);
  box-shadow: none;
}

/* 执行过程：可折叠的工具调用轨迹（助手气泡内，位于正文上方） */
.bubble details.proc {
  margin: 0 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}

.bubble details.proc summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.bubble details.proc summary::-webkit-details-marker {
  display: none;
}

.bubble details.proc summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform var(--dur) var(--ease);
}

.bubble details.proc[open] summary::before {
  transform: rotate(90deg);
}

.bubble .proc-title {
  letter-spacing: .02em;
}

.bubble .proc-count {
  margin-left: auto;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10.5px;
  font-weight: 700;
}

.bubble .proc-steps {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 220px;
  padding: 4px 10px 8px;
  overflow-y: auto;
  border-top: 1px dashed var(--border);
}

.bubble .proc-step {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  padding: 3px 0;
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 1.5;
}

.bubble .proc-mark {
  flex: 0 0 auto;
  width: 14px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.bubble .proc-step.ok .proc-mark {
  color: var(--success);
}

.bubble .proc-step.fail .proc-mark,
.bubble .proc-step.fail .proc-label {
  color: var(--danger);
}

.bubble .proc-label {
  font-weight: 600;
  white-space: nowrap;
}

.bubble .proc-args,
.bubble .proc-result {
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* 思考过程：工具轮次间的模型旁白，与执行过程并列的独立折叠块 */
.bubble details.proc.proc-think {
  border-style: dashed;
}

.bubble details.proc.proc-think summary {
  color: var(--text-2);
}

.bubble .proc-think-steps {
  gap: 8px;
  max-height: 320px;
}

.bubble .proc-think-text {
  padding-left: 9px;
  border-left: 2px solid var(--border);
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bubble .proc-think-text > :first-child {
  margin-top: 0;
}

.bubble .proc-think-text > :last-child {
  margin-bottom: 0;
}

/* 气泡内极简 Markdown 排版 */
.bubble p + p {
  margin-top: 8px;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 12px 0 6px;
  font-size: 1.02em;
  font-weight: 700;
  line-height: 1.4;
}

.bubble h1:first-child,
.bubble h2:first-child,
.bubble h3:first-child,
.bubble p:first-child,
.bubble ul:first-child,
.bubble pre:first-child {
  margin-top: 0;
}

.bubble ul {
  margin: 8px 0;
  padding-left: 20px;
}

.bubble li + li {
  margin-top: 2px;
}

.bubble a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-style: dashed;
  text-underline-offset: 2px;
  word-break: break-all;
}

.bubble a:hover {
  text-decoration-style: solid;
}

.msg.user .bubble a {
  color: var(--on-brand);
  text-decoration-color: var(--user-link-underline);
}

.bubble code {
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: .88em;
}

.msg.user .bubble code {
  background: var(--user-code-bg);
}

.bubble pre {
  margin: 10px 0;
  padding: 12px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--code-block-bg);
}

.bubble pre code {
  padding: 0;
  background: none;
  font-size: 12.5px;
  line-height: 1.6;
}

/* 流式光标 / 状态 */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  border-radius: 1px;
  background: var(--brand);
  vertical-align: -.16em;
  animation: gh-blink 1s step-end infinite;
}

@keyframes gh-blink {
  50% {
    opacity: 0;
  }
}

.bubble-status {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  animation: gh-pulse 1.6s ease-in-out infinite;
}

.status-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

@keyframes gh-pulse {
  50% {
    opacity: .5;
  }
}

/* ---------------- 空状态 ---------------- */
.empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 0 40px;
  text-align: center;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 18px;
  border-radius: var(--radius-xl);
  background: var(--brand-grad);
  color: var(--on-brand);
  font-size: 24px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
}

.empty-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .2px;
}

.empty-sub {
  max-width: 460px;
  margin-top: 8px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.7;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  box-shadow: var(--shadow-xs);
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.chip:hover {
  border-color: var(--brand-border);
  background: var(--brand-soft);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.chip:active {
  transform: none;
}

/* ---------------- 输入区 ---------------- */
.composer-wrap {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 22px 16px;
  background: var(--bg);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  max-width: 820px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition:
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.composer:focus-within {
  border-color: var(--brand-border);
  box-shadow: 0 0 0 4px var(--brand-ring), var(--shadow-sm);
}

.composer:hover:not(:focus-within) {
  box-shadow: var(--shadow-sm);
}

.icon-btn {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--muted);
  transition:
    background var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--brand-border);
  background: var(--brand-soft);
  color: var(--brand);
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: .45;
}

#input {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  max-height: 200px;
  padding: 7px 4px;
  overflow-y: auto;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
  resize: none;
}

#input::placeholder {
  color: var(--muted);
}

#input:focus {
  outline: none;
}

#input:focus-visible {
  outline: none;
}

.send-btn {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 20px;
}

.composer-hint {
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
}

/* ---------------- Skill 编辑弹窗 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 12, 20, .55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: gh-fade-in var(--dur) var(--ease);
}

@keyframes gh-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: min(620px, 100%);
  max-height: min(86vh, 760px);
  overflow-y: auto;
  padding: 22px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: .1px;
}

.modal-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
}

.req {
  color: var(--danger);
  font-style: normal;
}

.field input,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.55;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.field textarea {
  resize: vertical;
  min-height: 120px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.field-hint {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

body.is-locked {
  overflow: hidden;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 100;
  max-width: min(560px, calc(100vw - 32px));
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  transform: translateX(-50%);
  animation: gh-toast-in var(--dur) var(--ease);
}

@keyframes gh-toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------------- 响应式：<900px 侧栏折叠为顶部横向条 ---------------- */
@media (max-width: 899px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    flex: 0 0 auto;
    flex-direction: column;
    gap: 10px;
    width: auto;
    min-height: 0;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0;
  }

  .model-panel {
    flex: 0 0 auto;
    gap: 6px;
  }

  .sidebar-label {
    display: none;
  }

  .model-list {
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0;
    padding: 2px 0;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .model-item {
    flex: 0 0 auto;
    width: auto;
    min-width: 168px;
    max-width: 240px;
  }

  .sidebar-foot {
    display: none;
  }



  .task-panel {
    padding-top: 0;
    border-top: 0;
  }

  .evt-panel {
    padding-top: 0;
    border-top: 0;
  }

  .evt-list {
    max-height: 132px;
  }

  .task-list {
    max-height: 132px;
  }

  .chat {
    min-height: 0;
  }

  /* 移动端：抽屉改为全屏覆盖层，不再挤压对话区 */
  .drawer {
    position: fixed;
    inset: 0;
    z-index: 90;
    flex: none;
    border-left: 0;
    box-shadow: var(--shadow-lg);
  }

  .chat-head {
    padding: 12px 16px;
  }

  .messages {
    padding: 20px 14px 6px;
  }

  .composer-wrap {
    padding: 8px 14px 12px;
  }
}

/* ---------------- 响应式：<560px 进一步压缩 ---------------- */
@media (max-width: 559px) {
  .sidebar {
    gap: 8px;
    padding: 8px 10px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .brand-name {
    font-size: 14px;
  }

  .brand-sub {
    display: none;
  }

  .model-item {
    min-width: 150px;
    max-width: 210px;
    padding: 9px 10px 9px 12px;
  }

  .chat-head {
    padding: 10px 12px;
  }


  .task-list {
    max-height: 108px;
  }

  .task-schedule-row {
    flex-direction: column;
    gap: 14px;
  }

  .modal {
    padding: 12px;
  }

  .modal-card {
    padding: 18px;
    border-radius: var(--radius-lg);
  }

  .current-model {
    font-size: 14px;
  }

  .current-model-sub {
    font-size: 11px;
  }

  .btn-sm {
    padding: 5px 10px;
  }

  .messages {
    padding: 16px 10px 4px;
  }

  .message-list {
    gap: 18px;
  }

  .bubble {
    max-width: 94%;
    padding: 10px 13px;
  }

  .empty {
    padding: 16px 0 28px;
  }

  .empty-mark {
    width: 48px;
    height: 48px;
    margin-bottom: 14px;
    font-size: 20px;
  }

  .empty-title {
    font-size: 18px;
  }

  .empty-sub {
    font-size: 12.5px;
  }

  .prompt-chips {
    gap: 6px;
  }

  .chip {
    padding: 7px 11px;
    font-size: 12px;
  }

  .composer-wrap {
    padding: 6px 10px 10px;
  }

  .composer {
    gap: 8px;
    padding: 8px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .send-btn {
    height: 36px;
    padding: 0 14px;
  }

  .toast {
    bottom: 18px;
  }
}

/* ---------------- 动效降级 ---------------- */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }

  .messages {
    scroll-behavior: auto !important;
  }
}
