:root {
  color-scheme: light;
  --bg: #fff8fb;
  --surface: #ffffff;
  --surface-soft: #fff0f5;
  --surface-strong: #ffe1eb;
  --surface-selected: #ffc2d4;
  --ink: #492d38;
  --ink-soft: #755663;
  --ink-faint: #8b6b78;
  --accent: #eb668d;
  --accent-action: #bd3d66;
  --accent-action-hover: #a8345c;
  --accent-ink: #8f294e;
  --success: #34866c;
  --income: #28775f;
  --income-soft: #e4f4ed;
  --expense: #a8345c;
  --warning: #a6661b;
  --danger: #c5425d;
  --line: #efd3dd;
  --focus: #8f3658;
  --shadow-soft: 0 8px 26px rgba(126, 54, 79, 0.07);
  --shadow-float: 0 18px 48px rgba(126, 54, 79, 0.14);
  --page-gutter: 16px;
  --section-gap: 20px;
  --chart-fill: #bd3d66;
  --chart-track: #f8e2ea;
  --chart-income: #2a78d6;
  --chart-expense: #a8345c;
  --nav-height: 56px;
  --content-max: 480px;
  --radius-card: 22px 22px 22px 7px;
  --radius-control: 15px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #24191e;
    --surface: #302128;
    --surface-soft: #3a252e;
    --surface-strong: #4a2a36;
    --surface-selected: #743247;
    --ink: #fff3f7;
    --ink-soft: #e2c8d2;
    --ink-faint: #c3a5b0;
    --accent: #ff86a8;
    --accent-action: #b83d66;
    --accent-action-hover: #a8345c;
    --accent-ink: #ffabc1;
    --success: #79c9ae;
    --income: #8bd8be;
    --income-soft: #27443b;
    --expense: #ffabc1;
    --warning: #e5b872;
    --danger: #ff8ca5;
    --line: #573845;
    --focus: #ffc2d4;
    --shadow-soft: 0 8px 26px rgba(0, 0, 0, 0.15);
    --shadow-float: 0 18px 48px rgba(0, 0, 0, 0.28);
    --chart-fill: #d95b83;
    --chart-track: #49303a;
    --chart-income: #3987e5;
    --chart-expense: #d95b83;
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% -5%, color-mix(in srgb, var(--surface-selected) 46%, transparent) 0 96px, transparent 98px),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

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

button:not(:disabled),
input:not(:disabled),
textarea:not(:disabled) {
  cursor: pointer;
}

input[type="text"],
input[type="month"],
input[type="datetime-local"],
textarea {
  cursor: text;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

[hidden] {
  display: none !important;
}

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

.app-shell {
  --chat-keyboard-inset: 0px;
  --chat-safari-composer-top: 0px;
  position: relative;
  width: min(100%, var(--content-max));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 28px);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
}

.app-shell.is-booting .account-button {
  visibility: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 18px 12px;
}

.brand-button,
.icon-button,
.text-button,
.back-button,
.month-step,
.intro-close,
.bottom-nav button,
.record-row,
.highest-record,
.filter-chip,
.segmented-control button,
.category-option {
  border: 0;
  background: transparent;
}

.brand-button {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-height: 48px;
  padding: 0;
  text-align: left;
}

.brand-button > span:last-child {
  display: grid;
  gap: 1px;
}

.brand-button strong {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 16px;
  letter-spacing: 0.02em;
}

.brand-button small {
  color: var(--ink-soft);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 52% 48% 45% 55% / 48% 52% 48% 52%;
  background: var(--accent-action);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent-action) 26%, transparent);
  color: #fff8fb;
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", sans-serif;
  font-size: 19px;
  font-weight: 700;
  transform: rotate(-5deg);
}

.icon-button,
.back-button,
.month-step,
.intro-close {
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.icon-button {
  color: var(--ink-soft);
  font-size: 20px;
}

.storage-alert {
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 16px 12px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--line));
  border-left: 5px solid var(--danger);
  border-radius: 7px 18px 18px 7px;
  background: color-mix(in srgb, var(--surface) 92%, var(--danger));
  box-shadow: var(--shadow-soft);
}

.storage-alert:not([hidden]) {
  display: flex;
}

.storage-alert strong {
  display: block;
  color: var(--danger);
  font-size: 14px;
}

.storage-alert p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}

.pwa-install-shortcut-wrap:not([hidden]) {
  display: inline-flex;
}

.pwa-install-shortcut {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--accent-action) 34%, var(--line));
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-selected) 52%, var(--surface));
  box-shadow: var(--shadow-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.pwa-install-shortcut svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.pwa-install-shortcut:disabled {
  opacity: 0.7;
}

@media (max-width: 359px) {
  .app-header {
    gap: 8px;
    padding-inline: 12px;
  }

  .brand-button {
    gap: 8px;
  }

  .brand-button small,
  .pwa-install-shortcut span {
    display: none;
  }

  .pwa-install-shortcut {
    width: 44px;
    padding-inline: 0;
  }
}

.intro-card {
  position: relative;
  grid-template-columns: 42px minmax(0, 1fr) 44px;
  gap: 12px;
  align-items: start;
  margin: 4px 16px 14px;
  padding: 17px 12px 17px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-strong);
}

.intro-card:not([hidden]) {
  display: grid;
}

.intro-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 20px;
}

.intro-copy h2 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

.intro-copy p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.intro-close {
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: 0;
  box-shadow: none;
  color: var(--ink-soft);
  font-size: 22px;
}

.app-main {
  min-width: 0;
}

.view {
  padding: 4px var(--page-gutter) 28px;
}

.view-heading,
.entry-header,
.section-title-row,
.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.view-heading,
.entry-header {
  min-height: 56px;
  margin-bottom: 10px;
}

.entry-header {
  justify-content: flex-start;
}

.details-primary-heading {
  min-height: 56px;
  margin-bottom: 10px;
}

.details-primary-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
}

.app-shell.is-details-view > .active-ledger-switcher {
  display: none;
}

.app-shell.is-primary-entry-view .entry-header {
  display: none;
}

.view-heading h1,
.entry-header h1 {
  margin: 2px 0 0;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: clamp(25px, 7.4vw, 31px);
  line-height: 1.12;
  letter-spacing: -0.01em;
}

.view-heading h1:focus,
.entry-header h1:focus {
  outline: none;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.text-button {
  min-height: 44px;
  padding: 8px 4px;
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
}

.details-heading-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.details-heading-actions .text-button {
  white-space: nowrap;
}

.details-ledger-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20px auto;
  gap: 7px;
  align-items: center;
  min-width: 0;
  min-height: 52px;
  padding: 6px 9px 6px 11px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 6px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  text-align: left;
}

.details-ledger-button > svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--accent-ink);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.details-ledger-copy,
.details-ledger-action {
  display: grid;
  min-width: 0;
}

.details-ledger-copy small,
.details-ledger-action small {
  color: var(--ink-soft);
  font-size: 8px;
  line-height: 1.25;
}

.details-ledger-copy strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.details-ledger-action {
  justify-items: end;
  white-space: nowrap;
}

.details-ledger-action strong {
  color: var(--accent-ink);
  font-size: 9px;
}

.details-member-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.details-member-button:active {
  background: var(--surface-strong);
}

.details-member-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.details-account-button {
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--accent-ink);
}

.details-account-button:active {
  background: var(--surface-soft);
}

.details-account-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-button {
  flex: 0 0 44px;
  color: var(--accent-ink);
  font-size: 30px;
  line-height: 1;
}

.month-switcher {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  column-gap: 12px;
  align-items: center;
  width: 100%;
  margin-bottom: 14px;
}

.month-overview {
  margin-bottom: 12px;
}

.month-overview .month-switcher {
  margin-bottom: 10px;
}

.month-step {
  position: relative;
  z-index: 2;
  margin: 0;
  padding: 0;
  color: var(--accent-ink);
  font-size: 30px;
  line-height: 1;
}

.month-picker {
  position: relative;
  z-index: 1;
  display: block;
  min-width: 0;
  overflow: hidden;
}

.month-picker input {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  text-align: center;
}

.month-picker-display {
  display: grid;
  place-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
}

.month-picker-display .month-display {
  min-width: 0;
  padding-inline: 10px;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.month-picker-display input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.month-picker-display:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.total-card,
.stats-hero {
  position: relative;
  overflow: hidden;
  padding: 24px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
  border-radius: 13px 30px 13px 30px;
  background: var(--surface-strong);
  box-shadow: var(--shadow-soft);
}

.total-card p,
.stats-hero p {
  position: relative;
  z-index: 1;
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.total-card strong,
.stats-hero > strong {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
  font-size: clamp(36px, 11vw, 48px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.18;
  letter-spacing: -0.015em;
  overflow-wrap: normal;
  white-space: nowrap;
}

.total-card > span {
  position: relative;
  z-index: 1;
  display: inline-block;
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 12px;
}

.total-decoration {
  position: absolute;
  width: 130px;
  height: 130px;
  right: -58px;
  bottom: -82px;
  border: 20px solid var(--surface-selected);
  border-radius: 50%;
  opacity: 0.42;
}

.month-summary-card,
.stats-hero {
  padding: 20px 20px 18px 24px;
  border-left: 5px solid var(--accent-action);
  border-radius: 8px 25px 8px 25px;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent-action) 9%, transparent);
}

.month-summary-card strong,
.stats-hero > strong {
  font-size: clamp(34px, 10.5vw, 46px);
}

.filter-section,
.records-section,
.ranking-card,
.highest-card,
.form-section {
  margin-top: var(--section-gap);
}

.section-title-row {
  align-items: flex-end;
  margin-bottom: 12px;
}

.records-section > .section-title-row {
  align-items: center;
  margin-bottom: 10px;
}

#records-summary {
  max-width: 66%;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  text-align: right;
}

.section-title-row h2,
.ranking-card h2,
.highest-card h2,
.form-section h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}

.section-title-row > span,
#records-summary,
.field-label-row span {
  color: var(--ink-soft);
  font-size: 12px;
}

.filter-strip {
  display: flex;
  gap: 9px;
  max-width: 100%;
  padding: 3px 0 8px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
}

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

.filter-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: max-content;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: none;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.filter-chip[aria-pressed="true"] {
  border-color: var(--accent-action);
  background: var(--surface-selected);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--accent-action);
}

.filter-check {
  color: var(--accent-ink);
  font-weight: 700;
}

.segmented-control {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-soft);
}

.segmented-control button,
.segmented-control label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 11px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

.segmented-control button[aria-pressed="true"],
.segmented-control label:has(input:checked) {
  background: var(--surface);
  box-shadow: 0 3px 12px color-mix(in srgb, var(--ink) 9%, transparent);
  color: var(--ink);
}

.segment-selected-mark {
  display: none;
  flex: 0 0 auto;
  color: var(--accent-ink);
  font-weight: 800;
}

.segmented-control button[aria-pressed="true"] .segment-selected-mark,
.segmented-control label:has(input:checked) .segment-selected-mark {
  display: inline;
}

.record-type-fieldset {
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.record-type-fieldset legend {
  margin: 0 0 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
}

.record-type-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.record-type-control label {
  cursor: pointer;
}

.record-type-control label:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.compact-segmented {
  width: 100%;
}

.category-filter-layer {
  margin-top: 12px;
}

.category-filter-layer > p {
  margin: 0 0 3px;
  color: var(--ink-soft);
  font-size: 12px;
}

.cashflow-kpi-grid,
.stats-cashflow-grid {
  position: relative;
  z-index: 1;
  display: grid;
  min-width: 0;
  margin: 13px 0 0;
}

.stats-hero-heading {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.stats-hero-heading .section-kicker,
.stats-period-label {
  margin: 0;
}

.stats-period-label {
  color: var(--ink-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.stats-cashflow-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin-top: 9px;
}

.stats-cashflow-grid > div {
  min-width: 0;
}

.cashflow-kpi-grid dt,
.cashflow-kpi-grid dd,
.stats-cashflow-grid dt,
.stats-cashflow-grid dd {
  margin: 0;
}

.stats-cashflow-grid .balance-kpi {
  grid-column: 1 / -1;
  padding-bottom: 13px;
  border-bottom: 1px solid color-mix(in srgb, var(--accent-action) 24%, var(--line));
}

.stats-cashflow-grid dt {
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 650;
}

.stats-cashflow-grid .balance-kpi dd {
  max-width: 100%;
  margin-top: 2px;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
  font-size: clamp(34px, 10.6vw, 46px);
  font-weight: 760;
  line-height: 1.08;
  letter-spacing: -0.028em;
  overflow-wrap: anywhere;
}

.stats-cashflow-grid .income-kpi,
.stats-cashflow-grid .expense-kpi {
  display: grid;
  align-content: start;
  gap: 3px;
  padding: 12px 9px 0 1px;
}

.stats-cashflow-grid .expense-kpi {
  padding-right: 1px;
  padding-left: 13px;
  border-left: 1px solid color-mix(in srgb, var(--accent-action) 20%, var(--line));
}

.stats-cashflow-grid .income-kpi dd,
.stats-cashflow-grid .expense-kpi dd {
  min-width: 0;
  font-size: clamp(14px, 4vw, 17px);
  font-weight: 740;
  line-height: 1.25;
  letter-spacing: -0.018em;
  overflow-wrap: anywhere;
}

.stats-balance-insight {
  position: relative;
  z-index: 1;
  margin: 13px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.45;
}

.cashflow-balance-scale {
  --income-size: 0%;
  --expense-size: 0%;
  position: relative;
  z-index: 1;
  margin-top: 15px;
  padding: 10px 11px 11px;
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  border-radius: 13px;
  background: color-mix(in srgb, var(--surface) 68%, transparent);
}

.cashflow-scale-labels,
.cashflow-scale-plot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2px minmax(0, 1fr);
}

.cashflow-scale-labels {
  gap: 0;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 650;
}

.cashflow-scale-labels span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.cashflow-scale-labels span:last-child {
  grid-column: 3;
  justify-content: flex-end;
  text-align: right;
}

.cashflow-scale-labels i {
  width: 8px;
  height: 8px;
  border-radius: 3px;
}

.cashflow-scale-labels .income-mark {
  background: var(--chart-income);
}

.cashflow-scale-labels .expense-mark {
  background: var(--chart-expense);
}

.cashflow-scale-plot {
  align-items: stretch;
  height: 10px;
}

.cashflow-scale-half {
  display: flex;
  min-width: 0;
  background: color-mix(in srgb, var(--chart-track) 88%, transparent);
}

.cashflow-scale-half i {
  display: block;
  height: 100%;
  transition: width 220ms ease-out;
}

.cashflow-scale-half.income-half {
  justify-content: flex-end;
  border-radius: 5px 0 0 5px;
}

.cashflow-scale-half.income-half i {
  width: var(--income-size);
  border-radius: 4px 0 0 4px;
  background: var(--chart-income);
}

.cashflow-scale-half.expense-half {
  border-radius: 0 5px 5px 0;
}

.cashflow-scale-half.expense-half i {
  width: var(--expense-size);
  border-radius: 0 4px 4px 0;
  background: var(--chart-expense);
}

.cashflow-scale-axis {
  z-index: 1;
  width: 2px;
  background: var(--ink);
}

.cashflow-summary-card {
  min-width: 0;
  padding: 13px 16px 11px 18px;
}

.cashflow-summary-card > p {
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.cashflow-kpi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin-top: 2px;
}

.cashflow-kpi-grid > div {
  min-width: 0;
}

.cashflow-kpi-grid .balance-primary {
  grid-column: 1 / -1;
  padding: 0 2px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--accent-action) 22%, var(--line));
}

.cashflow-kpi-grid .balance-primary dd {
  max-width: 100%;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
  font-size: clamp(29px, 9.2vw, 40px);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  line-height: 1.08;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.cashflow-kpi-grid .income-kpi,
.cashflow-kpi-grid .expense-kpi {
  display: grid;
  align-content: start;
  gap: 1px;
  padding: 7px 7px 1px 2px;
}

.cashflow-kpi-grid .expense-kpi {
  padding-right: 2px;
  padding-left: 10px;
  border-left: 1px solid color-mix(in srgb, var(--accent-action) 18%, var(--line));
}

.cashflow-kpi-grid dt {
  color: var(--ink-faint);
  font-size: 10px;
  font-weight: 600;
}

.cashflow-kpi-grid .income-kpi dd,
.cashflow-kpi-grid .expense-kpi dd {
  min-width: 0;
  color: var(--ink);
  font-size: clamp(12px, 3.7vw, 15px);
  font-weight: 720;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.cashflow-summary-card > .summary-count {
  display: block;
  margin-top: 5px;
  color: var(--ink-faint);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.income-kpi dd,
.record-amount.is-income,
.highest-amount.is-income {
  color: var(--income);
}

.expense-kpi dd,
.record-amount.is-expense,
.highest-amount.is-expense {
  color: var(--expense);
}

.balance-kpi.is-negative dd {
  color: var(--danger);
}

.balance-kpi.is-positive dd {
  color: var(--income);
}

.record-type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-right: 5px;
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.record-type-badge.income {
  color: var(--income);
}

.record-type-badge.expense {
  color: var(--expense);
}

.date-group + .date-group {
  margin-top: 20px;
}

.date-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 4px 8px;
}

.date-group-title h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.date-group-title span {
  color: var(--ink-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.record-list {
  display: grid;
  gap: 9px;
}

.record-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  width: 100%;
  min-height: 68px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 6px;
  background: var(--surface);
  box-shadow: 0 5px 16px rgba(126, 54, 79, 0.035);
  scroll-margin-block: 120px;
  text-align: left;
  transition: border-color 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.record-row:hover {
  border-color: var(--accent);
}

.record-row:active {
  transform: scale(0.992);
}

.record-icon,
.category-icon,
.highest-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  background: var(--surface-soft);
  font-size: 21px;
}

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

.record-copy strong,
.record-copy small {
  display: block;
}

.record-copy strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-copy small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 12px;
}

.record-amount {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.record-trailing,
.highest-trailing {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.record-disclosure {
  color: var(--ink-faint);
  font-size: 21px;
  font-weight: 500;
  line-height: 1;
}

.editable-records .date-group + .date-group {
  margin-top: 16px;
}

.editable-records .date-group-title {
  min-height: 36px;
  margin: 0;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 13px 13px 0 0;
  background: var(--surface-soft);
}

.editable-records .date-group-title h3 {
  color: var(--ink);
}

.editable-records .record-list {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0 0 16px 6px;
  background: var(--surface);
}

.editable-records .record-row {
  min-height: 66px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: background-color 160ms ease, box-shadow 160ms ease;
}

.editable-records .record-row + .record-row {
  border-top: 1px solid var(--line);
}

.editable-records .record-row:hover {
  border-color: transparent;
  background: var(--surface-soft);
}

.editable-records .record-row:active {
  background: var(--surface-strong);
  transform: none;
}

.editable-records .record-row.is-highlighted {
  border-left: 4px solid var(--success);
  background: color-mix(in srgb, var(--surface) 88%, var(--success));
  box-shadow: none;
}

.record-row.is-highlighted {
  border-color: var(--success);
  background: color-mix(in srgb, var(--surface) 88%, var(--success));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 28%, transparent);
  animation: saved-pop 220ms ease-out;
}

.empty-state {
  display: grid;
  justify-items: center;
  padding: 42px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  text-align: center;
}

.empty-illustration {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin-bottom: 14px;
  border-radius: 22px 22px 22px 7px;
  background: var(--surface-strong);
  font-size: 30px;
  transform: rotate(-3deg);
}

.empty-state h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.empty-state p {
  max-width: 26ch;
  margin: 7px 0 17px;
  color: var(--ink-soft);
  font-size: 13px;
}

.compact-empty {
  padding-block: 34px;
  border: 0;
  background: transparent;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-weight: 600;
}

.primary-button {
  background: var(--accent-action);
  box-shadow: 0 9px 24px color-mix(in srgb, var(--accent-action) 24%, transparent);
  color: #fff8fb;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-action-hover);
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button.compact {
  min-height: 44px;
  padding-inline: 13px;
  font-size: 12px;
  white-space: nowrap;
}

.danger-button {
  border-color: color-mix(in srgb, var(--danger) 44%, var(--line));
  background: color-mix(in srgb, var(--surface) 88%, var(--danger));
  color: var(--danger);
}

.amount-section {
  padding: 14px 15px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-action);
  border-radius: 8px 20px 8px 20px;
  background: var(--surface-strong);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent-action) 8%, transparent);
  text-align: left;
}

.amount-section > label {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
}

.field-priority {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid color-mix(in srgb, var(--accent-action) 32%, var(--line));
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 650;
  line-height: 1;
}

.amount-control {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  max-width: 250px;
  margin: 2px 0 0;
}

.amount-control > span {
  margin: 3px 4px 0 0;
  color: var(--ink-soft);
  font-size: clamp(23px, 7vw, 30px);
  font-weight: 700;
}

.amount-control input {
  width: min(100%, 210px);
  min-width: 0;
  padding: 2px 0 3px;
  border: 0;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
  font-size: clamp(32px, 10vw, 42px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
  line-height: 1.15;
  white-space: nowrap;
  text-align: center;
}

.amount-control input:focus-visible {
  outline: none;
  border-bottom-color: transparent;
  box-shadow: inset 0 -4px 0 var(--accent-action);
}

.amount-control input::placeholder {
  color: color-mix(in srgb, var(--ink-soft) 55%, transparent);
}

.amount-control input[aria-invalid="true"] {
  border-bottom-color: var(--danger);
}

.amount-control input[aria-invalid="true"]:focus-visible {
  box-shadow: inset 0 -4px 0 var(--danger);
}

.amount-section .field-help {
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.4;
}

.field-help {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.field-error {
  margin: 7px 0 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
}

.category-fieldset {
  min-width: 0;
  padding: 20px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.category-fieldset legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.category-fieldset > .field-help {
  margin-top: -1px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 10px 8px;
  margin-top: 16px;
}

.category-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-width: 0;
  min-height: 48px;
  padding: 16px 1px 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

.category-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.category-option:has(input:checked) {
  border-color: var(--accent-action);
  background: var(--surface-selected);
}

.category-name {
  min-width: 0;
  white-space: nowrap;
}

.category-option input:checked ~ .category-name {
  color: var(--ink);
  font-weight: 650;
}

.category-option input:checked ~ .category-check {
  display: grid;
}

.category-option:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.category-check {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  place-items: center;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-action);
  color: #fff8fb;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
}

.category-check svg {
  width: 8px;
  height: 8px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.optional-fields {
  padding: 20px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.field-label,
.field-label-row {
  font-size: 13px;
  font-weight: 600;
}

.field-label {
  display: block;
  margin: 17px 0 7px;
}

.field-label-row {
  margin: 17px 0 7px;
}

.field-label-row .field-label {
  margin: 0;
}

.note-meta-row {
  justify-content: space-between;
  margin-top: 0;
}

.field-control {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-soft);
  color: var(--ink);
}

.field-control[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.note-input {
  min-height: 94px;
  resize: vertical;
}

.entry-time-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  max-width: 100%;
  margin-top: 17px;
  padding: 10px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
}

.entry-time-display {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 14px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.entry-time-display svg {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.entry-time-input.field-control {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.entry-time-picker:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.entry-time-picker:has(.entry-time-input[aria-invalid="true"]) {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

#entry-view .field-control,
#entry-view .category-option,
#entry-view .field-error {
  scroll-margin-bottom: 120px;
}

.entry-actions {
  position: sticky;
  bottom: calc(var(--safe-bottom) + 8px);
  z-index: 5;
  margin-top: 18px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow-float);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.save-button {
  width: 100%;
}

#entry-view .entry-danger-zone {
  margin-top: 34px;
  padding: 24px 0 0;
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--danger) 38%, var(--line));
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.entry-danger-zone .full-button {
  margin-top: 16px;
}

.button-loader {
  width: 17px;
  height: 17px;
  margin-left: 9px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.stats-hero {
  text-align: left;
}

.stats-kpi-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 0;
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid color-mix(in srgb, var(--accent-action) 22%, var(--line));
}

.stats-kpi-grid > div {
  min-width: 0;
}

.stats-kpi-grid > div + div {
  padding-left: 16px;
  border-left: 1px solid color-mix(in srgb, var(--accent-action) 22%, var(--line));
}

.stats-kpi-grid dt,
.stats-kpi-grid dd {
  margin: 0;
}

.stats-kpi-grid dt {
  color: var(--ink-soft);
  font-size: 11px;
}

.stats-kpi-grid dd {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 3px;
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.stats-kpi-grid dd b {
  overflow: hidden;
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-kpi-grid dd small {
  color: var(--ink-soft);
  font-size: 11px;
  white-space: nowrap;
}

.ranking-card,
.highest-card {
  padding: 20px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.ranking-card h2,
.highest-card h2,
.highest-card h3 {
  margin-top: 4px;
}

.highest-section {
  margin-top: var(--section-gap);
}

.highest-title-row {
  align-items: flex-end;
  margin-bottom: 10px;
}

.highest-title-row > span {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
  text-align: right;
}

.ranking-type-control {
  margin-top: 14px;
}

.ranking-list .bar-fill {
  background: var(--chart-expense);
}

.ranking-list.is-income .bar-fill {
  background: var(--chart-income);
}

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

.highest-grid .highest-card {
  min-width: 0;
  margin-top: 0;
}

#highest-expense-card {
  border-left: 4px solid var(--chart-expense);
}

#highest-income-card {
  border-left: 4px solid var(--chart-income);
}

.ranking-caption {
  max-width: 13em;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
  text-align: right;
}

.ranking-list {
  display: grid;
  gap: 18px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.rank-row {
  display: grid;
  gap: 8px;
  padding: 2px 0;
  border-radius: 8px;
}

.rank-row:focus-visible {
  outline-offset: 6px;
}

.rank-meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
}

.rank-number {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rank-label {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
}

.rank-label span {
  margin-right: 6px;
}

.rank-value {
  max-width: 46vw;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  overflow-wrap: anywhere;
  text-align: right;
}

.rank-value small {
  margin-left: 4px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 500;
}

.bar-track {
  position: relative;
  height: 9px;
  margin-left: 31px;
  overflow: visible;
  border-radius: 0 5px 5px 0;
  background: var(--chart-track);
}

.bar-fill {
  width: var(--bar-size, 0%);
  height: 100%;
  min-width: 2px;
  border-radius: 0 4px 4px 0;
  background: var(--chart-fill);
  transition: width 220ms ease-out, filter 160ms ease;
}

.rank-row:hover .bar-fill,
.rank-row:focus .bar-fill {
  filter: brightness(1.09);
}

.highest-record {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) minmax(0, auto);
  gap: 11px;
  align-items: center;
  width: 100%;
  min-height: 68px;
  margin-top: 14px;
  padding: 11px 7px 7px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  text-align: left;
  transition: background-color 160ms ease, transform 120ms ease;
}

.highest-record:hover,
.highest-record:focus-visible {
  background: var(--surface-soft);
}

.highest-record:active {
  transform: scale(0.992);
}

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

.highest-copy strong,
.highest-copy small {
  display: block;
}

.highest-copy strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.highest-copy small {
  color: var(--ink-soft);
  font-size: 12px;
}

.highest-amount {
  max-width: 40vw;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  overflow-wrap: anywhere;
  text-align: right;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  width: min(100%, var(--content-max));
  min-height: calc(var(--nav-height) + var(--safe-bottom));
  padding: 10px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  box-shadow: 0 -12px 36px rgba(126, 54, 79, 0.09);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.bottom-nav button {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  min-height: 64px;
  padding: 4px 6px;
  border-radius: 15px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 500;
  transition: color 140ms ease, background-color 140ms ease;
}

.bottom-nav button:active {
  background: var(--surface-soft);
}

.bottom-nav button[aria-current="page"] {
  color: var(--accent-ink);
  font-weight: 700;
}

.bottom-nav button[aria-current="page"]::after {
  content: "";
  position: absolute;
  bottom: 2px;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent-action);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-size: 23px;
  line-height: 1;
}

.nav-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bottom-nav .add-nav {
  min-height: 68px;
  margin-top: 0;
  color: var(--accent-ink);
  font-weight: 700;
}

.bottom-nav .add-nav:active {
  background: transparent;
}

.add-nav-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 3px solid color-mix(in srgb, var(--surface) 94%, transparent);
  border-radius: 17px 17px 17px 7px;
  background: var(--accent-action);
  box-shadow:
    0 9px 22px color-mix(in srgb, var(--accent-action) 28%, transparent),
    inset 0 1px 0 color-mix(in srgb, #ffffff 42%, transparent);
  color: #fff8fb;
  font-size: 26px;
  font-weight: 450;
  line-height: 1;
  transition: filter 140ms ease, box-shadow 140ms ease;
}

.add-nav:active .add-nav-icon {
  filter: brightness(0.94);
  box-shadow:
    0 5px 14px color-mix(in srgb, var(--accent-action) 24%, transparent),
    inset 0 1px 0 color-mix(in srgb, #ffffff 32%, transparent);
}

.app-dialog {
  width: min(calc(100% - 32px), 410px);
  max-height: min(82vh, 640px);
  padding: 0;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 28px 28px 28px 9px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 26px 80px rgba(42, 21, 29, 0.28);
}

.app-dialog::backdrop {
  background: rgba(44, 25, 33, 0.54);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.dialog-card {
  padding: 25px;
}

.dialog-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  border-radius: 16px 16px 16px 5px;
  font-size: 21px;
  font-weight: 700;
}

.dialog-icon.warning {
  background: color-mix(in srgb, var(--surface) 80%, var(--warning));
  color: var(--warning);
}

.dialog-icon.danger {
  background: color-mix(in srgb, var(--surface) 80%, var(--danger));
  color: var(--danger);
}

.dialog-icon.info {
  background: var(--surface-strong);
  color: var(--accent-ink);
}

.dialog-card h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.35;
}

.dialog-card > p {
  margin: 9px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.7;
}

.dialog-list {
  display: grid;
  gap: 9px;
  margin: 14px 0 20px;
  padding-left: 20px;
  color: var(--ink-soft);
  font-size: 13px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.dialog-actions.stacked {
  grid-template-columns: 1fr;
}

.dialog-actions.stacked .secondary-button {
  grid-row: 2;
}

.dialog-card > .primary-button:last-child {
  width: 100%;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 18px);
  z-index: 60;
  width: min(calc(100% - 36px), 410px);
  padding: 13px 16px;
  border: 1px solid color-mix(in srgb, var(--success) 42%, var(--line));
  border-radius: 15px;
  background: color-mix(in srgb, var(--surface) 90%, var(--success));
  box-shadow: var(--shadow-float);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  transform: translateX(-50%);
  animation: toast-in 200ms ease-out;
}

.toast[data-kind="error"] {
  border-color: color-mix(in srgb, var(--danger) 52%, var(--line));
  background: color-mix(in srgb, var(--surface) 90%, var(--danger));
  color: var(--danger);
}

.toast[data-kind="warning"] {
  border-color: color-mix(in srgb, var(--warning) 52%, var(--line));
  background: color-mix(in srgb, var(--surface) 90%, var(--warning));
  color: var(--warning);
}

.chart-tooltip {
  position: fixed;
  z-index: 70;
  display: grid;
  min-width: 120px;
  max-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--ink);
  box-shadow: var(--shadow-float);
  color: var(--bg);
  pointer-events: none;
}

.chart-tooltip strong {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip span {
  margin-top: 2px;
  opacity: 0.78;
  font-size: 11px;
}

.noscript-message {
  position: fixed;
  inset: 20px;
  z-index: 100;
  padding: 20px;
  border: 2px solid var(--danger);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
}

.app-shell.is-storage-blocked .bottom-nav .add-nav,
.app-shell.is-storage-blocked [data-action="go-add"] {
  pointer-events: none;
  opacity: 0.45;
}

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

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
}

@keyframes saved-pop {
  0% { transform: scale(0.985); }
  100% { transform: scale(1); }
}

@media (min-width: 560px) {
  body {
    padding-block: 24px;
  }

  .app-shell {
    min-height: calc(100dvh - 48px);
    border: 1px solid var(--line);
    border-radius: 32px;
    box-shadow: var(--shadow-float);
  }

  .bottom-nav {
    bottom: 24px;
    border: 1px solid var(--line);
    border-radius: 0 0 32px 32px;
  }
}

@media (max-width: 359px) {
  .app-header,
  .view {
    padding-inline: 12px;
  }

  .intro-card,
  .storage-alert {
    margin-inline: 12px;
  }

  .total-card,
  .stats-hero {
    padding-inline: 19px;
  }

  .cashflow-summary-card {
    padding-inline: 14px;
  }

  .total-card strong,
  .stats-hero > strong {
    font-size: clamp(30px, 10.2vw, 38px);
  }

  .amount-control input {
    font-size: clamp(31px, 10vw, 38px);
  }

  .category-fieldset {
    padding-inline: 6px;
  }

  .category-grid {
    column-gap: 3px;
  }

  .stats-kpi-grid {
    grid-template-columns: 1fr;
  }

  .stats-kpi-grid > div + div {
    margin-top: 10px;
    padding: 10px 0 0;
    border-top: 1px solid color-mix(in srgb, var(--accent-action) 22%, var(--line));
    border-left: 0;
  }

  .ranking-card > .section-title-row,
  .highest-title-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .ranking-caption,
  .highest-title-row > span {
    max-width: none;
    text-align: left;
  }

  .record-row {
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 8px;
    padding-inline: 9px;
  }

  .record-icon {
    width: 42px;
    height: 42px;
  }

  .record-amount {
    font-size: 13px;
  }

  .dialog-card {
    padding: 21px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app-header {
    padding-top: 8px;
  }

  .entry-actions {
    position: static;
  }

  .bottom-nav {
    min-height: calc(56px + var(--safe-bottom));
  }
}

@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;
  }
}

@media (forced-colors: active) {
  .pwa-install-shortcut,
  .pwa-install-step-number {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  .brand-mark,
  .add-nav-icon,
  .primary-button,
  .category-check,
  .bar-fill,
  .cashflow-scale-labels i,
  .cashflow-scale-half i {
    border: 2px solid ButtonText;
    background: Highlight;
    color: HighlightText;
  }

  .amount-control input:focus-visible {
    outline: 3px solid Highlight;
    outline-offset: 3px;
    border-bottom-color: CanvasText;
    box-shadow: none;
  }

  .entry-time-picker:focus-within {
    outline-color: Highlight;
  }

  .entry-time-picker:has(.entry-time-input[aria-invalid="true"]) {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }

  .bar-track,
  .cashflow-balance-scale,
  .cashflow-scale-half {
    border: 1px solid CanvasText;
  }

  .cashflow-scale-axis {
    background: CanvasText;
  }

  #highest-expense-card,
  #highest-income-card {
    border-left-color: Highlight;
  }

  .record-row.is-highlighted,
  .filter-chip[aria-pressed="true"],
  .segmented-control button[aria-pressed="true"],
  .segmented-control label:has(input:checked),
  .category-option:has(input:checked) {
    outline: 3px solid Highlight;
  }

  .record-type-badge {
    border-color: CanvasText;
    color: CanvasText;
  }

  .month-summary-card,
  .amount-hero,
  .stats-hero {
    border-left-color: Highlight;
  }

  .editable-records .date-group-title,
  .editable-records .record-list {
    border-color: CanvasText;
  }
}

/* V1.0.1 authentication, account and legacy-ledger views */

input[type="password"] {
  cursor: text;
}

.account-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 72px;
  min-height: 44px;
  max-width: 42%;
  padding: 8px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
}

.account-button > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--ink-faint);
  box-shadow: 0 0 0 1px var(--ink-faint);
}

.account-button.is-authenticated .account-dot {
  background: var(--success);
  box-shadow: 0 0 0 1px var(--success);
}

.guest-view,
.auth-view,
.account-view,
.legacy-view {
  padding-top: 4px;
}

.guest-hero {
  position: relative;
  overflow: hidden;
  padding: 30px 24px 26px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 15px 34px 15px 34px;
  background:
    radial-gradient(circle at 92% 8%, color-mix(in srgb, var(--surface-selected) 72%, transparent) 0 55px, transparent 57px),
    var(--surface-strong);
  box-shadow: var(--shadow-soft);
}

.guest-hero h1 {
  max-width: 11ch;
  margin: 5px 0 12px;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: clamp(30px, 9vw, 40px);
  line-height: 1.13;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.guest-hero > p:not(.eyebrow) {
  max-width: 34ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.75;
}

.guest-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.boundary-card,
.legacy-entry-card,
.account-boundary-card,
.account-section,
.entry-danger-zone,
.danger-zone,
.legacy-danger-zone {
  margin-top: 18px;
  padding: 20px 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.boundary-card h2,
.legacy-entry-card h2,
.account-boundary-card h2,
.account-section h2,
.entry-danger-zone h2,
.danger-zone h2,
.legacy-danger-zone h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.boundary-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding-left: 21px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.65;
}

.boundary-list strong {
  color: var(--ink);
}

.legacy-entry-card,
.account-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
}

.legacy-entry-card p,
.account-section p,
.entry-danger-zone p:not(.section-kicker),
.danger-zone p,
.legacy-danger-zone p {
  margin: 5px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.6;
}

.auth-card {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 16px 28px 16px 28px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-soft);
}

.auth-tab {
  min-height: 44px;
  padding: 8px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.auth-tab[aria-selected="true"] {
  background: var(--surface);
  box-shadow: 0 3px 12px color-mix(in srgb, var(--ink) 9%, transparent);
  color: var(--accent-ink);
}

.auth-panel {
  padding-top: 20px;
}

.auth-label {
  display: block;
  margin: 15px 0 7px;
  font-size: 13px;
  font-weight: 600;
}

.auth-panel .auth-label:first-of-type,
.dialog-card .auth-label {
  margin-top: 0;
}

.auth-input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 16px;
}

.auth-input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.password-control {
  position: relative;
  display: flex;
  align-items: stretch;
}

.password-control .auth-input {
  padding-right: 68px;
}

.password-control > button {
  position: absolute;
  top: 2px;
  right: 2px;
  bottom: 2px;
  min-width: 58px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
}

.form-summary {
  margin-bottom: 13px;
  padding: 11px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 48%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 92%, var(--danger));
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
}

.password-help-copy {
  margin: 13px 2px 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.password-help-copy strong {
  margin-right: 4px;
  color: var(--ink);
}

.auth-submit,
.full-button,
.account-form-button {
  width: 100%;
  margin-top: 18px;
}

.profile-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 13px;
  align-items: center;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 14px 27px 14px 27px;
  background: var(--surface-strong);
  box-shadow: var(--shadow-soft);
}

.profile-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 18px 18px 18px 6px;
  background: var(--accent-action);
  color: #fff8fb;
  font-family: ui-rounded, "SF Pro Rounded", sans-serif;
  font-size: 22px;
  font-weight: 700;
}

.profile-card h2,
.profile-card p {
  margin: 0;
}

.profile-card h2 {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-card p {
  color: var(--ink-soft);
  font-size: 11px;
}

.account-boundary-card dl {
  display: grid;
  gap: 0;
  margin: 13px 0 0;
}

.account-boundary-card dl > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.account-boundary-card dt {
  color: var(--ink-soft);
}

.account-boundary-card dd {
  margin: 0;
  font-weight: 650;
}

.account-boundary-card > p {
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.6;
}

.password-section {
  display: block;
}

.password-section form {
  margin-top: 16px;
  padding-top: 1px;
  border-top: 1px solid var(--line);
}

.entry-danger-zone,
.danger-zone,
.legacy-danger-zone {
  border-color: color-mix(in srgb, var(--danger) 34%, var(--line));
  background: color-mix(in srgb, var(--surface) 96%, var(--danger));
}

.entry-danger-zone h2,
.danger-zone h2,
.legacy-danger-zone h2 {
  color: var(--danger);
}

.legacy-warning {
  padding: 15px;
  border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--line));
  border-left: 5px solid var(--warning);
  border-radius: 6px 17px 17px 6px;
  background: color-mix(in srgb, var(--surface) 92%, var(--warning));
}

.legacy-warning strong {
  font-size: 13px;
}

.legacy-warning p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.legacy-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 14px 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.legacy-tabs button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.legacy-tabs button[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--accent-ink);
}

.legacy-records-list {
  margin-top: 20px;
}

.record-row.is-read-only {
  cursor: default;
}

.record-row.is-read-only:active {
  transform: none;
}

.legacy-danger-zone {
  margin-top: 24px;
}

.app-shell.is-secondary-view {
  padding-bottom: calc(28px + var(--safe-bottom));
}

.app-shell.is-details-view .app-header,
.app-shell.is-details-view .intro-card {
  display: none;
}

.app-shell.is-details-view #details-view {
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

.app-shell.is-entry-view {
  padding-bottom: calc(20px + var(--safe-bottom));
}

.app-shell.is-entry-view .app-header {
  display: none;
}

.app-shell.is-entry-view .storage-alert {
  margin-top: calc(8px + env(safe-area-inset-top, 0px));
}

.app-shell.is-entry-view #entry-view {
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(30px + var(--safe-bottom));
}

.app-shell.is-entry-view .toast {
  bottom: calc(18px + var(--safe-bottom));
}

.dialog-card .password-control {
  margin-top: 7px;
}

@media (max-width: 359px) {
  .guest-actions {
    grid-template-columns: 1fr;
  }

  .guest-hero {
    padding-inline: 19px;
  }

  .auth-card {
    padding-inline: 13px;
  }

  .legacy-entry-card,
  .account-section {
    align-items: flex-start;
    flex-direction: column;
  }

  .legacy-entry-card .secondary-button,
  .account-section .secondary-button {
    width: 100%;
  }
}

@media (forced-colors: active) {
  .profile-mark,
  .account-dot,
  .auth-tab[aria-selected="true"],
  .legacy-tabs button[aria-pressed="true"] {
    border: 2px solid ButtonText;
    background: Highlight;
    color: HighlightText;
  }

  .legacy-warning,
  .entry-danger-zone,
  .danger-zone,
  .legacy-danger-zone {
    border-color: CanvasText;
  }
}

/* V1.1 multi-ledger, collaboration and chat-entry views */

.active-ledger-switcher {
  width: calc(100% - 32px);
  margin: 2px 16px 12px;
}

.ledger-spine-card {
  --ledger-spine-color: var(--accent-action);
  position: relative;
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  gap: 13px;
  align-items: center;
  min-width: 0;
  min-height: 64px;
  padding: 9px 13px 9px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px 19px 19px 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--ink);
  text-align: left;
}

.ledger-spine {
  align-self: stretch;
  width: 9px;
  min-height: 44px;
  border-right: 1px solid color-mix(in srgb, var(--ledger-spine-color) 60%, var(--line));
  background: var(--ledger-spine-color);
}

.ledger-switcher-copy,
.ledger-switcher-copy strong,
.ledger-switcher-copy small {
  display: block;
  min-width: 0;
}

.ledger-switcher-copy strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-switcher-copy small {
  margin-top: 1px;
  color: var(--ink-soft);
  font-size: 11px;
}

.ledger-switcher-action {
  display: grid;
  justify-items: end;
  gap: 1px;
  color: var(--accent-ink);
  white-space: nowrap;
}

.ledger-switcher-action strong,
.ledger-switcher-action small {
  display: block;
}

.ledger-switcher-action strong {
  font-size: 11px;
  font-weight: 800;
}

.ledger-switcher-action small {
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 650;
}

.entry-mode-switcher {
  margin-bottom: 16px;
}

.ledger-primary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}

.ledger-shelf + .ledger-shelf {
  margin-top: 24px;
}

.ledger-list {
  display: grid;
  gap: 10px;
}

.ledger-list-empty,
.ledger-limit-note,
.privacy-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.ledger-list-empty {
  padding: 20px 16px;
  border: 1px dashed var(--line);
  border-radius: 15px;
  background: var(--surface);
  text-align: center;
}

.ledger-limit-note,
.privacy-note {
  margin-top: 18px;
  padding: 13px 14px;
  border-left: 4px solid var(--warning);
  border-radius: 6px 14px 14px 6px;
  background: color-mix(in srgb, var(--surface) 92%, var(--warning));
}

.ledger-row {
  width: 100%;
  transition: border-color 160ms ease, transform 160ms ease, background-color 160ms ease;
}

.ledger-row:hover {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.ledger-row:active {
  transform: scale(0.992);
}

.ledger-row[aria-current="true"] {
  border-color: var(--accent-action);
  box-shadow: inset 0 0 0 1px var(--accent-action), var(--shadow-soft);
}

.ledger-row-status {
  display: grid;
  justify-items: end;
  gap: 2px;
  color: var(--ink-soft);
  font-size: 11px;
  white-space: nowrap;
}

.ledger-row-status strong {
  color: var(--accent-ink);
  font-size: 11px;
}

.ledger-form-card,
.join-code-card,
.chat-compose-card,
.ledger-settings-card,
.share-card,
.members-card,
.member-leave-zone,
.ledger-delete-zone {
  padding: 20px 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.ledger-editor-form .ledger-form-card > .auth-label:first-child,
.join-code-card .auth-label:first-child {
  margin-top: 0;
}

.currency-fieldset {
  min-width: 0;
  margin: 22px 0 0;
  padding: 18px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.currency-fieldset legend {
  padding: 0;
  font-size: 14px;
  font-weight: 700;
}

.currency-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

.currency-grid label {
  position: relative;
  min-width: 0;
  cursor: pointer;
}

.currency-grid input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.currency-grid label > span {
  position: relative;
  display: grid;
  grid-template-columns: minmax(38px, auto) minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  min-height: 76px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 15px 15px 15px 5px;
  background: var(--surface-soft);
}

.currency-grid b {
  grid-row: 1 / 3;
  overflow-wrap: anywhere;
  color: var(--accent-ink);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.currency-grid strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.currency-grid small {
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.currency-grid i {
  position: absolute;
  top: 6px;
  right: 6px;
  display: none;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-action);
  color: #fff8fb;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
}

.currency-grid input:checked + span {
  border-color: var(--accent-action);
  background: var(--surface-selected);
  box-shadow: inset 0 0 0 1px var(--accent-action);
}

.currency-grid input:checked + span i {
  display: grid;
}

.currency-grid input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.currency-grid input:disabled + span {
  cursor: not-allowed;
  opacity: 0.58;
}

.invite-code-input {
  width: 100%;
  min-height: 74px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 17px 17px 17px 6px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: clamp(34px, 12vw, 48px);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.22em;
  text-align: center;
}

.invite-code-input::placeholder {
  color: color-mix(in srgb, var(--ink-faint) 45%, transparent);
}

.invite-code-input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.attempts-note {
  margin: 10px 0 0;
  color: var(--warning);
  font-size: 12px;
  font-weight: 650;
}

.ledger-identity-card {
  grid-template-columns: 9px minmax(0, 1fr) auto;
  min-height: 82px;
  padding-right: 15px;
}

.ledger-identity-card h2,
.ledger-identity-card p {
  margin: 0;
}

.ledger-identity-card h2 {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-identity-card p {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}

.role-badge,
.member-role {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.ledger-settings-card,
.share-card,
.members-card,
.member-leave-zone,
.ledger-delete-zone {
  margin-top: 18px;
}

.ledger-settings-card > .section-title-row,
.share-card > .section-title-row,
.members-card > .section-title-row {
  align-items: center;
}

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

.compact-currency-grid label > span {
  grid-template-columns: 1fr;
  grid-template-rows: auto auto;
  justify-items: center;
  min-height: 68px;
  text-align: center;
}

.compact-currency-grid b {
  grid-row: auto;
  font-size: 13px;
}

.compact-currency-grid strong {
  font-size: 10px;
}

.currency-locked-note {
  margin: 12px 0 0;
  padding: 11px 12px;
  border-left: 4px solid var(--warning);
  border-radius: 5px 12px 12px 5px;
  background: color-mix(in srgb, var(--surface) 90%, var(--warning));
  color: var(--ink-soft);
  font-size: 11px;
}

.invite-card {
  margin-top: 12px;
  padding: 17px;
  border: 1px solid color-mix(in srgb, var(--accent-action) 35%, var(--line));
  border-radius: 16px 16px 16px 5px;
  background: var(--surface-soft);
  text-align: center;
}

.invite-card > p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.invite-code {
  display: block;
  margin: 8px 0 2px;
  color: var(--ink);
  font-size: clamp(38px, 13vw, 52px);
  font-weight: 780;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.16em;
  line-height: 1.15;
}

.invite-countdown {
  color: var(--warning) !important;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.invite-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.invite-actions button {
  min-width: 0;
  min-height: 44px;
  padding-inline: 8px;
  font-size: 12px;
}

.invite-risk-note,
.members-permission-note,
.chat-submit-actions p {
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.65;
}

.member-list,
.chat-item-list {
  display: grid;
  gap: 0;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.member-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  min-height: 62px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.member-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px 14px 14px 5px;
  background: var(--surface-strong);
  color: var(--accent-ink);
  font-weight: 750;
}

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

.member-copy strong,
.member-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-copy strong {
  font-size: 13px;
}

.member-copy small {
  color: var(--ink-soft);
  font-size: 10px;
}

.member-row-action {
  min-width: 44px;
  min-height: 44px;
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--danger) 36%, var(--line));
  border-radius: 12px;
  background: transparent;
  color: var(--danger);
  font-size: 11px;
  font-weight: 650;
}

.member-leave-zone,
.ledger-delete-zone {
  border-color: color-mix(in srgb, var(--danger) 34%, var(--line));
  background: color-mix(in srgb, var(--surface) 96%, var(--danger));
}

.member-leave-zone h2,
.ledger-delete-zone h2 {
  margin: 0;
  color: var(--danger);
  font-size: 16px;
}

.member-leave-zone p,
.ledger-delete-zone p {
  margin: 5px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.chat-compose-card {
  border-left: 5px solid var(--accent-action);
  border-radius: 8px 25px 8px 25px;
  background: var(--surface-strong);
}

.chat-compose-card .note-meta-row {
  margin-top: 0;
}

.chat-input {
  min-height: 148px;
  background: var(--surface);
  line-height: 1.7;
  resize: vertical;
}

.chat-examples {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.chat-examples p {
  margin: 3px 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.chat-examples strong {
  color: var(--ink);
}

.chat-submit-actions {
  display: grid;
}

.chat-submit-actions p {
  margin: 7px 5px 0;
  text-align: center;
}

.chat-results {
  margin-top: 24px;
}

.chat-results > .section-title-row {
  align-items: flex-start;
}

.chat-item-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 6px;
  background: var(--surface);
}

.chat-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 70px;
  padding: 11px 12px;
  border-left: 4px solid var(--ink-faint);
}

.chat-item + .chat-item {
  border-top: 1px solid var(--line);
}

.chat-item[data-status="saving"] { border-left-color: var(--warning); }
.chat-item[data-status="saved"] { border-left-color: var(--success); }
.chat-item[data-status="failed"] { border-left-color: var(--danger); }
.chat-item[data-status="unsent"] { border-left-color: var(--ink-faint); }

.chat-item-copy {
  min-width: 0;
}

.chat-item-copy strong,
.chat-item-copy small {
  display: block;
}

.chat-item-copy strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-copy small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.45;
}

.chat-item-state {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.chat-status-label {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.chat-item[data-status="saving"] .chat-status-label { color: var(--warning); }
.chat-item[data-status="saved"] .chat-status-label { color: var(--success); }
.chat-item[data-status="failed"] .chat-status-label { color: var(--danger); }
.chat-item[data-status="unsent"] .chat-status-label { color: var(--ink-soft); }

.chat-retry-button {
  min-width: 44px;
  min-height: 44px;
  padding: 7px 9px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
}

.record-row.is-read-only .record-disclosure {
  display: none;
}

.record-readonly-label {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-left: 5px;
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 700;
}

.app-shell.is-ledgers-view,
.app-shell.is-ledger-form-view,
.app-shell.is-ledger-join-view,
.app-shell.is-ledger-members-view,
.app-shell.is-chat-view {
  padding-bottom: calc(28px + var(--safe-bottom));
}

.app-shell.is-ledgers-view .app-header,
.app-shell.is-ledger-form-view .app-header,
.app-shell.is-ledger-join-view .app-header,
.app-shell.is-ledger-members-view .app-header,
.app-shell.is-chat-view .app-header,
.app-shell.is-ledgers-view > .active-ledger-switcher,
.app-shell.is-ledger-form-view > .active-ledger-switcher,
.app-shell.is-ledger-join-view > .active-ledger-switcher,
.app-shell.is-ledger-members-view > .active-ledger-switcher {
  display: none;
}

.app-shell.is-ledgers-view .ledgers-view,
.app-shell.is-ledger-form-view .ledger-form-view,
.app-shell.is-ledger-join-view .ledger-join-view,
.app-shell.is-ledger-members-view .ledger-members-view,
.app-shell.is-chat-view .chat-view {
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
}

@media (max-width: 359px) {
  .active-ledger-switcher {
    width: calc(100% - 24px);
    margin-inline: 12px;
  }

  .ledger-primary-actions {
    grid-template-columns: 1fr;
  }

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

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

  .currency-grid label > span {
    min-height: 68px;
  }

  .invite-actions {
    grid-template-columns: 1fr;
  }

  .invite-actions button {
    width: 100%;
  }

  .ledger-identity-card {
    grid-template-columns: 9px minmax(0, 1fr);
  }

  .ledger-identity-card .role-badge {
    grid-column: 2;
    justify-self: start;
  }

  .chat-results > .section-title-row {
    flex-direction: column;
    gap: 4px;
  }
}

@media (forced-colors: active) {
  .ledger-spine,
  .currency-grid input:checked + span i {
    border: 2px solid ButtonText;
    background: Highlight;
    color: HighlightText;
  }

  .ledger-row[aria-current="true"],
  .currency-grid input:checked + span,
  .chat-item[data-status] {
    outline: 3px solid Highlight;
    outline-offset: 1px;
  }

  .currency-grid input:focus-visible + span {
    outline-color: Highlight;
  }

  .ledger-limit-note,
  .privacy-note,
  .currency-locked-note,
  .member-leave-zone,
  .ledger-delete-zone,
  .chat-compose-card {
    border-color: CanvasText;
  }

  .role-badge,
  .member-role,
  .chat-status-label,
  .record-readonly-label {
    border-color: CanvasText;
    color: CanvasText;
  }
}

.highest-record-host {
  min-width: 0;
}

.highest-record.is-read-only {
  cursor: default;
}

.view-heading h1[tabindex="-1"]:focus:not([data-route-focus]),
.entry-header h1[tabindex="-1"]:focus:not([data-route-focus]) {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
  border-radius: 4px;
}

.view-heading h1[data-route-focus]:focus,
.entry-header h1[data-route-focus]:focus,
h1[tabindex="-1"][data-route-focus]:focus {
  outline: none;
}

.app-dialog {
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
  overflow: hidden;
}

.app-dialog .dialog-card {
  max-height: inherit;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(25px + env(safe-area-inset-bottom, 0px));
  scrollbar-gutter: stable;
}

/* V1.2 primary chat tab and ledger-bookmark navigation */
.bottom-nav {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 4px;
  padding: 5px 8px calc(2px + var(--safe-bottom));
}

.bottom-nav button,
.bottom-nav .add-nav {
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 3px 2px 1px;
  border: 1px solid transparent;
  border-radius: 14px 14px 8px 8px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 600;
  transition: color 140ms ease, background-color 140ms ease, transform 140ms ease;
}

.bottom-nav button[aria-current="page"] {
  border-color: color-mix(in srgb, var(--accent-action) 28%, var(--line));
  background: var(--surface-strong);
  color: var(--accent-ink);
  box-shadow: 0 -4px 14px color-mix(in srgb, var(--accent-action) 10%, transparent);
  transform: translateY(-3px);
}

.bottom-nav button[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 3px;
  width: 22px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent-action);
}

.bottom-nav button[aria-current="page"]::after {
  display: none;
}

.bottom-nav .nav-icon,
.bottom-nav .add-nav .nav-icon {
  width: 23px;
  height: 23px;
}

.bottom-nav .nav-icon svg,
.bottom-nav .add-nav .nav-icon svg {
  width: 21px;
  height: 21px;
  stroke-width: 1.9;
}

.bottom-nav .add-nav .nav-icon {
  border: 1px solid currentColor;
  border-radius: 9px 9px 9px 4px;
}

.bottom-nav button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.app-shell.is-chat-view {
  min-height: 100dvh;
  padding-bottom: calc(var(--safe-bottom) + 18px);
}

.app-shell.is-chat-view .bottom-nav {
  display: none;
}

.app-shell.is-entry-view:not(.is-secondary-view) {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 18px);
}

.app-shell.is-entry-view:not(.is-secondary-view) #entry-view {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px);
}

.app-shell.is-chat-view .app-header {
  display: none;
}

.app-shell.is-chat-view .chat-view {
  display: grid;
  gap: 22px;
  min-height: calc(100dvh - 220px);
  padding-top: 0;
}

.chat-page-heading {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: calc(64px + env(safe-area-inset-top, 0px));
  padding: calc(8px + env(safe-area-inset-top, 0px)) 4px 8px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.chat-page-heading .eyebrow {
  display: none;
}

.chat-page-heading h1 {
  grid-column: 2;
  margin: 0;
  font-size: clamp(20px, 6vw, 25px);
  line-height: 1.15;
  text-align: center;
}

.chat-private-badge {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.chat-assistant-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px 12px 12px 4px;
  background: var(--accent-action);
  color: #fff8fb;
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", sans-serif;
  font-size: 14px;
  font-weight: 800;
}

.chat-thread {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: var(--chat-thread-min-height, calc(100dvh - 182px - var(--safe-bottom)));
  padding: 14px 12px 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface-soft);
  overflow: hidden;
}

.chat-thread.is-empty {
  display: flex;
  flex-direction: column;
}

.chat-thread:not(.is-empty) {
  align-content: start;
}

.chat-history-status {
  margin: 4px 0;
  color: var(--ink-soft);
  font-size: 11px;
  text-align: center;
}

.chat-empty {
  display: grid;
  align-self: stretch;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  margin-top: 0;
  margin-bottom: auto;
  padding: 12px 0 2px;
  text-align: left;
}

.chat-empty .chat-message {
  width: fit-content;
  max-width: min(100%, 330px);
}

.chat-thread.is-empty .chat-item-list:empty {
  display: none;
}

.chat-item-list {
  display: grid;
  gap: 6px;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.chat-turn {
  display: grid;
  gap: 6px;
  padding: 5px 0 9px;
}

.chat-turn:last-child {
  scroll-margin-bottom: calc(170px + var(--safe-bottom));
}

.chat-message {
  display: grid;
  grid-template-columns: 34px minmax(0, auto);
  gap: 8px;
  align-items: end;
  max-width: 88%;
}

.chat-message.is-user {
  grid-template-columns: minmax(0, auto) 34px;
  justify-self: end;
}

.chat-user-avatar.avatar-swatch {
  width: 34px;
  height: 34px;
  border-radius: 12px 12px 4px 12px;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--ink) 8%, transparent);
  font-size: 13px;
  line-height: 1;
}

.chat-message.is-assistant {
  width: fit-content;
  justify-self: start;
}

.chat-message.is-assistant .chat-bubble {
  width: fit-content;
  max-width: 100%;
}

.chat-bubble {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 5px 16px color-mix(in srgb, var(--ink) 6%, transparent);
}

.chat-message.is-user .chat-bubble {
  border-color: color-mix(in srgb, var(--accent-action) 34%, var(--line));
  border-radius: 16px 16px 5px 16px;
  background: color-mix(in srgb, var(--surface) 76%, var(--accent-soft));
}

.chat-message.is-assistant .chat-bubble {
  border-radius: 16px 16px 16px 5px;
}

.chat-bubble p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-bubble-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 8px;
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 9px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.chat-bubble-meta .is-error,
.chat-turn[data-status="failed"] .chat-bubble-meta {
  color: var(--danger);
  font-weight: 700;
}

.chat-record-receipt {
  display: grid;
  gap: 3px;
  width: fit-content;
  max-width: min(100%, 68vw);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.chat-record-receipt-heading {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 8px;
}

.chat-record-receipt-type {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 750;
}

.chat-record-receipt-heading strong {
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chat-record-receipt-detail {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  min-width: 0;
}

.chat-record-receipt-summary {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: normal;
}

.chat-record-receipt-summary time {
  white-space: nowrap;
}

.chat-record-receipt-action {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  margin-block: -6px;
  padding: 8px 0 8px 4px;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 800;
  text-align: right;
}

.chat-record-deleted {
  display: inline-flex;
  margin-top: 6px;
  padding: 2px 6px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 700;
}

.chat-turn-action {
  justify-self: end;
  min-width: 44px;
  min-height: 44px;
  padding: 7px 11px;
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: var(--surface);
  color: var(--danger);
  font-size: 11px;
  font-weight: 750;
}

.chat-form {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  display: grid;
  gap: 4px;
  width: min(100%, var(--content-max));
  padding: 7px 10px calc(7px + var(--safe-bottom));
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: color-mix(in srgb, var(--surface-soft) 88%, var(--surface));
  box-shadow: 0 -1px 0 color-mix(in srgb, var(--line) 72%, transparent), 0 -6px 18px color-mix(in srgb, var(--ink) 7%, transparent);
  transform: translate3d(-50%, 0, 0);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  will-change: transform;
}

.app-shell.is-chat-view .chat-view {
  padding-bottom: var(--chat-view-bottom-padding, calc(104px + var(--safe-bottom)));
}

.app-shell.is-chat-keyboard-open .chat-view {
  padding-bottom: var(--chat-view-bottom-padding, calc(104px + var(--chat-keyboard-inset)));
}

.app-shell.is-chat-keyboard-open .chat-thread {
  min-height: max(280px, var(--chat-thread-min-height, calc(100dvh - 182px - var(--safe-bottom) - var(--chat-keyboard-inset))));
}

.app-shell.is-chat-keyboard-open .chat-form {
  padding: 6px 8px;
  transform: translate3d(-50%, calc(-1 * var(--chat-keyboard-inset)), 0);
}

.app-shell.is-ios-safari.is-chat-keyboard-open .chat-form {
  position: absolute;
  top: var(--chat-safari-composer-top);
  bottom: auto;
  padding: 5px 8px;
  box-shadow: 0 -1px 0 color-mix(in srgb, var(--line) 72%, transparent);
  transform: translate3d(-50%, 0, 0);
}

.app-shell.is-ios.is-chat-keyboard-open .chat-composer-meta {
  display: none;
}

.app-shell.is-ios.is-chat-keyboard-open .chat-composer {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.is-ios.is-chat-keyboard-open .chat-send-button {
  display: none;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.chat-input {
  width: 100%;
  min-height: 44px;
  max-height: 132px;
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--line) 88%, var(--ink-faint));
  border-radius: 9px;
  background: var(--surface);
  box-shadow: inset 0 1px 2px color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--ink);
  font: inherit;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}

.chat-send-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  min-width: 60px;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--accent-action);
  color: #fff8fb;
  font-size: 12px;
  font-weight: 800;
}

.chat-send-button svg {
  display: none;
}

.chat-send-button:disabled {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-faint);
}

.chat-composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-inline: 3px;
  color: var(--ink-soft);
  font-size: 9px;
}

.chat-composer-meta p {
  margin: 0;
  line-height: 1.45;
}

.chat-composer-meta span {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 359px) {
  .bottom-nav {
    gap: 1px;
    padding-inline: 4px;
  }

  .bottom-nav button,
  .bottom-nav .add-nav {
    padding-inline: 0;
    font-size: 9px;
  }

  .chat-thread {
    padding-inline: 8px;
  }

  .chat-message {
    max-width: 94%;
  }

  .chat-send-button {
    min-width: 56px;
    grid-template-columns: minmax(0, 1fr);
    padding-inline: 9px;
  }

  .chat-send-button span {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
  }

  .chat-composer-meta p {
    max-width: 220px;
  }
}

@media (forced-colors: active) {
  .bottom-nav button[aria-current="page"],
  .chat-page-heading,
  .chat-bubble,
  .chat-record-receipt-action,
  .chat-thread,
  .chat-form {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  .bottom-nav button[aria-current="page"] {
    outline: 3px solid Highlight;
    outline-offset: -3px;
  }

  .bottom-nav button[aria-current="page"]::before,
  .chat-assistant-mark {
    background: Highlight;
    color: HighlightText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bottom-nav button,
  .chat-message {
    transition: none;
  }

  .bottom-nav button[aria-current="page"] {
    transform: none;
  }
}

/* Profile home */

.app-shell.is-profile-view .account-button,
.app-shell.is-account-view .account-button {
  display: none;
}

.profile-home-view,
#my-authenticated {
  gap: 16px;
}

#my-authenticated {
  display: grid;
}

.my-identity-card,
.my-growth-card,
.annual-ledger-card,
.my-guest-card,
.pwa-install-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.my-identity-card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 13px;
  align-items: center;
  min-height: 112px;
  padding: 18px 14px 18px 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at 14% 22%, color-mix(in srgb, var(--surface-selected) 52%, transparent) 0 34px, transparent 35px),
    linear-gradient(135deg, var(--surface) 46%, var(--surface-soft));
}

.my-identity-card::after {
  position: absolute;
  right: 54px;
  bottom: -22px;
  width: 72px;
  height: 48px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: 50%;
  content: "";
  transform: rotate(-14deg);
  pointer-events: none;
}

.my-avatar {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border: 2px solid color-mix(in srgb, var(--surface) 72%, transparent);
  border-radius: 46% 54% 52% 48% / 52% 45% 55% 48%;
  background: linear-gradient(145deg, var(--surface-selected), var(--accent));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent-action) 20%, transparent);
  color: var(--ink);
  font-size: 27px;
  font-weight: 850;
  line-height: 1;
}

.my-avatar::after {
  position: absolute;
  top: -7px;
  right: 4px;
  width: 19px;
  height: 11px;
  border-radius: 100% 0 100% 0;
  background: var(--income);
  content: "";
  transform: rotate(-20deg);
}

.my-avatar[data-variant="1"] { border-radius: 54% 46% 45% 55% / 46% 54% 48% 52%; }
.my-avatar[data-variant="2"] { background: linear-gradient(155deg, var(--surface-strong), var(--accent-action)); }
.my-avatar[data-variant="3"] { border-radius: 50% 50% 43% 57% / 55% 44% 56% 45%; background: linear-gradient(135deg, var(--surface-selected), var(--accent-action)); }

.my-identity-copy {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.my-identity-copy h2,
.my-identity-copy p {
  margin: 0;
}

.my-identity-copy h2 {
  overflow: hidden;
  font-size: clamp(20px, 6vw, 27px);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-identity-copy > p:last-child {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 11px;
}

.my-settings-link {
  position: relative;
  z-index: 1;
  min-width: 52px;
  min-height: 44px;
  padding: 8px 2px;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.my-growth-card,
.annual-ledger-card {
  display: grid;
  gap: 14px;
  padding: 17px;
}

.my-growth-card .section-title-row > span {
  color: var(--ink-faint);
  font-size: 10px;
}

.my-growth-card h2,
.annual-ledger-card h2,
.annual-chart-heading h3,
.my-guest-card h2 {
  margin: 0;
}

.my-growth-card h2,
.annual-ledger-card h2 {
  font-size: 18px;
}

.my-growth-grid,
.annual-summary {
  display: grid;
  margin: 0;
}

.my-growth-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 17px;
  overflow: hidden;
  background: var(--surface-soft);
}

.my-growth-grid > div {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding: 12px 9px;
}

.my-growth-grid > div + div {
  border-left: 1px solid var(--line);
}

.my-growth-grid dt,
.my-growth-grid dd,
.my-growth-grid small,
.annual-summary dt,
.annual-summary dd {
  margin: 0;
}

.my-growth-grid dt {
  color: var(--ink-soft);
  font-size: 10px;
}

.my-growth-grid dd {
  overflow: hidden;
  font-size: clamp(16px, 5vw, 21px);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-growth-grid small {
  color: var(--ink-faint);
  font-size: 8px;
  line-height: 1.35;
}

.my-growth-grid .is-experience dd {
  color: var(--accent-ink);
}

.annual-ledger-card {
  overflow: hidden;
}

.annual-heading-row,
.annual-chart-heading,
.annual-legend,
.year-switcher {
  display: flex;
  align-items: center;
}

.annual-heading-row,
.annual-chart-heading {
  justify-content: space-between;
  gap: 12px;
}

.year-switcher {
  flex: 0 0 auto;
  gap: 2px;
  min-height: 44px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
}

.year-switcher button {
  display: grid;
  place-items: center;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent-ink);
  font-size: 22px;
  line-height: 1;
}

.year-switcher button:disabled {
  color: var(--ink-faint);
  opacity: .45;
}

.year-switcher strong {
  min-width: 38px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.annual-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}

.annual-summary > div {
  min-width: 0;
  padding: 11px 12px;
  background: var(--surface-soft);
}

.annual-summary > div + div {
  border-left: 1px solid var(--line);
}

.annual-summary .is-balance {
  grid-column: 1 / -1;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(120deg, var(--surface-strong), var(--surface-soft));
}

.annual-summary .is-income {
  border-left: 0;
}

.annual-summary dt {
  color: var(--ink-soft);
  font-size: 10px;
}

.annual-summary dd {
  overflow: hidden;
  font-size: 17px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.annual-summary .is-balance dd {
  font-size: 26px;
}

.annual-summary .is-income dd { color: var(--income); }
.annual-summary .is-expense dd { color: var(--expense); }

.annual-highlights {
  display: grid;
  gap: 8px;
}

.annual-highlights h3 {
  margin: 0;
  font-size: 13px;
}

.annual-highlight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.annual-highlight {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  min-height: 126px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface-soft);
}

.annual-highlight.is-expense {
  border-top: 3px solid var(--expense);
}

.annual-highlight.is-income {
  border-top: 3px solid var(--income);
}

.annual-highlight-label,
.annual-highlight-meta,
.annual-highlight-note,
.annual-highlight-empty {
  margin: 0;
}

.annual-highlight-label {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 750;
}

.annual-highlight-detail {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.annual-highlight-detail strong {
  color: var(--ink);
  font-size: clamp(15px, 4.8vw, 20px);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
}

.annual-highlight-meta,
.annual-highlight-note,
.annual-highlight-empty {
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.45;
}

.annual-highlight-note {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}

.annual-highlight-empty {
  align-self: center;
  padding-block: 12px;
}

.annual-chart-heading h3 {
  font-size: 13px;
}

.annual-legend {
  gap: 10px;
  color: var(--ink-soft);
  font-size: 9px;
}

.annual-legend span {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.annual-legend i {
  width: 7px;
  height: 7px;
  border-radius: 2px;
}

.annual-legend i.is-income { background: var(--chart-income); }
.annual-legend i.is-expense { background: var(--chart-expense); }

.annual-month-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 3px;
  min-height: 126px;
  padding: 10px 8px 7px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background:
    repeating-linear-gradient(to top, transparent 0 27px, color-mix(in srgb, var(--line) 56%, transparent) 28px),
    var(--surface-soft);
}

.annual-month {
  display: grid;
  grid-template-rows: 94px auto;
  gap: 5px;
  min-width: 0;
}

.annual-month-bars {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}

.annual-month-bar {
  display: block;
  width: min(6px, 38%);
  height: var(--bar-size);
  min-height: 0;
  border-radius: 4px 4px 1px 1px;
}

.annual-month-bar.is-income { background: var(--chart-income); }
.annual-month-bar.is-expense {
  background: repeating-linear-gradient(135deg, var(--chart-expense) 0 3px, color-mix(in srgb, var(--chart-expense) 64%, var(--surface)) 3px 5px);
}

.annual-month-label {
  overflow: hidden;
  color: var(--ink-faint);
  font-size: 8px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

.annual-empty {
  margin: -4px 0 0;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
}

.my-guest-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 34px 22px;
  text-align: center;
}

.my-guest-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 46% 54% 52% 48%;
  background: var(--surface-selected);
  color: var(--accent-ink);
  font-size: 26px;
  font-weight: 850;
}

.my-guest-card p {
  max-width: 260px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.my-guest-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(100px, 1fr));
  gap: 10px;
  width: min(100%, 250px);
  margin-top: 4px;
}

.pwa-install-card {
  display: grid;
  gap: 14px;
  align-items: start;
  padding: 18px 16px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--surface-selected) 38%, var(--surface)), var(--surface));
}

.pwa-install-copy {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}

.pwa-install-mark {
  display: grid;
  flex: 0 0 48px;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: var(--surface-selected);
  color: var(--accent-ink);
}

.pwa-install-mark svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.pwa-install-copy h2,
.pwa-install-copy p {
  margin: 0;
}

.pwa-install-copy h2 {
  margin-top: 2px;
  font-size: 16px;
  line-height: 1.25;
}

.pwa-install-copy > div > p:last-child {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.5;
}

.pwa-install-steps {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pwa-install-steps li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.55;
}

.pwa-install-step-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid color-mix(in srgb, var(--accent-action) 34%, var(--line));
  border-radius: 50%;
  background: var(--surface-selected);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 750;
}

.pwa-install-step-copy {
  padding-top: 4px;
}

.pwa-install-note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.5;
}

.pwa-install-button {
  width: 100%;
  min-height: 44px;
  padding-inline: 13px;
  white-space: nowrap;
}

@media (max-width: 359px) {
  .my-identity-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .my-settings-link {
    grid-column: 2;
    justify-self: start;
    min-height: 36px;
    margin-top: -9px;
  }

  .my-avatar {
    width: 60px;
    height: 60px;
  }

  .my-growth-grid > div {
    padding-inline: 7px;
  }

  .my-growth-grid small {
    min-height: 22px;
  }

  .annual-ledger-card {
    padding-inline: 13px;
  }

  .annual-highlight-grid {
    grid-template-columns: 1fr;
  }

  .annual-highlight {
    min-height: 108px;
  }

  .annual-month-chart {
    gap: 2px;
    padding-inline: 5px;
  }

  .pwa-install-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .pwa-install-button {
    width: 100%;
  }
}

@media (forced-colors: active) {
  .my-identity-card,
  .my-growth-card,
  .annual-ledger-card,
  .my-guest-card,
  .pwa-install-card,
  .my-growth-grid,
  .annual-summary,
  .annual-highlight,
  .annual-month-chart,
  .year-switcher {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  .my-avatar,
  .my-avatar::after,
  .my-guest-mark,
  .annual-legend i,
  .annual-month-bar {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }

  .annual-month-bar.is-expense {
    border: 1px dashed CanvasText;
    background: Canvas;
  }
}

@media (prefers-reduced-motion: reduce) {
  .annual-month-bar,
  .my-avatar {
    transition: none;
  }
}

/* V1.3 amount-led entry and account avatars */

.app-shell.is-entry-view {
  --entry-save-height: 60px;
  padding-bottom: 0;
}

.app-shell.is-entry-view #entry-view,
.app-shell.is-entry-view #entry-form,
.app-shell.is-entry-view .entry-primary-card,
.app-shell.is-entry-view .category-fieldset,
.app-shell.is-entry-view .optional-fields {
  min-width: 0;
  max-width: 100%;
}

.app-shell.is-entry-view #entry-view {
  padding-bottom: 0;
}

.app-shell.is-entry-view #entry-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(8px, 1.35dvh, 12px);
  align-content: start;
}

.entry-primary-card {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
  padding: clamp(13px, 2dvh, 18px);
  border: 1px solid color-mix(in srgb, var(--accent-action) 30%, var(--line));
  border-radius: 10px 26px 10px 26px;
  background:
    radial-gradient(circle at 91% 8%, color-mix(in srgb, var(--surface-selected) 72%, transparent) 0 42px, transparent 43px),
    linear-gradient(145deg, var(--surface-strong), color-mix(in srgb, var(--surface) 76%, var(--surface-strong)));
  box-shadow: 0 14px 34px color-mix(in srgb, var(--accent-action) 13%, transparent);
}

.entry-primary-card .amount-section,
.entry-primary-card .record-type-fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.entry-primary-card .amount-section {
  display: grid;
  justify-items: center;
  align-content: center;
  padding: 0;
  text-align: center;
}

.entry-primary-card .amount-section > label {
  position: relative;
  z-index: 1;
  justify-content: center;
  min-height: 22px;
  color: var(--accent-ink);
  font-size: 12px;
  letter-spacing: .02em;
}

.entry-primary-card .field-priority,
.app-shell.is-entry-view .category-fieldset .field-priority {
  min-height: 18px;
  padding: 1px 6px;
  font-size: 9px;
}

.entry-primary-card .amount-control {
  justify-content: center;
  width: 100%;
  max-width: 100%;
  margin: 4px auto 1px;
}

.entry-primary-card .amount-control > span {
  flex: 0 0 auto;
  margin: 5px 5px 0 0;
  color: var(--accent-ink);
  font-size: clamp(24px, 7vw, 32px);
}

.entry-primary-card .amount-control input {
  width: min(100%, 330px);
  max-width: 100%;
  min-width: 0;
  min-height: 58px;
  padding: 0 2px 2px;
  border-bottom-width: 0;
  color: var(--ink);
  caret-color: var(--accent-action);
  font-size: clamp(38px, 11.5vw, 52px);
  font-weight: 760;
  letter-spacing: -.035em;
  line-height: 1;
  text-align: center;
}

.entry-primary-card .amount-control input:focus-visible {
  border-radius: 10px;
  box-shadow: inset 0 -4px 0 var(--accent-action);
}

.entry-primary-card .amount-control input[aria-invalid="true"] {
  border-radius: 10px;
  box-shadow: inset 0 -4px 0 var(--danger);
}

.entry-primary-card .amount-section .field-help {
  max-width: 34ch;
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.35;
  text-wrap: balance;
}

.entry-primary-card .amount-section .field-error {
  margin-top: 4px;
  text-align: center;
}

.entry-primary-card .record-type-fieldset {
  padding-top: 8px;
  border-top: 1px solid color-mix(in srgb, var(--accent-action) 20%, var(--line));
}

.entry-primary-card .record-type-fieldset legend {
  margin-bottom: 5px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
}

.entry-primary-card .record-type-control {
  width: 100%;
  min-height: 48px;
  padding: 3px;
  background: color-mix(in srgb, var(--surface-soft) 84%, transparent);
}

.entry-primary-card .record-type-control label {
  min-height: 44px;
  font-size: 13px;
}

.app-shell.is-entry-view .category-fieldset {
  display: grid;
  align-content: center;
  width: 100%;
  margin-top: 0;
  padding: clamp(10px, 1.55dvh, 14px) 7px;
  border-radius: 22px 22px 22px 8px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--ink) 5%, transparent);
}

.app-shell.is-entry-view .category-fieldset legend {
  padding-inline: 5px;
  font-size: 13px;
  font-weight: 700;
}

.app-shell.is-entry-view .category-grid {
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 5px 4px;
  margin-top: 7px;
}

.app-shell.is-entry-view .category-option {
  display: grid;
  grid-template-rows: 19px auto;
  place-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 54px;
  padding: 6px 1px 4px;
  border-radius: 13px;
  font-size: 10px;
  line-height: 1.1;
}

.category-icon {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 19px;
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 750;
  line-height: 1;
}

.app-shell.is-entry-view .category-option:has(input:checked) {
  border-color: var(--accent-action);
  background: var(--surface-selected);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-action) 38%, transparent);
}

.app-shell.is-entry-view .category-option:has(input:checked) .category-icon {
  transform: translateY(-1px);
}

.app-shell.is-entry-view .category-check {
  top: 3px;
  right: 3px;
}

.app-shell.is-entry-view .optional-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  align-content: center;
  margin-top: 0;
  padding: clamp(10px, 1.55dvh, 14px);
  border-radius: 22px 22px 8px 22px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--ink) 5%, transparent);
}

.entry-note-field,
.entry-date-field {
  display: grid;
  align-content: start;
  min-width: 0;
}

.entry-note-field {
  grid-template-rows: auto auto auto;
}

.entry-date-field {
  grid-template-rows: auto auto auto;
}

.app-shell.is-entry-view .note-meta-row {
  min-height: 19px;
  margin: 0 0 13px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 700;
}

.app-shell.is-entry-view .note-input {
  min-height: 56px;
  max-height: 108px;
  padding: 10px 11px;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
}

.app-shell.is-entry-view .entry-time-picker {
  justify-self: start;
  width: fit-content;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 8px 0 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
}

.app-shell.is-entry-view .entry-time-picker:has(.entry-time-input[aria-invalid="true"]) {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

.app-shell.is-entry-view .entry-time-display {
  display: grid;
  grid-template-columns: 18px minmax(0, auto);
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
}

.app-shell.is-entry-view .entry-time-display svg {
  width: 18px;
  height: 18px;
}

.app-shell.is-entry-view .entry-date-field .field-error,
.app-shell.is-entry-view .entry-note-field .field-error {
  margin-top: 4px;
}

.app-shell.is-entry-view.is-primary-entry-view {
  --entry-fixed-clearance: calc(var(--entry-save-height) + var(--nav-height) + var(--safe-bottom) + 22px);
  padding-bottom: 0;
}

.app-shell.is-entry-view.is-primary-entry-view #entry-view {
  padding-bottom: 0;
}

.app-shell.is-primary-entry-view .entry-header {
  display: none;
}

.app-shell.is-primary-entry-view #entry-form {
  grid-template-rows:
    minmax(160px, .95fr)
    minmax(132px, .72fr)
    minmax(92px, .55fr);
  align-content: stretch;
  min-height: calc(100vh - env(safe-area-inset-top, 0px) - 8px);
  min-height: calc(100dvh - env(safe-area-inset-top, 0px) - 8px);
  padding-bottom: var(--entry-fixed-clearance);
  scroll-padding-bottom: var(--entry-fixed-clearance);
}

.app-shell.is-primary-entry-view .entry-primary-card,
.app-shell.is-primary-entry-view .category-fieldset,
.app-shell.is-primary-entry-view .optional-fields {
  align-self: stretch;
}

.app-shell.is-primary-entry-view .entry-actions {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 7px);
  z-index: 22;
  width: min(calc(100% - 24px), calc(var(--content-max) - 24px));
  margin: 0;
  padding: 5px;
  transform: translateX(-50%);
}

.app-shell.is-primary-entry-view .save-button,
.app-shell.is-entry-view #delete-entry {
  min-height: 48px;
}

.app-shell.is-entry-view:not(.is-primary-entry-view) #entry-view {
  padding-bottom: calc(26px + var(--safe-bottom));
}

.app-shell.is-entry-view:not(.is-primary-entry-view) #entry-form {
  grid-template-rows: none;
  min-height: 0;
  padding-bottom: 8px;
}

.app-shell.is-entry-view:not(.is-primary-entry-view) .entry-actions {
  position: sticky;
  bottom: calc(var(--safe-bottom) + 8px);
  z-index: 12;
  margin-top: 4px;
}

#entry-view.is-editing .entry-danger-zone {
  margin-top: 28px;
  padding-bottom: calc(10px + var(--safe-bottom));
}

.app-shell.is-entry-view #entry-view .field-control,
.app-shell.is-entry-view #entry-view .category-option,
.app-shell.is-entry-view #entry-view .field-error {
  scroll-margin-bottom: calc(var(--entry-save-height) + var(--nav-height) + var(--safe-bottom) + 22px);
}

.my-avatar-control {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 2px;
}

.my-avatar-edit {
  min-width: 68px;
  min-height: 44px;
  margin-bottom: -12px;
  padding: 8px 3px;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 800;
}

.avatar-swatch {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--surface) 72%, transparent);
  border-radius: 46% 54% 52% 48% / 52% 45% 55% 48%;
  background: linear-gradient(145deg, var(--surface-selected), var(--accent));
  color: var(--ink);
  font-weight: 850;
}

.avatar-swatch > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-swatch[data-avatar-key="blossom"] { background: linear-gradient(145deg, var(--surface), var(--accent)); }
.avatar-swatch[data-avatar-key="leaf"] { background: linear-gradient(145deg, var(--surface-strong), var(--income)); }
.avatar-swatch[data-avatar-key="sunset"] { background: linear-gradient(145deg, var(--accent), var(--expense)); }
.avatar-swatch[data-avatar-key="ocean"] { background: linear-gradient(145deg, var(--surface-soft), #78a8bb); }
.avatar-swatch[data-avatar-key="plum"] { background: linear-gradient(145deg, var(--surface-selected), #9b789d); }
.avatar-swatch[data-avatar-key="unavailable"] { border-radius: 50%; background: var(--surface-soft); color: var(--ink-faint); }

.avatar-dialog .dialog-card {
  width: min(100%, 440px);
}

.avatar-editor-card {
  display: grid;
  gap: 12px;
  max-height: min(90dvh, 720px);
  overflow-y: auto;
}

.avatar-editor-heading,
.avatar-upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.avatar-editor-heading h2,
.avatar-editor-heading p,
.avatar-sharing-note {
  margin: 0;
}

.avatar-preview {
  justify-self: center;
  width: 88px;
  height: 88px;
  font-size: 30px;
  box-shadow: var(--shadow-soft);
}

.avatar-builtins {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.avatar-builtins legend {
  padding-inline: 4px;
  font-size: 13px;
  font-weight: 750;
}

.avatar-choice-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 6px;
}

.avatar-choice-grid label {
  position: relative;
  min-width: 0;
  cursor: pointer;
}

.avatar-choice-grid input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.avatar-choice-grid .avatar-swatch {
  min-height: 58px;
  padding: 5px 1px;
  border-color: var(--line);
  font-size: 17px;
}

.avatar-choice-grid small {
  display: block;
  margin-top: 2px;
  font-size: 8px;
  font-weight: 650;
}

.avatar-choice-grid input:checked + .avatar-swatch {
  border-color: var(--accent-action);
  box-shadow: inset 0 0 0 2px var(--surface), 0 0 0 2px var(--accent-action);
}

.avatar-choice-grid input:checked + .avatar-swatch::after {
  position: absolute;
  top: 2px;
  right: 3px;
  content: "✓";
  font-size: 10px;
}

.avatar-choice-grid input:focus-visible + .avatar-swatch {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.avatar-upload-row {
  align-items: center;
}

.avatar-upload-row > span,
.avatar-sharing-note {
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.45;
}

.avatar-upload-button {
  flex: 0 0 auto;
  min-height: 44px;
  cursor: pointer;
}

.record-icon-wrap {
  position: relative;
  width: 46px;
  height: 46px;
}

.creator-avatar {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 22px;
  height: 22px;
  border-width: 2px;
  border-radius: 50%;
  font-size: 8px;
  box-shadow: 0 2px 7px color-mix(in srgb, var(--ink) 16%, transparent);
}

.member-avatar.avatar-swatch {
  font-size: 13px;
}

@media (max-height: 720px) {
  .entry-primary-card { gap: 5px; padding: 8px; }
  .entry-primary-card .amount-control { margin-top: 1px; }
  .entry-primary-card .amount-control input { min-height: 52px; font-size: clamp(38px, 11.5vw, 44px); }
  .entry-primary-card .amount-section .field-help { margin-top: 1px; font-size: 9px; }
  .entry-primary-card .record-type-fieldset { padding-top: 5px; }
  .entry-primary-card .record-type-fieldset legend { margin-bottom: 3px; }
  .entry-primary-card .record-type-control { min-height: 44px; }
  .app-shell.is-entry-view .category-fieldset { padding-block: 7px; }
  .app-shell.is-entry-view .category-grid { margin-top: 5px; }
  .app-shell.is-entry-view .category-option { min-height: 48px; }
  .app-shell.is-entry-view .optional-fields { padding: 7px; }
  .app-shell.is-entry-view .note-input { min-height: 56px; }
  .app-shell.is-entry-view .entry-time-picker { min-height: 44px; }
}

@media (max-width: 359px), (max-height: 640px) {
  .app-shell.is-primary-entry-view #entry-form { gap: 6px; }
  .entry-primary-card { gap: 5px; padding: 8px; }
  .entry-primary-card .amount-control input { min-height: 52px; font-size: 38px; }
  .app-shell.is-entry-view .category-fieldset { padding-inline: 3px; }
  .app-shell.is-entry-view .category-grid { gap: 3px; }
  .app-shell.is-entry-view .category-option { min-height: 48px; }
  .app-shell.is-entry-view .optional-fields { grid-template-columns: minmax(0, 1fr); padding: 7px; }
}

@media (max-width: 330px) {
  .app-shell.is-primary-entry-view #entry-form {
    padding-bottom: calc(var(--entry-fixed-clearance) + 64px);
  }

  .app-shell.is-entry-view .optional-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-shell.is-entry-view .entry-time-picker { width: fit-content; }
  .avatar-choice-grid { grid-template-columns: repeat(3, minmax(44px, 1fr)); }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app-shell.is-primary-entry-view #entry-form {
    grid-template-rows: none;
    min-height: 0;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  }

  .app-shell.is-primary-entry-view .entry-actions {
    position: static;
    width: 100%;
    margin-top: 4px;
    transform: none;
  }
}

@media (forced-colors: active) {
  .entry-primary-card,
  .category-fieldset,
  .optional-fields,
  .category-option,
  .avatar-swatch,
  .avatar-builtins,
  .avatar-choice-grid input:checked + .avatar-swatch,
  .creator-avatar {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  .app-shell.is-entry-view .category-option:has(input:checked),
  .avatar-choice-grid input:checked + .avatar-swatch {
    outline: 3px solid Highlight;
    background: Highlight;
    color: HighlightText;
  }

  .category-icon { color: currentColor; }
}

@media (prefers-reduced-motion: reduce) {
  .category-option,
  .category-icon,
  .record-type-control label,
  .avatar-swatch,
  .creator-avatar { transition: none; }

  .app-shell.is-entry-view .category-option:has(input:checked) .category-icon { transform: none; }
}
