:root {
  --bg: #f2f5f3;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 40px;
}

header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--primary);
  color: #fff;
  padding: 14px 16px 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 19px;
  margin-bottom: 10px;
}

.logo { color: #fff; }

nav { display: flex; gap: 8px; }

.nav-btn {
  flex: 1;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  padding: 9px 0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.nav-btn.active { background: #fff; color: var(--primary-dark); }
.nav-btn:not(.active):hover { background: rgba(255, 255, 255, 0.3); }

main { max-width: 520px; margin: 0 auto; padding: 14px 14px 30px; }

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

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.card h3 {
  font-size: 15px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.day-head { display: flex; align-items: center; justify-content: space-between; }

.day-date { font-weight: 800; font-size: 17px; margin-bottom: 6px; }

.chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.chip-open { background: var(--primary-soft); color: var(--primary-dark); }
.chip-closed { background: #e2e8f0; color: var(--muted); }

.btn {
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  padding: 11px 16px;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost { background: #eef2f1; color: var(--text); }
.btn-ghost:hover { background: #e2e8f0; }

.btn-sm { padding: 9px 14px; font-size: 13px; }

.btn-block { width: 100%; margin-top: 10px; }

.km-row { display: flex; gap: 10px; margin-bottom: 12px; }

.km-box {
  flex: 1;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.km-box.km-total { background: var(--primary-soft); }

.km-label { display: block; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.km-value { font-weight: 800; font-size: 16px; display: block; margin-top: 3px; }
.km-muted { color: var(--muted); font-weight: 700; font-size: 16px; }

input, select {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text);
  outline: none;
}

input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15); }

.add-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.add-form input, .add-form select { flex: 1; min-width: 90px; }
.add-form .btn { flex: 0 0 auto; }

.list { list-style: none; }

.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.list li:first-child { border-top: none; }

.list .src, .list .obs { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.list .obs { color: var(--text); }

.list .empty { color: var(--muted); justify-content: center; font-style: italic; border-top: none; }

.amt { font-weight: 800; white-space: nowrap; }

.del {
  border: none;
  background: var(--danger-soft);
  color: var(--danger);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}

.summary .sum-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.sum-row strong { font-size: 16px; }
.strong { font-weight: 800; font-size: 16px; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; }
.strong:last-of-type { border-bottom: none; }

.positive { color: var(--primary-dark); }
.negative { color: var(--danger); }

/* metas */
.goal-card .goal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.goal-name { font-weight: 800; font-size: 16px; }
.goal-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

.bar {
  height: 12px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}

.bar-fill { height: 100%; background: linear-gradient(90deg, #22c55e, var(--primary)); border-radius: 999px; transition: width 0.3s; }

.goal-stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.goal-stats b { color: var(--text); }

/* historico */
.hist-day summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 700;
}

.hist-day summary::-webkit-details-marker { display: none; }
.hist-date { font-weight: 800; }
.hist-net { font-weight: 800; }

.hist-detail { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 6px; }

.hist-list { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.hist-list b { color: var(--text); }

.empty-card { text-align: center; color: var(--muted); padding: 30px 16px; }

/* modal */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 50;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px 24px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
}

.modal h3 { font-size: 17px; margin-bottom: 14px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

.rec-box {
  background: var(--primary-soft);
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  line-height: 1.5;
  color: #14532d;
  margin: 10px 0;
}

.rec-box.warn { background: var(--warn-soft); border-color: #fde68a; color: #78350f; }
.rec-box.danger { background: var(--danger-soft); border-color: #fecaca; color: #7f1d1d; }

.warn { font-size: 13px; color: var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
