/* ==========================================================================
   医生备忘录 PWA —— 样式
   设计语言与安卓版一致：浅蓝渐变底 + 白色大圆角卡片 + 主色药丸按钮。
   所有颜色都走 CSS 变量 / var(--…)，由 js/theme.js 在切换配色/深浅色时重写 ——
   所以这里**没有一条**深色模式的媒体查询或 [data-theme] 覆盖规则。
   ========================================================================== */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --page-pad: 14px;
  --card-pad: 16px;
  --r-card: 24px;
  --r-field: 14px;
  --r-pill: 30px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 56px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
  color: var(--on-surface);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.55;
}

/* 手写体：安卓端用「马善政毛笔楷书」，iOS 上系统自带的楷体气质最接近 */
.hand {
  font-family: "Kaiti SC", "STKaiti", KaiTi, "Kaiti TC", serif;
}

/* ---------------------------------------------------------------- 排印阶梯
   中文专用：letter-spacing 归零（Material 默认的字距是为拉丁字母设计的，
   中文加上会显得松散发虚），行高调大。字号收敛成一条阶梯。 */

.t-display     { font-size: 30px; line-height: 1.28; font-weight: 700; }
.t-h-med       { font-size: 22px; line-height: 1.36; font-weight: 600; }
.t-h-small     { font-size: 20px; line-height: 1.40; font-weight: 600; }
.t-title-l     { font-size: 17px; line-height: 1.42; font-weight: 600; }
.t-title-m     { font-size: 16px; line-height: 1.44; font-weight: 600; }
.t-title-s     { font-size: 14px; line-height: 1.44; font-weight: 500; }
.t-body-l      { font-size: 15px; line-height: 1.55; }
.t-body-m      { font-size: 13px; line-height: 1.54; }
.t-body-s      { font-size: 12px; line-height: 1.44; }
.t-label-l     { font-size: 14px; line-height: 1.44; font-weight: 500; letter-spacing: .01em; }
.t-label-m     { font-size: 12px; line-height: 1.36; font-weight: 500; letter-spacing: .01em; }
.t-label-s     { font-size: 11px; line-height: 1.36; font-weight: 500; letter-spacing: .02em; }

.muted   { color: var(--on-surface-variant); }
.brand   { color: var(--brand); }
.danger  { color: var(--danger); }
.nowrap  { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp3 {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.center { text-align: center; }
.prewrap { white-space: pre-wrap; word-break: break-word; }

/* ---------------------------------------------------------------- 布局骨架 */

#app { display: flex; flex-direction: column; min-height: 100%; }

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

/* 内容区：只有这里滚动，顶栏与底部导航栏固定 */
.content {
  flex: 1;
  padding: var(--page-pad);
  padding-bottom: calc(var(--page-pad) + 24px);
  display: flex; flex-direction: column; gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.content.has-tabbar { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); }
.content.has-bottombar { padding-bottom: calc(78px + var(--safe-bottom)); }

/* ---------------------------------------------------------------- 顶栏
   安卓版二级页顶栏是「主色渐变 + 白字」，与首页头卡同一套视觉语言。 */

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: var(--safe-top);
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  box-shadow: 0 4px 16px rgba(20, 60, 110, .14);
}
.topbar-row {
  display: flex; align-items: center; gap: 6px;
  min-height: 52px; padding: 0 8px;
}
.topbar-title {
  flex: 1; text-align: center; font-size: 17px; font-weight: 600; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-btn {
  appearance: none; border: 0; background: rgba(255, 255, 255, .16);
  color: #fff; width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1; cursor: pointer; flex: 0 0 auto;
}
.topbar-btn:active { background: rgba(255, 255, 255, .30); }
.topbar-btn.ghost { background: transparent; }
.topbar-spacer { width: 36px; flex: 0 0 auto; }

/* ---------------------------------------------------------------- 卡片 */

.card {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--card-shadow);
  padding: var(--card-pad);
}
.card.flush { padding: 0; overflow: hidden; }
.card.tight { padding: 12px; }

.card-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px;
}
.card-title > .t { font-size: 16px; font-weight: 600; }
.section-title {
  font-size: 14px; font-weight: 500; color: var(--brand);
  padding-top: 6px; margin-bottom: -4px;
}

.row-divider { height: 1px; background: var(--outline-variant); margin: 10px 0; }

/* 列表项外壳 */
.list-card {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--card-shadow);
  padding: 12px 14px;
  display: flex; gap: 10px; align-items: flex-start;
  cursor: pointer;
}
.list-card:active { transform: scale(.995); }
.list-card .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }

/* ---------------------------------------------------------------- 按钮 */

.btn {
  appearance: none; border: 0; cursor: pointer;
  border-radius: var(--r-pill);
  font-family: inherit; font-size: 16px; font-weight: 600;
  padding: 0 18px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:disabled { opacity: .45; }
.btn.primary:active { filter: brightness(.94); }
.btn.subtle {
  background: var(--tile-bg); color: var(--brand);
  border: 1px solid var(--tile-border);
  font-size: 14px; min-height: 36px; padding: 0 14px; font-weight: 500;
}
.btn.ghost { background: transparent; color: var(--brand); font-size: 14px; min-height: 32px; padding: 0 8px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.block { width: 100%; }

/* 底部固定主操作栏（安卓版的 BottomActionBar：全宽 50dp 药丸） */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 10px var(--page-pad) calc(10px + var(--safe-bottom));
  background: var(--bg-bottom);
  border-top: 1px solid var(--outline-variant);
  display: flex; gap: 10px;
}
.bottom-bar .btn { flex: 1; min-height: 50px; }

/* 悬浮新增键 */
.fab {
  position: fixed; right: 18px; z-index: 26;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand); color: #fff; border: 0;
  font-size: 26px; line-height: 1; cursor: pointer;
  box-shadow: 0 8px 20px rgba(30, 90, 160, .30);
  display: flex; align-items: center; justify-content: center;
}
.fab:active { filter: brightness(.94); }

/* ---------------------------------------------------------------- 底部导航栏 */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--panel-bg);
  border-top: 1px solid var(--outline-variant);
  display: flex; align-items: stretch;
}
.tabbar button {
  flex: 1; appearance: none; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--on-surface-variant); font-family: inherit;
}
.tabbar button.on { color: var(--brand); }
.tabbar .ico { font-size: 19px; line-height: 1; }
.tabbar .lbl { font-size: 10px; font-weight: 500; letter-spacing: .02em; }

/* ---------------------------------------------------------------- 表单 */

.field {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--tile-border);
  border-radius: var(--r-field); padding: 10px 12px; min-height: 46px;
}
.field > .label {
  color: var(--on-surface-variant); font-size: 13px; flex: 0 0 auto;
  min-width: 46px;
}
.field input, .field textarea, .field select {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font-family: inherit; font-size: 15px; color: var(--on-surface);
  padding: 0; resize: none;
}
.field input::placeholder, .field textarea::placeholder { color: var(--on-surface-variant); opacity: .75; }
.field .unit { color: var(--on-surface-variant); font-size: 13px; flex: 0 0 auto; }

/* 看起来像一行文本、点上去能编辑 */
.field.bare {
  background: transparent; border: 0; border-bottom: 1px solid var(--outline-variant);
  border-radius: 0; padding: 8px 0;
}

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--tile-border);
  border-radius: var(--r-pill); padding: 8px 14px; min-height: 40px;
}
.search input { flex: 1; border: 0; outline: 0; background: transparent;
  font-family: inherit; font-size: 14px; color: var(--on-surface); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; appearance: none; cursor: pointer; font-family: inherit;
  border: 1px solid var(--tile-border); background: var(--surface);
  color: var(--on-surface-variant);
  border-radius: var(--r-pill); padding: 5px 14px; font-size: 13px;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }

.switch {
  position: relative; width: 46px; height: 28px; border-radius: 14px;
  background: var(--outline); border: 0; cursor: pointer; flex: 0 0 auto;
  transition: background .16s;
}
.switch.on { background: var(--brand); }
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform .16s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch.on::after { transform: translateX(18px); }

/* ---------------------------------------------------------------- 标签 */

.tag {
  display: inline-flex; align-items: center; gap: 3px;
  border-radius: 999px; padding: 2px 9px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.tag.red    { background: var(--tag-red-bg);    color: var(--tag-red-fg); }
.tag.orange { background: var(--tag-orange-bg); color: var(--tag-orange-fg); }
.tag.blue   { background: var(--tag-blue-bg);   color: var(--tag-blue-fg); }
.tag.green  { background: var(--tag-green-bg);  color: var(--tag-green-fg); }
.tag.grey   { background: var(--surface-variant); color: var(--on-surface-variant); }

/* 双栏（左侧分类窄栏 + 右侧列表） */
.split { display: flex; gap: 0; flex: 1; min-height: 0; }
.rail {
  flex: 0 0 98px; display: flex; flex-direction: column; gap: 4px;
  padding: 10px 8px; overflow-y: auto;
}
.rail-item {
  appearance: none; border: 0; cursor: pointer; font-family: inherit;
  background: transparent; color: var(--on-surface);
  border-radius: var(--r-field); padding: 9px 8px; text-align: left;
  font-size: 13px; display: flex; flex-direction: column; gap: 1px;
}
.rail-item.on { background: var(--tile-bg); color: var(--brand); font-weight: 600; }
.rail-item .n { font-size: 10px; color: var(--on-surface-variant); }
.rail-item.on .n { color: var(--brand); opacity: .8; }
.rail-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; padding: 10px var(--page-pad) 20px 4px; }

/* ---------------------------------------------------------------- 图片 */

.thumb {
  width: 56px; height: 56px; border-radius: 10px; object-fit: cover;
  background: var(--tile-bg); border: 1px solid var(--tile-border); flex: 0 0 auto;
}
.thumb-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.thumb-row::-webkit-scrollbar { display: none; }
.tile-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px;
}
.cert-tile {
  background: var(--tile-bg); border: 1px solid var(--tile-border);
  border-radius: var(--r-field); overflow: hidden; position: relative;
  aspect-ratio: 3 / 4; display: flex; align-items: center; justify-content: center;
  color: var(--on-surface-variant); font-size: 12px; cursor: pointer;
}
.cert-tile img { width: 100%; height: 100%; object-fit: cover; }
.cert-tile .cam {
  position: absolute; right: 6px; bottom: 6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; color: var(--brand); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
.cert-tile .count {
  position: absolute; top: 6px; right: 6px;
  background: var(--brand); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 1px 7px;
}

/* ---------------------------------------------------------------- 弹层 */

.scrim {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 18, 30, .42);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease-out;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 16px var(--page-pad) calc(16px + var(--safe-bottom));
  animation: rise .2s cubic-bezier(.2, .8, .3, 1);
  display: flex; flex-direction: column; gap: 12px;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6 } to { transform: none; opacity: 1 } }

.sheet.dialog {
  border-radius: 20px; margin: auto; max-width: 400px;
  align-self: center; padding: 18px;
}
.scrim.center { align-items: center; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 76px);
  z-index: 200; max-width: 88vw;
  background: rgba(18, 30, 44, .93); color: #fff;
  border-radius: var(--r-field); padding: 10px 16px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: fade .15s ease-out;
}

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 46px 20px; color: var(--on-surface-variant); text-align: center;
}
.empty .ico { font-size: 34px; opacity: .5; }

/* 进度 / 遮罩 */
.busy {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(8, 18, 30, .34);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; color: #fff; font-size: 14px;
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.32); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ---------------------------------------------------------------- 照片墙输入 */

.img-input {
  display: flex; gap: 10px; align-items: center;
  background: var(--tile-bg); border: 1px dashed var(--tile-border);
  border-radius: var(--r-field); padding: 10px 12px; color: var(--brand);
  font-size: 14px; cursor: pointer;
}

/* 正文图文混排的编辑器 */
.rich-editor {
  min-height: 180px; background: var(--surface);
  border: 1px solid var(--tile-border); border-radius: var(--r-field);
  padding: 10px 12px; font-size: 15px; line-height: 1.7;
  outline: 0; white-space: pre-wrap; word-break: break-word;
  overflow-y: auto;
}
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--on-surface-variant); opacity: .7; }
.rich-editor img { max-width: 100%; border-radius: 10px; display: block; margin: 6px 0; }
.rich-editor .voice-chip {
  display: inline-flex; align-items: center; gap: 5px; margin: 6px 0;
  background: var(--tile-bg); border: 1px solid var(--tile-border);
  border-radius: 999px; padding: 4px 12px; color: var(--brand); font-size: 13px;
}
.editor-toolbar {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  padding: 8px 0 0;
}

/* 统计条 */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 88px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bars .bar > i { width: 100%; background: var(--brand); border-radius: 6px 6px 2px 2px; display: block; min-height: 2px; opacity: .85; }
.bars .bar > span { font-size: 10px; color: var(--on-surface-variant); }

/* 月历 */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal .dow { text-align: center; font-size: 11px; color: var(--on-surface-variant); padding: 4px 0; }
.cal .day {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; border-radius: 10px; cursor: pointer;
  font-size: 14px; position: relative;
}
.cal .day.other { opacity: .3; }
.cal .day.today { border: 1px solid var(--brand); }
.cal .day.sel { background: var(--brand); color: #fff; }
.cal .dots { display: flex; gap: 2px; height: 5px; }
.cal .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--brand); display: block; }
.cal .dots i.over { background: var(--danger); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
