* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: #0f172a;
  color: #e2e8f0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: 70px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px 10px;
  position: sticky; top: 0; z-index: 5;
  background: #0f172a;
}
.topbar h1 { font-size: 18px; margin: 0; }
.date-display { font-size: 12px; color: #94a3b8; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 12px; color: #94a3b8; }
.logout-link { font-size: 12px; color: #ef4444; text-decoration: none; font-weight: 600; }
.logout-link-block {
  display: inline-block; margin-top: 10px; color: #ef4444; text-decoration: none;
  font-weight: 600; font-size: 14px;
}

.tabbar {
  display: flex; overflow-x: auto;
  gap: 4px; padding: 0 10px 8px;
  position: sticky; top: 44px; z-index: 5;
  background: #0f172a;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  flex: 0 0 auto;
  background: #1e293b; color: #94a3b8;
  border: none; border-radius: 20px;
  padding: 8px 14px; font-size: 13px;
  white-space: nowrap;
}
.tab-btn.active { background: #22c55e; color: #0f172a; font-weight: 600; }

main { padding: 12px; max-width: 720px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }

.card-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 14px;
}
.stat-card {
  background: #1e293b; border-radius: 14px; padding: 14px;
}
.stat-label { font-size: 12px; color: #94a3b8; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; color: #f1f5f9; }

.panel {
  background: #1e293b; border-radius: 14px;
  padding: 16px; margin-bottom: 14px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; color: #cbd5e1; }

.cal-summary { display: flex; justify-content: space-between; margin-bottom: 10px; }
.cal-summary div { display: flex; flex-direction: column; align-items: center; flex: 1; }
.cal-summary span { font-size: 11px; color: #94a3b8; }
.cal-summary strong { font-size: 18px; }

.progress-bar { height: 10px; background: #334155; border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: #22c55e; width: 0%; transition: width .2s; }
.progress-fill.over { background: #ef4444; }

.mini-stats { display: flex; justify-content: space-between; gap: 8px; }
.mini-stats div { display: flex; flex-direction: column; align-items: center; flex: 1; }
.mini-stats span { font-size: 11px; color: #94a3b8; }
.mini-stats strong { font-size: 16px; margin-top: 4px; }

.goal-bar-wrap { margin-top: 14px; }
.goal-bar-labels { display: flex; justify-content: space-between; font-size: 11px; color: #94a3b8; margin-bottom: 4px; }
.goal-bar { position: relative; height: 10px; background: #334155; border-radius: 6px; }
.goal-bar-fill { position: absolute; top: 0; left: 0; height: 100%; background: #22c55e; border-radius: 6px; }
.goal-bar-marker {
  position: absolute; top: -6px; width: 3px; height: 22px;
  background: #f59e0b; border-radius: 2px;
}

.food-list { display: flex; flex-direction: column; gap: 10px; }
.food-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #0f172a; border-radius: 10px; padding: 10px 12px;
}
.food-row .food-name { font-size: 14px; font-weight: 600; }
.food-row .food-unit { font-size: 11px; color: #94a3b8; display: block; }
.food-row .food-cal { font-size: 11px; color: #64748b; }
.qty-controls { display: flex; align-items: center; gap: 10px; }
.qty-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: #334155; color: #f1f5f9;
  font-size: 18px; line-height: 1;
}
.qty-btn:active { background: #22c55e; color: #0f172a; }
.qty-val { min-width: 24px; text-align: center; font-weight: 600; }
.food-list.compact .food-row { padding: 8px 10px; }

.food-row > div:first-child { flex: 1; min-width: 0; padding-right: 8px; }
.food-row.add-row .qty-controls { flex: 0 0 auto; }
.qty-input {
  width: 64px; background: #0f172a; border: 1px solid #334155;
  color: #f1f5f9; border-radius: 8px; padding: 8px 6px; font-size: 14px;
  text-align: center;
}
.qty-input.edit-qty { width: 56px; }
.add-btn {
  background: #22c55e; color: #0f172a; border: none;
  border-radius: 8px; padding: 8px 12px; font-weight: 600; font-size: 13px;
  white-space: nowrap;
}
.full-input {
  width: 100%; background: #0f172a; border: 1px solid #334155;
  color: #f1f5f9; border-radius: 8px; padding: 10px; font-size: 14px;
}
.empty-hint { color: #64748b; font-size: 13px; margin: 4px 0 0; }

.food-master-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.master-row {
  display: flex; gap: 6px; align-items: center;
  background: #0f172a; border-radius: 10px; padding: 8px;
}
.master-row .master-name { flex: 1.4; min-width: 0; }
.master-row .master-unit { flex: 1; min-width: 0; }
.master-row .master-cal { flex: 0 0 64px; }
.master-row input {
  background: #1e293b; border: 1px solid #334155; color: #f1f5f9;
  border-radius: 6px; padding: 7px 6px; font-size: 13px; width: 100%;
}
.master-row .master-del {
  flex: 0 0 auto; background: none; border: none; color: #ef4444;
  font-size: 18px; padding: 4px 6px;
}
.food-master-add { display: flex; flex-wrap: wrap; gap: 8px; }
.food-master-add input {
  flex: 1; min-width: 100px; background: #0f172a; border: 1px solid #334155;
  color: #f1f5f9; border-radius: 8px; padding: 10px; font-size: 14px;
}
.food-master-add button {
  background: #22c55e; color: #0f172a; border: none;
  border-radius: 8px; padding: 10px 16px; font-weight: 600; font-size: 14px;
  width: 100%;
}

@media (max-width: 420px) {
  .master-row { flex-wrap: wrap; }
  .master-row .master-name, .master-row .master-unit { flex: 1 1 100%; }
  .master-row .master-cal { flex: 1 1 70px; }
}

.entry-form { display: flex; flex-wrap: wrap; gap: 8px; }
.entry-form input, .misc-entry input {
  flex: 1; min-width: 110px;
  background: #0f172a; border: 1px solid #334155; color: #f1f5f9;
  border-radius: 8px; padding: 10px; font-size: 14px;
}
.entry-form button, .misc-entry button, #miscAddBtn, #weightSaveBtn, #waistSaveBtn, #settingsSaveBtn, #exportBtn {
  background: #22c55e; color: #0f172a; border: none;
  border-radius: 8px; padding: 10px 16px; font-weight: 600; font-size: 14px;
}
.misc-entry { display: flex; flex-wrap: wrap; gap: 8px; }

.inline-edit { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 14px; }
.inline-edit input {
  width: 100px; background: #0f172a; border: 1px solid #334155;
  color: #f1f5f9; border-radius: 8px; padding: 8px; text-align: right;
}

.file-import-label {
  display: block; margin-top: 12px; background: #334155;
  border-radius: 8px; padding: 10px; text-align: center; font-size: 14px; cursor: pointer;
}
.file-import-label input { display: none; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 6px; text-align: left; border-bottom: 1px solid #334155; }
th { color: #94a3b8; font-weight: 600; }
td button { background: none; border: none; color: #94a3b8; font-size: 14px; padding: 2px 6px; }
td button.danger { color: #ef4444; }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #22c55e; color: #0f172a; padding: 10px 18px;
  border-radius: 20px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .25s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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