:root {
  color-scheme: light;
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --text: #1D1D1F;
  --secondary: #6E6E73;
  --accent: #007AFF;
  --success: #34C759;
  --warning: #FF9500;
  --danger: #FF3B30;
  --border: #E5E5EA;
  --shadow: 0 10px 28px rgba(29, 29, 31, 0.08);
  --soft-shadow: 0 4px 16px rgba(29, 29, 31, 0.06);
  --radius: 8px;
  --nav-height: 78px;
  font-family: "Helvetica Neue", "Tiro Bangla", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  overflow-x: hidden;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", "Tiro Bangla", Helvetica, Arial, sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

noscript {
  display: block;
  margin: 24px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.app-frame {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px calc(var(--nav-height) + 26px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 14px;
}

.app-header h1 {
  margin: 3px 0 0;
  font-size: 1.9rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--secondary);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.month-chip,
.count-pill {
  flex: 0 0 auto;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 700;
}

.screen {
  display: grid;
  gap: 14px;
}

.dashboard-hero,
.summary-card,
.stat-card,
.category-card,
.soft-card,
.accordion-card,
.form-card,
.grocery-card,
.settings-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--soft-shadow);
}

.dashboard-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 18px;
}

.hero-copy h2 {
  margin: 5px 0 6px;
  font-size: 1.65rem;
  line-height: 1.06;
  letter-spacing: 0;
}

.hero-copy p:last-child {
  margin: 0;
  color: var(--secondary);
  line-height: 1.35;
}

.hero-total {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

.hero-total span {
  color: var(--secondary);
  font-size: 0.88rem;
  font-weight: 700;
}

.hero-total strong {
  font-size: 2.2rem;
  line-height: 1;
  letter-spacing: 0;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 24px 18px;
  border: 1px dashed #C7C7CC;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
  text-align: center;
}

.empty-state h2 {
  margin: 2px 0 0;
  font-size: 1.2rem;
}

.empty-state p {
  margin: 0 0 8px;
  color: var(--secondary);
}

.empty-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.1);
  color: var(--accent);
}

.primary-summary {
  padding: 16px;
  box-shadow: var(--shadow);
}

.summary-topline,
.card-title-row,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.summary-topline h3 {
  margin: 4px 0 0;
  font-size: 2.05rem;
  line-height: 1;
  letter-spacing: 0;
}

.status-badge,
.status-dot {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
}

.status-badge.safe,
.status-dot.purchased {
  background: rgba(52, 199, 89, 0.12);
  color: #1F8B3A;
}

.status-badge.moderate {
  background: rgba(0, 122, 255, 0.12);
  color: var(--accent);
}

.status-dot.in-cart {
  background: rgba(0, 122, 255, 0.12);
  color: #0066CC;
}

.status-badge.warning,
.status-dot.pending {
  background: rgba(255, 149, 0, 0.14);
  color: #B46100;
}

.status-badge.over {
  background: rgba(255, 59, 48, 0.12);
  color: #C5221F;
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0 7px;
  color: var(--secondary);
  font-size: 0.82rem;
  font-weight: 700;
}

.progress-copy span {
  min-width: 0;
}

.progress-copy span:last-child {
  text-align: right;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #EFEFF4;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--success);
  transition: width 220ms ease;
}

.progress-fill.moderate {
  background: var(--accent);
}

.progress-fill.warning {
  background: var(--warning);
}

.progress-fill.over {
  background: var(--danger);
}

.metric-grid,
.history-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric-grid {
  margin-top: 12px;
}

.metric-tile,
.stat-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #FBFBFD;
}

.metric-tile span,
.stat-card span {
  display: block;
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
}

.metric-tile strong,
.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.05rem;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.metric-tile.success strong {
  color: #1F8B3A;
}

.metric-tile.warning strong {
  color: #B46100;
}

.metric-tile.danger strong {
  color: var(--danger);
}

.stat-card {
  min-height: 88px;
  padding: 10px 7px;
}

.stat-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.1);
  color: var(--accent);
}

.stat-card.stat-pending {
  border-color: rgba(255, 149, 0, 0.28);
  background: #FEF3C7;
}

.stat-card.stat-pending .stat-icon {
  color: #B46100;
  background: rgba(255, 255, 255, 0.48);
}

.stat-card.stat-pending span {
  color: #B46100;
}

.stat-card.stat-in-cart {
  border-color: rgba(0, 122, 255, 0.24);
  background: #DBEAFE;
}

.stat-card.stat-in-cart .stat-icon {
  color: #075985;
  background: rgba(255, 255, 255, 0.5);
}

.stat-card.stat-in-cart span {
  color: #075985;
}

.stat-card.stat-purchased {
  border-color: rgba(52, 199, 89, 0.24);
  background: #DCFCE7;
}

.stat-card.stat-purchased .stat-icon {
  color: #1F6B35;
  background: rgba(255, 255, 255, 0.5);
}

.stat-card.stat-purchased span {
  color: #1F6B35;
}

.quick-stats .stat-card span,
.quick-stats .stat-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-stats .stat-card span {
  font-size: 0.82rem;
}

.quick-stats .stat-card strong {
  font-size: 0.95rem;
  overflow-wrap: normal;
}

.section-block {
  display: grid;
  gap: 10px;
}

.section-heading h2 {
  margin: 3px 0 0;
  font-size: 1.18rem;
  line-height: 1.16;
  letter-spacing: 0;
}

.category-grid,
.entry-list,
.accordion-list,
.settings-list {
  display: grid;
  gap: 10px;
}

.settings-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
  padding: 4px 2px 0;
  color: var(--primary);
}

.settings-list-head strong {
  font-size: 0.94rem;
  line-height: 1.2;
}

.settings-list-head span {
  min-width: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--secondary);
  background: var(--control-bg);
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
}

.category-card,
.grocery-card,
.settings-row {
  padding: 14px;
}

.category-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.category-title > div {
  min-width: 0;
}

.category-title h3,
.grocery-card h3,
.settings-row h3 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.item-name-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.repeat-label {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #EAF2FF;
  color: var(--accent);
  font-size: 0.66rem;
  font-style: normal;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.category-title p,
.grocery-card p,
.settings-row p {
  margin: 3px 0 0;
  color: var(--secondary);
  font-size: 0.8rem;
  line-height: 1.35;
}

.category-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #F2F2F7;
  color: var(--accent);
}

.category-card > .card-title-row > strong {
  flex: 0 0 auto;
  font-size: 1.02rem;
}

.card-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  color: var(--secondary);
  font-size: 0.79rem;
}

.card-facts b {
  color: var(--text);
}

.soft-card,
.empty-mini {
  padding: 15px;
  color: var(--secondary);
}

.empty-mini {
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.35;
}

.grocery-card.compact {
  padding: 12px;
}

.grocery-card.pending {
  border-color: rgba(255, 149, 0, 0.28);
  background: rgba(255, 249, 235, 0.96);
}

.grocery-card.in-cart {
  border-color: rgba(0, 122, 255, 0.24);
  background: rgba(235, 245, 255, 0.96);
}

.grocery-card.purchased {
  border-color: rgba(52, 199, 89, 0.24);
  background: rgba(239, 250, 242, 0.96);
}

.price-stack {
  flex: 0 0 auto;
  display: grid;
  justify-items: end;
  gap: 5px;
}

.price-stack strong {
  white-space: nowrap;
}

.item-actions,
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.accordion-card {
  overflow: hidden;
}

.accordion-button {
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 0;
  background: var(--card);
  color: var(--text);
  text-align: left;
}

.accordion-button small {
  display: block;
  margin-top: 3px;
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 600;
}

.accordion-content {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

.history-categories {
  display: grid;
  gap: 8px;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--secondary);
  font-size: 0.86rem;
}

.history-row strong {
  color: var(--text);
  white-space: nowrap;
}

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

.add-month-card {
  gap: 10px;
}

.month-select-field {
  display: grid;
  gap: 6px;
  color: var(--secondary);
  font-size: 0.82rem;
  font-weight: 700;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.compact-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.detailed-form {
  grid-template-columns: 0.72fr 0.8fr 1.24fr 1.24fr;
  gap: 10px;
  align-items: end;
}

.detailed-form .field-category,
.detailed-form .field-item {
  grid-column: span 2;
}

.detailed-form .field-unit,
.detailed-form .field-unit-type,
.detailed-form .field-unit-price,
.detailed-form .field-total {
  min-width: 0;
  align-self: stretch;
}

.detailed-form .segmented-field,
.detailed-form button.full-width,
.compact-form button.full-width {
  grid-column: 1 / -1;
}

.quick-form .quick-name,
.quick-form .quick-price,
.quick-form .quick-category,
.quick-form .quick-status,
.budget-form .budget-month-field,
.budget-form .budget-total-field,
.category-form .category-name-field,
.category-form .category-icon-field,
.item-form .item-name-field,
.item-form .item-category-field,
.item-form .item-unit-field,
.item-form .item-price-field {
  grid-column: span 2;
  min-width: 0;
}

.form-grid label,
.field-total,
.segmented-wrapper,
.inline-form label {
  display: grid;
  gap: 6px;
  color: var(--secondary);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FFFFFF;
  color: var(--text);
  padding: 0 12px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.compact-form input,
.compact-form select {
  min-height: 44px;
  padding: 0 8px;
  font-size: 0.95rem;
  text-overflow: ellipsis;
}

.compact-form label {
  min-width: 0;
}

.compact-form label > span,
.compact-form .segmented-wrapper > span,
.detailed-form .field-total > span {
  min-height: 1.9em;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  column-gap: 0.2em;
  font-size: 0.74rem;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.detailed-form label > span em {
  color: #A1A1A6;
  font-style: normal;
  font-weight: 500;
}

.compact-form .segmented-field {
  min-width: 0;
  align-self: end;
}

.compact-form .segmented-field label > span {
  min-height: 38px;
}

input:focus,
select:focus {
  border-color: rgba(0, 122, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.12);
}

.total-preview {
  display: grid;
  gap: 4px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #FBFBFD;
}

.detailed-form .total-preview {
  min-height: 44px;
  align-content: center;
  gap: 0;
  padding: 0 8px;
  overflow: hidden;
}

.total-preview span,
.total-preview small {
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 700;
}

.total-preview strong {
  font-size: 1.45rem;
  line-height: 1.05;
}

.detailed-form .total-preview strong {
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detailed-form .total-preview small {
  display: none;
}

.segmented-field {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #F2F2F7;
}

.status-flow-field {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented-field legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.segmented-field label {
  position: relative;
  display: block;
  border-radius: 7px;
  color: var(--secondary);
  font-size: 0.9rem;
  font-weight: 800;
}

.segmented-field input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  opacity: 0;
}

.segmented-field label > span {
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  pointer-events: none;
}

.status-flow-field label > span {
  min-height: 54px;
  font-size: 1.68rem;
}

.status-flow-field .icon {
  width: 1.2em;
  height: 1.2em;
}

.segmented-field input:checked + span {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 5px rgba(29, 29, 31, 0.12);
}

.primary-button,
.secondary-button,
.text-action,
.icon-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: 0;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.primary-button {
  padding: 0 16px;
  background: var(--accent);
  color: white;
  box-shadow: 0 10px 22px rgba(0, 122, 255, 0.22);
}

.secondary-button {
  padding: 0 16px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--accent);
}

.text-action {
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text);
  font-size: 0.84rem;
}

.text-action.success {
  color: #1F8B3A;
}

.text-action.cart {
  color: var(--accent);
}

.text-action.warning {
  color: #B46100;
}

.icon-button {
  width: 48px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text);
}

.icon-button.subtle {
  width: 42px;
  min-height: 42px;
  background: #F9F9FB;
  color: var(--secondary);
}

.icon-button.danger {
  color: var(--danger);
}

.primary-button:active,
.secondary-button:active,
.text-action:active,
.icon-button:active,
.nav-item:active {
  transform: scale(0.98);
}

.full-width {
  width: 100%;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

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

.compact-unit-form .secondary-button {
  min-height: 44px;
}

.unit-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.unit-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #FBFBFD;
  color: var(--secondary);
  font-size: 0.82rem;
  font-weight: 700;
}

.unit-chip button {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: #EFEFF4;
  color: var(--secondary);
}

.settings-row {
  display: grid;
  gap: 10px;
}

.bottom-nav {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 20;
  width: auto;
  max-width: 520px;
  min-height: var(--nav-height);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-flow: column;
  gap: 4px;
  margin: 0 auto;
  padding: 7px;
  border: 1px solid rgba(229, 229, 234, 0.92);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 16px 42px rgba(29, 29, 31, 0.14);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.nav-item {
  min-width: 0;
  min-height: 58px;
  display: grid;
  place-items: center;
  gap: 2px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--secondary);
  font-size: 0.69rem;
  font-weight: 800;
}

.nav-item.active {
  background: rgba(0, 122, 255, 0.1);
  color: var(--accent);
}

.nav-item span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 1rem;
  line-height: 1;
}

.category-icon .icon,
.empty-icon .icon,
.stat-icon .icon {
  font-size: 1.02rem;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-height) + 28px + env(safe-area-inset-bottom));
  z-index: 30;
  width: min(calc(100% - 32px), 460px);
  margin: 0 auto;
  padding: 13px 14px;
  border-radius: 12px;
  background: rgba(29, 29, 31, 0.92);
  color: white;
  box-shadow: 0 12px 34px rgba(29, 29, 31, 0.22);
  text-align: center;
  font-weight: 800;
}

.toast.warning {
  background: rgba(180, 97, 0, 0.95);
}

.toast.neutral {
  background: rgba(84, 84, 88, 0.95);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: end center;
  padding: 18px 18px calc(var(--nav-height) + env(safe-area-inset-bottom) + 18px);
  background: rgba(29, 29, 31, 0.26);
  backdrop-filter: blur(10px);
}

.confirm-sheet {
  width: min(100%, 380px);
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid rgba(60, 60, 67, 0.16);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 46px rgba(29, 29, 31, 0.2);
}

.confirm-sheet h2 {
  margin: 0;
  font-size: 1.14rem;
  line-height: 1.2;
}

.confirm-sheet p {
  margin: 0;
  color: var(--secondary);
  font-size: 0.94rem;
  line-height: 1.38;
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.confirm-actions button {
  min-height: 46px;
}

@media (max-width: 360px) {
  .detailed-form .field-unit,
  .detailed-form .field-unit-type,
  .detailed-form .field-unit-price,
  .detailed-form .field-total {
    grid-column: span 2;
  }
}

@media (min-width: 720px) {
  .app-frame {
    padding: 28px 22px calc(var(--nav-height) + 34px);
  }

  .app-header h1 {
    font-size: 2.35rem;
  }

  .dashboard-hero {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .hero-total {
    min-width: 260px;
    display: grid;
    justify-items: end;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .quick-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .quick-stats {
    gap: 10px;
  }

  .add-month-card {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
    align-items: end;
  }

  .quick-stats .stat-card {
    min-height: 104px;
    padding: 12px;
  }

  .quick-stats .stat-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
  }

  .quick-stats .stat-card span {
    font-size: 0.95rem;
  }

  .quick-stats .stat-card strong {
    font-size: 1.05rem;
  }

  .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .detailed-form {
    grid-template-columns: 0.72fr 0.8fr 1.24fr 1.24fr;
  }

  .form-grid .full-width,
  .form-grid button.full-width,
  .segmented-field {
    grid-column: 1 / -1;
  }

  .settings-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .row-actions,
  .item-actions {
    margin-top: 0;
  }
}

@media (min-width: 980px) {
  .category-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

:root {
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --text: #1D1D1F;
  --secondary: #6E6E73;
  --border: rgba(60, 60, 67, 0.14);
  --control-bg: #F9F9FB;
  --shadow: 0 10px 30px rgba(29, 29, 31, 0.075);
  --soft-shadow: 0 5px 18px rgba(29, 29, 31, 0.055);
  --nav-height: 76px;
}

body {
  background: var(--bg);
  font-weight: 400;
}

.app-frame {
  width: min(100%, 560px);
  padding: max(18px, env(safe-area-inset-top)) 14px calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
}

.app-header {
  align-items: center;
  padding: 8px 2px 18px;
}

.app-header h1 {
  margin-top: 2px;
  font-size: 2.15rem;
  font-weight: 800;
  line-height: 1;
}

.eyebrow,
.section-kicker {
  color: #73737A;
  font-size: 0.76rem;
  font-weight: 650;
}

.month-chip,
.count-pill {
  min-height: 30px;
  border-color: rgba(60, 60, 67, 0.12);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 1px 2px rgba(29, 29, 31, 0.035);
  font-weight: 650;
}

.screen {
  gap: 12px;
}

.overview-card,
.summary-card,
.stat-card,
.category-card,
.soft-card,
.accordion-card,
.form-card,
.grocery-card,
.settings-row {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--soft-shadow);
}

.overview-card {
  display: grid;
  gap: 15px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.overview-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.overview-copy {
  min-width: 0;
}

.overview-copy h2 {
  margin: 5px 0 4px;
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: 0;
}

.overview-copy p:last-child {
  margin: 0;
  color: var(--secondary);
  font-size: 0.95rem;
  line-height: 1.34;
}

.overview-balance {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding-top: 2px;
}

.overview-balance span {
  color: var(--secondary);
  font-size: 0.86rem;
  font-weight: 650;
}

.overview-balance strong {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: 0;
  white-space: nowrap;
}

.overview-card .progress-copy {
  margin: 0 0 -5px;
  font-size: 0.78rem;
  font-weight: 650;
}

.overview-card .progress-track {
  height: 7px;
  background: #ECECF1;
}

.overview-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 0;
}

.metric-tile,
.stat-card {
  border-color: rgba(60, 60, 67, 0.12);
  background: var(--control-bg);
}

.metric-tile {
  padding: 12px;
}

.metric-tile span,
.stat-card span {
  color: #6F6F76;
  font-weight: 650;
}

.metric-tile strong,
.stat-card strong {
  font-weight: 800;
}

.quick-stats {
  gap: 8px;
}

.stat-card {
  min-height: 82px;
  display: grid;
  align-content: start;
  padding: 10px;
}

.stat-icon,
.category-icon,
.empty-icon {
  background: #EAF2FF;
  color: var(--accent);
}

.stat-icon {
  width: 58px;
  height: 58px;
  margin-bottom: 10px;
}

.quick-stats .stat-icon .icon {
  font-size: 1.88rem;
}

.quick-stats .stat-card.stat-pending {
  border-color: rgba(255, 149, 0, 0.28);
  background: #FEF3C7;
}

.quick-stats .stat-card.stat-pending .stat-icon {
  color: #B46100;
  background: rgba(255, 255, 255, 0.52);
}

.quick-stats .stat-card.stat-pending span {
  color: #B46100;
}

.quick-stats .stat-card.stat-in-cart {
  border-color: rgba(0, 122, 255, 0.24);
  background: #DBEAFE;
}

.quick-stats .stat-card.stat-in-cart .stat-icon {
  color: #075985;
  background: rgba(255, 255, 255, 0.52);
}

.quick-stats .stat-card.stat-in-cart span {
  color: #075985;
}

.quick-stats .stat-card.stat-purchased {
  border-color: rgba(52, 199, 89, 0.24);
  background: #DCFCE7;
}

.quick-stats .stat-card.stat-purchased .stat-icon {
  color: #1F6B35;
  background: rgba(255, 255, 255, 0.52);
}

.quick-stats .stat-card.stat-purchased span {
  color: #1F6B35;
}

.quick-stats .stat-card span {
  font-size: 1rem;
}

.quick-stats .stat-card strong {
  font-size: 1.06rem;
}

.section-block {
  gap: 9px;
}

.section-heading {
  align-items: center;
}

.section-heading h2 {
  margin-top: 2px;
  font-size: 1.24rem;
  font-weight: 800;
}

.form-card {
  gap: 13px;
  padding: 16px;
}

.add-month-card {
  gap: 11px;
}

.form-grid label,
.field-total,
.segmented-wrapper,
.inline-form label,
.month-select-field {
  color: #6F6F76;
  font-weight: 650;
}

input,
select {
  min-height: 48px;
  border-color: rgba(60, 60, 67, 0.14);
  background: var(--control-bg);
  font-weight: 600;
}

input::placeholder {
  color: #A1A1A6;
  font-weight: 500;
}

.compact-form input,
.compact-form select,
.compact-unit-form input,
.compact-unit-form .secondary-button {
  min-height: 46px;
}

input:focus,
select:focus {
  border-color: rgba(0, 122, 255, 0.72);
  background: #FFFFFF;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.11);
}

.total-preview {
  border-color: rgba(60, 60, 67, 0.14);
  background: var(--control-bg);
}

.segmented-field {
  border: 0;
  background: #ECECF1;
}

.segmented-field label {
  font-weight: 700;
}

.segmented-field input:checked + span {
  box-shadow: 0 1px 4px rgba(29, 29, 31, 0.14);
}

.segmented-field input[value="pending"]:checked + span {
  color: #7A4B00;
  background: #FEF3C7;
  box-shadow: 0 1px 5px rgba(122, 75, 0, 0.12);
}

.segmented-field input[value="in-cart"]:checked + span {
  color: #075985;
  background: #DBEAFE;
  box-shadow: 0 1px 5px rgba(7, 89, 133, 0.12);
}

.segmented-field input[value="purchased"]:checked + span {
  color: #1F6B35;
  background: #DCFCE7;
  box-shadow: 0 1px 5px rgba(31, 107, 53, 0.12);
}

.primary-button,
.secondary-button,
.text-action,
.icon-button {
  font-weight: 750;
}

.primary-button {
  box-shadow: 0 8px 20px rgba(0, 122, 255, 0.2);
}

.secondary-button,
.text-action,
.icon-button {
  border-color: rgba(60, 60, 67, 0.14);
}

.grocery-card,
.settings-row,
.accordion-card {
  box-shadow: 0 3px 12px rgba(29, 29, 31, 0.045);
}

.accordion-button {
  min-height: 58px;
}

.empty-state {
  border-color: rgba(60, 60, 67, 0.2);
  background: rgba(255, 255, 255, 0.72);
}

.bottom-nav {
  left: 0;
  right: 0;
  bottom: 0;
  max-width: none;
  min-height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  padding: 5px 10px calc(5px + env(safe-area-inset-bottom));
  border-width: 1px 0 0;
  border-color: rgba(60, 60, 67, 0.16);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: none;
}

.nav-item {
  min-height: 56px;
  border-radius: 8px;
  color: #6F6F76;
  font-size: 0.68rem;
  font-weight: 650;
}

.nav-item.active {
  background: transparent;
  color: var(--accent);
}

.nav-item .icon {
  font-size: 1.18rem;
}

.nav-item.active .icon {
  transform: translateY(-1px);
}

.toast {
  bottom: calc(var(--nav-height) + 16px + env(safe-area-inset-bottom));
}

@media (min-width: 720px) {
  .app-frame {
    width: min(100%, 780px);
    padding: 28px 22px calc(var(--nav-height) + 34px);
  }

  .screen {
    gap: 16px;
  }

  .app-header h1 {
    font-size: 2.5rem;
  }

  .overview-card {
    gap: 17px;
    padding: 20px;
  }

  .overview-copy h2 {
    font-size: 1.8rem;
  }

  .overview-balance strong {
    font-size: 3rem;
  }

  .overview-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .quick-stats .stat-card {
    min-height: 96px;
  }

  .bottom-nav {
    left: 50%;
    right: auto;
    bottom: 14px;
    width: min(calc(100% - 32px), 520px);
    min-height: var(--nav-height);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 7px;
    border-width: 1px;
    border-radius: 18px;
    box-shadow: 0 16px 42px rgba(29, 29, 31, 0.12);
    transform: translateX(-50%);
  }
}

@media (min-width: 980px) {
  .app-frame {
    width: min(100%, 860px);
  }
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.settings-row > div:first-child {
  min-width: 0;
}

.settings-row .row-actions {
  flex: 0 0 auto;
  margin-top: 0;
}

.settings-row .icon-button.subtle {
  width: 40px;
  min-height: 40px;
}

@media (max-width: 380px) {
  .settings-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-row .row-actions {
    align-self: flex-end;
  }
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 42px;
  background-color: var(--control-bg);
  background-image: none;
  background-clip: padding-box;
}

.compact-form select {
  padding-right: 34px;
}

select:focus {
  background-color: #FFFFFF;
  background-image: none;
}

.status-badge.neutral {
  background: rgba(142, 142, 147, 0.14);
  color: #636366;
}

.account-card {
  gap: 18px;
  padding: 18px;
}

.sync-note,
.helper-text {
  margin: 0;
  color: var(--secondary);
  font-size: 0.86rem;
  line-height: 1.38;
}

.sync-note {
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid rgba(60, 60, 67, 0.12);
  border-radius: var(--radius);
  background: var(--control-bg);
}

.sync-note strong {
  color: var(--text);
}

.sync-note p {
  margin: 0;
}

.sync-note code {
  color: var(--text);
  font-family: "SFMono-Regular", ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
}

.auth-form .auth-name-field,
.auth-form .auth-email-field,
.auth-form .auth-password-field {
  grid-column: 1 / -1;
  min-width: 0;
}

.sign-in-form .auth-email-field,
.sign-in-form .auth-password-field {
  grid-column: span 2;
}

.sign-in-form {
  column-gap: 12px;
  row-gap: 14px;
}

.forgot-password-action {
  grid-column: 1 / -1;
  justify-self: end;
  margin-top: -2px;
  margin-bottom: 4px;
}

.sign-in-form button.full-width {
  min-height: 50px;
}

.text-link-button {
  width: fit-content;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  box-shadow: none;
  font-size: 0.84rem;
  font-weight: 800;
}

.text-link-button:hover {
  color: #005FCC;
  background: transparent;
  box-shadow: none;
}

.auth-panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.auth-panel {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.auth-panel h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

@media (max-width: 680px) {
  .auth-panel-grid {
    grid-template-columns: 1fr;
  }

  .sign-in-form .auth-email-field,
  .sign-in-form .auth-password-field {
    grid-column: 1 / -1;
  }
}

.profile-card {
  gap: 15px;
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: 13px;
}

.profile-photo-preview {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  background: #FFFFFF;
  color: var(--accent);
  border: 1px solid rgba(60, 60, 67, 0.12);
}

.profile-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.profile-photo-preview .icon {
  font-size: 1.42rem;
}

.profile-hero h2 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.15;
}

.profile-hero p {
  margin: 4px 0 0;
  color: var(--secondary);
  font-size: 0.88rem;
  line-height: 1.3;
}

.profile-form .profile-name-field,
.profile-form .profile-photo-field {
  grid-column: span 2;
  min-width: 0;
}

.profile-row,
.family-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px;
  border: 1px solid rgba(60, 60, 67, 0.12);
  border-radius: var(--radius);
  background: var(--control-bg);
}

.profile-row img,
.family-row img,
.profile-avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 999px;
}

.profile-row img,
.family-row img {
  object-fit: contain;
  object-position: center;
  background: #FFFFFF;
}

.profile-avatar {
  display: grid;
  place-items: center;
  background: #EAF2FF;
  color: var(--accent);
}

.profile-avatar.small {
  width: 36px;
  height: 36px;
}

.profile-row > div,
.family-row > div {
  min-width: 0;
  flex: 1 1 auto;
}

.profile-row h3,
.family-row h3 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.2;
}

.profile-row p,
.family-row p {
  margin: 3px 0 0;
  color: var(--secondary);
  font-size: 0.8rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.family-form {
  grid-template-columns: minmax(0, 1fr) auto;
}

.family-actions {
  display: grid;
}

.family-list {
  display: grid;
  gap: 8px;
}

.family-row.pending {
  border-style: dashed;
}

.family-row .icon-button {
  flex: 0 0 auto;
}

button.stat-card {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button.stat-card:active {
  transform: scale(0.98);
}

button.stat-card:focus-visible {
  border-color: rgba(0, 122, 255, 0.72);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.11);
  outline: none;
}

select,
select:focus,
select:active,
select:hover {
  background-image: none !important;
}

select option,
select optgroup {
  background: #FFFFFF !important;
  background-image: none !important;
  color: #1D1D1F;
}

.form-grid label:has(> select),
.month-select-field:has(> select),
.inline-form label:has(> select) {
  position: relative;
}

.form-grid label:has(> select)::after,
.month-select-field:has(> select)::after,
.inline-form label:has(> select)::after {
  content: "";
  position: absolute;
  right: 13px;
  bottom: 18px;
  width: 9px;
  height: 9px;
  border-right: 2px solid #6E6E73;
  border-bottom: 2px solid #6E6E73;
  border-radius: 1px;
  pointer-events: none;
  transform: rotate(45deg);
}

.compact-form label:has(> select)::after {
  right: 11px;
  bottom: 17px;
  width: 8px;
  height: 8px;
}

.form-grid label:has(> select:focus)::after,
.month-select-field:has(> select:focus)::after,
.inline-form label:has(> select:focus)::after {
  border-color: var(--accent);
}

.share-list-actions {
  display: grid;
  align-self: end;
}

.share-list-button {
  width: 100%;
  min-width: 128px;
  padding-inline: 12px;
}

.add-month-card {
  grid-template-columns: minmax(0, 1fr) minmax(128px, auto);
  align-items: end;
}

.add-month-card .section-heading {
  grid-column: 1 / -1;
}

.add-month-card .month-select-field {
  min-width: 0;
}

.eyebrow,
.section-kicker {
  display: none;
}

.section-heading h2,
.export-preview-head h2 {
  margin-top: 0;
}

.header-user-menu {
  position: relative;
  flex: 0 0 auto;
}

.header-user-button {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(60, 60, 67, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--accent);
  box-shadow: 0 4px 14px rgba(29, 29, 31, 0.06);
}

.header-user-button img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  object-fit: cover;
  object-position: center;
  background: #FFFFFF;
}

.header-user-button .icon {
  font-size: 1.05rem;
}

.header-user-button:active {
  transform: scale(0.98);
}

.user-menu-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: 172px;
  display: grid;
  gap: 4px;
  padding: 7px;
  border: 1px solid rgba(60, 60, 67, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 34px rgba(29, 29, 31, 0.16);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.user-menu-popover button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  text-align: left;
}

.user-menu-popover button:active {
  background: #F2F2F7;
}

.user-menu-popover .icon {
  color: var(--accent);
}

.export-control-card {
  gap: 12px;
}

.export-preview-card {
  gap: 14px;
}

.export-preview-head,
.export-category-title,
.export-item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.export-preview-head h2 {
  margin: 2px 0 0;
  font-size: 1.36rem;
  line-height: 1.1;
}

.export-preview-head > strong {
  flex: 0 0 auto;
  font-size: 1.36rem;
}

.export-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.receipt-list {
  display: grid;
  gap: 11px;
}

.receipt-category {
  overflow: hidden;
  border: 1px solid rgba(60, 60, 67, 0.12);
  border-radius: var(--radius);
  background: var(--control-bg);
}

.receipt-category-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  background: #FBFBFD;
  border-bottom: 1px solid rgba(60, 60, 67, 0.1);
}

.receipt-category-head h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.receipt-category-head strong {
  flex: 0 0 auto;
  white-space: nowrap;
}

.receipt-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.receipt-table th {
  padding: 10px 12px 8px;
  color: var(--secondary);
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: left;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(60, 60, 67, 0.1);
}

.receipt-table th:first-child {
  width: 49%;
}

.receipt-table th:nth-child(2),
.receipt-table th:nth-child(3),
.receipt-table td:nth-child(2),
.receipt-table td:nth-child(3) {
  text-align: right;
}

.receipt-table td {
  padding: 10px 12px;
  vertical-align: top;
  border-bottom: 1px solid rgba(60, 60, 67, 0.08);
}

.receipt-table tr:last-child td {
  border-bottom: 0;
}

.receipt-table td:first-child strong,
.receipt-table td:first-child span {
  display: block;
}

.receipt-table td:first-child strong {
  font-size: 0.9rem;
  line-height: 1.2;
}

.receipt-table td:first-child span {
  margin-top: 3px;
  color: var(--secondary);
  font-size: 0.74rem;
  line-height: 1.25;
}

.receipt-table td:nth-child(2),
.receipt-table td:nth-child(3) {
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
}

.receipt-table em {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  margin-left: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-style: normal;
  font-weight: 800;
}

.receipt-table em.pending {
  color: #7A4B00;
  background: rgba(255, 204, 0, 0.22);
}

.receipt-table em.in-cart {
  color: #075985;
  background: rgba(0, 122, 255, 0.14);
}

.receipt-table em.purchased {
  color: #1F6B35;
  background: rgba(52, 199, 89, 0.18);
}

.export-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.export-actions button {
  min-width: 0;
  min-height: 48px;
}

@media (min-width: 720px) {
  .add-month-card {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 240px) auto;
    align-items: end;
  }

  .add-month-card .section-heading {
    grid-column: auto;
    align-self: center;
  }

  .share-list-button {
    min-width: 132px;
  }

  .export-control-card {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
    align-items: end;
  }

  .export-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
