/* ---------- Reset / base ------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #1c1c1e;
  background: #f4f5f7;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
input, button, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- Layout ------------------------------------------------------ */
.app-header {
  background: #1f3d5a;
  color: #fff;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.app-nav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  background: #2a4c6e;
  padding: 0.4rem 0.5rem;
  position: sticky;
  top: 2.7rem;
  z-index: 9;
}
.app-nav a {
  color: #fff;
  text-decoration: none;
  padding: 0.5rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  white-space: nowrap;
  opacity: 0.85;
}
.app-nav a.active {
  background: rgba(255,255,255,0.15);
  opacity: 1;
  font-weight: 600;
}
.app-nav .spacer { flex: 1; }
.app-nav button.logout {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 0.35rem 0.7rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

/* ---------- Cards ------------------------------------------------------- */
.card {
  background: #fff;
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #5a6573;
}
.card .meta {
  font-size: 0.8rem;
  color: #6c757d;
  margin-top: -0.25rem;
  margin-bottom: 0.75rem;
}

/* ---------- Forms ------------------------------------------------------- */
.form-row { display: flex; flex-direction: column; margin-bottom: 0.85rem; }
.form-row label {
  font-size: 0.85rem;
  color: #5a6573;
  margin-bottom: 0.35rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
input[type="text"], input[type="date"], input[type="number"],
input[type="password"], input[type="search"], input[type="file"],
textarea, select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.7rem 0.85rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: #fff;
  font-size: 1rem;
  line-height: 1.4;
  -webkit-appearance: none;        /* iOS strips the chunky native chrome */
  appearance: none;
}
input[type="file"] { padding: 0.5rem; background: #f9fafb; }
/* iOS Safari renders empty `<input type="date">` shorter than a text input
   because there's no value text. Pin min-height so it matches the others. */
input[type="date"] {
  -webkit-min-logical-width: 0;
  min-height: 2.85rem;
  display: block;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #4a86c8;
  outline-offset: 0;
  border-color: #4a86c8;
}
textarea { min-height: 4.5rem; resize: vertical; }

/* Use grid (not flex) so children honor min-width and don't push container wider */
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.row-2 > * { min-width: 0; }

/* ---------- Buttons ----------------------------------------------------- */
.btn {
  display: inline-block;
  padding: 0.85rem 1rem;
  border-radius: 0.65rem;
  border: 1px solid transparent;
  background: #4a86c8;
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary  { background: #2a6d3c; }
.btn.danger   { background: #b6342a; }
.btn.neutral  { background: #6c757d; }
.btn.outline {
  background: #fff;
  border: 1px solid #d1d5db;
  color: #1c1c1e;
}
.btn.block { display: block; width: 100%; }
.btn.small { padding: 0.4rem 0.7rem; font-size: 0.9rem; border-radius: 0.5rem; }

/* Money In / Money Out toggle */
.type-toggle { display: flex; gap: 0.5rem; }
.type-toggle button {
  flex: 1;
  padding: 1rem;
  border-radius: 0.75rem;
  border: 2px solid #d1d5db;
  background: #fff;
  color: #1c1c1e;
  font-weight: 600;
  font-size: 1.05rem;
  cursor: pointer;
}
.type-toggle button.active.in { background: #2a6d3c; color: #fff; border-color: #2a6d3c; }
.type-toggle button.active.out { background: #b6342a; color: #fff; border-color: #b6342a; }

/* Category grid */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}
.cat-grid button {
  padding: 1rem 0.75rem;
  border-radius: 0.65rem;
  border: 2px solid #d1d5db;
  background: #fff;
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  min-height: 4.2rem;
}
.cat-grid button.active {
  background: #2a4c6e;
  color: #fff;
  border-color: #2a4c6e;
}
@media (min-width: 480px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Ledger ------------------------------------------------------ */
.ledger-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.ledger-header h2 { margin: 0; }

.ledger-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }

.ledger-row {
  background: #f9fafb;
  border-radius: 0.55rem;
  padding: 0.4rem 0.6rem;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid #eef0f3;
}
.row-toggle {
  background: none;
  border: none;
  padding: 0.35rem 0;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1rem auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.row-toggle .caret { color: #8a94a0; display: inline-flex; }
.row-toggle .caret svg { transition: transform 0.15s; }
.ledger-row.expanded .row-toggle .caret svg { transform: rotate(90deg); }

.row-date {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  color: #1c1c1e;
}
.row-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.18;
  min-width: 0;
  overflow: hidden;
}
.row-meta .meta-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta .meta-line-1 { font-size: 0.85rem; color: #1c1c1e; }
.row-meta .meta-line-2 { font-size: 0.74rem; color: #6c757d; margin-top: 1px; }
.row-amt {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}
.ledger-row.in  .row-amt { color: #2a6d3c; }
.ledger-row.out .row-amt { color: #b6342a; }

.row-icons { display: flex; gap: 0.15rem; align-items: center; margin-left: 0.4rem; }
.icon-btn {
  background: none;
  border: none;
  padding: 0.45rem;
  border-radius: 0.4rem;
  color: #5a6573;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #e9eef3; color: #1c1c1e; }
.icon-btn.del-btn:hover { color: #b6342a; }

.row-detail {
  grid-column: 1 / -1;
  display: none;
  padding: 0.5rem 0 0.2rem;
  margin-top: 0.35rem;
  border-top: 1px dashed #d1d5db;
}
.ledger-row.expanded .row-detail { display: block; }
.detail-row {
  display: grid;
  grid-template-columns: 9.5rem 1fr;
  gap: 0.5rem;
  padding: 0.15rem 0;
  font-size: 0.85rem;
}
.detail-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #6c757d;
}
.detail-value { word-break: break-word; }
@media (max-width: 420px) {
  .detail-row { grid-template-columns: 8rem 1fr; }
  .row-toggle { gap: 0.35rem; }
  .ledger-row { padding: 0.4rem 0.5rem; }
}

/* ---------- Dashboard --------------------------------------------------- */
.balance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.balance-cell {
  background: #f9fafb;
  border-radius: 0.6rem;
  padding: 0.75rem;
}
.balance-cell .name {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #6c757d;
  letter-spacing: 0.4px;
}
.balance-cell .amt {
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}
.balance-cell.total {
  background: #1f3d5a;
  color: #fff;
  grid-column: 1 / -1;
}
.balance-cell.total .name { color: #cdd9e6; }
.totals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.totals-table th, .totals-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid #eef0f3;
}
.totals-table td.amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals-table tfoot td { font-weight: 600; border-top: 2px solid #d1d5db; border-bottom: none; }
.totals-table tr.in  td.amt.in-amt  { color: #2a6d3c; }
.totals-table tr.out td.amt.out-amt { color: #b6342a; }
.totals-table td.amt.in-amt  { color: #2a6d3c; }
.totals-table td.amt.out-amt { color: #b6342a; }

/* 13-month meeting-to-meeting tables */
h3.thirteen-account {
  margin: 1rem 0 0.4rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #5a6573;
  border-bottom: 1px solid #eef0f3;
  padding-bottom: 0.25rem;
}
h3.thirteen-account:first-child { margin-top: 0; }
table.thirteen-table { font-size: 0.85rem; }
table.thirteen-table td:first-child, table.thirteen-table th:first-child {
  white-space: nowrap;
}
/* Shrink any totals-style table on phones so 4-5 numeric columns still fit */
@media (max-width: 480px) {
  .totals-table { font-size: 0.78rem; }
  .totals-table th, .totals-table td { padding: 0.35rem 0.25rem; }
}

/* ---------- Settings list ---------------------------------------------- */
.setting-card {
  background: #f9fafb;
  border: 1px solid #eef0f3;
  border-radius: 0.55rem;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
}
.setting-card.archived { background: #f2f3f5; border-style: dashed; }
.setting-card.locked { background: #f7f7fa; opacity: 0.92; }

.readonly-bal {
  padding: 0.7rem 0.85rem;
  border: 1px solid transparent;
  background: #fff;
  border-radius: 0.5rem;
  font-variant-numeric: tabular-nums;
}
.readonly-bal .amt { font-weight: 600; font-size: 1rem; }
.readonly-bal .muted { display: block; font-size: 0.75rem; }

.setting-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.6rem;
}
.small-note {
  font-size: 0.75rem;
  color: #8a94a0;
  font-style: italic;
}
h3.add-heading {
  font-size: 0.9rem;
  margin: 1rem 0 0.5rem;
  color: #5a6573;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.muted code {
  background: #eef0f3;
  padding: 0.05rem 0.3rem;
  border-radius: 0.25rem;
  font-size: 0.85em;
}

/* ---------- Misc -------------------------------------------------------- */
.error-banner {
  background: #fce8e6;
  color: #8a1f17;
  border: 1px solid #f1b4ad;
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.success-banner {
  background: #e3f2e6;
  color: #1f5b30;
  border: 1px solid #b8d8c0;
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.muted { color: #6c757d; font-size: 0.85rem; }
.center { text-align: center; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Login ------------------------------------------------------- */
.login-box {
  max-width: 360px;
  margin: 4rem auto 1rem;
  background: #fff;
  padding: 1.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.login-box h1 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  text-align: center;
}

/* ---------- Saved-confirmation overlay --------------------------------- */
.checkmark-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.55);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
}
.checkmark-overlay.show { opacity: 1; }
.checkmark-overlay .check-circle {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: #2a6d3c;
  box-shadow: 0 6px 18px rgba(42, 109, 60, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0.4);
  opacity: 0;
}
.checkmark-overlay.show .check-circle {
  animation: cm-pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes cm-pop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}
.checkmark-overlay .check-circle svg { width: 58px; height: 58px; }
.checkmark-overlay .check-circle svg path {
  stroke: white;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  stroke-dasharray: 50;
  stroke-dashoffset: 50;
}
.checkmark-overlay.show .check-circle svg path {
  animation: cm-draw 0.38s 0.18s ease-out forwards;
}
@keyframes cm-draw { to { stroke-dashoffset: 0; } }

/* ---------- Modal ------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  background: #fff;
  border-radius: 0.75rem;
  padding: 1.25rem;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal.wide { max-width: 640px; }
.modal h2 { margin-top: 0; font-size: 1.1rem; }
.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
