:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --primary: #4a90d9;
  --primary-soft: #e8f1fb;
  --accent: #f7b7c3;
  --text: #2b2f36;
  --muted: #8a94a6;
  --border: #e6ebf2;
  --danger: #e2607a;
  --ok: #4caf84;
  --shadow: 0 2px 10px rgba(40, 60, 90, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- 登录 ---------- */
#login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e8f1fb 0%, #fdeef1 100%); z-index: 50;
}
#login .box {
  background: var(--card); padding: 32px 28px; border-radius: 18px; box-shadow: var(--shadow);
  width: 320px; max-width: 90vw; text-align: center;
}
#login h1 { font-size: 22px; margin: 0 0 4px; }
#login p { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
#login input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 15px;
  margin-bottom: 12px;
}
.btn {
  display: inline-block; border: none; border-radius: 10px; padding: 11px 16px; font-size: 15px;
  cursor: pointer; background: var(--primary); color: #fff; font-weight: 600; width: 100%;
  transition: opacity .15s;
}
.btn:hover { opacity: .9; }
.btn.sec { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: #fdeef1; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); width: auto; padding: 8px 12px; }

/* ---------- 布局 ---------- */
#app { display: none; }
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; background: var(--card); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { font-size: 18px; font-weight: 700; padding: 6px 10px 14px; color: var(--primary); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px;
  color: var(--text); cursor: pointer; font-size: 15px; user-select: none;
}
.nav-item:hover { background: var(--primary-soft); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .ico { width: 20px; text-align: center; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.topbar select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; max-width: 50vw; }
.main { padding: 20px; padding-bottom: 90px; }

/* ---------- 卡片/表单 ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 14px; font-size: 17px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; flex: 1 1 140px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 56px; }
.form-actions { margin-top: 12px; display: flex; gap: 10px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: #fff;
}
.item .meta { font-size: 13px; color: var(--muted); }
.item .title { font-weight: 600; }
.item img.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; border: 1px solid var(--border); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--primary-soft); color: var(--primary); }
.tag.poop { background: #fff3e0; color: #d98a2b; }
.tag.wet { background: #e8f1fb; color: #4a90d9; }
.tag.mixed { background: #f3e8fb; color: #9b59b6; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; font-size: 14px; }

/* ---------- 概览 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat .lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }
.dol-banner { background: linear-gradient(135deg, #4a90d9, #6fb1e0); color: #fff; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.dol-banner .big { font-size: 30px; font-weight: 800; }

/* ---------- 底部导航(移动端) ---------- */
.bottom-nav { display: none; }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: 320px; }

/* ---------- 照片 ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery .ph { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: #fff; }
.gallery .ph img { width: 100%; height: 120px; object-fit: cover; display: block; }
.gallery .ph .cap { padding: 6px 8px; font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #2b2f36; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 100;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

.section-title { font-size: 15px; font-weight: 700; margin: 4px 0 12px; color: var(--text); }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); cursor: pointer; font-size: 14px; background: #fff; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 14px; padding-bottom: 90px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
    border-top: 1px solid var(--border); justify-content: space-around; padding: 6px 0;
    z-index: 20; box-shadow: 0 -2px 10px rgba(40,60,90,.06);
  }
  .bottom-nav .nav-item { flex-direction: column; gap: 2px; font-size: 11px; padding: 4px 6px; flex: 1; justify-content: center; }
  .bottom-nav .nav-item .ico { font-size: 18px; }
  .bottom-nav .nav-item span.txt { font-size: 11px; }
  .topbar { padding: 12px 14px; }
}

/* ---------- 列表操作按钮 ---------- */
.item .actions { display: flex; gap: 6px; flex: 0 0 auto; }
.item .actions .btn { width: auto; padding: 7px 12px; font-size: 13px; }

/* ---------- 编辑弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 30, 50, .45); z-index: 150;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); border-radius: 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  width: 540px; max-width: 96vw; max-height: 88vh; overflow: auto; padding: 18px;
}
.modal h3 { margin: 0 0 12px; font-size: 16px; }
.modal .form-actions { justify-content: flex-end; }

/* ---------- 喂养奶量明细行 ---------- */
.feed-line { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.feed-line .fl_type { flex: 0 0 110px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; }
.feed-line .fl_amt { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.feed-line .fl_del { flex: 0 0 auto; }

/* ---------- 缩略图（可点击） ---------- */
.thumb-wrap { position: relative; cursor: pointer; flex: 0 0 auto; }
.thumb-wrap .play, .gallery .ph .play {
  position: absolute; top: 4px; right: 4px; background: rgba(0, 0, 0, .55); color: #fff;
  border-radius: 999px; padding: 1px 7px; font-size: 11px; pointer-events: none;
}

/* ---------- 媒体查看器（抖音式播放模式） ---------- */
.viewer { position: fixed; inset: 0; background: #0b0e13; z-index: 200; display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; gap: 10px; padding: 14px 16px; color: #fff; }
.viewer-top .vmeta { flex: 1; min-width: 0; }
.viewer-top .vtitle { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-top .vsub { font-size: 12px; opacity: .75; margin-top: 2px; }
.viewer-btn {
  background: rgba(255, 255, 255, .12); border: none; color: #fff; border-radius: 999px;
  width: 36px; height: 36px; font-size: 16px; cursor: pointer; flex: 0 0 auto;
}
.viewer-btn:hover { background: rgba(255, 255, 255, .22); }
.viewer-body { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; touch-action: none; transform-origin: center center; }
.viewer-nav {
  position: absolute; top: 0; bottom: 0; width: 28%; display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, .8); font-size: 40px; cursor: pointer; user-select: none; opacity: 0; transition: opacity .15s;
}
.viewer-nav:hover { opacity: 1; }
/* 触屏无 hover：让左右翻页热区常驻半透明可见，点屏幕左右即可翻页（即使已放大） */
@media (hover: none) and (pointer: coarse) {
  .viewer-nav { opacity: .32; }
}
.viewer-nav.prev { left: 0; }
.viewer-nav.next { right: 0; }
.viewer-count { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,.7); font-size: 12px; }

/* ---------- 照片墙视频 ---------- */
.gallery .ph { cursor: pointer; position: relative; }
.gallery .ph img, .gallery .ph video.gallery-media { width: 100%; height: 120px; object-fit: cover; display: block; background: #000; }
.gallery .ph video.gallery-media { pointer-events: none; }

/* ---- 按日切换总览 ---- */
.day-nav { margin-bottom: 16px; }
.dn-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.dn-row input[type="date"] { flex: 1; min-width: 0; }
.dn-stats { display: flex; flex-wrap: wrap; gap: 8px; }
.dn-chip {
  background: var(--bg, #f5f7fa); border: 1px solid var(--border, #e3e8ef);
  border-radius: 10px; padding: 5px 12px; font-size: 13px; color: var(--muted, #5b6472);
}
.dn-chip b { font-size: 15px; color: var(--text, #2b2f36); }
.chart-sm { width: 100%; height: 220px; }

/* ---------- 移动端防溢出 ---------- */
body { overflow-x: hidden; }
.field { min-width: 0; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; }
.form-actions { flex-wrap: wrap; }
.item { min-width: 0; }
.item div { min-width: 0; }
.item .title, .item .meta { overflow-wrap: anywhere; }
.feed-line { min-width: 0; }
.feed-line .fl_amt { min-width: 0; }
.dn-row { flex-wrap: nowrap; }
.tabs { max-width: 100%; }

@media (max-width: 768px) {
  .card { padding: 14px; max-width: 100%; }
  .modal { padding: 14px; width: 100%; max-width: 100vw; border-radius: 14px 14px 0 0; align-self: flex-end; }
  .modal-mask { align-items: flex-end; padding: 0; }
  .form-actions { gap: 8px; }
  .form-actions .btn { min-width: 0; flex: 1 1 auto; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }
  .stat { padding: 12px; }
  .stat .num { font-size: 22px; }
  .item { padding: 10px 12px; }
  .item .actions .btn { padding: 7px 10px; font-size: 12px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .btn { padding: 11px 12px; }
}

/* ---------- 顶部设置按钮（移动端主要入口；桌面端也可见） ---------- */
.top-settings {
  margin-left: auto; border: 1px solid var(--border); background: #fff; border-radius: 999px;
  width: 34px; height: 34px; font-size: 16px; cursor: pointer; line-height: 1; flex: 0 0 auto;
}
.top-settings:hover { background: var(--primary-soft); }

/* ---------- 事件时间轴 ---------- */
.timeline { display: flex; flex-direction: column; max-height: 62vh; overflow-y: auto; padding-right: 6px; }
.timeline::-webkit-scrollbar { width: 6px; }
.timeline::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.timeline::-webkit-scrollbar-track { background: transparent; }
.tl-item { display: flex; gap: 12px; }
.tl-side { flex: 0 0 52px; text-align: right; padding-top: 2px; }
.tl-side .tl-date { font-weight: 700; font-size: 15px; color: var(--primary); line-height: 1.2; }
.tl-side .tl-year { font-size: 12px; color: var(--muted); }
.tl-axis { flex: 0 0 14px; display: flex; flex-direction: column; align-items: center; }
.tl-axis .tl-dot {
  width: 12px; height: 12px; border-radius: 999px; background: var(--primary);
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); margin-top: 6px; flex: 0 0 auto;
}
.tl-axis .tl-dot.future { background: #e2607a; }
.tl-axis::after { content: ""; flex: 1; width: 2px; background: var(--border); margin-top: 4px; }
.tl-item:last-child .tl-axis::after { display: none; }
.tl-body { flex: 1; min-width: 0; padding: 0 0 18px 2px; }
.tl-body .tl-head { font-weight: 600; overflow-wrap: anywhere; }
.tl-body .tl-desc { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tl-body .tl-thumb { margin-top: 8px; }
.tl-body .tl-thumb img, .tl-body .tl-thumb video { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); display: block; background: #000; }
/* 事件配图网格（一个事件多张媒体） */
.tl-media { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.tl-media .tl-thumb { margin-top: 0; }
.tl-media .tl-thumb img, .tl-media .tl-thumb video { width: 100%; aspect-ratio: 1; height: auto; }
.tl-body .tl-actions { display: flex; gap: 6px; margin-top: 8px; }
.tl-body .tl-actions .btn { width: auto; padding: 6px 12px; font-size: 13px; }

/* ---------- 查看器增强：箭头常显 + 移动端隐藏（滑动为主） ---------- */
.viewer { overscroll-behavior: contain; }
.viewer-body { touch-action: none; }
.viewer-body img, .viewer-body video { transition: transform .18s ease; will-change: transform; }
.viewer-body.dragging img, .viewer-body.dragging video { transition: none; }

.viewer-nav { opacity: 1; }
.viewer-nav b {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 999px; font-weight: 400;
  background: rgba(255, 255, 255, .16); font-size: 26px; line-height: 1;
}
.viewer-nav:hover b { background: rgba(255, 255, 255, .3); }
/* 无鼠标的触屏设备：隐藏箭头，以滑动手势为主 */
@media (hover: none) and (pointer: coarse) {
  .viewer-nav { display: none; }
}

/* ---------- 查看器：加载提示 + 视频按需播放 ---------- */
.viewer-body .vloading {
  position: absolute; color: rgba(255, 255, 255, .7); font-size: 13px; letter-spacing: .5px;
}
.viewer-body .vplay {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; width: 100%; height: 100%; color: #fff; cursor: pointer;
}
.viewer-body .vplay-btn {
  width: 72px; height: 72px; border-radius: 999px; background: rgba(255, 255, 255, .18);
  display: flex; align-items: center; justify-content: center; font-size: 30px; padding-left: 5px;
}
.viewer-body .vplay-btn:active { background: rgba(255, 255, 255, .32); }
.viewer-body .vplay-tip { text-align: center; font-size: 13px; line-height: 1.7; opacity: .85; }
.viewer-body .vplay-tip span { font-size: 12px; opacity: .7; }

/* ---------- 设置页头像 ---------- */
.avatar-preview {
  width: 72px; height: 72px; border-radius: 16px; object-fit: cover;
  background: var(--primary-soft); border: 1px solid rgba(0, 0, 0, .06);
}

/* ---------- 设置页大文件清单 ---------- */
.large-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.large-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 10px; background: var(--bg);
}
.large-item > img {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex: 0 0 auto;
  background: var(--primary-soft);
}
.large-meta { flex: 1 1 auto; min-width: 0; }
.large-name {
  font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.large-meta .meta { font-size: 12px; margin: 0; }
