:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --surface-soft: #F4EFE6;
  --plum: #231B2E;
  --plum-light: #372848;
  --gold: #C89D54;
  --gold-soft: #F5EBD7;
  --text: #1F1B24;
  --text-sub: #6E6676;
  --text-muted: #9C94A5;
  --border: #ECE6DC;
  --green: #1E8E68;
  --green-soft: #E6F6F0;
  --amber: #D9822B;
  --amber-soft: #FEF3E6;
  --red: #D64B5A;
  --red-soft: #FDECEF;
  --rose: #C85A7C;
  --rose-soft: #FCECF2;
  --blue: #2F7DD1;
  --blue-soft: #E9F3FE;
  --shadow: 0 8px 24px rgba(35, 27, 46, 0.06);
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body { min-height: 100vh; display: flex; justify-content: center; }

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background: var(--bg);
  padding-top: calc(10px + var(--safe-top));
  padding-bottom: calc(110px + var(--safe-bottom));
  position: relative;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 18px 12px;
}

.brand-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--plum);
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-date { font-size: 11px; color: var(--text-sub); margin-top: 2px; }

.top-actions { display: flex; gap: 6px; align-items: center; }

.pill-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--plum);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.pill-btn:active { transform: scale(0.96); }
.pill-gold { background: var(--gold-soft); border-color: #E5CFA2; color: #7C5619; }
.pill-plum { background: var(--plum); border-color: var(--plum); color: #F5DA9E; }

.tab-panel { display: none; padding: 0 15px; animation: fadeIn 0.12s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.hero-card {
  background: linear-gradient(145deg, #231B2E 0%, #372848 62%, #473357 100%);
  color: #FFFDF9;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 14px 32px rgba(35, 27, 46, 0.2);
  margin-bottom: 13px;
  position: relative;
  overflow: hidden;
}
.hero-card::after {
  content: "";
  position: absolute;
  top: -36px; right: -36px;
  width: 130px; height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200, 157, 84, 0.28) 0%, transparent 70%);
  pointer-events: none;
}

.hero-label { font-size: 12px; color: rgba(255, 253, 249, 0.74); display: flex; justify-content: space-between; align-items: center; }
.hero-amount { font-size: 32px; font-weight: 700; margin: 6px 0 10px; }
.hero-amount small { font-size: 16px; color: var(--gold); margin-right: 2px; }

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.hero-metric-item .m-label { font-size: 11px; color: rgba(255, 255, 255, 0.65); }
.hero-metric-item .m-val { font-size: 14px; font-weight: 600; margin-top: 3px; }
.gold-text { color: #F0CA82; }
.danger-text { color: #FF949E; }
.ok-text { color: #7EE4BE; }

.progress-wrap { margin-top: 12px; }
.progress-head { display: flex; justify-content: space-between; font-size: 11px; color: rgba(255, 255, 255, 0.84); margin-bottom: 5px; }
.progress-track { width: 100%; height: 7px; background: rgba(255, 255, 255, 0.15); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #D9AF64, #F5DA9E); border-radius: 999px; transition: width 0.35s ease; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 13px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(236, 230, 220, 0.72);
}

.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.card-title { font-size: 15px; font-weight: 700; color: var(--plum); display: flex; align-items: center; gap: 5px; }
.card-sub { font-size: 11px; color: var(--text-muted); }

.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-gold { background: var(--gold-soft); color: #8B621D; }
.badge-plum { background: #EFEBF5; color: var(--plum); }
.badge-rose { background: var(--rose-soft); color: var(--rose); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }

.split-bar { display: flex; height: 9px; border-radius: 999px; overflow: hidden; background: var(--surface-soft); margin-bottom: 10px; }
.split-seg { height: 100%; transition: width 0.35s ease; }
.seg-basic { background: #8E849C; }
.seg-energy { background: #1E8E68; }
.seg-leverage { background: #C89D54; }
.seg-leak { background: #D64B5A; }

.split-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.legend-item { display: flex; justify-content: space-between; align-items: center; font-size: 12px; padding: 7px 10px; background: var(--bg); border-radius: 10px; }
.legend-left { display: flex; align-items: center; gap: 6px; color: var(--text-sub); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.filter-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; }
.filter-chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-sub); font-size: 12px; padding: 5px 11px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.filter-chip.active { background: var(--plum); color: #FFF; border-color: var(--plum); }

.list-item { display: flex; justify-content: space-between; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.list-item:last-child { border-bottom: none; padding-bottom: 2px; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-size: 14px; font-weight: 600; color: var(--text); word-break: break-word; line-height: 1.45; }
.item-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.item-right { text-align: right; display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.amount-neg { font-size: 14px; font-weight: 700; color: var(--text); }
.amount-pos { font-size: 14px; font-weight: 700; color: var(--green); }
.amount-leak { font-size: 14px; font-weight: 700; color: var(--red); }

.del-btn { background: none; border: none; color: #C3BCCB; font-size: 16px; padding: 2px 4px; cursor: pointer; }
.del-btn:active { color: var(--red); }

/* Grids & Health widgets */
.tri-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 13px; }
.mini-stat {
  background: var(--surface);
  border-radius: 17px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid rgba(236, 230, 220, 0.72);
  cursor: pointer;
}
.mini-stat .ms-icon { font-size: 18px; margin-bottom: 3px; }
.mini-stat .ms-val { font-size: 16px; font-weight: 700; color: var(--plum); }
.mini-stat .ms-label { font-size: 11px; color: var(--text-sub); margin-top: 2px; }
.mini-stat .ms-badge { margin-top: 5px; }

.check-dots { display: flex; gap: 8px; align-items: center; }
.check-dot {
  flex: 1;
  padding: 10px 6px;
  border-radius: 13px;
  border: 1.5px dashed var(--border);
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 600;
}
.check-dot.done { background: var(--gold-soft); border: 1.5px solid var(--gold); color: #7D581B; }

/* Water tracker */
.water-bar-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.water-track { flex: 1; height: 12px; background: var(--blue-soft); border-radius: 999px; overflow: hidden; }
.water-fill { height: 100%; background: linear-gradient(90deg, #5AA6F8, #2F7DD1); border-radius: 999px; transition: width 0.3s ease; }

/* Quick tap chips for stool / mood / skin / cycle */
.tap-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.tap-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 12px;
  cursor: pointer;
}
.tap-chip.active { background: var(--plum); color: #F5DA9E; border-color: var(--plum); }
.tap-chip.rose-active { background: var(--rose); color: #FFF; border-color: var(--rose); }

/* Meal Photo Card */
.photo-drop {
  border: 1.5px dashed #D6C3A0;
  background: #FCF9F3;
  border-radius: 16px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 10px;
}
.meal-thumb {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.ai-nutrition-box {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--green-soft);
  color: #165B43;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
}

.chart-box { width: 100%; height: 112px; margin-top: 4px; }

.status-cycle-btn { border: none; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 600; cursor: pointer; }

.briefing-block {
  background: var(--bg);
  border-left: 3px solid var(--gold);
  border-radius: 0 12px 12px 0;
  padding: 10px 12px;
  margin-bottom: 9px;
  font-size: 13px;
  line-height: 1.6;
}
.briefing-block strong { color: var(--plum); }

.auto-cost-box {
  background: #F6F2FA;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--plum);
  line-height: 1.6;
}

.btn-primary {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(135deg, #231B2E, #3E2D52);
  color: #F6DFB0;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:active { transform: scale(0.98); }
.btn-gold {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(135deg, #D9AE62, #B88739);
  color: #FFF;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-outline {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: var(--surface);
  color: var(--plum);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 9px; }

/* Floating Quick Add Pill */
.fab-float {
  position: fixed;
  right: max(18px, calc(50% - 222px));
  bottom: calc(74px + var(--safe-bottom));
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, #D9AE62, #B88739);
  color: #FFF;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(184, 135, 57, 0.42);
  cursor: pointer;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 5px;
}
.fab-float:active { transform: scale(0.94); }

/* 5-Tab Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  padding: 7px 4px calc(7px + var(--safe-bottom));
  z-index: 50;
}

.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 3px 0;
}
.nav-item .nav-ico { font-size: 19px; line-height: 1.1; }
.nav-item.active { color: var(--plum); }

/* Modal Bottom Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 16, 30, 0.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.open { display: flex; }

.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 16px 18px calc(22px + var(--safe-bottom));
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(28px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

.sheet-handle { width: 38px; height: 4px; border-radius: 999px; background: #DFD8CE; margin: 0 auto 12px; }
.sheet-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 13px; padding-bottom: 2px; }
.sheet-tab { border: 1px solid var(--border); background: var(--bg); color: var(--text-sub); border-radius: 999px; padding: 6px 11px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.sheet-tab.active { background: var(--plum); color: #F4DAA4; border-color: var(--plum); }

.form-group { margin-bottom: 11px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-sub); margin-bottom: 5px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--gold); background: #FFF; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.stars-row { display: flex; gap: 8px; }
.star-btn {
  flex: 1;
  padding: 9px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
  cursor: pointer;
}
.star-btn.active { background: var(--gold-soft); border-color: var(--gold); }

.empty-state { text-align: center; padding: 18px 8px; color: var(--text-muted); font-size: 12.5px; }

.toast {
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--plum);
  color: #F6DFB0;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.pin-overlay {
  position: fixed; inset: 0; background: var(--plum); color: #FFFDF9;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; z-index: 300;
}
.pin-overlay.open { display: flex; }
.pin-dots { display: flex; gap: 14px; margin: 18px 0 26px; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--gold); }
.pin-dot.filled { background: var(--gold); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 70px); gap: 14px; }
.pin-key { width: 70px; height: 70px; border-radius: 50%; border: 1px solid rgba(240, 202, 130, 0.3); background: rgba(255, 255, 255, 0.08); color: #FFF; font-size: 23px; font-weight: 600; cursor: pointer; }
.pin-key:active { background: rgba(200, 157, 84, 0.35); }
