:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f0f4f7;
  --ink: #151922;
  --muted: #667085;
  --border: #dce3ea;
  --blue: #1769e0;
  --blue-pressed: #0f55b8;
  --green: #20724d;
  --green-bg: #e9f7ef;
  --amber: #956514;
  --amber-bg: #fff5db;
  --red: #bd3f22;
  --red-bg: #fff0eb;
  --shadow: 0 10px 30px rgba(27, 39, 53, 0.08);
  --nav-height: 74px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: inherit;
  text-decoration: none;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
}

.auth-mode {
  background: #f6f8fb;
}

.auth-screen,
.loading-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 380px);
  padding: 26px 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 14px 0 24px;
  text-align: center;
  font-size: 30px;
  line-height: 1.1;
}

.app-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto;
}

.app-mark img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 14px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
}

.section-head h2,
.budget-goal-line h2,
.date-group h2,
.expense-row h3,
.budget-card h3 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(var(--nav-height) + 22px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pull-refresh {
  position: fixed;
  left: 50%;
  top: calc(-42px + env(safe-area-inset-top));
  z-index: 30;
  min-width: 132px;
  min-height: 34px;
  display: grid;
  place-items: center;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, color 140ms ease, background 140ms ease;
}

.pull-refresh.is-visible {
  opacity: 1;
}

.pull-refresh.is-ready {
  color: var(--blue);
  background: #eef5ff;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(100%, 760px);
  min-height: var(--nav-height);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.nav-item {
  min-width: 0;
  min-height: 54px;
  display: grid;
  place-items: center;
  gap: 2px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.nav-item span {
  height: 22px;
  font-size: 22px;
  line-height: 1;
}

.nav-item strong {
  font-size: 12px;
}

.nav-item.is-active {
  color: var(--blue);
  background: #eef5ff;
}

.budget-module {
  margin-bottom: 12px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-head h2 {
  font-size: 18px;
  line-height: 1.2;
}

.budget-goal-line {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.budget-goal-line h2 {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.budget-goal-line strong {
  color: var(--ink);
}

.budget-scroll {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, calc(100vw - 48px));
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  padding: 2px 2px 12px;
  scrollbar-width: none;
}

.budget-scroll::-webkit-scrollbar {
  display: none;
}

.budget-card {
  min-height: 148px;
  scroll-snap-align: start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.budget-card.skeleton {
  background:
    linear-gradient(90deg, #f1f4f7 25%, #e8edf2 37%, #f1f4f7 63%);
  background-size: 400% 100%;
  animation: shimmer 1.35s ease-in-out infinite;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.budget-card h3 {
  font-size: 16px;
}

.budget-card h3 span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.status-text {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.status-green {
  border-color: #c9e8d5;
}

.status-green .variance,
.status-green .detail {
  color: var(--green);
}

.status-green .status-text {
  color: var(--green);
}

.status-amber {
  border-color: #edd9a4;
}

.status-amber .variance,
.status-amber .detail {
  color: var(--amber);
}

.status-amber .status-text {
  color: var(--amber);
}

.status-red {
  border-color: #f0c7bb;
}

.status-red .variance,
.status-red .detail {
  color: var(--red);
}

.status-red .status-text {
  color: var(--red);
}

.status-neutral .variance,
.status-neutral .status-text,
.status-neutral .detail {
  color: var(--muted);
}

.variance {
  margin: 9px 0 3px;
  font-size: 21px;
  font-weight: 850;
  line-height: 1.15;
}

.muted,
.forecast,
.expense-row p,
.setting-row small,
.member-list p,
.center-state p {
  color: var(--muted);
}

.muted,
.detail,
.forecast {
  margin: 0;
  font-size: 13px;
}

.detail {
  margin-top: 6px;
  font-weight: 750;
}

.forecast {
  margin-top: 8px;
}

.progress-track {
  position: relative;
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #ecf0f4;
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: currentColor;
}

.progress-marker {
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 2px;
  margin-left: -1px;
  background: #111827;
}

.entry-tool,
.target-editor,
.goal-setup,
.settings-section,
.date-group,
.recent-home {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.goal-setup {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px;
  border-color: #bfd7ff;
  background: linear-gradient(180deg, #f6faff 0%, #ffffff 100%);
  box-shadow: 0 8px 22px rgba(23, 105, 224, 0.08);
}

.goal-setup h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.goal-setup-form {
  display: grid;
  gap: 10px;
}

.recent-home {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  margin-bottom: 16px;
  padding: 12px 14px;
}

.recent-home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.recent-home-head h2 {
  margin: 0;
  font-size: 15px;
}

.recent-home-head a {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.recent-home-list {
  display: grid;
  gap: 2px;
}

.recent-home-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding-top: 8px;
  border-top: 1px solid #edf1f5;
}

.recent-home-row h3 {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-home-row p,
.recent-home-empty {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.recent-home-row strong {
  font-size: 14px;
}

.entry-tool {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.amount-entry {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  min-height: 116px;
  padding: 26px 18px 18px;
  border: 2px solid rgba(23, 105, 224, 0.72);
  border-radius: 8px;
  background: linear-gradient(180deg, #f7fbff 0%, #ffffff 100%);
  box-shadow: 0 8px 22px rgba(23, 105, 224, 0.1);
}

.amount-entry:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(23, 105, 224, 0.14);
}

.amount-label {
  position: absolute;
  left: 18px;
  top: 12px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 850;
}

.amount-symbol {
  color: #6b778c;
  font-size: 34px;
  font-weight: 800;
}

.amount-entry input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 58px;
  font-weight: 850;
  line-height: 1;
  text-align: left;
}

.amount-entry input::placeholder {
  color: #c9d1da;
}

.date-control {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: center;
  gap: 8px;
}

.date-control input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  text-align: center;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  outline: 0;
}

.field input:focus,
.date-control input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.14);
}

.field.compact input {
  min-height: 44px;
}

.merchant-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.merchant-suggestions {
  display: grid;
  gap: 6px;
  margin-top: -4px;
  padding: 6px;
  border: 1px solid #cfe0f7;
  border-radius: 8px;
  background: #f7fbff;
}

.merchant-suggestions[hidden] {
  display: none;
}

.merchant-suggestion {
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  color: var(--ink);
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #dbe8f8;
  text-align: left;
}

.merchant-suggestion span {
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.merchant-suggestion small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.merchant-suggestion mark {
  padding: 0;
  color: var(--blue);
  background: transparent;
}

.merchant-strip::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  max-width: 190px;
  padding: 0 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink);
  background: #ffffff;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-action,
.secondary-action,
.text-action,
.icon-button {
  border: 0;
  cursor: pointer;
  font-weight: 800;
}

.primary-action,
.secondary-action {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 16px;
}

.primary-action {
  color: #ffffff;
  background: var(--blue);
}

.primary-action:active {
  background: var(--blue-pressed);
}

.primary-action.small {
  min-height: 42px;
}

.secondary-action {
  border: 1px solid var(--border);
  color: var(--ink);
  background: #ffffff;
}

.text-action {
  min-height: 36px;
  padding: 0 4px;
  color: var(--blue);
  background: transparent;
}

.icon-button {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--blue);
  background: #eef5ff;
  font-size: 22px;
  line-height: 1;
}

.icon-button.danger {
  width: 38px;
  height: 38px;
  color: var(--red);
  background: var(--red-bg);
}

.target-editor {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  background: #fbfcfe;
}

.action-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.history-list {
  display: grid;
  gap: 12px;
}

.date-group {
  overflow: hidden;
}

.date-group header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.date-group h2 {
  font-size: 15px;
}

.expense-rows {
  display: grid;
}

.expense-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 12px 14px;
  border-bottom: 1px solid #edf1f5;
}

.expense-row:last-child {
  border-bottom: 0;
}

.expense-row h3 {
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.2;
}

.expense-row p {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.load-more {
  width: 100%;
}

.settings-section {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 16px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 62px;
  padding-top: 10px;
  border-top: 1px solid #edf1f5;
}

.member-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.setting-row span {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.setting-row strong {
  font-size: 15px;
}

.setting-row small {
  font-size: 13px;
}

input[role="switch"] {
  width: 48px;
  height: 30px;
  flex: 0 0 auto;
  appearance: none;
  border: 1px solid #c8d1dc;
  border-radius: 999px;
  background: #dce3ea;
  position: relative;
  transition: background 160ms ease, border-color 160ms ease;
}

input[role="switch"]::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.28);
  transition: transform 160ms ease;
}

input[role="switch"]:checked {
  border-color: var(--blue);
  background: var(--blue);
}

input[role="switch"]:checked::before {
  transform: translateX(18px);
}

.member-list {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid #edf1f5;
}

.member-list p {
  margin: 0;
  overflow-wrap: anywhere;
}

.sharing-list p {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sharing-list span {
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
}

.invite-form,
.accept-invite-form {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid #edf1f5;
}

.text-action.inline {
  min-height: 0;
  margin-left: auto;
  padding: 0;
  font-size: 12px;
}

.settings-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

.danger-action {
  margin-top: 8px;
  color: var(--red);
  background: var(--red-bg);
}

.checkbox-row {
  border-top: 0;
  padding-top: 0;
}

.checkbox-row input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--blue);
}

.center-state {
  min-height: 48vh;
  display: grid;
  place-items: center;
  text-align: center;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #d7e3f2;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 14px + env(safe-area-inset-bottom));
  z-index: 50;
  width: min(calc(100% - 32px), 420px);
  transform: translateX(-50%);
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #172033;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.toast[hidden] {
  display: none;
}

body.is-offline::before {
  content: "Offline";
  position: fixed;
  left: 50%;
  top: calc(8px + env(safe-area-inset-top));
  z-index: 60;
  transform: translateX(-50%);
  padding: 5px 10px;
  border-radius: 999px;
  color: #6b3d00;
  background: #ffe6af;
  font-size: 12px;
  font-weight: 800;
}

@media (min-width: 720px) {
  body {
    background: #e9eef4;
  }

  .app-shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .screen {
    padding-left: 22px;
    padding-right: 22px;
  }

  .budget-scroll {
    grid-auto-columns: minmax(260px, 1fr);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }

  100% {
    background-position: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
