:root {
  color-scheme: light;
  --bg: #f7fbf8;
  --surface: #ffffff;
  --ink: #14231d;
  --muted: #34473d;
  --line: #d9e5de;
  --brand: #073f31;
  --brand-2: #0b5a45;
  --mint: #dff8e7;
  --warn: #8a5a00;
  --warn-bg: #fff5cc;
  --danger: #a62920;
  --danger-bg: #fde7e4;
  --shadow: 0 16px 40px rgba(7, 63, 49, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  overflow-x: clip;
}

body {
  margin: 0;
  min-width: 280px;
  padding-bottom: calc(5.4rem + env(safe-area-inset-bottom));
  overflow-x: clip;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
  max-width: 100%;
}

button {
  min-height: 44px;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid #0b5a45;
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 0.5rem;
  transform: translateY(-160%);
  z-index: 5;
  background: var(--brand);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: rgba(247, 251, 248, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 760;
  font-size: 1.2rem;
  color: var(--brand);
  min-width: 0;
}

.brand img {
  flex: 0 0 auto;
  border-radius: 0.45rem;
}

.brand span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  min-width: 0;
}

.user-label {
  max-width: 34vw;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 680;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell {
  width: min(100%, 1024px);
  margin: 0 auto;
  padding: clamp(0.65rem, 3.8vw, 1.25rem);
}

.auth-shell {
  width: min(100%, 480px);
  margin: 0 auto;
  padding: clamp(0.85rem, 4vw, 1.25rem);
}

section,
dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

section {
  border-radius: 0.5rem;
  padding: clamp(0.8rem, 4vw, 1rem);
  min-width: 0;
}

.app-panel[hidden] {
  display: none;
}

.app-panel {
  min-height: calc(100svh - 9rem);
}

h1,
h2,
h3,
p {
  margin-top: 0;
  overflow-wrap: anywhere;
}

h1 {
  margin-bottom: 0.2rem;
  font-size: clamp(1.6rem, 7vw, 2.5rem);
  line-height: 1.2;
}

h2 {
  margin-bottom: 0.75rem;
  font-size: 1.12rem;
}

h3 {
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.muted,
.eyebrow {
  color: var(--muted);
}

.eyebrow {
  margin-bottom: 0.2rem;
  font-size: 0.78rem;
  font-weight: 750;
}

.week-nav,
.section-title,
.form-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.week-nav > div,
.section-title > * {
  min-width: 0;
}

.form-actions,
.dialog-actions {
  flex-wrap: wrap;
}

.icon-button,
.text-button,
.secondary-button,
.primary-button,
.danger-button {
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  padding: 0.65rem 0.9rem;
  font-weight: 720;
  background: #fff;
  color: var(--brand);
  max-width: 100%;
  white-space: normal;
}

.icon-button {
  min-width: 44px;
  font-size: 1.4rem;
  line-height: 1;
}

.primary-button,
.secondary-button {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.secondary-button {
  background: var(--brand-2);
}

.danger-button {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.budget-box {
  margin-top: 1rem;
}

.electricity-alert {
  margin-top: 1rem;
  padding: 0.85rem;
  border: 1px solid #e5c75b;
  border-radius: 0.5rem;
  background: var(--warn-bg);
  color: var(--warn);
}

.electricity-alert h2 {
  margin-bottom: 0.35rem;
}

.electricity-alert p {
  margin-bottom: 0;
  font-weight: 680;
}

.status-pill {
  display: inline-flex;
  max-width: 100%;
  min-height: 32px;
  align-items: center;
  margin-bottom: 0.75rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  font-weight: 760;
  background: var(--mint);
  color: var(--brand);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.status-pill.warning {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: #e5c75b;
}

.status-pill.over {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #efaaa3;
}

.meter {
  height: 1rem;
  overflow: hidden;
  border-radius: 999px;
  background: #e8f0ec;
  border: 1px solid var(--line);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--brand-2);
}

.budget-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0.9rem 0 0;
}

.budget-grid div {
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

dt {
  color: var(--muted);
  font-size: 0.8rem;
}

dd {
  margin: 0.2rem 0 0;
  overflow-wrap: anywhere;
  font-weight: 800;
  line-height: 1.5;
}

.field,
.field-row {
  display: grid;
  gap: 0.45rem;
}

.auth-form {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.settings-form {
  display: grid;
  gap: 0.55rem;
}

.invite-form {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.auth-form[hidden] {
  display: none;
}

.check-field {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
}

.check-field input {
  width: 1.2rem;
  min-height: 1.2rem;
}

.entry-form-block {
  margin: 0.85rem 0 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.entry-progress-card {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #f7fbf8;
}

.entry-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.entry-progress-header h3,
.entry-progress-card p {
  margin-bottom: 0;
}

.entry-progress-header span {
  flex: 0 0 auto;
  font-weight: 820;
  color: var(--brand);
}

.entry-progress-meter {
  height: 0.85rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e8f0ec;
}

.entry-progress-meter span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--brand-2);
}

.entry-progress-meter.over span {
  background: var(--danger);
}

.entry-budget-preview {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.55rem;
  padding: 0.62rem 0.7rem;
  border: 1px solid #b9d8c9;
  border-radius: 0.5rem;
  background: var(--mint);
  color: var(--brand);
  font-weight: 720;
  line-height: 1.25;
}

.entry-budget-preview[hidden] {
  display: none;
}

.entry-budget-preview.over {
  border-color: #efaaa3;
  background: var(--danger-bg);
  color: var(--danger);
}

.entry-budget-face {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: #fff;
  font-size: 1.2rem;
}

.field-row {
  grid-template-columns: 1fr;
}

label {
  font-weight: 720;
  overflow-wrap: anywhere;
}

input,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid #b8c9c0;
  border-radius: 0.5rem;
  padding: 0.7rem 0.75rem;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.field-help {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.field-error {
  min-height: 1.2rem;
  margin-bottom: 0.45rem;
  color: var(--danger);
  font-weight: 650;
}

.entry-card {
  display: grid;
  gap: 0.65rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}

.entry-card:first-child {
  border-top: 0;
}

.entry-main {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.entry-main > div {
  min-width: 0;
}

.entry-store {
  margin: 0 0 0.15rem;
  font-weight: 820;
}

.entry-amount {
  flex: 0 1 auto;
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
  font-weight: 860;
}

.entry-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  padding: 0.55rem clamp(0.35rem, 2vw, 0.75rem) calc(0.55rem + env(safe-area-inset-bottom));
  background: rgba(247, 251, 248, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.bottom-nav-inner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(0.12rem, 1.2vw, 0.35rem);
  width: min(100%, 680px);
  margin: 0 auto;
}

.nav-tab {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.16rem;
  min-width: 0;
  min-height: 52px;
  padding: 0.28rem 0.2rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.nav-tab span[aria-hidden="true"] {
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 860;
  line-height: 1;
}

.nav-tab[aria-selected="true"] {
  border-color: #b9d8c9;
  background: var(--mint);
  color: var(--brand);
}

.nav-tab[aria-selected="true"] span[aria-hidden="true"] {
  background: var(--brand);
  color: #fff;
}

.stats-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.stat-card,
.chart-row {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.75rem;
}

.chart-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chart-label {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 720;
  min-width: 0;
}

.chart-label span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chart-label span:last-child {
  flex: 0 1 auto;
  text-align: right;
}

.chart-bar {
  margin-top: 0.45rem;
  height: 0.7rem;
  border-radius: 999px;
  background: #e8f0ec;
  overflow: hidden;
}

.chart-bar span {
  display: block;
  height: 100%;
  background: var(--brand-2);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  table-layout: fixed;
}

caption {
  text-align: left;
  color: var(--muted);
  padding-bottom: 0.4rem;
}

th,
td {
  padding: 0.65rem 0.45rem;
  border-top: 1px solid var(--line);
  text-align: left;
  overflow-wrap: anywhere;
}

dialog {
  width: min(calc(100% - 2rem), 420px);
  border-radius: 0.5rem;
  padding: 1rem;
  max-width: calc(100% - 2rem);
}

dialog::backdrop {
  background: rgba(20, 35, 29, 0.38);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (min-width: 720px) {
  .shell {
    padding-top: 1.25rem;
  }

  .field-row,
  .stats-summary {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 900px) {
  body {
    padding-bottom: 0;
  }

  .app-header {
    position: fixed;
    right: 0;
    left: 0;
  }

  .shell {
    width: min(100% - 17rem, 880px);
    margin: 0 0 0 16rem;
    padding-top: 6rem;
    padding-bottom: 3rem;
  }

  .auth-shell {
    padding-top: 6rem;
  }

  .app-panel {
    min-height: calc(100svh - 9rem);
  }

  .bottom-nav {
    top: 4.15rem;
    right: auto;
    bottom: 0;
    width: 14rem;
    padding: 1rem;
    border-top: 0;
    border-right: 1px solid var(--line);
    background: rgba(247, 251, 248, 0.98);
  }

  .bottom-nav-inner {
    display: flex;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .nav-tab {
    grid-template-columns: 1.6rem 1fr;
    justify-items: start;
    align-content: center;
    min-height: 48px;
    padding: 0.45rem 0.65rem;
    text-align: left;
    font-size: 0.92rem;
  }
}

@media (min-width: 1200px) {
  .shell {
    margin-left: calc(50vw - 340px);
  }
}

@media (max-width: 359px) {
  .app-header {
    padding: 0.72rem 0.65rem;
  }

  .brand {
    font-size: 1.05rem;
  }

  .brand img {
    width: 30px;
    height: 30px;
  }

  .budget-grid {
    grid-template-columns: 1fr;
  }

  .nav-tab {
    font-size: 0.68rem;
  }

  .nav-tab span[aria-hidden="true"] {
    width: 1.18rem;
    height: 1.18rem;
    font-size: 0.7rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .meter span,
  .entry-progress-meter span,
  .chart-bar span {
    transition: width 180ms ease;
  }
}

@media (forced-colors: active) {
  .meter span,
  .entry-progress-meter span,
  .chart-bar span {
    background: CanvasText;
  }
}
