:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #242426;
  --surface-3: #313134;
  --text: #ffffff;
  --muted: rgba(235, 235, 245, 0.6);
  --muted-2: rgba(235, 235, 245, 0.3);
  --line: rgba(84, 84, 88, 0.48);
  --line-strong: rgba(84, 84, 88, 0.65);
  --blue: #0a84ff;
  --green: #32d74b;
  --red: #ff453a;
  --orange: #ff9f0a;
  --purple: #bf5af2;
  --cyan: #64d2ff;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --header-h: 48px;
  --tabbar-h: 54px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  overflow-x: hidden;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.3;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

button:active {
  opacity: 0.72;
}

/* ---------- App shell & header ---------- */

.app-shell {
  position: relative;
  width: min(100%, 520px);
  min-height: 100%;
  margin: 0 auto;
  padding: calc(var(--safe-top) + var(--header-h) + 14px) 16px
    calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
}

/* Fixed (not sticky) so iOS rubber-band overscroll can never reveal content
   behind it, and paints the safe-area/status-bar strip with an opaque layer. */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: calc(var(--safe-top) + var(--header-h));
  padding: var(--safe-top) max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  border-bottom: 0.5px solid var(--line);
  background: rgba(18, 18, 20, 0.86);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.app-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--bg);
  opacity: 0.72;
}

.app-header.is-scrolled {
  background: rgba(14, 14, 16, 0.96);
  border-bottom-color: var(--line-strong);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.brand img {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.brand p {
  display: none;
}

.brand h1 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 17px;
  font-weight: 660;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
}

.circle-button,
.sync-button,
.week-controls button {
  border: 0;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
}

.circle-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 15px;
}

.sync-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 46px;
  height: 32px;
  border-radius: 999px;
  color: var(--blue);
  font-size: 16px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(50, 215, 75, 0.16);
}

.status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(255, 69, 58, 0.16);
}

/* ---------- Views ---------- */

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: view-in 180ms ease;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.notice {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(10, 132, 255, 0.14);
}

.notice.show {
  display: flex;
}

.notice strong,
.notice span {
  display: block;
}

.notice strong {
  font-size: 14px;
  font-weight: 640;
}

.notice span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
}

.notice button {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
  font-size: 13px;
}

/* ---------- Cards & panels ---------- */

.hero-panel,
.panel {
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

.overline,
.subtle {
  margin: 0;
  color: var(--muted);
}

.overline {
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0.01em;
}

.hero-panel h2 {
  margin: 4px 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.subtle {
  font-size: 12.5px;
}

.progress-ring {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--surface) 58%, transparent 60%),
    conic-gradient(var(--blue) var(--progress, 0deg), rgba(255, 255, 255, 0.1) 0);
  font-size: 13px;
  font-weight: 660;
}

.cycle-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}

.cycle-info {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.cycle-info h2 {
  margin: 2px 0;
  font-size: 19px;
  font-weight: 680;
}

/* Donut always sits centered above the legend, never side-by-side — a category
   legend can run to a dozen+ rows, and a fixed-size chart next to a long list
   just strands empty space beside itself. Stacking scales to any list length. */
.donut-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.donut-layout canvas {
  flex: 0 0 auto;
}

.donut-layout .category-list {
  width: 100%;
}

.meter-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  margin: 12px 0 14px;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.segmented button {
  min-height: 30px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.segmented button.is-active {
  color: var(--text);
  background: var(--surface-3);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 14px;
}

.stat-card {
  min-height: 84px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface);
}

.stat-card span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: var(--blue);
  background: rgba(10, 132, 255, 0.15);
  font-size: 13px;
  font-weight: 700;
}

.stat-card p {
  margin: 10px 0 3px;
  color: var(--muted);
  font-size: 12.5px;
}

.stat-card strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  font-weight: 660;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  margin-top: 14px;
  padding: 16px;
}

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

.section-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 660;
  line-height: 1.2;
}

.section-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- Grouped lists (iOS-style rows inside one card) ---------- */

.category-list,
.expense-list,
.pending-list {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.category-list:empty,
.expense-list:empty,
.pending-list:empty {
  background: transparent;
}

.category-row,
.expense-row {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 0.5px solid var(--line);
  color: var(--text);
  background: transparent;
  text-align: left;
}

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

.category-row {
  cursor: pointer;
}

.category-line,
.expense-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 12px;
}

.category-name {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 600;
}

.category-name span:first-child {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  font-size: 13px;
}

.category-name span:last-child,
.expense-row h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-amount {
  flex: 0 0 auto;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  height: 4px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.bar-fill {
  width: var(--width, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--color, var(--blue));
}

.key-value {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--line);
  color: var(--muted);
  font-size: 13.5px;
}

.key-value:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.key-value strong {
  color: var(--text);
  font-weight: 620;
  text-align: right;
}

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.full {
  grid-column: 1 / -1;
}

label {
  display: grid;
  min-width: 0;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  min-width: 0;
  border: 0.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface-2);
  outline: none;
  transition: box-shadow 120ms ease, border-color 120ms ease;
}

input,
select {
  height: 42px;
  padding: 0 12px;
  font-size: 15px;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

input[type="date"],
input[type="datetime-local"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  line-height: 42px;
  text-align: left;
  -webkit-appearance: none;
  appearance: none;
  color-scheme: dark;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value {
  width: 100%;
  min-width: 0;
  margin: 0;
  text-align: left;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  flex: 0 0 auto;
  margin-left: 4px;
  filter: invert(1) brightness(1.4);
  opacity: 0.7;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  font-weight: 560;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) center, calc(100% - 12px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

textarea {
  resize: vertical;
  min-height: 104px;
  padding: 11px 12px;
  font-size: 15px;
  line-height: 1.4;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.22);
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 15px;
  font-weight: 640;
  cursor: pointer;
}

.primary-button {
  background: var(--blue);
}

.secondary-button {
  color: var(--text);
  background: var(--surface-2);
}

.danger-button {
  color: #ffb4ae;
  background: rgba(255, 69, 58, 0.16);
}

/* ---------- Review (pending) ---------- */

.pending-card {
  padding: 14px;
  border-bottom: 0.5px solid var(--line);
}

.pending-card:last-child {
  border-bottom: 0;
}

.pending-card h3 {
  margin: 0 0 3px;
  font-size: 15.5px;
  font-weight: 660;
}

.pending-card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.pending-actions {
  display: grid;
  gap: 10px;
}

.pending-select-label {
  color: var(--muted);
}

.pending-buttons {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.pending-buttons .danger-button {
  min-width: 84px;
  padding: 0 14px;
}

/* ---------- Expenses list & filters ---------- */

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

.filter-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.filter-panel .search-field {
  position: relative;
}

.filter-panel .search-field input {
  padding-left: 34px;
  border-radius: 999px;
  background: var(--surface-2);
}

.filter-panel .search-field::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 12px;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  border: 1.6px solid var(--muted);
  border-radius: 50%;
}

.filter-panel .search-field::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 22px;
  width: 6px;
  height: 1.6px;
  transform: translateY(3px) rotate(45deg);
  background: var(--muted);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.filter-row label {
  gap: 4px;
}

.filter-panel select#expenseCategoryFilter {
  border-radius: 999px;
}

#clearExpenseFilters {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.expense-row {
  padding: 11px 14px;
}

.expense-row h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.expense-row strong {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.expense-row strong.hp-good {
  color: var(--green);
}

.expense-row strong.hp-bad {
  color: var(--red);
}

.expense-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}

/* ---------- Reports ---------- */

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}

.metric-strip.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0 0;
}

.metric-strip div {
  min-width: 0;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.metric-strip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 620;
}

.metric-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 640;
  line-height: 1.25;
  overflow-wrap: break-word;
  font-variant-numeric: tabular-nums;
}

.chart {
  display: block;
  width: 100%;
  height: 170px;
  max-height: 240px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

#dailyChart {
  height: 176px;
}

#monthChart {
  height: 160px;
}

#categoryChart {
  height: 210px;
}

.helper {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.week-controls {
  display: flex;
  gap: 6px;
}

.week-controls button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--blue);
  font-size: 19px;
}

/* ---------- Tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px max(6px, env(safe-area-inset-left)) calc(4px + var(--safe-bottom));
  border-top: 0.5px solid var(--line);
  background: rgba(18, 18, 20, 0.86);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.tabbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--bg);
  opacity: 0.72;
}

.tab {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 44px;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
  cursor: pointer;
}

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab span:not(.tab-icon) {
  font-weight: 560;
  font-size: 10px;
}

.tab.is-active {
  color: var(--blue);
}

#pendingBadge:not(:empty) {
  position: absolute;
  top: 0;
  right: calc(50% - 22px);
  display: grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  color: white;
  background: var(--red);
  font-size: 10px;
  font-weight: 700;
  font-style: normal;
}

/* ---------- Dialog & toast ---------- */

dialog {
  width: min(calc(100% - 24px), 520px);
  max-height: 86dvh;
  margin: auto;
  padding: 18px;
  border: 0;
  border-radius: 20px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.dialog-body {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

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

.dialog-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 680;
}

.dialog-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.dialog-head button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  color: var(--blue);
  background: var(--surface-2);
  font-weight: 620;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  z-index: 80;
  max-width: min(90%, 420px);
  padding: 10px 16px;
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-3);
  font-size: 13.5px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.show {
  pointer-events: auto;
}

.toast .toast-undo {
  padding: 0 2px;
  border: none;
  background: none;
  color: var(--blue);
  font-size: 13.5px;
  font-weight: 700;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 45vh;
  padding: 32px 20px;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

@media (max-width: 390px) {
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .hero-panel h2 {
    font-size: 26px;
  }

  .progress-ring {
    width: 54px;
    height: 54px;
  }

  #reportsView .panel {
    padding: 13px;
  }

  #reportsView .section-head h2 {
    font-size: 16px;
  }

  #reportsView .section-head p {
    font-size: 12px;
  }
}

/* ---------- House Purchase Plan ---------- */

.hp-subnav {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 10px 0 18px;
  padding: 4px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)),
    rgba(255, 255, 255, 0.055);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.hp-subnav button {
  min-height: 36px;
  border-radius: 11px;
  font-size: 12px;
  letter-spacing: 0;
  color: var(--muted);
}

.hp-subnav button.is-active {
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.075)),
    rgba(10, 132, 255, 0.12);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.hp-section {
  display: none;
}

.hp-section.is-active {
  display: block;
}

.hp-alerts {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.hp-alert {
  padding: 11px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.4;
}

.hp-alert.amber {
  background: rgba(255, 159, 10, 0.14);
  color: #ffcf8a;
}

.hp-alert.red {
  background: rgba(255, 69, 58, 0.14);
  color: #ffb4ae;
}

.hp-alert.green {
  background: rgba(50, 215, 75, 0.14);
  color: #8feb9c;
}

.stat-card.hp-status-green strong {
  color: var(--green);
}

.stat-card.hp-status-amber strong {
  color: var(--orange);
}

.stat-card.hp-status-red strong {
  color: var(--red);
}

.hp-progress-panel {
  margin-top: 0;
}

.hp-kv {
  margin-top: 4px;
}

.plan-row + .plan-row {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 0.5px solid var(--line);
}

.plan-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.plan-row-head h3 {
  font-size: 14px;
  font-weight: 650;
}

.hp-month-rail {
  display: flex;
  gap: 8px;
  margin: 6px -2px 14px;
  padding: 2px 2px 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.hp-month-rail::-webkit-scrollbar {
  display: none;
}

.hp-month-chip {
  flex: 0 0 auto;
  min-width: 118px;
  display: grid;
  gap: 4px;
  min-height: 78px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  text-align: left;
  scroll-snap-align: center;
}

.hp-month-chip.is-active {
  border-color: rgba(10, 132, 255, 0.78);
  background: rgba(10, 132, 255, 0.16);
  box-shadow: 0 0 0 1px rgba(10, 132, 255, 0.18) inset;
}

.hp-month-chip span {
  font-size: 12px;
  color: var(--muted);
}

.hp-month-chip strong {
  font-size: 14px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hp-month-chip em {
  width: fit-content;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
}

.hp-month-chip em.done {
  background: rgba(50, 215, 75, 0.16);
  color: #8feb9c;
}

.hp-month-chip em.partial {
  background: rgba(255, 159, 10, 0.16);
  color: #ffd59a;
}

.hp-month-chip em.open {
  background: rgba(142, 142, 147, 0.16);
  color: rgba(235, 235, 245, 0.72);
}

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

.hp-big {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hp-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.hp-pill {
  flex: 0 0 auto;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 640;
  white-space: nowrap;
}

.hp-pill.good {
  background: rgba(50, 215, 75, 0.16);
  color: #8feb9c;
}

.hp-pill.bad {
  background: rgba(255, 69, 58, 0.16);
  color: #ff9f96;
}

.hp-bar {
  height: 6px;
  margin-top: 12px;
}

.hp-note {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.hp-payment-form {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.045);
}

.hp-payment-form + .hp-payment-form {
  margin-top: 12px;
}

.hp-payment-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hp-payment-head h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.hp-payment-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.hp-payment-head .tab-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--blue);
  background: rgba(10, 132, 255, 0.13);
}

.hp-compare-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hp-compare-cols > div {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.hp-compare-cols span {
  font-size: 12px;
  color: var(--muted);
}

.hp-compare-cols strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.hp-compare-cols strong.hp-good {
  color: var(--green);
}

.hp-compare-cols strong.hp-bad {
  color: var(--red);
}

.hp-verdict {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.hp-verdict .hp-note {
  margin-top: 0;
}

.hp-kv .key-value strong.hp-good {
  color: var(--green);
}

.hp-kv .key-value strong.hp-bad {
  color: var(--red);
}

.hp-yearly-table {
  display: grid;
  gap: 10px;
}

.hp-year-row {
  border-radius: var(--radius-md);
  background: var(--surface-2);
  overflow: hidden;
}

.hp-year-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 660;
  cursor: pointer;
}

.hp-year-summary .tab-icon {
  color: var(--muted);
  font-size: 12px;
}

.hp-year-months {
  display: none;
  border-top: 0.5px solid var(--line);
}

.hp-year-row.is-expanded .hp-year-months {
  display: block;
}

.hp-year-month-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 0.5px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
}

.hp-year-month-row:last-child {
  border-bottom: 0;
}

.hp-tx-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.expense-row.hp-deleted {
  opacity: 0.5;
}

.expense-row.hp-deleted h3 {
  text-decoration: line-through;
}

/* ================================================================
   Desktop layout (>=900px): sidebar nav + wide multi-column
   dashboard/reports grids, replacing the phone's single-column
   stack + bottom tab bar. Same markup, same data, same API calls —
   only presentation differs. Everything above this point still
   governs phones untouched.
   ================================================================ */
@media (min-width: 900px) {
  :root {
    --sidebar-w: 248px;
  }

  .app-shell {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: calc(var(--safe-top) + var(--header-h) + 28px) 40px 48px calc(var(--sidebar-w) + 40px);
  }

  main {
    max-width: 1120px;
    margin: 0 auto;
  }

  /* Header stays a full-width top strip; only the content below shifts right of the sidebar. */
  .app-header {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }

  .brand h1 {
    font-size: 18px;
  }

  /* Sidebar: the same nav buttons, restyled from a floating bottom pill into a fixed left column. */
  .tabbar {
    position: fixed;
    top: calc(var(--safe-top) + var(--header-h));
    left: 0;
    right: auto;
    bottom: 0;
    z-index: 25;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    grid-template-columns: none;
    gap: 4px;
    padding: 20px 14px;
    border-top: 0;
    border-right: 0.5px solid var(--line);
    border-radius: 0;
    transform: none;
    box-shadow: none;
  }

  .tab {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: 14px;
  }

  .tab span:not(.tab-icon) {
    font-size: 14px;
    font-weight: 600;
  }

  .tab-icon {
    font-size: 18px;
  }

  .tab.is-active {
    background: rgba(10, 132, 255, 0.16);
  }

  #pendingBadge:not(:empty) {
    position: static;
    margin-left: auto;
  }

  .toast {
    bottom: 32px;
  }

  /* Hover affordances only for real pointers, so touch (e.g. iPad at desktop width) is unaffected. */
  @media (hover: hover) and (pointer: fine) {
    .tab:not(.is-active):hover {
      background: rgba(255, 255, 255, 0.06);
    }

    .category-row:hover,
    .expense-row:hover,
    .pending-card:hover {
      background: rgba(255, 255, 255, 0.04);
    }

    .primary-button:hover {
      filter: brightness(1.1);
    }

    .secondary-button:hover {
      background: var(--surface-3);
    }
  }

  /* Two-column forms: Amount/Merchant, Category/Date, Budget/Saving target sit side by side. */
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Overview: an "at a glance" left column next to Categories/Insights on the right.
     Each column is a plain block wrapper that stacks its own children independently —
     deliberately NOT CSS grid rows, because grid would force both columns' rows to the
     same height (e.g. a short hero card stretched to match a long category list). */
  /* .is-active is required in the selector: #id alone outguns ".view{display:none}"
     on specificity and would force this view visible even when inactive. */
  #dashboardView.is-active {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 24px;
  }

  /* iPad Safari matches the isiOS check in app.js, so this can still appear at desktop
     width — keep it a full-width banner above the two columns rather than a third column. */
  #dashboardView #installHint {
    flex-basis: 100%;
  }

  .dashboard-col-a {
    flex: 1.3 1 0;
    min-width: 0;
  }

  .dashboard-col-b {
    flex: 1 1 0;
    min-width: 0;
  }

  .dashboard-col-b .panel:first-child {
    margin-top: 0;
  }

  /* Expenses: filters collapse into a single toolbar row instead of a stacked mini-form. */
  .filter-panel {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    align-items: center;
    gap: 12px;
  }

  .filter-panel .full {
    grid-column: auto;
  }

  .filter-row {
    display: contents;
  }

  #clearExpenseFilters {
    white-space: nowrap;
  }

  /* Reports: a two-column dashboard of report cards instead of one long stack.
     Same independent-column approach as Overview, for the same reason — the cards in
     one column (e.g. Payment Insights) can be much taller than their row's counterpart. */
  #reportsView.is-active {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 24px;
  }

  #reportsView > .cycle-panel {
    flex-basis: 100%;
  }

  .reports-col-a,
  .reports-col-b {
    flex: 1 1 0;
    min-width: 0;
  }

  .reports-col-a .panel:first-child,
  .reports-col-b .panel:first-child {
    margin-top: 0;
  }
}

@media (min-width: 1280px) {
  main {
    max-width: 1240px;
  }
}
