:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e6e8eb;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --primary: #4f46e5;
  --primary-soft: #eef0fe;
  --primary-2: #14b8a6;
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #22c55e;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 16px rgba(0,0,0,.04);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }

#app { display: flex; height: 100vh; overflow: hidden; min-width: 900px; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; font-weight: 700; font-size: 16px;
}
.brand-logo { font-size: 20px; }
.nav { flex: 1; padding: 6px 12px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px; margin: 2px 0;
  border: none; background: transparent; color: var(--text-2);
  border-radius: var(--radius-sm); text-align: left; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item .ic { width: 20px; text-align: center; font-size: 15px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }

/* ---------- 主区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  flex-shrink: 0;
}
.topbar-title { font-weight: 600; font-size: 15px; min-width: 80px; }
.topbar-search { flex: 1; max-width: 420px; }
.topbar-search input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 20px; background: var(--surface-2); outline: none;
}
.topbar-search input:focus { background: #fff; border-color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.today-chip { color: var(--text-3); font-size: 13px; }
.add-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 22px; line-height: 1;
  box-shadow: var(--shadow);
}
.add-btn:hover { filter: brightness(1.05); }
.icon-btn {
  border: none; background: transparent; font-size: 18px; color: var(--text-2);
  width: 36px; height: 36px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); }
.menu-toggle { display: none; }

.content { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }
.view-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 12px; flex-wrap: wrap;
}
.view-head h2 { margin: 0; font-size: 20px; }

/* ---------- 通用卡片/网格 ---------- */
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stat { }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.muted { color: var(--text-3); }
.empty { text-align: center; color: var(--text-3); padding: 40px 0; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; background: var(--surface-2); color: var(--text-2);
}
.pill.primary { background: var(--primary-soft); color: var(--primary); }
.pill.ok { background: #e7f8ee; color: var(--ok); }
.pill.warn { background: #fef3e2; color: var(--warn); }
.pill.danger { background: #fdeaea; color: var(--danger); }
.pill.info { background: #e8f1ff; color: #2b6cb0; }

/* ---------- 列表/项 ---------- */
.item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.item:hover { border-color: #d4d7dd; }
.item .it-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.item .it-meta { color: var(--text-3); font-size: 12px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.item .it-actions { margin-top: 8px; display: flex; gap: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.btn {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 13px; border-radius: var(--radius-sm);
  font-size: 13px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: #f3c9c9; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px;
  background: var(--surface-2); color: var(--text-2); margin: 2px 4px 2px 0;
}

/* ---------- 表单 ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none; background: #fff;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 90px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 25宫格 ---------- */
.mg-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-width: 640px; margin: 0 auto; }
.mg-cell {
  aspect-ratio: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 13px; text-align: center; word-break: break-all;
  padding: 6px; min-height: 64px; transition: all .15s;
}
.mg-cell:hover { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.mg-cell.inner { background: #fef7e6; border-color: #f0d78c; }
.mg-cell.outer { background: #f5f5f5; }
.mg-cell input, .mg-cell textarea {
  width: 100%; height: 100%; border: 0; outline: 0; resize: none;
  font: inherit; text-align: center; background: transparent;
  line-height: 1.3; padding: 2px;
}
.mg-cell textarea { text-align: left; font-size: 12px; }
.mg-center {
  background: var(--primary-soft); border-color: var(--primary);
  font-weight: 700; font-size: 15px;
}
.mg-legend { display: flex; gap: 16px; justify-content: center; font-size: 12px; color: var(--text-2); }
.mg-legend span { display: inline-flex; align-items: center; gap: 5px; }
.mg-legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.mg-legend .dot.c { background: var(--primary-soft); border: 1px solid var(--primary); }
.mg-legend .dot.i { background: #fef7e6; border: 1px solid #f0d78c; }
.mg-legend .dot.o { background: #f5f5f5; border: 1px solid var(--border); }
.mg-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: center; }
.mg-result { margin-top: 18px; }
.mg-result .mg-topic {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; gap: 8px;
}
.mg-topic .mg-t-text { flex: 1; font-size: 14px; }
.mg-topic .mg-t-acts { display: flex; gap: 4px; flex-shrink: 0; }
.mg-topic .mg-t-acts button { font-size: 11px; }

/* ---------- 日历 ---------- */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cal-head .month { font-size: 17px; font-weight: 600; min-width: 130px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; color: var(--text-3); font-size: 12px; padding: 4px 0; }
.cal-cell {
  min-height: 92px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px; font-size: 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; overflow: hidden;
}
.cal-cell:hover { border-color: var(--primary); }
.cal-cell.other { background: var(--surface-2); color: var(--text-3); }
.cal-cell.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal-cell .dnum { font-weight: 600; }
.ev-dot { font-size: 11px; padding: 1px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-work { background: #e7eefe; color: #3b6fe0; }
.ev-life { background: #eafaf0; color: #1a9e54; }
.ev-content { background: var(--primary-soft); color: var(--primary); }

/* ---------- 时间线（首页） ---------- */
.timeline { position: relative; padding-left: 8px; }
.tl-item { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.tl-time { width: 54px; color: var(--text-2); font-weight: 600; font-size: 13px; flex-shrink: 0; }
.tl-body { flex: 1; }

/* ---------- 分栏布局（列表 + 右侧工作区） ---------- */
.split { display: flex; gap: 16px; align-items: flex-start; }
.split-left { flex: 1; min-width: 0; }
.split-right { width: min(520px, 48%); flex-shrink: 0; position: sticky; top: 0; align-self: flex-start; }
/* 脚本页：左侧脚本列表固定宽度，右侧工作区占满剩余 */
.scripts-left.split-left { flex: 0 0 256px; width: 256px; }
.scripts-right.split-right { flex: 1 1 auto; width: auto; min-width: 0; }
/* 工作区 */
.workspace { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.workspace.empty { color: var(--text-3); text-align: center; padding: 40px 0; }
.ws-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.ws-title { font-weight: 700; font-size: 18px; color: var(--text); word-break: break-all; min-width: 0; }
.ws-body { display: flex; flex-direction: column; gap: 18px; }
.ws-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 12px; }
.ws-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; letter-spacing: .01em; }
.ws-field input, .ws-field textarea, .ws-field select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; outline: none; font-family: inherit; font-size: 14.5px; line-height: 1.45; color: var(--text);
  box-sizing: border-box; transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.ws-field select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  min-height: 42px;
}
.ws-field select:hover { border-color: #c2c8d0; background-color: #fafbfc; }
.ws-field textarea { resize: vertical; min-height: 120px; line-height: 1.65; }
.ws-field input:focus, .ws-field textarea:focus, .ws-field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background-color: #fff; }
.ws-field input::placeholder, .ws-field textarea::placeholder { color: var(--text-3); }
.ws-checks { display: flex; flex-wrap: wrap; gap: 10px; }
.ws-checks label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text); margin: 0; }
.ws-meta { margin-top: 14px; color: var(--text-3); font-size: 12px; }

/* 脚本页专用工作区：上方元信息，下方大面积正文 */
.scripts-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}
.scripts-meta {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 12px;
  align-items: end;
}
.scripts-meta .ws-field { margin-bottom: 0; min-width: 0; }
.scripts-meta .ws-field.title input { font-size: 15px; font-weight: 600; min-height: 42px; }
.scripts-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  width: 100%;
}
.content-field {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
  align-self: stretch;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.ws-field-head { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-bottom: 7px; }
.content-field label { margin: 0; }
.fs-toggle { margin-left: 12px; flex-shrink: 0; }
.fs-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }
/* 正文全屏：隐藏左侧卡片列表，正文占满整个内容区 */
.content.fs-scripts { display: flex; flex-direction: column; overflow: hidden; padding: 20px 24px; height: 100%; }
.content.fs-scripts .split { flex: 1 1 0px; min-height: 0; align-items: stretch; height: 100%; }
.split.fs-all .split-left { display: none !important; }
.split.fs-all .split-right {
  flex: 1 1 0px;
  width: 100%;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.split.fs-all .workspace {
  flex: 1 1 0px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  padding: 20px 24px;
  border: none;
  box-shadow: none;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.split.fs-all .ws-body {
  flex: 1 1 0px;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0;
}
.split.fs-all .scripts-meta { display: none !important; }
.split.fs-all .scripts-layout {
  flex: 1 1 0px;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}
.split.fs-all .content-field {
  flex: 1 1 0px;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  height: 100%;
  margin: 0;
  overflow: hidden;
}
.split.fs-all .content-field .ws-field-head { margin-bottom: 12px; }
.split.fs-all .content-field textarea {
  height: 100%;
  min-height: 0;
  width: 100%;
  resize: none;
  overflow-y: auto;
}
.content-field textarea {
  flex: 1 1 auto;
  min-height: 380px;
  resize: vertical;
  font-size: 15px;
  line-height: 1.75;
  width: 100% !important;
  min-width: 0;
  margin: 0;
  box-sizing: border-box;
}
.scripts-content .ws-field {
  margin-bottom: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}
.scripts-content .ws-field textarea {
  flex: 1;
  min-height: 380px;
  resize: none;
  font-size: 15px;
  line-height: 1.75;
}

/* 工作区：左侧字段 2 列多行，正文独占右侧一列 */
.ws-body.cols-right-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}
.ws-body.cols-right-content .ws-field { margin-bottom: 0; }
.ws-body.cols-right-content .ws-field.content-wide {
  grid-column: 2;
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 260px;
}
.ws-body.cols-right-content .ws-field.content-wide textarea {
  flex: 1;
  min-height: 220px;
  resize: none;
}

.item.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.item { cursor: pointer; }

/* 分栏左侧卡片：紧凑列表 */
.split-left .item {
  padding: 8px 12px;
  margin-bottom: 6px;
  box-shadow: none;
  border-radius: 8px;
}
.split-left .item .it-title { font-size: 13px; font-weight: 600; word-break: break-word; }
.split-left .item .it-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.split-left .item .it-tags .pill { flex-shrink: 0; }
.split-left .item .it-meta { font-size: 11px; margin-top: 2px; }
.split-left .item .it-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.split-left .item .it-summary {
  margin-top: 6px;
  color: var(--text-2);
  font-size: 12px;
  word-break: break-word;
  white-space: pre-wrap;
}

/* ---------- 模态框 ---------- */
.modal-root { position: fixed; inset: 0; display: none; z-index: 50; }
.modal-root.open { display: block; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.32); }
.modal {
  position: relative; width: min(560px, 92vw); max-height: 88vh; overflow-y: auto;
  margin: 6vh auto; background: var(--surface); border-radius: var(--radius);
  padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.22);
}
.modal h3 { margin: 0 0 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #1f2329; color: #fff; padding: 12px 16px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 320px; font-size: 13px;
  animation: toastIn .25s ease;
}
.toast .t-title { font-weight: 600; margin-bottom: 2px; }
.toast .t-body { opacity: .85; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 图表 ---------- */
.chart-svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------- 题词器 ---------- */
.tp-editor { display: flex; flex-direction: column; }
.tp-settings { margin-bottom: 12px; align-items: flex-end; }
.tp-field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.tp-field select, .tp-field input {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; outline: none;
}
.tp-field select:focus, .tp-field input:focus { border-color: var(--primary); }
.tp-check { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-2); padding-bottom: 8px; cursor: pointer; }
.tp-textarea {
  width: 100%; min-height: 420px; resize: vertical;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; font-size: 15px; line-height: 1.8; background: #fff;
}
.tp-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* 全屏舞台 */
.tp-stage {
  position: fixed; inset: 0; z-index: 200;
  background: #000; color: #fff;
}
.tp-stage.tp-hidecursor { cursor: none; }
.tp-scroll {
  position: absolute; inset: 0; overflow-y: auto; scrollbar-width: none;
}
.tp-scroll::-webkit-scrollbar { display: none; }
.tp-text {
  max-width: 900px; margin: 0 auto;
  padding: 45vh 40px 60vh;
  line-height: 1.8; font-weight: 600; letter-spacing: .02em;
  text-align: center;
}
.tp-text p { margin: 0 0 .4em; }
.tp-text.tp-mirror { transform: scaleX(-1); }
.tp-guide {
  position: absolute; left: 0; right: 0; top: 33%; height: 2.2em; pointer-events: none;
  background: rgba(79, 70, 229, .16);
  border-top: 2px solid rgba(79, 70, 229, .75);
  border-bottom: 1px solid rgba(79, 70, 229, .3);
}
/* 悬浮控制条 */
.tp-ctrl {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(10px);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  background: rgba(28, 28, 32, .92); border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; padding: 10px 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  box-shadow: 0 10px 32px rgba(0,0,0,.5);
}
.tp-ctrl.show { opacity: 1; pointer-events: auto; transform: translateX(-50%); }
.tp-ctrl-group { display: flex; align-items: center; gap: 4px; padding: 0 4px; border-left: 1px solid rgba(255,255,255,.12); }
.tp-ctrl-tag { font-size: 11px; color: rgba(255,255,255,.5); margin: 0 2px; }
.tp-ctrl-lbl { font-size: 13px; color: #fff; min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; }
.tp-btn {
  border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.08);
  color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 13px; line-height: 1;
}
.tp-btn:hover { background: rgba(255,255,255,.18); }

/* ---------- 移动端 ---------- */
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 30; }
@media (max-width: 860px) {
  .sidebar { position: relative; transform: none; z-index: auto; height: auto; }
  .scrim, .menu-toggle { display: none !important; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .topbar-search { display: none; }
  .split { flex-direction: column; }
  .split-right { width: 100%; position: static; }
}
