/* Money Book — mobile-first styles */
:root {
  --green: #1b7a43;
  --green-dark: #135c32;
  --green-light: #e7f4ec;
  --gold: #e8a90c;
  --gold-light: #fdf3d7;
  --red: #c0392b;
  --red-light: #fdecea;
  --ink: #1d2521;
  --muted: #6b7671;
  --line: #e3e8e5;
  --bg: #f6f8f7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(29, 37, 33, 0.08);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* ---------- top bar ---------- */
.topbar {
  background: var(--green);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  letter-spacing: 0.2px;
}
.status { display: flex; align-items: center; gap: 0.6rem; }
.net-dot {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block;
  background: #9adbb6;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.25);
}
.net-dot.offline { background: var(--gold); }
.pending-badge {
  background: var(--gold);
  color: #4a3703;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}
.lock-btn {
  background: rgba(255,255,255,0.16);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- layout ---------- */
.container { max-width: 640px; margin: 0 auto; padding: 1rem; }
.inline-form { display: inline; }
.center { text-align: center; }

.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 1.2rem 0 0.6rem;
  color: var(--ink);
}
.sub-title { font-size: 0.95rem; font-weight: 700; margin: 0 0 0.35rem; }
.help-text { color: var(--muted); font-size: 0.88rem; margin: 0.25rem 0 0.75rem; }

/* ---------- alerts / notes ---------- */
.alert {
  padding: 0.75rem 1rem;
  margin: 0.6rem 0;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 500;
}
.alert-success { background: var(--green-light); color: var(--green-dark); }
.alert-danger { background: var(--red-light); color: var(--red); }
.alert-warning { background: var(--gold-light); color: #6b5309; }
.offline-note {
  background: var(--gold-light);
  color: #6b5309;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  margin: 0.6rem 0;
}
.records-note { border-left: 4px solid var(--gold); }
.empty-note {
  color: var(--muted);
  text-align: center;
  padding: 1.4rem 1rem;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- balance ---------- */
.balance-card {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
  border-radius: 18px;
  padding: 1.4rem 1.2rem;
  margin-top: 0.4rem;
  box-shadow: 0 4px 14px rgba(19, 92, 50, 0.28);
}
.balance-label {
  font-size: 0.85rem;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.balance-amount {
  font-size: 2.2rem;
  font-weight: 800;
  margin: 0.25rem 0 0.4rem;
  word-break: break-all;
}
.balance-sub { font-size: 0.88rem; opacity: 0.95; display: flex; gap: 0.8rem; }
.balance-sub .pos { color: #c9f2da; }
.balance-sub .neg { color: #ffd9a1; }

.totals-row { display: flex; gap: 0.75rem; margin-top: 0.75rem; }
.total-card {
  flex: 1;
  background: #fff;
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--line);
}
.total-card.in { border-left-color: var(--green); }
.total-card.out { border-left-color: var(--red); }
.total-label { font-size: 0.78rem; color: var(--muted); }
.total-value { font-size: 1.15rem; font-weight: 700; margin-top: 0.15rem; }
.total-card.in .total-value { color: var(--green-dark); }
.total-card.out .total-value { color: var(--red); }

/* ---------- add form ---------- */
.add-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 0.5rem;
}
.add-section .section-title { margin-top: 0; }

.type-toggle {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.type-toggle input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.type-toggle label {
  flex: 1;
  text-align: center;
  padding: 0.85rem 0.5rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  border: 2px solid var(--line);
  color: var(--muted);
  background: #fff;
  user-select: none;
}
.type-toggle input#type-in:checked + label {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
}
.type-toggle input#type-out:checked + label {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0.7rem 0 0.3rem;
}
.input {
  width: 100%;
  padding: 0.8rem 0.9rem;
  font-size: 1rem;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
.input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(27, 122, 67, 0.15);
}
.amount-input {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.5px;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.5rem; }
.chip {
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.chip.selected {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 600;
}

.two-cols { display: flex; gap: 0.75rem; }
.two-cols > div { flex: 1; min-width: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  padding: 0.9rem 1.2rem;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  color: #fff;
  background: var(--green);
}
.btn:active { transform: scale(0.985); }
.btn-save { width: 100%; margin-top: 1rem; }
.btn-ghost {
  background: #fff;
  color: var(--green-dark);
  border: 1.5px solid var(--green);
  width: 100%;
  margin-top: 0.6rem;
}
.btn-danger { background: var(--red); width: 100%; margin-top: 0.6rem; }
.btn-small {
  width: auto;
  padding: 0.55rem 0.95rem;
  font-size: 0.88rem;
  margin-top: 0;
}
.btn[disabled] { opacity: 0.6; }

.filter-row, .export-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.filter-row .input { flex: 1; }
.export-row { flex-wrap: wrap; }

/* ---------- transaction list ---------- */
.tx-list { display: flex; flex-direction: column; gap: 0.5rem; }
.tx-row {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.8rem;
}
.tx-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; font-weight: 800;
  flex-shrink: 0;
}
.tx-icon.in { background: var(--green-light); color: var(--green-dark); }
.tx-icon.out { background: var(--red-light); color: var(--red); }
.tx-main { flex: 1; min-width: 0; }
.tx-cat { font-weight: 600; font-size: 0.95rem; }
.tx-date {
  color: var(--muted); font-size: 0.78rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-amounts { text-align: right; flex-shrink: 0; }
.tx-amount { font-weight: 700; font-size: 0.98rem; }
.tx-amount.pos { color: var(--green-dark); }
.tx-amount.neg { color: var(--red); }
.tx-balance { color: var(--muted); font-size: 0.72rem; }
.tx-actions { display: flex; flex-direction: column; gap: 0.35rem; margin-left: 0.2rem; }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}
.icon-btn.danger { color: var(--red); }

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-around;
  padding: 0.4rem 0 calc(0.4rem + env(safe-area-inset-bottom));
  z-index: 20;
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 1rem;
  border-radius: 10px;
  min-width: 72px;
}
.bottom-nav a.active { color: var(--green-dark); background: var(--green-light); }
.nav-icon { font-size: 1.25rem; line-height: 1.2; }

/* ---------- unlock screen ---------- */
.unlock-body {
  background: var(--green);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.unlock-card {
  background: #fff;
  border-radius: 20px;
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.unlock-logo {
  width: 64px; height: 64px;
  margin: 0 auto 0.7rem;
  background: var(--green);
  color: #fff;
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 800;
}
.unlock-title { margin: 0 0 0.3rem; font-size: 1.3rem; }
.pin-input {
  text-align: center;
  font-size: 1.6rem;
  letter-spacing: 0.6rem;
  margin-top: 0.5rem;
}

/* ---------- pending (offline) entries ---------- */
.tx-row.pending {
  border: 1.5px dashed var(--gold);
  background: #fffdf5;
}
.tx-row.pending .tx-balance { color: #a07908; }
.pending-chip {
  background: var(--gold-light);
  color: #6b5309;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  margin-left: 0.4rem;
  vertical-align: middle;
}
.balance-pending {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  color: #ffe9b3;
}

/* ---------- guide ---------- */
.guide-step { margin-bottom: 0.6rem; }
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  background: var(--green);
  color: #fff;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 800;
  margin-right: 0.4rem;
}
.text-in { color: var(--green-dark); }
.text-out { color: var(--red); }

/* ---------- auth + admin ---------- */
.text-link { color: var(--green-dark); font-weight: 700; }
.field-label.left { text-align: left; }
.help-text.spaced { margin-top: 1rem; }
.badge-admin {
  background: var(--gold-light);
  color: #6b5309;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  vertical-align: middle;
}
.reset-details {
  margin: -0.3rem 0 0.5rem;
  padding: 0 0.4rem;
}
.reset-details summary {
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.25rem 0;
}
.reset-form { display: flex; gap: 0.5rem; padding: 0.4rem 0 0.6rem; }
.reset-form .input { flex: 1; }
.remove-user-form { padding-bottom: 0.6rem; }
.btn-danger-outline {
  background: #fff;
  color: var(--red);
  border: 1.5px solid var(--red);
}

/* ---------- larger screens ---------- */
@media (min-width: 700px) {
  .balance-amount { font-size: 2.6rem; }
}

/* ---------- v6: review release (books, modals, filters, polish) ---------- */

/* Tappable record rows (button elements) inherit the card look. */
button.tx-row,
.tx-open-inline {
  font: inherit;
  color: inherit;
  text-align: left;
  border: 0;
  cursor: pointer;
  width: 100%;
}
button.tx-row:active { transform: scale(0.995); }
.tx-open-inline {
  background: none;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0;
  flex: 1;
  min-width: 0;
}
.tx-row .tx-main, .tx-open-inline .tx-main { display: block; }
.tx-row .tx-cat, .tx-row .tx-date { display: block; }
.tx-row .tx-amounts { display: block; }
.tx-row .tx-amount, .tx-row .tx-balance { display: block; }

/* Topbar book chip */
.book-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  max-width: 40vw;
}
.book-chip span {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-chip svg { width: 14px; height: 14px; flex: none; }

/* Bottom nav SVG icons */
.nav-icon svg { width: 22px; height: 22px; display: block; }
.bottom-nav a { color: var(--muted); }
.bottom-nav a.active { color: var(--green-dark); }

/* Custom modal */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 19, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  z-index: 60;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow: auto;
  padding: 1.1rem 1.2rem 1.2rem;
}
.modal-title { margin: 0 0 0.5rem; font-size: 1.05rem; }
.modal-body p { margin: 0.25rem 0 0; color: var(--ink); line-height: 1.5; }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.modal-actions .btn { width: auto; margin-top: 0; padding: 0.55rem 1rem; }
.tx-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid #eef2ef;
}
.tx-detail-row:last-child { border-bottom: 0; }
.tx-detail-label { color: var(--muted); font-size: 0.85rem; }
.tx-detail-value { font-weight: 600; text-align: right; word-break: break-word; }
.tx-detail-value.pos { color: var(--green-dark); }
.tx-detail-value.neg { color: var(--red); }

/* Loading state on buttons */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  animation: mb-spin 0.7s linear infinite;
}
.btn-ghost.btn-loading::after, .btn-plain.btn-loading::after {
  border-color: rgba(27, 122, 67, 0.3);
  border-top-color: var(--green);
}
@keyframes mb-spin { to { transform: rotate(360deg); } }

/* Inline field error + textarea */
.field-error {
  color: var(--red);
  font-size: 0.8rem;
  margin: 0.25rem 0 0;
}
textarea.input.notes-input {
  resize: vertical;
  min-height: 2.7rem;
  font: inherit;
}
select.input { appearance: auto; }

/* Privacy agreement row */
.agree-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin: 0.9rem 0 0.2rem;
  font-size: 0.86rem;
  text-align: left;
  color: var(--ink);
}
.agree-row input { margin-top: 0.2rem; width: 1.05rem; height: 1.05rem; }

/* Records filter panel */
.filter-panel {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.8rem;
  margin-bottom: 0.9rem;
}
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.filter-range { display: flex; gap: 0.6rem; grid-column: 1 / -1; }
.filter-range > div { flex: 1; }
.filter-actions { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.filter-panel .field-label { margin-top: 0; }

/* Books list in Settings */
.book-list { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.5rem 0; }
.book-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  border: 1.5px solid #e3eae5;
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
}
.book-row.active { border-color: var(--green); background: var(--green-light); }
.book-name { font-weight: 700; font-size: 0.95rem; }
.book-active-tag {
  background: var(--green);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  margin-left: 0.4rem;
}
.book-cur { color: var(--muted); font-size: 0.8rem; }
.book-row .btn { width: auto; margin-top: 0; }
.settings-details { margin-top: 0.6rem; }
.settings-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--green-dark);
  padding: 0.3rem 0;
}

/* All devices: comfortable layouts beyond phones */
@media (min-width: 700px) {
  .container { max-width: 640px; }
  .topbar-inner, .bottom-nav { max-width: 640px; margin: 0 auto; }
  .filter-grid { grid-template-columns: 1fr 1fr 1fr; }
  .filter-range { grid-column: auto; }
}
@media (min-width: 1024px) {
  .container { max-width: 720px; }
  .topbar-inner, .bottom-nav { max-width: 720px; margin: 0 auto; }
}

/* Final Daily Balance mark (four strokes + gold slash) */
.brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.brand-mark { width: 26px; height: 26px; display: block; flex: none; }
.unlock-mark { width: 78px; height: 78px; margin: 0 auto 0.7rem; }
.unlock-mark svg { width: 100%; height: 100%; display: block; }
