/* ===================================================================
   Poop Tracker - Mobile-first CSS
   =================================================================== */

:root {
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --orange: #f59e0b;
  --orange-bg: #fffbeb;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --blue: #3b82f6;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* -------------------------------------------------------------------
   Header
   ------------------------------------------------------------------- */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 16px 0;
}

.title {
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  flex: 1;
  padding: 10px 0 12px;
  border: none;
  background: none;
  font-size: .95rem;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s, border-color .15s;
}

.tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* -------------------------------------------------------------------
   Main
   ------------------------------------------------------------------- */

.main {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.page { display: none; }
.page.active { display: block; }

/* -------------------------------------------------------------------
   Form
   ------------------------------------------------------------------- */

.field { margin-bottom: 18px; }

.label {
  display: block;
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--gray-700);
}

.required { color: var(--red); }

.input, .textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s;
}

.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.textarea { resize: vertical; }

/* 按钮选择组 */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

.btn-opt {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all .15s;
  background: #fff;
  color: var(--gray-700);
}

.btn-opt input { display: none; }

.btn-opt:active { transform: scale(.96); }

/* 选中状态 */
.btn-opt:has(input:checked) {
  border-color: var(--blue);
  background: #eff6ff;
  color: var(--blue);
  font-weight: 600;
}

/* 警告/危险选项选中高亮 */
.btn-opt.warn:has(input:checked) {
  border-color: var(--orange);
  background: var(--orange-bg);
  color: #92400e;
}

.btn-opt.danger:has(input:checked) {
  border-color: var(--red);
  background: var(--red-bg);
  color: #991b1b;
}

.field-err {
  font-size: .8rem;
  color: var(--red);
  margin-top: 4px;
  min-height: 1em;
}

.btn-submit {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--green);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s;
}

.btn-submit:active { opacity: .85; }
.btn-submit:disabled { opacity: .5; cursor: not-allowed; }

.form-msg {
  text-align: center;
  margin-top: 12px;
  font-size: .9rem;
  min-height: 1.5em;
}

.form-msg.success { color: var(--green); }
.form-msg.error { color: var(--red); }

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

.btn-sm {
  padding: 8px 14px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-outline {
  background: transparent;
  color: var(--blue);
}

.btn-outline:active { background: #eff6ff; }

/* -------------------------------------------------------------------
   List
   ------------------------------------------------------------------- */

.list-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.input-sm { padding: 8px 10px; font-size: .85rem; flex: 1; max-width: 160px; }

.list-container { min-height: 200px; }

/* 记录卡片 */
.record-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.record-card .rc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.record-card .rc-time {
  font-weight: 600;
  font-size: .95rem;
}

.record-card .rc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.record-card .tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: .8rem;
  font-weight: 500;
}

.tag-正常, .tag-顺畅 { background: var(--green-bg); color: #166534; }
.tag-偏硬, .tag-费力 { background: var(--orange-bg); color: #92400e; }
.tag-干结, .tag-哭闹 { background: var(--red-bg); color: #991b1b; }
.tag-偏稀 { background: #ecfeff; color: #155e75; }
.tag-水样 { background: #f0f9ff; color: #1e40af; }
.tag-少量 { background: var(--gray-100); color: var(--gray-700); }
.tag-中等 { background: var(--gray-100); color: var(--gray-700); }
.tag-大量 { background: var(--gray-100); color: var(--gray-700); }
.tag-黑色, .tag-红色 { background: var(--red-bg); color: #991b1b; }

.record-card .rc-note {
  margin-top: 6px;
  font-size: .85rem;
  color: var(--gray-500);
  padding-left: 4px;
  border-left: 2px solid var(--gray-200);
}

.empty-tip {
  text-align: center;
  color: var(--gray-400);
  padding: 48px 0;
  font-size: .95rem;
}

/* 分页 */
.pager {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0 24px;
}

.pager button {
  padding: 8px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: #fff;
  font-size: .85rem;
  cursor: pointer;
}

.pager .current {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* -------------------------------------------------------------------
   Stats
   ------------------------------------------------------------------- */

.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.stat-card h3 {
  font-size: .9rem;
  color: var(--gray-500);
  margin-bottom: 8px;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.stat-item {
  text-align: center;
  padding: 12px;
  border-radius: 8px;
  background: var(--gray-50);
}

.stat-item .num {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-item .lbl {
  font-size: .8rem;
  color: var(--gray-500);
  margin-top: 2px;
}

/* 条形图 */
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.bar-row .lbl {
  width: 50px;
  font-size: .85rem;
  text-align: right;
  flex-shrink: 0;
}

.bar-row .bar-track {
  flex: 1;
  height: 20px;
  background: var(--gray-100);
  border-radius: 99px;
  overflow: hidden;
}

.bar-row .bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .3s;
}

.bar-row .pct {
  width: 40px;
  font-size: .8rem;
  color: var(--gray-500);
  flex-shrink: 0;
}

/* 月度趋势 */
.month-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.month-row .month {
  width: 60px;
  font-size: .85rem;
  flex-shrink: 0;
}

.month-row .month-bar {
  flex: 1;
  height: 24px;
  display: flex;
  border-radius: 4px;
  overflow: hidden;
}

.month-row .seg-easy {
  background: var(--green);
  transition: width .3s;
}

.month-row .seg-hard {
  background: var(--orange);
  transition: width .3s;
}

.month-row .seg-bad {
  background: var(--red);
  transition: width .3s;
}

.month-row .month-total {
  width: 30px;
  font-size: .8rem;
  color: var(--gray-500);
  text-align: right;
}

.stats-loading {
  text-align: center;
  color: var(--gray-400);
  padding: 48px 0;
}
