* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f5f6f8;
  color: #1c2330;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 0;
}

h1 { margin: 0; font-size: 1.5rem; }
.status { margin: 0 16px 0 auto; font-size: 0.875rem; color: #5b6575; }
.status.error { color: #c62828; }
h2 { margin: 0 0 8px; font-size: 1.1rem; }

#summary {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 24px;
  background: #f5f6f8;
  border-bottom: 1px solid #dde1e8;
}

.stat {
  flex: 1 1 140px;
  background: #fff;
  border: 1px solid #dde1e8;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
}

.stat .label { font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }

#remaining-stat.under .value { color: #1a7f4b; }
#remaining-stat.over { background: #fdecec; border-color: #e5484d; }
#remaining-stat.over .value, #remaining-stat.over .label { color: #c62828; }

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 20px 24px 40px;
  align-items: start;
}

main section {
  background: #fff;
  border: 1px solid #dde1e8;
  border-radius: 8px;
  padding: 16px;
}

main section.wide { grid-column: 1 / -1; }

.hint { margin: 0 0 8px; color: #5b6575; font-size: 0.875rem; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; padding: 4px 6px; }
td { padding: 3px 4px; }
th.num, td.num { text-align: right; }
tfoot td { font-weight: 600; padding: 8px 6px; border-top: 2px solid #dde1e8; font-variant-numeric: tabular-nums; }

input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccd2dc;
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccd2dc;
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
select:focus { outline: 2px solid #3b82f6; outline-offset: -1px; }

.breakdown { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; }
.chart { flex: 0 0 260px; width: 260px; height: 260px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart path.segment { transition: opacity 0.15s ease; }
.chart path.segment:hover { opacity: 0.85; }
.chart .center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.chart .center .label { font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; }
.chart .center .value { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { flex: 1 1 320px; }
.legend td { padding: 5px 6px; font-variant-numeric: tabular-nums; }
.legend tbody tr + tr td { border-top: 1px solid #eef0f4; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }

input.amount { text-align: right; font-variant-numeric: tabular-nums; }
input:focus { outline: 2px solid #3b82f6; outline-offset: -1px; }

button {
  font: inherit;
  cursor: pointer;
}
button.add {
  margin-top: 8px;
  padding: 6px 12px;
  border: 1px dashed #98a2b3;
  background: transparent;
  border-radius: 6px;
  color: #344054;
}
button.add:hover { background: #f0f2f5; }
button.remove {
  border: none;
  background: transparent;
  color: #98a2b3;
  font-size: 1.1rem;
  padding: 2px 8px;
}
button.remove:hover { color: #c62828; }
button.link { border: none; background: none; color: #3b82f6; text-decoration: underline; }

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
}

/* ---- Phone pages (spend.html, history.html) ------------------------------ */

.phone [hidden] { display: none !important; }

body.phone {
  max-width: 560px;
  margin: 0 auto;
  font-size: 16px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
body.phone.sheet-open { overflow: hidden; }

.phone .phone-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 4px;
}
.phone .phone-header h1 { font-size: 1.35rem; }
.phone .phone-link {
  color: #3b82f6;
  text-decoration: none;
  padding: 10px 0 10px 16px;
}

.phone .sync-status {
  margin: 0;
  padding: 0 16px 8px;
  min-height: 1.4em;
  font-size: 0.8rem;
  color: #5b6575;
}
.phone .sync-status.warn { color: #b45309; }

.phone main.phone-main {
  display: block;
  padding: 0 16px 24px;
}
.phone main.phone-main section {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}

.phone .total-card {
  display: flex;
  flex-direction: column;
  background: #fff !important;
  border: 1px solid #dde1e8 !important;
  border-radius: 14px !important;
  padding: 14px 16px !important;
  margin-bottom: 14px;
}
.phone .total-card .label { font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; }
.phone .total-card .big { font-size: 2.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; color: #1a7f4b; }
.phone .total-card .sub { font-size: 0.85rem; color: #5b6575; }
.phone .total-card.over { background: #fdecec !important; border-color: #e5484d !important; }
.phone .total-card.over .big, .phone .total-card.over .label { color: #c62828; }

.phone .cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}
.phone button.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 120px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #dde1e8;
  border-radius: 14px;
  text-align: left;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.phone button.card:active { background: #eef2f8; }
.phone .card-name { font-weight: 600; font-size: 0.95rem; overflow-wrap: anywhere; }
.phone .card-left { font-size: 1.7rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; color: #1a7f4b; }
.phone .card-note { font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; }
.phone .card-sub { margin-top: auto; font-size: 0.78rem; color: #5b6575; font-variant-numeric: tabular-nums; }
.phone .bar { display: block; width: 100%; height: 6px; margin-top: 8px; background: #e8ebf0; border-radius: 3px; overflow: hidden; }
.phone .bar-fill { display: block; height: 100%; background: #1a7f4b; border-radius: 3px; }
.phone button.card.over { background: #fdecec; border-color: #e5484d; }
.phone button.card.over .card-left, .phone button.card.over .card-note { color: #c62828; }
.phone button.card.over .bar-fill { background: #c62828; }

.phone h2 { font-size: 1rem; margin: 0 0 8px; }
.phone .empty { color: #5b6575; font-size: 0.9rem; margin: 8px 0 16px; }

.phone .recent { list-style: none; margin: 0; padding: 0; background: #fff; border: 1px solid #dde1e8; border-radius: 14px; overflow: hidden; }
.phone .recent li + li { border-top: 1px solid #eef0f4; }
.phone button.recent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  text-align: left;
  color: inherit;
}
.phone button.recent-row:active { background: #eef2f8; }
.phone .recent-main { display: flex; flex-direction: column; min-width: 0; }
.phone .recent-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone .recent-meta { font-size: 0.78rem; color: #5b6575; }
.phone .recent-flag { font-size: 0.75rem; color: #b45309; }
.phone .recent-flag.error { color: #c62828; }
.phone .recent-amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.phone .tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  background: #fff;
  border-top: 1px solid #dde1e8;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.phone .tabbar a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  color: #5b6575;
  text-decoration: none;
  font-weight: 500;
}
.phone .tabbar a[aria-current="page"] { color: #3b82f6; box-shadow: inset 0 3px 0 #3b82f6; }

.phone .backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 20; }
.phone .sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: 92vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.2);
}
.phone .sheet h2 { font-size: 1.1rem; margin-bottom: 10px; }
.phone .field { display: block; margin-bottom: 12px; }
.phone .field > span { display: block; font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.phone .field input, .phone .field select {
  min-height: 48px;
  padding: 10px 12px;
  font-size: 16px;
  border-radius: 10px;
}
.phone .amount-field input { font-size: 2rem; font-weight: 700; text-align: left; font-variant-numeric: tabular-nums; }
.phone .form-error { color: #c62828; margin: 0 0 10px; font-size: 0.9rem; }
.phone .sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.phone .sheet-actions button {
  flex: 1 1 40%;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid #ccd2dc;
  background: #fff;
  font-weight: 600;
  color: #344054;
}
.phone .sheet-actions button.primary { background: #3b82f6; border-color: #3b82f6; color: #fff; flex-basis: 100%; }
.phone .sheet-actions button.danger { color: #c62828; border-color: #e5484d; }

/* Planner header link to the phone pages. */
.page-links { display: flex; gap: 12px; margin: 0 16px; }
.page-links a { color: #3b82f6; }

.phone .months { display: flex; flex-direction: column; gap: 10px; }
.phone details.month { background: #fff; border: 1px solid #dde1e8; border-radius: 14px; padding: 0 14px; }
.phone .month-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}
.phone .month-summary::-webkit-details-marker { display: none; }
.phone .month-summary::after { content: "\203a"; color: #98a2b3; font-size: 1.4rem; margin-left: 4px; transition: transform 0.15s ease; }
.phone details[open] > .month-summary::after { transform: rotate(90deg); }
.phone .month-name { flex: 1; }
.phone .month-total { font-variant-numeric: tabular-nums; }
.phone details.month h3 { margin: 8px 0 4px; font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; }
.phone .history-list { list-style: none; margin: 0 0 10px; padding: 0; }
.phone .history-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.phone .history-row + .history-row { border-top: 1px solid #eef0f4; }
.phone .history-left { display: flex; flex-direction: column; min-width: 0; }
.phone .history-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone .history-right { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* Log out button in the planner and phone headers. */
header .logout { margin-left: 16px; }
.phone .header-links { display: flex; align-items: baseline; }
.phone button.phone-link {
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
}

/* ---- Login page ---------------------------------------------------------- */

body.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  display: block;
  width: 100%;
  max-width: 360px;
  background: #fff;
  border: 1px solid #dde1e8;
  border-radius: 14px;
  padding: 24px 20px;
}
.login-card h1 { margin-bottom: 16px; }
.login-field { display: block; margin-bottom: 12px; }
.login-field > span { display: block; font-size: 0.75rem; color: #5b6575; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.login-field input { min-height: 48px; padding: 10px 12px; font-size: 16px; border-radius: 10px; }
.login-error { color: #c62828; margin: 0 0 12px; font-size: 0.9rem; }
.login-error[hidden] { display: none; }
.login-submit {
  width: 100%;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid #3b82f6;
  background: #3b82f6;
  color: #fff;
  font-weight: 600;
}
.login-submit:disabled { opacity: 0.6; cursor: default; }
