/* ============================================================
 * ai-todo · 接口篇 · 浅色科技感 UI
 * 视觉调性:白底 + 浅蓝 + 灰辅 + 青色点缀 / 平滑动画 / 等宽日志
 * ============================================================ */

:root {
  --bg:           #f6f8fc;
  --bg-card:      #ffffff;
  --bg-soft:      #f1f5f9;
  --line:         #e2e8f0;
  --line-strong:  #cbd5e1;
  --ink:          #0f172a;
  --ink-soft:     #334155;
  --ink-mute:     #64748b;
  --ink-dim:      #94a3b8;

  --primary:      #3b82f6;
  --primary-soft: #dbeafe;
  --primary-deep: #1d4ed8;
  --accent:       #06b6d4;
  --accent-soft:  #cffafe;
  --warn:         #f97316;
  --warn-soft:    #fff7ed;
  --ok:           #10b981;
  --ok-soft:      #d1fae5;
  --err:          #ef4444;
  --err-soft:     #fee2e2;

  --shadow-sm:    0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md:    0 4px 12px -2px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg:    0 12px 32px -8px rgba(15, 23, 42, .12), 0 4px 8px rgba(15, 23, 42, .04);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", Inter, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
code, kbd, pre { font-family: var(--font-mono); }

/* ============== 全局背景网格(科技感衬底)============== */

.bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(to right, rgba(59, 130, 246, .04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(59, 130, 246, .04) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 0;
}

/* ============== 三栏布局 ============== */

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 240px 1fr 340px;
  /* 必须显式锁行高 = 100vh,否则 grid 子项按内容高度算,内部 overflow:auto 不生效 */
  grid-template-rows: 100vh;
  height: 100vh;
  max-width: 1480px;
  margin: 0 auto;
  gap: 0;
  /* min-height: 0 让 grid 子项能正确响应内部 overflow */
  min-height: 0;
}

/* 三栏 grid 子项都需要 min-height: 0 + overflow: hidden,防止内容把容器撑大 */
.sidebar,
.chat,
.todos-panel {
  min-height: 0;
  overflow: hidden;
}

/* ============================================================
 * 左栏:会话列表
 * ============================================================ */

.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 12px;
  border-bottom: 1px dashed var(--line);
}

.sidebar__brand h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--ink);
}

.brand-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* brand-tag 已移除 */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--primary-deep); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }

.sidebar__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-dim);
  padding: 6px 4px 4px;
  font-weight: 600;
}

.session-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
  flex: 1;
  margin-right: -6px;
  padding-right: 6px;
}

.session-list::-webkit-scrollbar { width: 5px; }
.session-list::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 5px; }

.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .12s;
  position: relative;
}
.session-item:hover { background: var(--bg-soft); color: var(--ink); }
.session-item.active {
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-weight: 600;
}
.session-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.session-item__id {
  font-family: var(--font-mono);
  font-size: 11px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item__del {
  display: none;
  background: transparent;
  border: none;
  color: var(--ink-dim);
  font-size: 14px;
  padding: 0 4px;
  border-radius: 3px;
}
.session-item:hover .session-item__del { display: inline; }
.session-item__del:hover { color: var(--err); background: var(--err-soft); }

/* ============================================================
 * 中栏:对话主区
 * ============================================================ */

.chat {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  min-width: 0;
}

.chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}

.chat__mode {
  display: flex;
  gap: 0;
  background: var(--bg-soft);
  padding: 3px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
}

.chat__mode input { display: none; }

.chat__mode label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--ink-mute);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all .15s;
}

.chat__mode label code {
  font-size: 10.5px;
  background: transparent;
  padding: 0;
  color: inherit;
  opacity: .7;
}

.chat__mode input:checked + label {
  background: var(--bg-card);
  color: var(--primary-deep);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.chat__mode input:checked + label .mode-icon {
  color: var(--primary);
  font-weight: bold;
}

.mode-icon {
  font-size: 14px;
  color: var(--ink-dim);
  transition: color .15s;
}

.chat__tools {
  display: flex;
  gap: 6px;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--ink-soft);
  transition: all .12s;
}
.btn-ghost:hover { background: var(--bg-soft); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:active { transform: scale(.97); }

/* log-count 已移除 — 改为后端写 data/request.log 文件 */

/* === 自定义 Tooltip(显示在按钮下方,避免顶部溢出)=== */

.has-tip {
  position: relative;
}
.has-tip::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);    /* 在按钮下方 */
  right: 0;
  padding: 6px 10px;
  background: var(--ink);
  color: #fff;
  font-size: 11.5px;
  font-weight: 400;
  border-radius: var(--r-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
  z-index: 50;
  box-shadow: var(--shadow-md);
  letter-spacing: 0.2px;
}
.has-tip::before {
  content: "";
  position: absolute;
  top: calc(100% + 3px);    /* 三角朝上,挨着按钮底边 */
  right: 16px;
  border: 5px solid transparent;
  border-bottom-color: var(--ink);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
  z-index: 50;
}
.has-tip:hover::after,
.has-tip:hover::before {
  opacity: 1;
  transform: translateY(0);
}

/* === 消息列表 === */

.chat__messages {
  flex: 1;
  /* 关键 flex column 修复:子项默认 min-height: auto = 内容高度,导致永远不滚动。
     必须 min-height: 0 才能让 flex:1 + overflow-y:auto 真生效 */
  min-height: 0;
  overflow-y: auto;
  padding: 24px 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat__messages::-webkit-scrollbar { width: 6px; }
.chat__messages::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; }

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--ink-dim);
  padding: 40px 20px;
}
.empty-state__icon {
  font-size: 32px;
  color: var(--primary);
  margin-bottom: 8px;
  letter-spacing: 4px;
}
.empty-state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.empty-state__hint {
  font-size: 12.5px;
  color: var(--ink-mute);
}

/* === 消息气泡 + 头像 === */

.message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: msgIn .25s ease-out;
  max-width: 85%;
}
.message.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.avatar {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.avatar.ai {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.avatar.ai svg { width: 16px; height: 16px; }

.avatar.user {
  background: linear-gradient(135deg, #fb923c, #f97316);
  color: #fff;
  box-shadow: 0 0 0 3px var(--warn-soft);
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--r-md);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.6;
}

.message.ai .bubble {
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.message.user .bubble {
  background: var(--primary);
  color: #fff;
  border-top-right-radius: 4px;
  box-shadow: 0 2px 8px -2px rgba(59, 130, 246, .35);
}

/* 流式光标 */
.bubble.streaming::after {
  content: "▋";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: blink 0.85s steps(2) infinite;
  font-weight: 400;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* 思考中(LLM 还没产生第一个 token 时)— bubble 内显示三个脉动小点 */
.bubble.thinking {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
  min-width: 50px;
}
.thinking-dots {
  display: inline-flex;
  gap: 4px;
}
.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-mute);
  animation: thinking-dot 1.3s ease-in-out infinite;
}
.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.18s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes thinking-dot {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.8); }
  30%          { opacity: 1;    transform: scale(1.1); }
}

/* === SSE 思考进度时间线(只在 SSE 模式 + AI 消息上方显示)=== */

.trace {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg-card));
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 11.5px;
  font-family: var(--font-mono);
  max-width: 100%;
}
.trace.collapsed .trace-step.detail-step { display: none; }
.trace.collapsed .trace-summary { display: flex; }
.trace-summary {
  display: none;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--ink-mute);
}
.trace-summary:hover { color: var(--primary); }
.trace.collapsed { padding: 6px 10px; }

.trace-step {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  color: var(--ink-soft);
  animation: traceIn .2s ease-out;
}
@keyframes traceIn {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}

.trace-icon {
  flex-shrink: 0;
  width: 14px; height: 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}
.trace-step.thinking .trace-icon { background: var(--ink-mute); animation: pulse 1.2s ease-in-out infinite; }
.trace-step.tool-call .trace-icon { background: var(--warn); }
.trace-step.tool-result .trace-icon { background: var(--ok); }
.trace-step.fail .trace-icon { background: var(--err); }
.trace-step.completed .trace-icon { background: var(--primary); }

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

.trace-text {
  flex: 1;
  min-width: 0;
}
.trace-name { color: var(--ink); font-weight: 600; }
.trace-detail {
  display: block;
  margin-top: 2px;
  color: var(--ink-mute);
  word-break: break-all;
  white-space: pre-wrap;
  font-size: 10.5px;
  line-height: 1.5;
  max-height: 0;
  overflow: hidden;
  transition: max-height .2s;
}
.trace-step.expanded .trace-detail { max-height: 120px; overflow-y: auto; }
.trace-step .toggle {
  flex-shrink: 0;
  cursor: pointer;
  color: var(--ink-dim);
  font-size: 11px;
  margin-top: 1px;
  user-select: none;
}
.trace-step:hover .toggle { color: var(--primary); }

/* === 输入区 === */

.chat__compose {
  border-top: 1px solid var(--line);
  padding: 14px 22px 16px;
  background: var(--bg-card);
}

.compose-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 6px 6px 6px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.compose-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: var(--bg-card);
}

.compose-wrap textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  outline: none;
  padding: 8px 0;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  max-height: 160px;
}
.compose-wrap textarea::placeholder { color: var(--ink-dim); }

.btn-send {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  background: var(--primary);
  color: #fff;
  border: none;
  display: grid;
  place-items: center;
  transition: all .12s;
}
.btn-send:hover:not(:disabled) { background: var(--primary-deep); transform: translateY(-1px); }
.btn-send:disabled {
  background: var(--line-strong);
  cursor: not-allowed;
  opacity: 0.7;
}

.compose-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--ink-dim);
}
.compose-meta span:first-child { font-family: var(--font-mono); color: var(--ink-mute); }
.compose-meta__hint { font-style: italic; }

/* ============================================================
 * 右栏:月历 + 当日待办
 * ============================================================ */

.todos-panel {
  background: var(--bg-card);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.todos-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.todos-panel__header h2 {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.3px;
}

.btn-icon {
  width: 24px; height: 24px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-card);
  color: var(--ink-soft);
  font-size: 14px;
  display: grid;
  place-items: center;
  transition: all .12s;
}
.btn-icon:hover { background: var(--primary-soft); color: var(--primary-deep); border-color: var(--primary); }

/* === 日历网格 === */

.calendar {
  padding: 8px 14px 14px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  border-bottom: 1px solid var(--line);
}
.calendar__weekday {
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  color: var(--ink-dim);
  padding: 6px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.calendar__cell {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 4px 2px;
  font-size: 11.5px;
  color: var(--ink-soft);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .12s;
  background: transparent;
  position: relative;
}
.calendar__cell:hover { background: var(--bg-soft); border-color: var(--line-strong); }
.calendar__cell.other-month { color: var(--ink-dim); opacity: 0.55; }
.calendar__cell.today {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-deep);
  font-weight: 700;
}
.calendar__cell.selected {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}
.calendar__cell.selected .dot { background: #fff !important; }

.calendar__cell .day-num { font-weight: 600; }

.dots {
  margin-top: auto;
  display: flex;
  gap: 2px;
  align-items: center;
}
.dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--primary);
}
.dot.done { background: var(--ok); }

/* === 当日 todos === */

.todos-day {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
}
.todos-day__title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}
.todos-day__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.todos-day__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--ink);
  transition: all .12s;
  cursor: pointer;
  user-select: none;
}
.todos-day__item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.todos-day__item:active { transform: scale(.985); }
.todos-day__item.done {
  text-decoration: line-through;
  color: var(--ink-mute);
  background: transparent;
}
.todos-day__item.done:hover {
  border-color: var(--line-strong);
  background: var(--bg-soft);
}
.todos-day__item .check {
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1.5px solid var(--line-strong);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 9px;
  color: #fff;
}
.todos-day__item:hover .check {
  border-color: var(--primary);
}
.todos-day__item.done .check {
  background: var(--ok);
  border-color: var(--ok);
}

.time-badge {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--primary);
  color: #fff;
}
.todos-day__item.done .time-badge {
  background: var(--ink-dim);
}

.todos-day__item .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.todos-day__item .id {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-dim);
  margin-left: auto;
  flex-shrink: 0;
}

.todo-del {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-size: 12px;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s;
}
.todos-day__item:hover .todo-del { opacity: 1; }
.todo-del:hover {
  background: var(--err-soft);
  color: var(--err);
}

.todos-day__empty {
  padding: 16px 8px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 12px;
}

/* ============================================================
 * 响应式收尾
 * ============================================================ */

@media (max-width: 1100px) {
  .app { grid-template-columns: 200px 1fr 280px; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar, .todos-panel { display: none; }
}
