/* ============================================================
   排便记录 · 样式表（移动端优先，桌面宽屏双栏）
   ============================================================ */

*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; padding: 0; }

:root {
  --bg: #f7f4ef;
  --bg-2: #efe9e0;
  --surface: #ffffff;
  --ink: #2f2723;
  --muted: #6f625a;
  --line: #ece3d9;
  --accent: #8a6242;
  --accent-ink: #fffaf4;
  --chip: #f2ece4;
  --danger: #c0392b;
  --bar-bg: rgba(247, 244, 239, .86);
  --shadow: 0 1px 2px rgba(47, 39, 35, .05), 0 10px 28px rgba(47, 39, 35, .06);
  --shadow-lg: 0 24px 60px rgba(30, 20, 14, .28);
  --radius: 20px;
  --radius-sm: 14px;
}

[data-theme="dark"] {
  --bg: #12100e;
  --bg-2: #1b1815;
  --surface: #1c1917;
  --ink: #f0eae3;
  --muted: #a3968c;
  --line: #2e2823;
  --accent: #c89a70;
  --accent-ink: #241a12;
  --chip: #262120;
  --danger: #e0705f;
  --bar-bg: rgba(18, 16, 14, .84);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .3);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  transition: background .2s, color .2s;
}

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
}

/* ---------- 顶栏 ---------- */
.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .2px;
}
.brand .logo { font-size: 22px; line-height: 1; }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s, background .15s;
}
.icon-btn:active { transform: scale(.94); }
.app-bar-actions { display: flex; gap: 8px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.card-head h2 { font-size: 15.5px; font-weight: 800; }

.pill {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--chip);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill:empty { display: none; }

/* ---------- 今日大数字 ---------- */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(138, 98, 66, .10), transparent 55%),
    var(--surface);
}
[data-theme="dark"] .hero {
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(200, 154, 112, .13), transparent 55%),
    var(--surface);
}
.hero-date { font-size: 13px; font-weight: 700; color: var(--muted); }
.hero-count {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 62px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
}
.hero-count small {
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0;
}
.hero-count.bump { animation: bump .45s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.13); }
  100% { transform: scale(1); }
}
.hero-meta {
  font-size: 13px;
  color: var(--muted);
  min-height: 19px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  cursor: pointer;
  user-select: none;
  transition: transform .12s, filter .15s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.grow { flex: 1; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn .plus { font-size: 1.05em; line-height: 1; }
.btn-add {
  box-shadow: 0 6px 18px rgba(138, 98, 66, .26);
  font-size: 16px;
  padding: 13px 20px;
}
.hero-actions { display: flex; gap: 10px; flex: none; }
[data-theme="dark"] .btn-add { box-shadow: 0 6px 18px rgba(0, 0, 0, .4); }
.hidden { display: none !important; }

/* ---------- 记录列表 ---------- */
.timeline { list-style: none; }
.tl-item {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.tl-item:last-child { border-bottom: none; padding-bottom: 2px; }
.tl-time {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 46px;
}
.chip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13.5px;
  font-weight: 800;
  flex: none;
  background: var(--c, #9c948c);
}
.chip.none { background: var(--chip); color: var(--muted); }
.tl-note {
  font-size: 13.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.tl-note:empty::before { content: "—"; opacity: .5; }
.tl-actions { display: flex; gap: 6px; flex: none; }
.icon-mini {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: var(--chip);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s, background .15s;
}
.icon-mini:active { transform: scale(.92); }
.icon-mini.del { color: var(--danger); }

.empty {
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
  padding: 18px 0 10px;
}

/* ---------- 分段控件 ---------- */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--chip);
  border-radius: 12px;
}
.segmented button {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

/* ---------- 图表 ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .val { fill: var(--ink); font-size: 12px; font-weight: 800; text-anchor: middle; }
.chart .xl { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.chart .bar { transition: opacity .15s; }
.chart .bar.today { stroke: var(--accent); stroke-width: 2; }
.chart .bar.sel { stroke: var(--ink); stroke-width: 2.5; }
.chart .hit { cursor: pointer; }
.chart-tip {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 20px;
  font-variant-numeric: tabular-nums;
}
.chart-tip b { color: var(--ink); }
.legend {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

/* ---------- 历史 ---------- */
.day-group + .day-group { margin-top: 16px; }
.day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 2px;
  border-bottom: 1px dashed var(--line);
}
.day-title { font-size: 13.5px; font-weight: 800; }

/* ---------- 底部操作栏 ---------- */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
}

/* ---------- 弹窗：手机上为底部抽屉 ---------- */
dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: none;
  max-height: none;
}
dialog::backdrop {
  background: rgba(24, 16, 12, .45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.sheet,
#recordForm {
  width: min(94vw, 470px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}
.sheet-handle { display: none; }
.sheet h3,
#recordForm h3 { font-size: 17px; font-weight: 800; margin-bottom: 16px; }

.field { display: block; margin-bottom: 15px; }
.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}
.field-label .opt {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--chip);
  padding: 2px 7px;
  border-radius: 999px;
}
input[type="datetime-local"],
textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
textarea { resize: vertical; min-height: 62px; }
input[type="datetime-local"]:focus,
textarea:focus,
.btn:focus-visible,
.icon-btn:focus-visible,
.icon-mini:focus-visible,
.segmented button:focus-visible,
.bristol-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 布里斯托选择 ---------- */
.bristol-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
  gap: 8px;
}
.bristol-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 4px;
  font: inherit;
  cursor: pointer;
  background: var(--chip);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  transition: transform .12s, border-color .15s, background .15s;
}
.bristol-btn:active { transform: scale(.96); }
.bristol-btn .num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 13.5px;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.bristol-btn .lab {
  font-size: 10.5px;
  line-height: 1.2;
  color: var(--muted);
  text-align: center;
}
.bristol-btn.sel { border-color: var(--c); background: var(--surface); }
.bristol-btn.sel .lab { color: var(--ink); font-weight: 700; }
.hint { margin-top: 8px; font-size: 12px; color: var(--muted); }

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.sheet-actions .spacer { flex: 1; }

/* ---------- 提示条 ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 60;
  padding: 11px 20px;
  border-radius: 999px;
  background: rgba(38, 30, 25, .94);
  color: #fff7ee;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
  transition: opacity .22s, transform .22s;
}
[data-theme="dark"] #toast { background: rgba(240, 234, 227, .95); color: #241a12; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.foot {
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  padding: 20px 0 8px;
}

/* ============================================================
   小屏（手机）
   ============================================================ */
@media (max-width: 720px) {
  body { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .hero-actions { display: none; }
  .grid { display: block; }
  .col + .col { margin-top: 14px; }
  .hero { padding: 18px; }
  .hero-count { font-size: 56px; }
  .wrap { padding-left: 12px; padding-right: 12px; }

  dialog {
    margin: 0;
    inset: auto 0 0 0;
    width: 100%;
  }
  #recordForm,
  .sheet {
    width: 100%;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
    max-height: 90vh;
    overflow-y: auto;
  }
  dialog[open] { animation: sheet-up .26s cubic-bezier(.2, .9, .3, 1); }
  @keyframes sheet-up {
    from { transform: translateY(14px); opacity: .6; }
    to { transform: translateY(0); opacity: 1; }
  }
  .sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    margin: 2px auto 14px;
  }
  .sheet-actions { position: sticky; bottom: 0; background: var(--surface); padding-top: 6px; }

  /* 触控目标按手机习惯放大 */
  .icon-mini { width: 38px; height: 38px; font-size: 15px; }
  .segmented button { padding: 9px 13px; }
  .icon-btn { width: 42px; height: 42px; }
}

/* ============================================================
   大屏（桌面 / 平板横屏）
   ============================================================ */
@media (min-width: 721px) {
  .action-bar { display: none; }
  #toast { bottom: 34px; }
  .wrap { padding: max(18px, env(safe-area-inset-top)) 20px 0; }
}

@media (min-width: 900px) {
  .grid {
    display: grid;
    grid-template-columns: 1.32fr 1fr;
    gap: 14px;
    align-items: start;
  }
  .col + .col { margin-top: 0; }
  .card + .card { margin-top: 14px; }
  .hero-count { font-size: 68px; }
}

@media (hover: hover) {
  .icon-mini:hover { background: var(--bg-2); }
  .btn.primary:hover { filter: brightness(1.07); }
  .btn.ghost:hover { background: var(--bg-2); }
  .bristol-btn:hover { border-color: var(--line); }
  .icon-btn:hover { background: var(--chip); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

/* ============================================================
   登录页
   ============================================================ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(138, 98, 66, .12), transparent 60%),
    var(--bg);
}
.login-theme {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 10;
}
.login-wrap { width: 100%; max-width: 370px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 30px 22px 22px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo { font-size: 44px; line-height: 1; margin-bottom: 12px; }
.login-card h1 { font-size: 20px; font-weight: 800; }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 6px 0 20px; }
.pw-field { position: relative; }
.pw-field input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 14px 48px 14px 14px;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.pw-field input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
}
.login-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  min-height: 20px;
  margin: 9px 0 11px;
}
.login-btn { width: 100%; padding: 14px; font-size: 16px; }
.login-note { color: var(--muted); font-size: 11.5px; margin-top: 16px; }

/* ============================================================
   账号 / 注册登录 / 管理后台
   ============================================================ */
.user-chip {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  height: 40px;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, transform .12s;
}
.user-chip:active { transform: scale(.96); }
.user-chip.static { display: inline-flex; align-items: center; cursor: default; }
@media (hover: hover) { .user-chip:hover { background: var(--bg-2); } }

.back-link {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-right: 2px;
  border-radius: 10px;
  background: var(--chip);
  color: var(--ink);
  text-decoration: none;
  font-size: 17px;
  font-weight: 700;
}
.back-link:hover { background: var(--bg-2); }

.login-tabs { width: 100%; margin-bottom: 18px; }
.login-tabs button { flex: 1; }
.auth-form { text-align: left; }
.auth-form .field { margin-bottom: 13px; }
.auth-form input[type="text"],
.auth-form input[type="password"] {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 13px 14px;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.pw-field { position: relative; display: block; }
.pw-field input { padding-right: 48px !important; }
.login-card h1 { text-align: center; }

.account-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.account-name { font-size: 16px; font-weight: 800; }
.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.account-actions .btn { flex: 1; }

.badge {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  white-space: nowrap;
}
.badge.muted { background: var(--chip); color: var(--muted); }
.badge.ok { background: #5f8b2f; color: #fff; }

.invite-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.invite-form input[type="text"] {
  flex: 1 1 160px;
  font: inherit;
  font-size: 15px;
  padding: 11px 13px;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.invite-form select {
  font: inherit;
  font-size: 14px;
  padding: 11px 12px;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.admin-list { display: flex; flex-direction: column; }
.admin-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.admin-row:last-child { border-bottom: none; }
.admin-row-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.admin-row-sub {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.admin-note { color: var(--muted); font-size: 12.5px; }
.admin-row-actions {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}
.btn.sm { padding: 7px 13px; font-size: 13px; border-radius: 10px; }
.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1.5px;
  background: var(--chip);
  padding: 3px 9px;
  border-radius: 8px;
}
.tips { list-style: none; color: var(--muted); font-size: 13px; line-height: 1.9; }
.tips li::before { content: "· "; }
.tips code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--chip);
  padding: 1px 6px;
  border-radius: 6px;
}
