:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --line: #e5e8ed;
  --text: #132015;
  --muted: #637064;
  --green: #169b45;
  --green-dark: #117738;
  --danger: #d94040;
  --radius: 16px;
  --font: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
#app { max-width: 430px; margin: 0 auto; background: var(--surface); min-height: 100vh; box-shadow: 0 0 0 1px #e5e9f0; }
.shell { min-height: 100vh; padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
.screen { display: none; padding: 16px; }
.screen.active { display: block; }
.title { margin: 8px 0 6px; font-size: 30px; letter-spacing: -0.02em; }
.subtitle { margin: 0 0 14px; color: var(--muted); }
.section-title { margin: 8px 0 14px; font-size: 28px; letter-spacing: -0.02em; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 8px; }
.section-head h3 { margin: 0; font-size: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.label { display: block; margin-bottom: 8px; font-weight: 700; font-size: 14px; }
textarea, input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  font: inherit; color: var(--text); background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
.stack { display: grid; gap: 10px; margin-top: 10px; }
.btn {
  border: 0; border-radius: 12px; min-height: 46px; padding: 10px 12px;
  font: inherit; font-weight: 700; cursor: pointer;
}
.btn-green { background: var(--green); color: #fff; }
.btn-green:active { background: var(--green-dark); }
.btn-outline { background: #fff; border: 1px solid var(--green); color: var(--green); }
.btn-danger { background: #fff4f4; border: 1px solid #f3c4c4; color: var(--danger); }
.list { display: grid; gap: 10px; }
.item-row {
  position: relative;
  display: grid; grid-template-columns: 26px 1fr 86px 34px; gap: 8px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.item-row.active-row { border-color: #f1c4c4; box-shadow: inset 3px 0 0 #dc2f2f; }
.item-row.active-row::after {
  content: "";
  position: absolute;
  right: 154px;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: #dc2f2f;
  transform: translateY(-50%);
}
.item-row input[type="checkbox"] { width: 20px; height: 20px; }
.item-row .name, .item-row .price { padding: 9px 10px; }
.item-row .price { text-align: right; }
.del, .history-del, .add-row-btn {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid #f1c4c4;
  background: #fff4f4;
  color: #c23a3a;
  font-size: 19px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  padding: 0;
}
.add-row-btn { font-size: 23px; margin-left: auto; }
.del:active, .history-del:active, .add-row-btn:active { background: #ffe9e9; }
.summary { margin-top: 10px; display: grid; gap: 8px; }
.thumb-wrap { display: flex; align-items: center; gap: 10px; }
.thumb { width: 66px; height: 88px; object-fit: cover; border-radius: 8px; border: 1px solid #dce2e8; cursor: pointer; }
.thumb-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; background: #f8faf9; }
.empty { border: 1px dashed #ced6de; border-radius: 12px; color: #6b7782; text-align: center; padding: 16px; }
.history-card { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.history-del {
  position: absolute;
  right: 8px;
  top: 8px;
}
.history-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.history-head span { margin-right: 38px; white-space: nowrap; text-align: right; }
.history-row { display: flex; gap: 10px; align-items: flex-start; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: #fff; border: 1px solid #edf0f3; border-radius: 14px; padding: 8px 6px 7px; min-height: 88px; display:grid; align-content:start; justify-items:center; overflow:hidden; }
.tile small { font-weight: 800; display: block; margin-bottom: 5px; font-size: 11px; letter-spacing: -0.005em; white-space: nowrap; }
.tile strong { font-size: 24px; line-height: 1.05; letter-spacing: 0; font-weight: 800; margin-bottom: 6px; white-space: nowrap; max-width: 100%; text-overflow: clip; }
.tile-icon { width: 22px; height: 22px; display:grid; place-items:center; }
.tile .ic { width: 20px; height: 20px; display:block; }
.tile-today small, .tile-today strong { color: #1f8f49; }
.tile-week small, .tile-week strong { color: #3d79dc; }
.tile-month small, .tile-month strong { color: #5b41cb; }
.ic-today circle { fill: #169b45; opacity: 0.96; }
.ic-today path { fill: #ffffff; opacity: 0.95; }
.ic-week rect { fill: #3f7de6; }
.ic-month rect, .ic-month path { stroke: #6a45d4; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chart-card { margin-top: 10px; }
.seg { display:flex; background:#f1f4f2; border-radius: 10px; padding: 2px; gap:2px; }
.seg-btn { border:0; background:transparent; border-radius:8px; padding:6px 10px; font-weight:700; font-family:var(--font); color:#5e6a62; }
.seg-btn.active { background:#fff; color:#169b45; box-shadow: 0 0 0 1px #dde5df; }
.week-bars { height: 120px; display:grid; grid-template-columns: repeat(7,1fr); gap:8px; align-items:end; margin-top:6px; }
.wbar { display:grid; justify-items:center; align-items:end; gap:4px; }
.wbar .fill { width: 18px; min-height: 6px; background: linear-gradient(180deg,#2bc361,#169b45); border-radius: 7px 7px 4px 4px; }
.wbar small { color:#637064; font-size:10px; }
.line-chart { width:100%; height:120px; margin-top:4px; }
.line-chart circle { fill:#169b45; }
.week-labels { display:grid; grid-template-columns: repeat(7,1fr); gap:8px; margin-top:2px; }
.week-labels small { text-align:center; color:#637064; font-size:10px; }
.chart-wrap { display:grid; grid-template-columns: 36px 1fr; gap: 8px; align-items:start; margin-top:6px; }
.y-axis { height:120px; display:flex; flex-direction:column; justify-content:space-between; align-items:flex-end; }
.y-axis small { font-size:10px; color:#94a09a; font-weight:700; line-height:1; }
.sync-ok { color:#1f8f49; font-weight:800; font-size:13px; }
.sync-bad { color:#c23a3a; font-weight:800; font-size:13px; }
.day-row {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 10px; display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
  text-align: left;
}
.mini-thumb { width: 34px; height: 46px; object-fit: cover; border-radius: 6px; border: 1px solid #dde3ea; }
.bottom-nav {
  position: fixed; bottom: 0; width: min(430px, 100vw); border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
.tab { border: 0; background: transparent; color: #7d8980; font-family: var(--font); font-weight: 700; min-height: 44px; display:grid; place-items:center; gap:2px; font-size:12px; }
.tab .ico { font-size: 14px; line-height: 1; }
.tab.active { color: var(--green); }
.modal { position: fixed; inset: 0; background: rgba(15, 25, 18, 0.4); display: none; align-items: flex-end; }
.modal.show { display: flex; }
.sheet {
  width: min(430px, 100vw); margin: 0 auto; background: #fff; border-radius: 18px 18px 0 0;
  max-height: 92vh; overflow: auto; padding: 16px;
}
.review-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.review-top small { display: block; color: var(--muted); }
.image-sheet { padding: 14px; }
.full-image { width: 100%; border-radius: 10px; border: 1px solid #dbe1e8; margin-bottom: 10px; }
@media (min-width: 700px) {
  #app { margin: 18px auto; border-radius: 22px; overflow: hidden; }
}
.conf { display:block; margin-top:4px; font-size:11px; font-weight:700; }
.conf-high { color:#1f8a3b; }
.conf-medium { color:#b07311; }
.conf-low { color:#a33a3a; }

.fallback-msg { margin: 0 0 10px; padding: 10px; border-radius: 10px; background: #fff8e8; color: #8a5a00; border: 1px solid #f1d39a; font-size: 13px; font-weight: 700; }
.cal-grid { display:grid; grid-template-columns: repeat(7, 1fr); gap:6px; }
.dow { font-size: 11px; color: var(--muted); text-align:center; font-weight: 700; padding: 4px 0; }
.cal-cell { border: 1px solid var(--line); background:#fff; border-radius: 10px; min-height: 56px; padding: 6px 4px; display:grid; justify-items:center; align-content:start; gap:2px; }
.cal-cell .n { font-weight:700; font-size:12px; }
.cal-cell .dot { width:6px; height:6px; border-radius:50%; background: var(--green); }
.cal-cell .amt { font-size:10px; color:#497a54; }
.cal-cell.muted { opacity: .45; }
.cal-cell.sel { outline: 2px solid #b6e4c2; }
