:root {
  --brand: #1b6f5c;
  --brand-dark: #12503f;
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1f2523;
  --muted: #6b7570;
  --border: #e2e5e1;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* PIN screen */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.pin-card {
  background: var(--card);
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}
.pin-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.pin-card p { color: var(--muted); margin: 0 0 16px; }
.pin-card input {
  width: 100%;
  padding: 14px;
  font-size: 1.2rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  letter-spacing: 4px;
}
.pin-card button {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: white;
  font-weight: 600;
}
.error { color: var(--danger); font-size: 0.9rem; }

/* App shell */
header {
  padding: 16px 20px 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0 0 12px; font-size: 1.3rem; }
nav { display: flex; gap: 4px; }
.tab {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.view { padding: 16px; max-width: 560px; margin: 0 auto; }

/* Log view */
#logForm { display: flex; gap: 8px; }
#logInput {
  flex: 1;
  padding: 16px;
  font-size: 1.1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
}
#logForm button {
  padding: 0 20px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--brand);
  color: white;
}
.status { min-height: 1.2em; color: var(--muted); margin: 10px 2px; }

.entry-list { list-style: none; padding: 0; margin: 8px 0; }
.entry-list li {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.entry-desc { font-weight: 600; }
.entry-date { font-size: 0.8rem; color: var(--muted); }
.entry-right { display: flex; align-items: center; gap: 10px; }
.entry-amount { font-weight: 700; }
.chip {
  border: none;
  background: #eef3f1;
  color: var(--brand-dark);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Summary view */
.month-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 8px;
}
.month-row button {
  border: none;
  background: var(--card);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
}
#monthLabel { font-weight: 700; font-size: 1.05rem; min-width: 140px; text-align: center; }
.grand-total { text-align: center; color: var(--muted); margin: 4px 0 16px; font-size: 1.1rem; }
.grand-total strong { color: var(--text); }

.category-list { list-style: none; padding: 0; margin: 0; }
.category-item {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
}
.category-head { display: flex; justify-content: space-between; align-items: center; }
.category-name { font-weight: 600; }
.category-total { font-weight: 700; }
.category-entries {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: none;
}
.category-item.open .category-entries { display: block; }
.category-entries .sub-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--muted);
  padding: 4px 0;
}

/* Category picker bottom sheet */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.sheet-inner {
  background: var(--card);
  width: 100%;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
}
.sheet-inner h2 { margin: 0 0 12px; font-size: 1.1rem; }
.category-options { list-style: none; padding: 0; margin: 0 0 12px; }
.category-options li button {
  width: 100%;
  text-align: left;
  padding: 12px;
  border: none;
  background: var(--bg);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 0.95rem;
}
.secondary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
