:root {
  --bg: #f7f3eb;
  --bg-card: #fffdf9;
  --ink: #2a322e;
  --ink-soft: #5c6b63;
  --muted: #8a968f;
  --line: #e4ddd2;
  --brand: #3d6b5a;
  --brand-soft: #d8e8e0;
  --accent: #e8a87c;
  --accent-soft: #f8e6d6;
  --visit: #5b7c9a;
  --visit-soft: #dce7f0;
  --cook: #b86b4a;
  --cook-soft: #f3ddd3;
  --house: #7a6b9a;
  --house-soft: #e6e0f0;
  --shop: #6b8f4e;
  --shop-soft: #e0ecd6;
  --shift: #3d6b5a;
  --shift-soft: #d8e8e0;
  --danger: #b54a4a;
  --free-dash: #c9c2b6;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 28px rgba(42, 50, 46, 0.08);
  --nav-h: 72px;
  --top-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: none;
  background: none;
}
img { max-width: 100%; display: block; }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 4px;
  min-height: var(--top-h);
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-center { text-align: center; }
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  color: var(--brand);
}
.icon-btn:active { background: var(--brand-soft); }

.main {
  flex: 1;
  padding: 14px 14px 24px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 6px 8px var(--safe-b);
  background: var(--bg-card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(42, 50, 46, 0.05);
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}
.nav-btn .nav-ico { font-size: 1.25rem; line-height: 1; }
.nav-btn.active { color: var(--brand); background: var(--brand-soft); }
.nav-plus .plus-circle {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: 1.2rem;
  font-weight: 700;
}

/* Cards & lists */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 650;
}
.muted { color: var(--muted); font-size: 0.85rem; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand);
}
.chip.visit { background: var(--visit-soft); color: var(--visit); }
.chip.cook { background: var(--cook-soft); color: var(--cook); }
.chip.house { background: var(--house-soft); color: var(--house); }
.chip.shop { background: var(--shop-soft); color: var(--shop); }
.chip.shift { background: var(--shift-soft); color: var(--shift); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 650;
  background: var(--brand);
  color: #fff;
}
.btn:active { filter: brightness(0.95); }
.btn.secondary {
  background: var(--bg);
  color: var(--brand);
  border: 1px solid var(--line);
}
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field label {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--ink-soft);
}
.field input,
.field select,
.field textarea {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.field textarea { min-height: 96px; resize: vertical; }

/* Day timeline */
.timeline {
  position: relative;
  margin-top: 4px;
}
.hour-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  min-height: 56px;
}
.hour-label {
  font-size: 0.75rem;
  color: var(--muted);
  padding-top: 4px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.hour-slot {
  border-left: 2px solid var(--line);
  padding: 4px 0 4px 10px;
  position: relative;
}
.hour-slot.free {
  border-left-style: dashed;
  border-left-color: var(--free-dash);
}
.block {
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 6px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.block .block-time {
  font-size: 0.72rem;
  font-weight: 650;
  opacity: 0.8;
  margin-bottom: 2px;
}
.block .block-title { font-weight: 650; }
.block .block-meta { font-size: 0.78rem; margin-top: 4px; opacity: 0.9; }
.block.shift { background: var(--shift-soft); border-color: color-mix(in srgb, var(--shift) 25%, transparent); }
.block.visit { background: var(--visit-soft); border-color: color-mix(in srgb, var(--visit) 25%, transparent); }
.block.cook { background: var(--cook-soft); border-color: color-mix(in srgb, var(--cook) 25%, transparent); }
.block.house { background: var(--house-soft); border-color: color-mix(in srgb, var(--house) 25%, transparent); }
.block.shop { background: var(--shop-soft); border-color: color-mix(in srgb, var(--shop) 25%, transparent); }
.block.suggestion {
  border-style: dashed;
  opacity: 0.85;
}
.bring-list {
  margin: 8px 0 0;
  padding: 8px 10px;
  background: rgba(255,255,255,0.55);
  border-radius: 10px;
  font-size: 0.8rem;
}
.bring-list strong { display: block; margin-bottom: 4px; }
.bring-list ul { margin: 0; padding-left: 1.1em; }
.photo-thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.photo-thumbs img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.budget-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin: 10px 0;
}
.budget-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  border-radius: inherit;
}
.budget-extra {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.02em;
}

/* Week / Month */
.week-grid, .month-grid {
  display: grid;
  gap: 8px;
}
.week-grid { grid-template-columns: 1fr; }
.day-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.day-card.today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.day-card h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.mini-items { display: flex; flex-wrap: wrap; gap: 6px; }
.month-grid {
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.month-dow {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 0;
}
.month-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 44px;
}
.month-cell.other { color: var(--muted); opacity: 0.45; }
.month-cell.today { background: var(--brand); color: #fff; }
.month-cell.has-items:not(.today) { background: var(--bg-card); border-color: var(--line); }
.dots { display: flex; gap: 2px; }
.dots i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--brand);
  display: block;
}
.dots i.visit { background: var(--visit); }
.dots i.cook { background: var(--cook); }
.dots i.shift { background: var(--shift); }
.dots i.house { background: var(--house); }
.dots i.shop { background: var(--shop); }

/* Plus menu */
.plus-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.plus-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-height: 88px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--line);
  text-align: left;
  font-weight: 650;
}
.plus-item span.ico {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 1.1rem;
}
.plus-item .desc {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.list-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 650; }
.list-item .meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.check {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 2px solid var(--line);
  flex-shrink: 0;
  margin-top: 2px;
}
.check.on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  font-size: 0.85rem;
}
.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
}
.empty strong { display: block; color: var(--ink-soft); margin-bottom: 4px; }

/* Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 50, 46, 0.35);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  max-height: min(92dvh, 900px);
  background: var(--bg-card);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 40px rgba(42, 50, 46, 0.18);
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-b);
  transform: translateY(0);
  transition: transform 0.22s ease;
}
.sheet.hidden, .sheet-backdrop.hidden { display: none; }
.sheet-handle {
  width: 40px; height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 10px auto 0;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 4px;
}
.sheet-header h2 {
  margin: 0;
  font-size: 1.1rem;
}
.sheet-body {
  overflow: auto;
  padding: 8px 16px 20px;
  -webkit-overflow-scrolling: touch;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.hidden { display: none; }

.hidden { display: none !important; }

@media (min-width: 720px) {
  .week-grid { grid-template-columns: 1fr 1fr; }
}
