/* =========================================================================
   知识记录 · 模块样式（M5 · 复刻方案 §5.6 布局 / §5.8 组件规格，网页版 k=1）
   -------------------------------------------------------------------------
   尺寸：工具栏 46px / 图片卡 186（封面高 = 宽×1.22） / 链接书签条 232 /
        评论行头像 30 / 分区头徽标 26 / 数量药丸 19 / 封面缩略图 132×96。
   颜色全走 --p-* 设计 token（v 双主题）；新增 --sem-info 语义色（链接分区）。
   ========================================================================= */

/* ---------------- 补充 token：info 语义色（链接分区徽标） ---------------- */
:root {
  --sem-info-fg: #6CB6FF;  --sem-info-bg: #13293E;
}
[data-theme="light"] {
  --sem-info-fg: #0E7490;  --sem-info-bg: #DDF3F5;
}

/* 弹窗宽度档（知识 760，方案 §5.7）；personal-ui 的 ptModal 每次会清掉这些类 */
#modal-box.pt-know { width: min(760px, 100%); }

/* hidden 属性兜底：.pt-fld 的 display:grid 会盖掉浏览器默认的 [hidden]{display:none} */
.pt-dialog [hidden], .kd-wrap [hidden] { display: none !important; }

/* ============================ 一、视图骨架 ============================ */

.kd-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---- 工具栏（46px，FR-K1） ---- */
.kd-bar {
  flex: none; height: 46px; display: flex; align-items: center; gap: 8px;
  flex-wrap: nowrap; overflow: hidden;
}
.kd-bar .sp { flex: 1; min-width: 8px; }

.kd-tbtn {
  height: 30px; padding: 0 12px; border-radius: 8px; flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--p-field); border: 1px solid var(--p-border);
  color: var(--p-text); font-size: 12.5px; cursor: pointer; white-space: nowrap;
  transition: border-color .12s, filter .12s, background .12s, opacity .12s;
}
.kd-tbtn .ic { width: 14px; height: 14px; color: var(--p-muted); }
.kd-tbtn:hover { border-color: var(--p-border-hot); }
.kd-tbtn.primary { background: var(--p-primary); border-color: var(--p-primary); color: var(--p-on-primary); font-weight: 600; }
.kd-tbtn.primary .ic { color: var(--p-on-primary); }
.kd-tbtn.primary:hover { filter: brightness(1.08); }
.kd-tbtn.success { background: var(--p-green); border-color: var(--p-green); color: var(--p-on-primary); font-weight: 600; }
.kd-tbtn.success .ic { color: var(--p-on-primary); }
.kd-tbtn.success:hover { filter: brightness(1.08); }
.kd-tbtn.info { background: var(--p-cyan); border-color: var(--p-cyan); color: var(--p-on-primary); font-weight: 600; }
.kd-tbtn.info .ic { color: var(--p-on-primary); }
.kd-tbtn.info:hover { filter: brightness(1.08); }
.kd-tbtn.drop .lb.ph { color: var(--p-muted); }
.kd-tbtn.drop .ic { width: 13px; height: 13px; }
.kd-tbtn.busy { opacity: .45; pointer-events: none; }

.kd-date {
  height: 30px; min-width: 96px; padding: 0 10px; border-radius: 8px; flex: none;
  background: var(--p-field); border: 1px solid var(--p-border);
  color: var(--p-muted); font-size: 12px; cursor: pointer; text-align: center;
  transition: border-color .12s, color .12s;
}
.kd-date.has { color: var(--p-text); }
.kd-date:hover { border-color: var(--p-border-hot); }
.kd-dash { flex: none; color: var(--p-muted); font-size: 12px; }

/* ---- 滚动区 ---- */
.kd-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 6px 2px 22px; }
.kd-scroll::-webkit-scrollbar { width: 8px; }
.kd-scroll::-webkit-scrollbar-thumb { background: var(--p-border-hot); border-radius: 4px; }
.kd-scroll::-webkit-scrollbar-track { background: transparent; }

.kd-empty {
  text-align: center; color: var(--p-muted); font-size: 13px;
  padding: 64px 0; white-space: pre-line;
}

/* ============================ 二、三段分区（FR-K2 / K3） ============================ */

.kd-secs { display: flex; flex-direction: column; gap: 22px; padding: 4px 14px 0; }
.kd-sec { min-width: 0; }
.kd-sech { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; }
.kd-badge {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
}
.kd-badge .ic { width: 15px; height: 15px; }
.kd-badge.primary { background: var(--sem-primary-bg); color: var(--sem-primary-fg); }
.kd-badge.info { background: var(--sem-info-bg); color: var(--sem-info-fg); }
.kd-badge.muted { background: var(--sem-muted-bg); color: var(--sem-muted-fg); }
.kd-sech .nm { font-size: 13.5px; font-weight: 700; color: var(--p-text); }
.kd-pill {
  height: 19px; padding: 0 8px; border-radius: 10px; flex: none;
  display: inline-flex; align-items: center;
  background: var(--p-field); border: 1px solid var(--p-border);
  color: var(--p-muted); font-size: 11px;
}
.kd-line { flex: 1; height: 1px; background: var(--p-border); margin-left: 3px; }

/* ---- 网格容器（列数自适应：floor((宽+16)/(卡宽+16))） ---- */
.kd-grid { display: grid; grid-template-columns: repeat(auto-fill, 186px); gap: 16px; }
.kd-grid.lk { grid-template-columns: repeat(auto-fill, 232px); gap: 16px; }

/* ============================ 三、图片卡（海报网格） ============================ */

.kd-pcard { cursor: pointer; min-width: 0; }
.kd-pcard .cv {
  width: 100%; height: 227px; border-radius: 9px; overflow: hidden;
  border: 1px solid var(--p-border); background: var(--p-card);
  display: grid; place-items: center; color: var(--p-faint);
  transition: border-color .12s;
}
.kd-pcard .cv img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kd-pcard .cv.ph .ic { width: 40px; height: 40px; }
.kd-pcard:hover .cv { border-color: var(--p-primary); }
.kd-pcard .tt {
  margin-top: 7px; font-size: 13px; font-weight: 650; color: var(--p-text);
  line-height: 1.35; word-break: break-word;
}
.kd-pcard .sm {
  margin-top: 2px; font-size: 12px; color: var(--p-muted);
  line-height: 1.5; word-break: break-word;
}

/* ============================ 四、链接书签条 ============================ */

.kd-lcard {
  display: flex; align-items: center; gap: 11px; min-width: 0;
  padding: 9px 13px 9px 11px; border-radius: 12px;
  background: var(--p-card); border: 1px solid var(--p-border);
  cursor: pointer; min-height: 58px; transition: border-color .12s;
}
.kd-lcard:hover { border-color: var(--p-primary); }
.kd-lbadge {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: grid; place-items: center; color: #FFF;
}
.kd-lbadge .ic { width: 19px; height: 19px; }
.kd-lcard .mid { flex: 1; min-width: 0; }
.kd-lcard .tt {
  font-size: 13px; font-weight: 650; color: var(--p-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kd-lcard .sm {
  margin-top: 3px; font-size: 12px; color: var(--p-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ============================ 五、文件评论行 ============================ */

.kd-files { display: flex; flex-direction: column; }
.kd-frow {
  display: flex; gap: 10px; padding: 12px 4px; min-width: 0;
  cursor: pointer; border-radius: 8px;
  transition: background .12s;
}
.kd-frow + .kd-frow { border-top: 1px solid var(--p-border); }
.kd-frow:hover { background: var(--p-hover); }
.kd-ava {
  width: 30px; height: 30px; border-radius: 50%; flex: none; margin-top: 2px;
  display: grid; place-items: center; color: #FFF; font-size: 13px; font-weight: 700;
}
.kd-fmain { flex: 1; min-width: 0; }
.kd-fhead { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.kd-fhead .tt {
  flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; color: var(--p-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kd-fhead .time { flex: none; font-size: 11.5px; color: var(--p-faint); }
.kd-sm {
  margin-top: 6px; font-size: 12px; color: var(--p-muted);
  line-height: 1.6; word-break: break-word;
}
.kd-fmid { display: flex; align-items: center; gap: 8px; margin-top: 6px; min-width: 0; }
.kd-openlnk {
  max-width: 72%; display: inline-flex; align-items: center; gap: 5px;
  background: none; border: 0; padding: 0; cursor: pointer;
  font-size: 11.5px; text-decoration: underline; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; transition: filter .12s;
}
.kd-openlnk .ic { width: 13px; height: 13px; flex: none; }
.kd-openlnk:hover { filter: brightness(1.25); }
[data-theme="light"] .kd-openlnk:hover { filter: brightness(0.85); }
.kd-catpill {
  margin-left: auto; flex: none; font-size: 11px; padding: 2px 9px; border-radius: 9px;
  background: var(--sem-muted-bg); color: var(--sem-muted-fg);
}

/* 搜索命中闪一下（FR 定位） */
.kd-pcard.flash .cv, .kd-lcard.flash, .kd-frow.flash {
  animation: kdFlash 1.3s ease;
}
@keyframes kdFlash {
  0% { box-shadow: 0 0 0 2px var(--p-primary); }
  100% { box-shadow: 0 0 0 2px transparent; }
}

/* ============================ 六、编辑弹窗补充 ============================ */

.kd-attach.dragover { outline: 2px dashed var(--p-primary); outline-offset: 4px; border-radius: 8px; }

/* ---- 选择封面（FR-K13：缩略图 132×96 · 最多 4 列） ---- */
.kd-covergrid { display: grid; gap: 12px; justify-content: start; }
.kd-cvitem {
  position: relative; width: 132px; height: 96px; padding: 0; border-radius: 9px;
  overflow: hidden; cursor: pointer; background: var(--p-field);
  border: 2px solid var(--p-border); transition: border-color .12s;
}
.kd-cvitem img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kd-cvitem:hover { border-color: var(--p-border-hot); }
.kd-cvitem.sel { border-color: var(--p-primary); }
.kd-cvitem .ck {
  display: none; position: absolute; top: 6px; right: 6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--p-primary); color: var(--p-on-primary);
  font-size: 11px; font-style: normal; place-items: center; font-weight: 700;
}
.kd-cvitem.sel .ck { display: grid; }

/* ============================ 七、分类 / 类型管理弹层（FR-K10 / K11 · 580×450） ============================ */

.kd-ovl {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 10vh 20px 20px;
  animation: kdFadeIn .15s ease;
}
@keyframes kdFadeIn { from { opacity: 0; } to { opacity: 1; } }

.kd-mgr {
  width: min(580px, 100%); max-height: min(450px, 78vh);
  display: flex; flex-direction: column;
  background: var(--p-card); border: 1px solid var(--p-border-hot); border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .5);
  animation: kdPopIn .16s ease;
}
@keyframes kdPopIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.kd-mgr-head {
  flex: none; display: flex; gap: 11px; align-items: flex-start;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--p-border);
}
.kd-mgr-head .badge {
  width: 28px; height: 28px; border-radius: 8px; flex: none; margin-top: 1px;
  background: color-mix(in srgb, var(--p-primary) 15%, transparent);
  color: var(--p-primary); display: grid; place-items: center;
}
.kd-mgr-head .badge .ic { width: 16px; height: 16px; }
.kd-mgr-head .tt { font-size: 15px; font-weight: 650; color: var(--p-text); }
.kd-mgr-head .st { font-size: 11.5px; color: var(--p-faint); margin-top: 2px; }
.kd-mgr-head .modal-x { margin-left: auto; }

.kd-mgr-list {
  flex: 1; min-height: 190px; overflow-y: auto;
  padding: 10px 18px; display: flex; flex-direction: column; gap: 4px;
}
.kd-mgr-list::-webkit-scrollbar { width: 8px; }
.kd-mgr-list::-webkit-scrollbar-thumb { background: var(--p-border-hot); border-radius: 4px; }

.kd-mgr-row {
  position: relative; flex: none; height: 38px; padding: 0 12px;
  display: flex; align-items: center; gap: 0;
  background: var(--p-field); border: 1px solid var(--p-border); border-radius: 9px;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.kd-mgr-row:hover { border-color: var(--p-border-hot); }
.kd-mgr-row .dot {
  width: 9px; height: 9px; border-radius: 50%; margin: 0 16px 0 4px; flex: none;
  background: var(--p-muted);
}
.kd-mgr-row .nm {
  flex: 1; min-width: 0; font-size: 13px; color: var(--p-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kd-mgr-row .cnt {
  flex: none; font-size: 11px; color: var(--p-muted);
  background: var(--p-card); border: 1px solid var(--p-border); border-radius: 10px;
  padding: 2px 9px;
}
.kd-mgr-row.sel { background: var(--p-sel); border-color: transparent; }
.kd-mgr-row.sel::before {
  content: ''; position: absolute; left: 5px; top: 9px; bottom: 9px; width: 3px;
  border-radius: 2px; background: var(--p-primary);
}
.kd-mgr-row.sel .dot { background: var(--p-primary); }
.kd-mgr-row.sel .nm { font-weight: 650; }
.kd-mgr-empty { text-align: center; color: var(--p-muted); font-size: 12.5px; padding: 30px 0; }

.kd-mgr-foot {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 12px 18px 16px; border-top: 1px solid var(--p-border);
}
.kd-mgr-foot .stat { margin-right: auto; font-size: 11.5px; color: var(--p-muted); }
.kd-mbtn {
  height: 30px; padding: 0 13px; border-radius: 8px; flex: none;
  background: var(--p-field); border: 1px solid var(--p-border);
  color: var(--p-text); font-size: 12.5px; cursor: pointer;
  transition: border-color .12s, filter .12s;
}
.kd-mbtn:hover { border-color: var(--p-border-hot); }
.kd-mbtn.primary { background: var(--p-primary); border-color: var(--p-primary); color: var(--p-on-primary); font-weight: 600; }
.kd-mbtn.primary:hover { filter: brightness(1.08); }
.kd-mbtn.danger { background: var(--p-red); border-color: var(--p-red); color: var(--p-on-primary); font-weight: 600; }
[data-theme="dark"] .kd-mbtn.danger { color: #1A0E0E; }
.kd-mbtn.danger:hover { filter: brightness(1.08); }

/* ---- 弹层内的迷你录入 / 确认 ---- */
.kd-mini {
  position: absolute; top: 44%; left: 50%; transform: translate(-50%, -50%);
  width: min(460px, 92vw); z-index: 5;
  background: var(--p-card); border: 1px solid var(--p-border-hot); border-radius: 12px;
  padding: 16px 18px 14px; box-shadow: 0 18px 60px rgba(0, 0, 0, .55);
  animation: kdPopIn .15s ease;
}
.kd-mini .hd { font-size: 14px; font-weight: 650; color: var(--p-text); margin-bottom: 8px; }
.kd-mini .st { font-size: 11.5px; color: var(--p-faint); line-height: 1.6; margin-bottom: 6px; }
.kd-mini .msg { font-size: 13px; color: var(--p-text); line-height: 1.8; white-space: pre-line; }
.kd-mini .ft { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ============================ 八、大图查看器（FR-K14 · 恒定深色） ============================ */

.kd-viewer {
  position: fixed; inset: 0; z-index: 150; background: rgba(0, 0, 0, .92);
  display: none;
}
.kd-viewer.open { display: block; }
.kd-viewer .stage {
  position: absolute; inset: 0; overflow: hidden; cursor: grab;
  touch-action: none;
}
.kd-viewer .stage.grabbing { cursor: grabbing; }
.kd-viewer .stage img {
  position: absolute; left: 50%; top: 50%;
  max-width: none; user-select: none; -webkit-user-drag: none;
  transform-origin: center center; will-change: transform;
}
.kd-viewer .bar {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; z-index: 2;
  background: rgba(20, 20, 20, .82); border: 1px solid #3A3A3A; border-radius: 10px;
  padding: 6px 8px;
}
.kd-vbtn {
  height: 26px; min-width: 26px; padding: 0 8px; border-radius: 7px;
  background: transparent; border: 1px solid transparent; color: #DCDCDC;
  font-size: 12.5px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s;
}
.kd-vbtn:hover { background: rgba(255, 255, 255, .1); border-color: #4A4A4A; }
.kd-vbtn .ic { width: 14px; height: 14px; }
.kd-viewer .bar .pct { color: #BFBFBF; font-size: 11.5px; min-width: 40px; text-align: center; }
.kd-viewer .bar .gap { width: 1px; height: 18px; background: #3A3A3A; margin: 0 2px; }
.kd-viewer .cap {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  color: #CFCFCF; font-size: 12.5px; background: rgba(0, 0, 0, .5);
  padding: 6px 14px; border-radius: 8px; z-index: 2; max-width: 86vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kd-viewer .hint {
  position: absolute; bottom: 20px; right: 20px;
  color: #8C8C8C; font-size: 11px; z-index: 2;
}

/* ============================ 九、响应式（§5.9：工具栏允许换行两行） ============================ */
@media (max-width: 1080px) {
  .kd-bar { height: auto; min-height: 46px; flex-wrap: wrap; padding: 7px 0; row-gap: 6px; }
  .kd-bar .sp { display: none; }
}
@media (max-width: 860px) {
  .kd-grid, .kd-grid.lk { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .kd-pcard .cv { height: 196px; }
}
