:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --border: #ecebe6;
  --border-strong: #dcdad2;
  --text: #2b2b28;
  --text-2: #6b6a63;
  --text-3: #a09e95;
  --accent: #185fa5;
  --accent-soft: #eaf2fb;
  --danger: #b0362e;
  --danger-soft: #fbeceb;
  --wait: #8a5a0b;
  --wait-soft: #faf1de;
  --radius: 8px;
  --font: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

/* 关键修复：让 hidden 属性始终生效，不被 display 规则覆盖 */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; }

/* ============ 侧边栏 ============ */
.sidebar {
  width: 200px; flex: 0 0 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 8px;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 500;
  padding: 2px 10px 14px;
}
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.nav { display: flex; flex-direction: column; }
.nav-group {
  font-size: 11px; color: var(--text-3);
  padding: 16px 10px 4px;
  letter-spacing: 1px;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  text-align: left; border: none; background: none; cursor: pointer;
  font: inherit; color: var(--text-2);
  padding: 6px 10px; border-radius: 6px;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
  border-left-color: var(--accent);
}
.nav-item .badge {
  background: var(--accent); color: #fff; font-size: 11px; line-height: 15px;
  min-width: 15px; border-radius: 8px; text-align: center; padding: 0 4px;
}

/* ============ 顶栏 ============ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 46px; flex: 0 0 46px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.search {
  flex: 0 1 300px; border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 6px 10px; font: inherit; color: var(--text-3); background: var(--surface-2);
}
.topbar-right { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.workspace-control { display: flex; align-items: center; gap: 5px; white-space: nowrap; color: var(--text-2); font-size: 12px; }
.workspace-control select { min-width: 100px; max-width: 180px; padding: 5px; border: 1px solid var(--border-strong); border-radius: 6px; background: white; color: var(--text); font: inherit; }
.mode-chip { font-size: 12px; color: var(--text-3); }

/* ============ 视图 ============ */
.view { flex: 1; overflow-y: auto; padding: 22px 28px 60px; max-width: 860px; }
.view-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.view-title { font-size: 17px; font-weight: 500; }
.view-sub { font-size: 12px; color: var(--text-3); }
.view-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.back-link { font-size: 13px; color: var(--accent); cursor: pointer; margin-bottom: 10px; }
.back-link:hover { text-decoration: underline; }

/* 快速记录 */
.capture { display: flex; gap: 8px; margin-bottom: 16px; }
.capture input {
  flex: 1; border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 8px 12px; font: inherit; background: var(--surface);
}
.capture input:focus { outline: none; border-color: var(--accent); }

/* 按钮 */
.btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); padding: 6px 13px; border-radius: 6px;
  font: inherit; cursor: pointer; line-height: 1.4;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0c447c; }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: none; color: var(--text-3); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }

/* ============ 板块（无卡片、hairline 列表） ============ */
.section { margin-bottom: 20px; }
.section-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 500; color: var(--text-2);
  padding: 0 2px 4px;
}
.section-head .s-title { letter-spacing: .5px; }
.section-head .count { color: var(--text-3); font-weight: 400; }
.section-head .link-add { margin-left: auto; font-size: 12px; color: var(--accent); cursor: pointer; }
.section-head .link-add:hover { text-decoration: underline; }
.section-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.section-body .task:last-child,
.section-body .card:last-child,
.section-body .k-item:last-child,
.section-body .r-item:last-child { border-bottom: none; }

/* ============ 任务行（紧凑） ============ */
.task {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.task:hover { background: var(--surface-2); }
.dot {
  flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%;
  margin-top: 6px; background: var(--border-strong);
}
.dot-overdue { background: var(--danger); }
.dot-waiting { background: var(--wait); }
.dot-high { background: var(--accent); }
.t-main { flex: 1; min-width: 0; }
.t-title { font-size: 14px; line-height: 1.45; }
.t-title.done { color: var(--text-3); text-decoration: line-through; }
.t-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.5; }
.overdue-text { color: var(--danger); }
.t-actions { display: flex; gap: 4px; flex: 0 0 auto; align-items: center; }
.menu-btn { letter-spacing: 1px; }

/* 下拉菜单 */
.menu {
  position: fixed; z-index: 60; min-width: 128px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.10); padding: 4px;
}
.menu-item {
  display: block; width: 100%; text-align: left;
  border: none; background: none; cursor: pointer; font: inherit;
  color: var(--text); padding: 7px 12px; border-radius: 6px;
}
.menu-item:hover { background: var(--surface-2); }

/* ============ Focus（紧凑） ============ */
.focus {
  display: flex; align-items: center; gap: 10px;
  background: var(--accent-soft); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 14px;
}
.focus .f-label { font-size: 12px; color: var(--accent); font-weight: 500; white-space: nowrap; }
.focus .f-title { font-size: 14px; font-weight: 500; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.focus .f-actions { display: flex; gap: 6px; flex: 0 0 auto; }

/* ============ 卡片 / 条目 ============ */
.card {
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.card:hover { background: var(--surface-2); }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-title { font-size: 14px; font-weight: 500; }
.card-sub { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.card-meta { font-size: 12px; color: var(--text-3); margin-top: 3px; }

.k-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.k-item:hover { background: var(--surface-2); }
.k-title { font-size: 14px; font-weight: 500; }
.k-meta { font-size: 12px; color: var(--text-3); }

.r-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.r-name { font-size: 14px; font-weight: 500; }
.r-icon { font-size: 14px; flex: 0 0 auto; }
.r-loc { font-size: 12px; color: var(--text-2); flex: 1; min-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
a.r-loc { color: var(--accent); }
a.r-loc:hover { text-decoration: underline; }
.r-loc.muted { color: var(--text-3); }

/* 标签（克制的少量） */
.tag {
  font-size: 11px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px; white-space: nowrap;
}
.tag.waiting { color: var(--wait); background: var(--wait-soft); border-color: #f0dfb8; }

/* ============ 详情块 ============ */
.detail-block { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.detail-block h4 { margin: 0 0 8px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.detail-block.dim { opacity: .85; }
.primary-block { border-left: 3px solid var(--accent); }
.pre { white-space: pre-wrap; font-size: 13px; line-height: 1.7; color: var(--text); }
.progress-add { margin-top: 8px; }
.progress-add input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 7px 10px; font: inherit; background: var(--surface-2);
}
.progress-add input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

/* 知识文档阅读 */
.doc { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 26px; }
.doc-title { font-size: 20px; font-weight: 500; margin: 0 0 6px; }
.doc-meta { font-size: 12px; color: var(--text-3); margin-bottom: 14px; }
.doc-sec { margin-top: 18px; }
.doc-h { font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.doc-body { font-size: 14px; line-height: 1.75; color: var(--text); white-space: pre-wrap; }

/* ============ 其他 ============ */
.empty { color: var(--text-3); font-size: 13px; padding: 20px 12px; text-align: center; }
.more-link { font-size: 12px; color: var(--accent); cursor: pointer; padding: 8px 12px; }
.more-link:hover { text-decoration: underline; }
.collapse-entry { font-size: 13px; color: var(--text-2); padding: 8px 2px; cursor: pointer; user-select: none; }
.collapse-entry:hover { color: var(--text); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: 20px; padding: 3px 12px; font-size: 12px; cursor: pointer; color: var(--text-2);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.28);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  width: 460px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 12px; padding: 20px;
}
.modal h3 { margin: 0 0 14px; font-size: 15px; font-weight: 500; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.form-row input[type=text], .form-row input[type=date], .form-row select, .form-row textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 7px 10px; font: inherit; background: var(--surface);
}
.form-row textarea { min-height: 60px; resize: vertical; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--accent); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg .chip { border-radius: 6px; padding: 4px 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ============ 搜索面板 ============ */
.search-wrap { position: relative; flex: 0 1 360px; }
.search-wrap .search { width: 100%; }
.search-panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 60vh; overflow-y: auto; z-index: 55;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 10px; box-shadow: 0 10px 36px rgba(0,0,0,.14); padding: 6px;
}
.search-group { font-size: 11px; color: var(--text-3); padding: 10px 10px 4px; letter-spacing: .5px; }
.search-item { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.search-item:hover { background: var(--surface-2); }
.search-item.selected { background: var(--accent-soft); }
.si-title { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.si-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.si-snippet { font-size: 12px; color: var(--text-2); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-empty { font-size: 13px; color: var(--text-3); padding: 16px; text-align: center; }

/* ============ 资源上传 ============ */
.muted { font-size: 12px; color: var(--text-3); }
.drop-hint { font-size: 12px; color: var(--text-3); margin: -6px 0 12px; }
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 28px 16px; text-align: center; cursor: pointer;
  color: var(--text-2); background: var(--surface-2);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent);
}
.dz-hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.r-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.missing { color: var(--danger); font-size: 12px; }

/* ============ 示例标识 / 置顶 / 回收站 ============ */
.demo-tag {
  font-size: 11px; color: var(--text-3);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 0 5px; margin-left: 6px; white-space: nowrap; font-weight: 400;
}
.pin-btn {
  flex: 0 0 auto; cursor: pointer; font-size: 13px; line-height: 1;
  opacity: .30; user-select: none; padding: 0 2px;
}
.pin-btn:hover { opacity: 1; }
.pin-btn.pinned { opacity: 1; }
.card.dragging, .k-item.dragging { opacity: .45; }
.sidebar-foot { margin-top: 18px; padding-top: 10px; border-top: 1px solid var(--border); }

@media (max-width: 700px) {
  .app { flex-direction: column; height: 100dvh; }
  .sidebar { width: 100%; flex: 0 0 auto; overflow: visible; padding: 4px 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand, .nav-group, .sidebar-foot { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav-item { flex: 0 0 auto; min-height: 44px; white-space: nowrap; }
  .main { min-height: 0; }
  .topbar { height: auto; min-height: 48px; flex: 0 0 auto; flex-wrap: wrap; padding: 8px; }
  .topbar-right { order: -1; width: 100%; margin: 0; }
  .workspace-control { flex: 1; }
  .workspace-control select { flex: 1; min-width: 0; max-width: none; min-height: 40px; }
  .search-wrap { width: 100%; }
  .search { width: 100%; min-height: 40px; }
  .view { padding: 16px 12px 48px; width: 100%; }
  .capture input { min-width: 0; }
  .btn { min-height: 40px; }
  .focus { flex-wrap: wrap; }
}
.nav-item.subtle { color: var(--text-3); font-size: 12px; }
.nav-item.subtle:hover { color: var(--danger); background: var(--danger-soft); }
.hub-return { display: block; color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; padding: 10px; margin-bottom: 8px; border-radius: 8px; background: var(--accent-soft); }
.hub-return:hover { text-decoration: underline; }
@media (max-width: 700px) { .hub-return { display: inline-block; padding: 8px 10px; margin: 0 0 4px; } }

/* Consistent spacing for daily and personal forms; business behaviour stays in app.js. */
.sidebar { padding: 18px 12px; }
.brand { font-weight: 650; padding-bottom: 18px; }
.nav { gap: 2px; }
.nav-group { color: #777b82; font-weight: 600; letter-spacing: .05em; }
.nav-item { min-height: 36px; padding: 8px 10px; border-radius: 8px; }
.nav-item.active { font-weight: 650; }
.topbar-right { min-width: 0; gap: 10px; }
#oidcLogout { flex: 0 0 auto; white-space: nowrap; }
.view-head { gap: 10px; flex-wrap: wrap; }
.view-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }
.view form[id] { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.view form[id] label { display: flex; flex-direction: column; gap: 6px; flex: 1 1 150px; min-width: 0; color: var(--text-2); font-size: 13px; }
.view form[id] input, .view form[id] select, .view form[id] textarea { width: 100%; min-width: 0; min-height: 40px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 6px; background: white; font: inherit; color: var(--text); }
.view form[id] .btn { min-height: 40px; }
#todosDue, #todosAll, #todayHabits { padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text-2); }
#dailySummary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
#dailySummary p { margin: 0; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; line-height: 1.5; }
.view h3 { margin: 24px 0 12px; }
.view h4 { margin: 18px 0 10px; }
#exerciseForm { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-items: end; }
#exerciseForm .form-row { min-width: 0; margin: 0; }
#exerciseForm label { width: 100%; }
#exerciseForm #strengthFields, #exerciseForm #cardioFields { display: contents; }
#exerciseForm .exercise-note, #exerciseForm .exercise-actions { grid-column: 1 / -1; }
.exercise-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#exerciseHistory { display: grid; gap: 8px; margin-top: 12px; }
#exerciseHistory .r-item { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
#exerciseHistory .r-item span { flex: 1 1 220px; min-width: 0; }
@media (min-width: 701px) and (max-width: 1050px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px; }
  .topbar-right { flex-wrap: wrap; }
}
@media (max-width: 700px) {
  .sidebar { padding: 4px 8px; }
  .nav-item { min-height: 44px; }
  .topbar-right { display: flex; flex-wrap: wrap; }
  #oidcLogout { order: 2; }
  .view form[id] { padding: 14px; }
  .view form[id] label { flex-basis: 100%; }
  #dailySummary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #exerciseForm { grid-template-columns: minmax(0,1fr); }
}
