/* ============================================================
   detail.z01.css — 详情页阅读体验（临床路径「住院日程」等）
   两个作用：
   1) 把 <pre> 里的「| 分隔」原文表格化后的样式（手机、桌面都生效）
   2) 桌面端详情页排印：标题去重、行宽收窄、正文放大、字段加分隔线
   用法：ssmtj.html 中紧跟 desktop.z02.css 之后引入。
   ============================================================ */

/* ---------- 1. 兜底：JS 没跑到时，pre 至少要能换行、不横向截断 ----------
   原来 white-space:pre + monospace，862px 里塞 5964px 内容，
   右边 5000 多 px 被直接裁掉，用户根本看不到「住院第 2～7 天」之后的内容。 */
.detail-card pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
  overflow-x: auto;
}

/* ---------- 2. 表格化后的样式 ---------- */
.kv-table-wrap {
  margin: 2px 0 4px;
  border: 1px solid #e3e8ef;
  border-radius: 10px;
  background: #fff;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.kv-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12.5px;
  line-height: 1.6;
  color: #22303f;
}

.kv-table th,
.kv-table td {
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  border-right: 1px solid #eef2f6;
  border-bottom: 1px solid #eef2f6;
}

/* 首列固定窄一点，其余平均分 */
.kv-table thead th:first-child,
.kv-table tbody th {
  width: 92px;
}

.kv-table tr > *:last-child { border-right: 0; }
.kv-table tbody tr:last-child > * { border-bottom: 0; }

.kv-table thead th {
  background: #f4f8fc;
  font-weight: 600;
  color: #33465a;
  white-space: nowrap;
}

/* 首列 = 行标题（主要诊疗工作 / 重点医嘱 …） */
.kv-table tbody th {
  background: #fafcfe;
  font-weight: 600;
  color: #33465a;
}

/* 单元格里以 □ 开头的条目，一条一行，好扫 */
.kv-table .ck {
  padding-left: 1.05em;
  text-indent: -1.05em;
}
.kv-table .ck + .ck { margin-top: 3px; }
.kv-table .ck.sub {
  margin: 7px 0 2px;
  padding-left: 0;
  text-indent: 0;
  font-weight: 600;
  color: #4a5b6c;
}
.kv-table .ck.sub:first-child { margin-top: 0; }
.kv-table td.is-empty { color: #b6c2d0; }

/* ---------- 3. 宽表格搬到卡片外后，单独成一张全宽卡片 ---------- */
.path-sec-h {
  margin: 0 0 10px;
  font-size: calc(15px * var(--fs, 1));
  font-weight: 600;
  line-height: 1.4;
  color: #22303f;
}

/* 手机上 5 列必然要横滑，给一句提示，否则用户以为右边没内容 */
@media (max-width: 899px) {
  .path-sec-h::after {
    content: '左右滑动查看 ›';
    float: right;
    margin-top: 3px;
    font-size: 12px;
    font-weight: 400;
    color: #8a97a5;
  }
}

/* ============================================================
   3b. 手机端：住院日程按住院日折叠（第1天 / 2～7天 / 8～12天 / 13～14天）
   桌面宽度够、5 列一眼看全，所以折叠版默认不渲染可见；
   ≤899px 时反过来：藏掉横滑表格，只留折叠卡。
   ============================================================ */
.day-acc-wrap { display: none; }

@media (max-width: 899px) {

  /* 有折叠版就把横滑表格收起来（没有折叠版的表格照旧横滑） */
  .kv-table-wrap--acc { display: none; }

  /* 折叠版已经全部摊开，不需要「左右滑动」提示 */
  .path-sec.has-acc .path-sec-h::after { content: none; }

  .day-acc-wrap { display: block; }

  .day-acc {
    display: block;
    border: 1px solid #e3e8ef;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
  }
  .day-acc + .day-acc { margin-top: 9px; }

  .day-acc > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    list-style: none;
    cursor: pointer;
    font-size: calc(15px * var(--fs, 1));
    font-weight: 600;
    line-height: 1.4;
    color: #22303f;
  }
  .day-acc > summary::-webkit-details-marker { display: none; }
  .day-acc > summary:active { background: #f2f7fc; }

  .day-acc-t {
    flex: 1 1 auto;
    min-width: 0;
  }

  .day-acc-n {
    flex: 0 0 auto;
    padding: 1px 8px;
    border-radius: 999px;
    background: #f0f5fa;
    font-size: calc(11.5px * var(--fs, 1));
    font-weight: 400;
    line-height: 1.7;
    color: #5a6b7b;
  }

  /* 自绘箭头，替掉系统三角 */
  .day-acc-arw {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    margin-top: -3px;
    border-right: 1.8px solid #93a1b1;
    border-bottom: 1.8px solid #93a1b1;
    transform: rotate(45deg);
    transition: transform .18s ease, margin .18s ease;
  }
  .day-acc[open] > summary { border-bottom: 1px solid #eef2f6; }
  .day-acc[open] .day-acc-arw { margin-top: 2px; transform: rotate(225deg); }

  .day-acc-body { padding: 12px 14px 14px; }

  .day-acc-sec + .day-acc-sec {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #e8eef4;
  }

  /* 「主要诊疗工作 / 重点医嘱 / 主要护理工作」 */
  .day-acc-k {
    margin-bottom: 6px;
    font-size: calc(12px * var(--fs, 1));
    font-weight: 600;
    letter-spacing: .3px;
    color: #1a86d8;
  }

  .day-acc-v {
    font-size: calc(14px * var(--fs, 1));
    line-height: 1.72;
    color: #2b3a4a;
  }
  .day-acc-v .ck {
    padding-left: 1.05em;
    text-indent: -1.05em;
  }
  .day-acc-v .ck + .ck { margin-top: 4px; }

  /* 条目前面的「长期医嘱 / 临时医嘱 / 出院医嘱」小标题 */
  .day-acc-v .ck.sub {
    margin: 9px 0 4px;
    padding-left: 8px;
    text-indent: 0;
    border-left: 2px solid #d7e3f0;
    font-size: calc(12.5px * var(--fs, 1));
    font-weight: 600;
    color: #4a5b6c;
  }
  .day-acc-v .ck.sub:first-child { margin-top: 0; }
}

/* ---------- 3. 桌面端排印 ---------- */
@media (min-width: 900px) {

  /* 详情卡宽度：1060 → 940，配合下面 132px 标签列，正文约 750px ≈ 50 字/行；
     左右居中，否则右边会空出一大块 */
  .view > .detail-card {
    max-width: 940px;
    margin-left: auto;
    margin-right: auto;
  }

  /* 卡片里的 h2 与蓝色顶栏标题完全重复（顶栏一直可见），宽屏下没必要占一行 */
  .view > .detail-card > h2:first-child {
    display: none;
  }

  .view > .detail-card > .lead {
    margin-top: 0;
    font-size: calc(13px * var(--fs, 1));
  }

  .detail-card .kv {
    grid-template-columns: 132px minmax(0, 1fr);
    gap: 4px 16px;
  }

  .detail-card .kv .k {
    font-size: calc(13.5px * var(--fs, 1));
    color: #5a6b7b;
  }

  /* 正文：14px/21px → 15px/1.78，长段落读起来不再挤 */
  .detail-card .kv .v {
    font-size: calc(15px * var(--fs, 1));
    line-height: 1.78;
  }

  /* 字段之间加一条淡分隔线，长记录一眼能分段 */
  .detail-card .kv + .kv {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #eef2f6;
  }

  .kv-table-wrap { border-radius: 12px; }
  .kv-table { min-width: 0; font-size: calc(13px * var(--fs, 1)); }
  .kv-table th,
  .kv-table td { padding: 11px 12px; }
  .kv-table tbody th { width: 110px; }
  .kv-table thead th:first-child { width: 110px; }

  /* 住院日程这类宽表格：搬出卡片、占满内容区宽度（约 1126px），
     5 列每列 250px 左右，一条医嘱基本一两行就能放下 */
  .view > .detail-card.path-sec {
    max-width: none;
  }
  .path-sec .kv-table-wrap {
    border-radius: 12px;
  }
  .path-sec-h {
    font-size: calc(15.5px * var(--fs, 1));
  }

  /* ---- 带表格的字段：标签移到上方，把整行宽度让给表格 ----
     5 列的住院日程塞在 760px 的内容列里，每列只剩 140px，
     一个字换一行，行高被撑到七八百像素，根本没法读。 */
  .detail-card .kv:has(.kv-table-wrap) {
    display: block;
  }
  .detail-card .kv:has(.kv-table-wrap) .k {
    margin: 0 0 8px;
    padding: 0;
    font-size: calc(14px * var(--fs, 1));
    font-weight: 600;
    color: #22303f;
  }
  .detail-card .kv:has(.kv-table-wrap) .v {
    max-width: none;
  }
  .detail-card .kv:has(.kv-table-wrap) .kv-table {
    min-width: 880px;
  }

  /* 普通字段：内容列封顶，避免长句拉成一整行 */
  .detail-card .kv .v {
    max-width: 760px;
  }

  /* 「☆ 收藏此条」这类整宽按钮跟着卡片走：1060 比卡片还宽，右边会凸出去 */
  .view > .fav-btn,
  .view > .btn-block {
    display: block;
    width: 100%;
    max-width: 940px;
    align-self: center;
    margin-left: auto;
    margin-right: auto;
  }

  /* 底部 dock 是浮起来的，正文最后一行别被它压住 */
  #view {
    padding-bottom: 96px;
  }
}

/* ---------- 4. 暗色模式 ---------- */
html[data-theme="dark"] .kv-table-wrap {
  background: #141a22;
  border-color: rgba(255, 255, 255, .1);
}
html[data-theme="dark"] .kv-table {
  color: #dfe7f0;
}
html[data-theme="dark"] .kv-table th,
html[data-theme="dark"] .kv-table td {
  border-right-color: rgba(255, 255, 255, .08);
  border-bottom-color: rgba(255, 255, 255, .08);
}
html[data-theme="dark"] .kv-table thead th,
html[data-theme="dark"] .kv-table tbody th {
  background: rgba(255, 255, 255, .05);
  color: #c3d0de;
}
html[data-theme="dark"] .kv-table td.is-empty { color: #5c6b7b; }
html[data-theme="dark"] .kv-table .ck.sub { color: #9fb0c1; }
html[data-theme="dark"] .path-sec-h { color: #dfe7f0; }
html[data-theme="dark"] .detail-card .kv + .kv {
  border-top-color: rgba(255, 255, 255, .07);
}

/* 手机折叠卡（暗色） */
html[data-theme="dark"] .day-acc {
  background: #141a22;
  border-color: rgba(255, 255, 255, .1);
}
html[data-theme="dark"] .day-acc > summary { color: #dfe7f0; }
html[data-theme="dark"] .day-acc > summary:active { background: rgba(255, 255, 255, .06); }
html[data-theme="dark"] .day-acc[open] > summary { border-bottom-color: rgba(255, 255, 255, .08); }
html[data-theme="dark"] .day-acc-n {
  background: rgba(255, 255, 255, .08);
  color: #a9b8c6;
}
html[data-theme="dark"] .day-acc-arw { border-color: #7d8d9d; }
html[data-theme="dark"] .day-acc-sec + .day-acc-sec { border-top-color: rgba(255, 255, 255, .07); }
html[data-theme="dark"] .day-acc-k { color: #6ab5ee; }
html[data-theme="dark"] .day-acc-v { color: #ccd8e4; }
html[data-theme="dark"] .day-acc-v .ck.sub { color: #8fa1b3; }
