/* ===========================================================
   用药管家 —— 温暖纸感浅色主题
   =========================================================== */
:root {
  /* 色板：暖纸感 */
  --bg: #FAF6EF;
  --bg-grain: #F6F0E4;
  --surface: #FFFFFF;
  --surface-2: #F5EFE3;
  --surface-3: #EFE7D6;
  --text: #3A332C;
  --text-soft: #5C5247;
  --text-muted: #9A8E7E;
  --border: #E8DCC6;
  --border-soft: #F0E8D8;

  --accent: #D97757;        /* 赤陶橙 · 主强调 */
  --accent-press: #C46344;
  --accent-soft: #FBE7DD;
  --accent-ink: #8C3F22;

  --danger: #C8533C;
  --danger-soft: #F8E0D9;
  --warn: #D69536;
  --warn-soft: #FBEFD7;
  --ok: #6B8E4E;
  --ok-soft: #E9F0DF;

  /* 排版 */
  --font: "Manrope", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --fs: 16px;
  --fs-sm: 14px;
  --fs-xs: 12.5px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;

  /* 形态 */
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
  --sh-soft: 0 1px 2px rgba(120, 90, 60, 0.04), 0 6px 18px rgba(120, 90, 60, 0.06);
  --sh-lift: 0 2px 6px rgba(120, 90, 60, 0.08), 0 14px 40px rgba(120, 90, 60, 0.12);
  --gap: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12% 8%, rgba(217, 119, 87, 0.06), transparent 40%),
    radial-gradient(circle at 88% 0%, rgba(214, 149, 54, 0.05), transparent 35%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-bottom: 64px;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: var(--fs); }

/* ---------- 顶部 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 246, 239, 0.88);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; }
.brand-text h1 { font-size: var(--fs-xl); line-height: 1.2; }
.brand-text p { margin: 2px 0 0; font-size: var(--fs-xs); color: var(--text-muted); }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  border-radius: var(--r-sm);
  transition: all 0.18s ease;
  white-space: nowrap;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.icon-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- 主体 ---------- */
.app-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px;
}
.alerts { margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }

/* 提醒条 */
.alert {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-radius: var(--r);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
  animation: slideIn 0.3s ease both;
}
.alert .alert-ico { flex: 0 0 auto; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; }
.alert .alert-main { flex: 1; min-width: 0; }
.alert .alert-title { font-weight: 700; font-size: var(--fs); }
.alert .alert-sub { color: inherit; opacity: 0.8; font-size: var(--fs-xs); margin-top: 1px; }
.alert-danger { background: var(--danger-soft); border-color: #F0CABF; color: #8A3525; }
.alert-danger .alert-ico { background: var(--danger); color: #fff; }
.alert-warn { background: var(--warn-soft); border-color: #F0DAB0; color: #7A5512; }
.alert-warn .alert-ico { background: var(--warn); color: #fff; }
.alert-ok { background: var(--ok-soft); border-color: #D2DFC1; color: #44612D; }
.alert-ok .alert-ico { background: var(--ok); color: #fff; }

/* ---------- 仪表盘网格 ---------- */
.dashboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}
@media (min-width: 760px) {
  .dashboard {
    grid-template-columns: 1fr 1fr;
  }
  .card-today, .card-meds, .card-logs { grid-column: 1 / -1; }
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-soft);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 18px 20px 12px;
}
.card-head h2 { font-size: var(--fs-lg); }
.card-sub { font-size: var(--fs-sm); color: var(--text-muted); }
.card-body { padding: 4px 20px 20px; }

/* ---------- 按钮 ---------- */
.primary-btn, .add-btn, .text-btn, .ghost-btn, .danger-btn {
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 9px 16px;
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: all 0.16s ease;
  white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  line-height: 1.2;
}
.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:hover { background: var(--accent-press); }
.add-btn { background: var(--surface-2); color: var(--accent-ink); border-color: var(--border); }
.add-btn:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
.text-btn { background: transparent; color: var(--accent); padding: 9px 10px; }
.text-btn:hover { background: var(--accent-soft); }
.ghost-btn { background: var(--surface); color: var(--text-soft); border-color: var(--border); }
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.danger-btn { background: var(--surface); color: var(--danger); border-color: #ECC9BF; }
.danger-btn:hover { background: var(--danger-soft); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > button { flex: 1 1 auto; }

/* ---------- 今日用药 ---------- */
.today-list { display: flex; flex-direction: column; gap: 10px; }
.today-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--r);
  border: 1px solid var(--border-soft);
}
.today-item .ti-thumb {
  width: 42px; height: 42px; border-radius: var(--r-sm);
  object-fit: cover; background: var(--surface-3);
  flex: 0 0 auto;
}
.today-item .ti-ph { width: 42px; height: 42px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; flex: 0 0 auto; }
.ti-main { flex: 1; min-width: 0; }
.ti-name { font-weight: 600; }
.ti-dose { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 1px; }
.ti-amount {
  font-weight: 700; color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 5px 12px; border-radius: var(--r-pill);
  font-size: var(--fs-sm); white-space: nowrap;
  text-align: center;
}
.ti-sub { font-weight: 400; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.empty-hint { color: var(--text-muted); font-size: var(--fs-sm); padding: 18px 4px; text-align: center; }

/* ---------- 药品库存列表 ---------- */
.med-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .med-grid { grid-template-columns: 1fr 1fr; } }
.med-card {
  display: flex; gap: 12px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  transition: all 0.18s ease;
  overflow: hidden;
  min-width: 0;
}
.med-card:hover { border-color: var(--border); box-shadow: var(--sh-soft); }
.med-card.warn { border-color: #F0CABF; background: var(--danger-soft); }
.med-card.warn .mc-countdown { color: var(--danger); }
.med-thumb {
  width: 64px; height: 64px; border-radius: var(--r-sm);
  object-fit: cover; background: var(--surface-3);
  flex: 0 0 auto; cursor: pointer;
}
.mc-ph { width: 64px; height: 64px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-size: 22px; font-weight: 800; flex: 0 0 auto; }
.mc-main { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.mc-top { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; min-width: 0; }
.mc-name { font-weight: 700; font-size: var(--fs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mc-stock { font-weight: 700; color: var(--text-soft); white-space: nowrap; font-size: var(--fs-sm); flex-shrink: 0; }
.mc-dose { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-meta { font-size: 11px; color: var(--text-muted); line-height: 1.35; overflow: hidden; }
.mc-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; flex-wrap: wrap; }
.mc-countdown { font-size: var(--fs-xs); font-weight: 700; color: var(--text-soft); min-width: 0; flex: 1 1 auto; }
.mc-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mc-actions button { padding: 5px 8px; font-size: var(--fs-xs); white-space: nowrap; }
.badge { font-size: var(--fs-xs); font-weight: 700; padding: 3px 9px; border-radius: var(--r-pill); white-space: nowrap; }
.badge-danger { background: var(--danger); color: #fff; }
.badge-warn { background: var(--warn); color: #fff; }

/* ---------- 胃管 ---------- */
.tube-state { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.tube-ring { position: relative; width: 96px; height: 96px; flex: 0 0 auto; }
.tube-ring svg { transform: rotate(-90deg); }
.tube-ring .ring-num { position: absolute; inset: 0; display: grid; place-items: center; flex-direction: column; text-align: center; }
.tube-ring .ring-num b { font-size: var(--fs-xl); line-height: 1; }
.tube-ring .ring-num span { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.tube-info { flex: 1; min-width: 140px; }
.tube-info .ti-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: var(--fs-sm); border-bottom: 1px dashed var(--border-soft); }
.tube-info .ti-row:last-child { border-bottom: none; }
.tube-info .ti-row span:last-child { font-weight: 600; }
.tube-due { color: var(--danger) !important; }
.tube-empty { text-align: center; padding: 24px 8px; color: var(--text-muted); font-size: var(--fs-sm); }
.tube-empty .emoji { font-size: 30px; display: block; margin-bottom: 6px; }

/* ---------- 待办 ---------- */
.todo-input { display: flex; gap: 8px; margin-bottom: 12px; }
.todo-input input {
  flex: 1; min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.16s;
}
.todo-input input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.todo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.todo-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--r-sm); animation: slideIn 0.2s ease both; }
.todo-item.done { opacity: 0.55; }
.todo-item.done .todo-text { text-decoration: line-through; }
.todo-check { width: 22px; height: 22px; border: 2px solid var(--border); border-radius: 7px; flex: 0 0 auto; display: grid; place-items: center; background: var(--surface); transition: all 0.16s; }
.todo-item.done .todo-check { background: var(--ok); border-color: var(--ok); color: #fff; }
.todo-text { flex: 1; min-width: 0; word-break: break-word; }
.todo-del { background: none; border: none; color: var(--text-muted); padding: 4px; border-radius: 6px; opacity: 0; transition: opacity 0.16s; }
.todo-item:hover .todo-del { opacity: 1; }
.todo-del:hover { color: var(--danger); }

/* ---------- 就诊 ---------- */
.visit-list { display: flex; flex-direction: column; gap: 10px; }
.visit-item { display: flex; gap: 14px; padding: 14px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--r); }
.visit-date { flex: 0 0 auto; text-align: center; min-width: 56px; padding: 6px 0; background: var(--accent-soft); color: var(--accent-ink); border-radius: var(--r-sm); }
.visit-date b { display: block; font-size: var(--fs-xl); line-height: 1; }
.visit-date span { font-size: var(--fs-xs); }
.visit-main { flex: 1; min-width: 0; }
.visit-main .vm-place { font-weight: 700; }
.visit-main .vm-time { font-size: var(--fs-sm); color: var(--text-muted); }
.visit-main .vm-note { font-size: var(--fs-sm); color: var(--text-soft); margin-top: 4px; }
.visit-main .vm-doctor { font-size: var(--fs-xs); color: var(--text-muted); }
.visit-item.past { opacity: 0.62; }
.visit-del { background: none; border: none; color: var(--text-muted); align-self: flex-start; padding: 4px; border-radius: 6px; }
.visit-del:hover { color: var(--danger); }

/* ---------- 模态 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(58, 51, 44, 0.32);
  display: grid; place-items: center;
  padding: 18px;
  animation: fadeIn 0.2s ease both;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lift);
  animation: popIn 0.22s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}
.modal-head { padding: 20px 22px 6px; display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: var(--fs-xl); }
.modal-close { background: none; border: none; font-size: 22px; color: var(--text-muted); width: 36px; height: 36px; border-radius: 8px; }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 10px 22px 22px; }
.modal-foot { padding: 14px 22px 22px; display: flex; gap: 10px; }
.modal-foot button { flex: 1; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: var(--fs-sm); font-weight: 600; margin-bottom: 6px; color: var(--text-soft); }
.field .hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 5px; }
.field input[type="text"], .field input[type="number"], .field input[type="date"], .field input[type="datetime-local"], .field textarea, .field select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); color: var(--text); transition: all 0.16s;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { resize: vertical; min-height: 70px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* 开关 */
.switch { position: relative; display: inline-flex; width: 38px; height: 22px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; cursor: pointer; background: var(--surface-3); border-radius: 999px; transition: all .18s ease; }
.switch .slider::before { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,0.12); transition: all .18s ease; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }

.img-pick { display: flex; align-items: center; gap: 12px; }
.img-preview { width: 72px; height: 72px; border-radius: var(--r-sm); object-fit: cover; background: var(--surface-3); border: 1px solid var(--border); flex: 0 0 auto; }
.img-pick-btn { position: relative; }
.img-pick-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.freq-options { display: flex; gap: 8px; }
.freq-options label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px; border: 1px solid var(--border); border-radius: var(--r-sm); cursor: pointer; font-weight: 600; font-size: var(--fs-sm); background: var(--surface); }
.freq-options input { accent-color: var(--accent); }
.freq-options label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.calc-hint { background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--r-sm); padding: 10px 12px; font-size: var(--fs-sm); color: var(--text-soft); margin-top: 4px; }
.calc-hint b { color: var(--accent-ink); }

.form-section {
  padding: 14px 14px 8px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
}
.form-section-title {
  font-size: var(--fs-sm);
  font-weight: 800;
  letter-spacing: 0.2px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  display: inline-block;
  padding: 3px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
}

/* ---------- 操作日志 ---------- */
.log-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.log-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
}
.log-cat {
  flex: 0 0 auto;
  font-size: 11px; font-weight: 800;
  padding: 3px 8px;
  border-radius: 8px;
  line-height: 1.3;
  letter-spacing: 0.2px;
}
.log-cat.c-med { background: #EDE4F8; color: #5A3E92; }
.log-cat.c-nutri { background: #E2EFD4; color: #405A29; }
.log-cat.c-tube { background: #F6D9B5; color: #7D4A14; }
.log-cat.c-todo { background: #D9E7F6; color: #27507A; }
.log-cat.c-visit { background: #F3D6DC; color: #7B2C3A; }
.log-cat.c-data { background: #EEEEEE; color: #4A4A4A; }
.log-main { flex: 1 1 0; min-width: 0; }
.log-msg { font-size: var(--fs-sm); color: var(--text); line-height: 1.45; word-break: break-word; }
.log-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.log-empty { font-size: var(--fs-sm); color: var(--text-muted); padding: 12px 0; text-align: center; }
.log-more-btn {
  margin-top: 10px; width: 100%;
  padding: 9px;
  font-size: var(--fs-sm); font-weight: 700;
  color: var(--accent-ink);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all 0.16s;
}
.log-more-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: var(--r-pill);
  font-size: var(--fs-sm); font-weight: 600;
  box-shadow: var(--sh-lift); z-index: 80;
  animation: toastIn 0.25s ease both;
  max-width: 90vw; text-align: center;
}

/* ---------- footer ---------- */
.app-footer { text-align: center; color: var(--text-muted); font-size: var(--fs-xs); padding: 20px; }

/* ---------- 动画 ---------- */
@keyframes slideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
