:root {
  --brown: #6b4a3a;
  --brown-dark: #4a3226;
  --cream: #fdf8f3;
  --card-bg: #ffffff;
  --border: #e4d9cf;
  --text: #2c2220;
  --muted: #7a6a60;
  --food: #c97b3d;
  --drink: #3d7ac9;
  --danger: #c0392b;
  --success: #2e7d32;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--cream);
  color: var(--text);
  padding-bottom: 40px;
}

.topbar {
  background: var(--brown);
  color: white;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 720px;
  margin: 0 auto;
}
.topbar h1 { margin: 0; font-size: 1.3rem; }
.user-badge { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.user-badge button { background: none; border: none; color: white; font-size: 1rem; cursor: pointer; opacity: 0.85; }

.tabs {
  display: flex;
  max-width: 720px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}
.tab-btn {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab-btn.active {
  color: var(--brown);
  border-bottom-color: var(--brown);
  font-weight: 600;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

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

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }
.hint { color: var(--muted); font-size: 0.88rem; }
.hidden { display: none !important; }

.file-btn {
  display: block;
  text-align: center;
  background: var(--brown);
  color: white;
  padding: 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
}
.file-btn input { display: none; }

label { display: block; margin: 12px 0; font-size: 0.9rem; color: var(--muted); }
label input, label select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  background: white;
}

.item-row {
  display: grid;
  grid-template-columns: 2.2fr 1.1fr 0.8fr 0.9fr auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.item-row input, .item-row select {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  width: 100%;
}
.item-row .remove-item {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
}
.item-cat-food { border-left: 4px solid var(--food) !important; }
.item-cat-drink { border-left: 4px solid var(--drink) !important; }

.secondary-btn, .primary-btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
}
.secondary-btn { background: var(--border); color: var(--text); }
.primary-btn { background: var(--brown); color: white; font-weight: 600; }

.total-row { margin: 14px 0; font-size: 1.05rem; text-align: right; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; }

.notice {
  background: #fff3e0;
  border: 1px solid #ffcc80;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 10px;
}
.success { border-color: var(--success); text-align: center; }
.success button { margin-top: 10px; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters button { grid-column: span 2; margin-top: 8px; }

.entry-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.entry-card .entry-head {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}
.entry-card .entry-meta { color: var(--muted); font-size: 0.85rem; margin: 4px 0; }
.entry-card .entry-items { font-size: 0.9rem; margin-top: 6px; }
.entry-card .entry-items div { display: flex; justify-content: space-between; padding: 2px 0; }
.tag-food { color: var(--food); }
.tag-drink { color: var(--drink); }
.day-heading { margin: 20px 0 8px; color: var(--brown-dark); font-size: 1rem; border-bottom: 2px solid var(--border); padding-bottom: 4px; }

.totals-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; text-align: center; }
.totals-grid .stat { background: var(--cream); border-radius: 8px; padding: 10px; }
.totals-grid .stat .num { font-size: 1.2rem; font-weight: 700; display: block; }
.totals-grid .stat .lbl { font-size: 0.78rem; color: var(--muted); }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card {
  background: white; border-radius: 12px; padding: 20px; width: 90%; max-width: 340px;
}
.modal-card input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid var(--border); border-radius: 8px; }

.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.85rem; }
.bar-row .bar-label { width: 110px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { flex: 1; background: #eee; border-radius: 4px; height: 14px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 4px; }
.bar-row .bar-value { width: 70px; text-align: right; flex-shrink: 0; }
