/*
 * Spentlo UI polish layer.
 *
 * The legacy stylesheet contains the full product history. Keep this file
 * last-loaded and intentionally narrow: it defines the shared visual contract
 * and resolves responsive cascade conflicts against the current DOM.
 */

@keyframes authWordRotate {
  0%,
  20% {
    opacity: 1;
    transform: translateY(0);
  }

  25%,
  100% {
    opacity: 0;
    transform: translateY(-0.45em);
  }
}

:root {
  --border: var(--line);
  --text: var(--ink);
  --panel: var(--surface);
  --shadow-soft: 0 10px 28px rgba(15, 23, 42, 0.08);
  --button-ink: #ffffff;
  --on-accent: var(--button-ink);
  --radius: 14px;
  --radius-small: 10px;
  --radius-large: 20px;
  --control-height: 44px;
  --control-height-compact: 36px;
  --focus-ring: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
  --surface-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 34px rgba(15, 23, 42, 0.07);
  --surface-shadow-hover: 0 2px 4px rgba(15, 23, 42, 0.06), 0 18px 42px rgba(15, 23, 42, 0.11);
  --sidebar-width: 304px;
}

:root[data-accent="gold"],
:root[data-theme="dark"] {
  --button-ink: #07111f;
}

:root[data-theme="dark"] {
  --shadow-soft: 0 12px 32px rgba(0, 0, 0, 0.24);
  --surface-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 14px 36px rgba(0, 0, 0, 0.18);
  --surface-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.24), 0 20px 46px rgba(0, 0, 0, 0.24);
}

/* Shared controls */
.button {
  min-height: var(--control-height);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-small);
  transition:
    color 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease,
    box-shadow 180ms ease,
    transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.button.compact,
.small-button {
  min-height: var(--control-height-compact);
  border-radius: 9px;
}

.button.primary,
.small-button.accent,
.segmented-control button.active,
.chart-toggle button.active,
.scenario-toggle button.active,
.icon-toggle-button.active,
.field-help-button[aria-expanded="true"],
.dashboard-size-options button.active,
.avatar:not(.has-image),
.profile-photo-preview:not(.has-image) {
  color: var(--button-ink) !important;
}

.button:not(:disabled):active,
.small-button:not(:disabled):active,
.nav-link:not(:disabled):active {
  transform: translateY(1px) scale(0.985);
}

:where(button, a, input, select, textarea, summary, [role="button"], [tabindex]):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, #ffffff);
  outline-offset: 3px;
  box-shadow: var(--focus-ring);
}

.brand-button:focus-visible,
.metric-card[data-snapshot-detail]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent-glow) 74%, #ffffff);
  outline-offset: 3px;
}

.field input,
.field select,
.field textarea {
  min-height: var(--control-height);
  border-radius: var(--radius-small);
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    box-shadow 180ms ease;
}

.field textarea {
  min-height: 112px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.billing-cycle-toggle input:focus-visible + span,
.accent-option input:focus-visible + span,
.feedback-choice input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, #ffffff);
  outline-offset: 3px;
  box-shadow: var(--focus-ring);
}

/* Shared surfaces and alignment */
:is(
  .panel,
  .metric-card,
  .finance-card,
  .person-card,
  .security-card,
  .feedback-entry,
  .admin-user-card,
  .table-shell,
  .empty-state
) {
  border-color: var(--line);
  border-radius: var(--radius);
  box-shadow: var(--surface-shadow);
}

.security-card.reset-zone {
  border-color: color-mix(in srgb, var(--warning) 38%, var(--line));
  background: color-mix(in srgb, var(--warning) 7%, var(--surface-2));
}

.button.reset-action {
  color: #92400e;
  background: #fffbeb;
  border: 1px solid rgba(180, 83, 9, 0.34);
}

.button.reset-action:hover,
.button.reset-action:focus-visible {
  color: #78350f;
  background: #fef3c7;
  border-color: rgba(180, 83, 9, 0.58);
}

:root[data-theme="dark"] .button.reset-action {
  color: #fde68a;
  background: rgba(146, 64, 14, 0.2);
  border-color: rgba(251, 191, 36, 0.42);
}

:root[data-theme="dark"] .button.reset-action:hover,
:root[data-theme="dark"] .button.reset-action:focus-visible {
  color: #fef3c7;
  background: rgba(146, 64, 14, 0.32);
  border-color: rgba(251, 191, 36, 0.7);
}

.reset-account-card {
  width: min(560px, calc(100vw - 24px));
}

.reset-account-summary {
  display: grid;
  gap: 5px;
  margin: 0 0 16px;
  padding: 13px 14px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  line-height: 1.45;
}

.reset-account-summary strong {
  color: var(--ink);
}

.reset-account-error {
  margin: 2px 0 0;
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.4;
}

:where(.cards-grid, .people-grid, .accounts-grid, .planning-grid) {
  align-items: stretch;
}

:where(.cards-grid, .people-grid, .accounts-grid, .planning-grid) > :where(article, .panel, .finance-card, .person-card) {
  height: 100%;
  min-width: 0;
}

.finance-card-header,
.panel-header,
.section-heading {
  gap: 14px;
}

@media (hover: hover) and (pointer: fine) {
  .metric-card[data-snapshot-detail] {
    transition:
      border-color 180ms ease,
      box-shadow 220ms ease,
      transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .metric-card[data-snapshot-detail]:hover {
    border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
    box-shadow: var(--surface-shadow-hover);
    transform: translateY(-2px);
  }
}

.nav-link {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-small);
  transition:
    color 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease,
    transform 180ms ease;
}

.nav-link.active {
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 25%, transparent), transparent 82%),
    rgba(255, 255, 255, 0.1);
  border-color: color-mix(in srgb, var(--accent-glow) 30%, rgba(255, 255, 255, 0.12));
}

.nav-link.active::after {
  position: absolute;
  inset-block: 9px;
  left: 0;
  width: 3px;
  background: var(--accent-glow);
  border-radius: 999px;
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent-glow) 66%, transparent);
  content: "";
}

.workspace {
  max-width: 1600px;
}

#dashboardView.active {
  align-items: start;
}

#dashboardView > .metric-grid .metric-card {
  height: 100%;
}

/* Daily dashboard announcement: a calm editorial surface with a short
   entrance and persistent ambient motion on decorative layers only. */
#dashboardView > .dashboard-greeting {
  --announcement-mood: var(--accent);
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 15px;
  min-width: 0;
  min-height: 82px;
  overflow: hidden;
  padding: 15px 18px;
  background:
    radial-gradient(circle at 92% 8%, color-mix(in srgb, var(--announcement-mood) 19%, transparent), transparent 35%),
    linear-gradient(
      118deg,
      color-mix(in srgb, var(--accent) 10%, var(--surface)) 0%,
      var(--surface) 58%,
      color-mix(in srgb, var(--announcement-mood) 9%, var(--surface)) 100%
    );
  border-color: color-mix(in srgb, var(--announcement-mood) 28%, var(--line));
  box-shadow: var(--surface-shadow);
}

#dashboardView > .dashboard-greeting[data-greeting-tone="morning"] {
  --announcement-mood: #f59e0b;
}

#dashboardView > .dashboard-greeting[data-greeting-tone="afternoon"] {
  --announcement-mood: #38bdf8;
}

#dashboardView > .dashboard-greeting[data-greeting-tone="evening"] {
  --announcement-mood: #a78bfa;
}

#dashboardView > .dashboard-greeting[data-greeting-tone="special"] {
  --announcement-mood: #fb7185;
}

#dashboardView > .dashboard-greeting::before {
  position: absolute;
  inset-block: 14px;
  left: 0;
  z-index: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--announcement-mood), var(--accent));
  border-radius: 0 999px 999px 0;
  box-shadow: 0 0 18px color-mix(in srgb, var(--announcement-mood) 42%, transparent);
  content: "";
}

#dashboardView > .dashboard-greeting::after {
  position: absolute;
  top: -72px;
  right: -48px;
  z-index: 0;
  width: 180px;
  height: 180px;
  pointer-events: none;
  background: radial-gradient(circle, color-mix(in srgb, var(--announcement-mood) 19%, transparent), transparent 67%);
  border: 1px solid color-mix(in srgb, var(--announcement-mood) 13%, transparent);
  border-radius: 50%;
  content: "";
}

#dashboardView > .dashboard-greeting > * {
  position: relative;
  z-index: 1;
}

#dashboardView > .dashboard-greeting > .sr-only {
  position: absolute;
}

#dashboardView > .dashboard-greeting > .dashboard-greeting-body {
  min-width: 0;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-body > * {
  min-width: 0;
  max-width: 100%;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-icon {
  width: 50px;
  height: 50px;
  border-color: color-mix(in srgb, var(--announcement-mood) 34%, var(--line));
  border-radius: 17px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--announcement-mood) 24%, var(--surface)), var(--surface-2));
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, #ffffff 54%, transparent),
    0 10px 24px color-mix(in srgb, var(--announcement-mood) 18%, transparent);
}

#dashboardView > .dashboard-greeting .dashboard-greeting-icon > span {
  display: block;
  line-height: 1;
  filter: drop-shadow(0 3px 7px color-mix(in srgb, var(--announcement-mood) 24%, transparent));
}

#dashboardView > .dashboard-greeting > .dashboard-greeting-sparkles {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span {
  position: absolute;
  width: 5px;
  height: 5px;
  background: color-mix(in srgb, var(--announcement-mood) 65%, #ffffff);
  border-radius: 50%;
  box-shadow: 0 0 10px color-mix(in srgb, var(--announcement-mood) 52%, transparent);
  opacity: 0.48;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span::after {
  position: absolute;
  inset: -4px;
  border: 1px solid color-mix(in srgb, var(--announcement-mood) 56%, transparent);
  border-radius: inherit;
  content: "";
  opacity: 0;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span:nth-child(1) {
  top: 21px;
  right: 28px;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span:nth-child(2) {
  top: 43px;
  right: 58px;
  width: 3px;
  height: 3px;
  opacity: 0.34;
}

#dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span:nth-child(3) {
  top: 62px;
  right: 20px;
  width: 4px;
  height: 4px;
  opacity: 0.38;
}

#dashboardView > .dashboard-greeting .eyebrow {
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

#dashboardView > .dashboard-greeting h3 {
  max-width: 100%;
  overflow-wrap: anywhere;
}

#dashboardView > .dashboard-greeting #dashboardGreetingDetail {
  width: 100%;
  max-width: 72ch;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing {
  animation: spentlo-announcement-card-enter 460ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing::after {
  animation: spentlo-announcement-accent-enter 640ms cubic-bezier(0.2, 0.8, 0.2, 1) 80ms both;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing::before {
  animation: spentlo-announcement-accent-pulse 3.8s ease-in-out 680ms infinite;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-icon {
  animation: spentlo-announcement-icon-enter 520ms cubic-bezier(0.2, 0.8, 0.2, 1) 90ms both;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-icon > span {
  animation: spentlo-announcement-icon-float 4.8s ease-in-out 680ms infinite;
  transform-origin: 50% 55%;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing > .dashboard-greeting-sparkles {
  animation: spentlo-announcement-field-drift 8s ease-in-out 720ms infinite alternate;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-sparkles span {
  animation: spentlo-announcement-sparkle-enter 560ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-sparkles span:nth-child(2) {
  animation-delay: 90ms;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-sparkles span:nth-child(3) {
  animation-delay: 160ms;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-sparkles span::after {
  animation: spentlo-announcement-sparkle-pulse 3.2s ease-in-out 760ms infinite;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-sparkles span:nth-child(2)::after {
  animation-delay: 1.55s;
  animation-duration: 3.8s;
}

.app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting.is-announcing .dashboard-greeting-sparkles span:nth-child(3)::after {
  animation-delay: 2.25s;
  animation-duration: 3.5s;
}

@keyframes spentlo-announcement-card-enter {
  from {
    opacity: 0;
    transform: translateY(9px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes spentlo-announcement-accent-enter {
  from {
    opacity: 0;
    transform: translate3d(24px, -8px, 0) scale(0.88);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes spentlo-announcement-icon-enter {
  0% {
    opacity: 0;
    transform: translateY(7px) rotate(-5deg) scale(0.9);
  }
  72% {
    opacity: 1;
    transform: translateY(-1px) rotate(1deg) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) rotate(0) scale(1);
  }
}

@keyframes spentlo-announcement-sparkle-enter {
  from {
    opacity: 0;
    transform: translateY(5px) scale(0.6);
  }
}

@keyframes spentlo-announcement-accent-pulse {
  0%,
  100% {
    opacity: 0.68;
    transform: scaleY(0.78);
  }
  50% {
    opacity: 1;
    transform: scaleY(1);
    box-shadow: 0 0 25px color-mix(in srgb, var(--announcement-mood) 58%, transparent);
  }
}

@keyframes spentlo-announcement-icon-float {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-2px) rotate(2deg);
  }
}

@keyframes spentlo-announcement-field-drift {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(-5px, 2px, 0);
  }
}

@keyframes spentlo-announcement-sparkle-pulse {
  0%,
  100% {
    opacity: 0;
    transform: scale(0.45);
  }
  42% {
    opacity: 0.78;
  }
  68% {
    opacity: 0;
    transform: scale(1.8);
  }
}

@media (max-width: 900px) {
  #dashboardView > .dashboard-greeting {
    min-height: 76px;
    gap: 13px;
    padding: 14px 16px;
  }

  #dashboardView > .dashboard-greeting .dashboard-greeting-icon {
    width: 46px;
    height: 46px;
    border-radius: 15px;
  }
}

@media (max-width: 520px) {
  #dashboardView > .dashboard-greeting {
    align-items: start;
    gap: 11px;
    min-height: 0;
    padding: 12px 14px !important;
  }

  #dashboardView > .dashboard-greeting::before {
    inset-block: 12px;
  }

  #dashboardView > .dashboard-greeting .dashboard-greeting-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 14px;
    font-size: 1.12rem;
  }

  #dashboardView > .dashboard-greeting #dashboardGreetingDetail {
    font-size: 0.88rem !important;
    line-height: 1.35 !important;
  }

  #dashboardView > .dashboard-greeting .dashboard-greeting-meta {
    gap: 1px 8px;
  }

  #dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span:nth-child(1) {
    top: 17px;
    right: 19px;
  }

  #dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span:nth-child(2) {
    top: 37px;
    right: 39px;
  }

  #dashboardView > .dashboard-greeting .dashboard-greeting-sparkles span:nth-child(3) {
    top: 55px;
    right: 16px;
  }
}

:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting,
:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting::before,
:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting::after,
:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-icon,
:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-icon > span,
:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting > .dashboard-greeting-sparkles,
:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-sparkles span,
:root[data-motion="reduced"] .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-sparkles span::after {
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting,
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting::before,
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting::after,
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-icon,
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-icon > span,
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting > .dashboard-greeting-sparkles,
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-sparkles span,
  .app-shell:not(.hidden) #dashboardView.active > .dashboard-greeting .dashboard-greeting-sparkles span::after {
    animation: none !important;
  }
}

/* Calm but distinctive page motion. */
.view.active > :not(.dashboard-greeting) {
  animation: spentlo-surface-enter 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.view.active > :nth-child(2) { animation-delay: 35ms; }
.view.active > :nth-child(3) { animation-delay: 70ms; }
.view.active > :nth-child(4) { animation-delay: 105ms; }
.view.active > :nth-child(n + 5) { animation-delay: 135ms; }

@keyframes spentlo-surface-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* The auth word should never begin as an empty gap. */
.auth-word-rotator span:first-child {
  opacity: 1;
  transform: translateY(0);
}

/* Landscape tablets and compact monitors retain a balanced two-panel auth view. */
@media (min-width: 901px) and (max-width: 1180px) {
  .auth-screen {
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(440px, 1fr);
    align-items: stretch;
  }

  .auth-copy {
    min-height: 100vh;
    min-height: 100dvh;
    padding: clamp(28px, 4vw, 54px);
  }

  .auth-copy h2 {
    position: absolute;
    top: 50%;
    left: 50%;
    width: calc(100% - 64px);
    margin: 0;
    font-size: clamp(3rem, 5.6vw, 4.6rem);
    transform: translate(-50%, -50%);
  }

  .auth-card {
    align-self: center;
    width: min(460px, calc(100% - 32px));
    max-height: calc(100dvh - 40px);
    margin: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .auth-tabs {
    position: sticky;
    top: 0;
    z-index: 2;
  }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .auth-keyword-token {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.76rem;
  }
}

/* Portrait tablets keep the full keyword field layered behind the foreground copy. */
@media (min-width: 761px) and (max-width: 900px) {
  .auth-screen {
    display: block;
  }

  .auth-copy {
    min-height: clamp(280px, 34svh, 330px);
    padding: 26px clamp(28px, 6vw, 54px);
  }

  .auth-copy h2 {
    position: absolute;
    top: 56%;
    left: clamp(28px, 6vw, 54px);
    width: min(680px, calc(100% - 108px));
    margin: 0;
    font-size: clamp(3rem, 7vw, 4rem);
    transform: translateY(-50%);
  }

  .auth-card {
    align-self: auto;
    margin: 18px auto 40px;
  }

  .auth-keyword-playground {
    display: block;
  }

  .auth-keyword-token {
    min-height: 40px;
    padding: 8px 11px;
    font-size: 0.74rem;
  }

  .sidebar {
    padding-block: calc(10px + var(--safe-top)) 10px;
  }

  .user-card {
    min-height: 72px;
    margin: 9px 0;
    padding: 9px 11px;
  }

  .sidebar-footer {
    margin-top: 7px;
  }
}

/* Phone layout: the foreground stays readable while every keyword remains interactive behind it. */
@media (max-width: 760px) {
  .auth-copy {
    display: flex;
    min-height: clamp(300px, 38svh, 340px);
    padding: calc(16px + var(--safe-top)) max(16px, var(--safe-right)) 20px max(16px, var(--safe-left));
  }

  .auth-copy h2 {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    margin: clamp(20px, 4svh, 32px) 0 0;
    font-size: clamp(2.15rem, 10.5vw, 3rem);
    line-height: 0.98;
    transform: none;
  }

  .auth-word-rotator {
    display: grid;
    min-width: 0;
    min-height: 1em;
    margin-top: 2px;
  }

  .auth-keyword-playground {
    display: block;
  }

  .auth-keyword-token {
    min-height: 38px;
    padding: 7px 9px;
    font-size: 0.69rem;
  }

  /* Override the legacy density cap without fixing positions, so drag/pop coordinates keep working. */
  .auth-keyword-token:nth-of-type(n + 8) {
    display: inline-flex;
    align-items: center;
  }

  .auth-card {
    width: calc(100% - 20px);
    margin: 10px auto calc(26px + var(--safe-bottom));
    padding: 16px;
    border-radius: 18px;
  }

  .auth-tabs {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 52px;
    border-radius: 12px;
  }

  .workspace {
    padding: 16px max(12px, var(--safe-right)) calc(var(--mobile-nav-height) + 26px + var(--safe-bottom)) max(12px, var(--safe-left));
  }

  .topbar {
    align-items: center;
    margin-bottom: 14px;
  }

  .topbar h2 {
    font-size: clamp(1.9rem, 8vw, 2.35rem);
  }

  #dashboardView > .dashboard-greeting {
    padding: 12px 14px !important;
  }

  #dashboardView > .hero-panel,
  #dashboardView > .hero-panel[data-widget-size] {
    gap: 14px !important;
    padding: 18px !important;
    border-radius: 18px;
  }

  #dashboardView > .hero-panel h3,
  #dashboardView > .hero-panel[data-widget-size] h3 {
    font-size: clamp(1.85rem, 8.2vw, 2.4rem) !important;
    line-height: 1.04 !important;
  }

  #dashboardView > .hero-panel p,
  #dashboardView > .hero-panel #forecastNarrative {
    margin-top: 8px;
    font-size: 0.94rem !important;
    line-height: 1.35 !important;
  }

  #dashboardView > .hero-panel .forecast-stack,
  #dashboardView > .hero-panel[data-widget-size] .forecast-stack {
    min-height: 0 !important;
    padding: 0 !important;
    margin-top: 4px !important;
    border-radius: 0 !important;
  }

  #dashboardView > .metric-grid,
  #dashboardView > .metric-grid[data-widget-size] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  #dashboardView > .metric-grid .metric-card {
    min-height: 112px !important;
    padding: 13px !important;
  }

  #dashboardView > .metric-grid .metric-card strong {
    font-size: clamp(1.18rem, 5.8vw, 1.58rem) !important;
  }

  #dashboardView > .metric-grid .metric-card p {
    font-size: 0.82rem !important;
  }

  /* Undo late wildcard density rules that target clock/forecast internals. */
  #dashboardView .dashboard-clock-face,
  #dashboardView .dashboard-clock-face > span,
  #dashboardView .dashboard-clock-face > b,
  #dashboardView .clock-hand {
    min-height: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  #dashboardView .clock-hand {
    border-radius: 999px !important;
  }

  #insightsView .forecast-breakdown,
  #dashboardView .forecast-stack {
    padding: 0 !important;
  }

  .sidebar-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: stretch;
    gap: 4px;
    width: 100%;
  }

  .sidebar-actions > .text-button {
    flex: 1 1 0;
    justify-content: center;
    min-width: 0;
    min-height: 40px;
    padding-inline: 4px;
    text-align: center;
    white-space: nowrap;
  }
}

@media (max-width: 340px) {
  #dashboardView > .metric-grid,
  #dashboardView > .metric-grid[data-widget-size] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

@media (max-width: 760px) and (hover: none) and (pointer: coarse) {
  #cashFlowPanel .segmented-control button {
    min-height: 44px;
  }
}

/* Feature pages should consume the workspace instead of inheriting a narrow
   card track when only one or two goals exist. */
#budgetsView,
#budgetsView > .view-stack,
#budgetsView > .view-stack > section,
#budgetsView #goalsList {
  width: 100%;
  max-width: none;
  min-width: 0;
}

#budgetsView #goalsList {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}

#budgetsView #goalsList > .empty-state {
  grid-column: 1 / -1;
}

/* The persistent sidebar reduces the usable content width on compact
   monitors. Reflow page controls from the workspace width rather than
   retaining desktop minimum columns that are subsequently clipped. */
@media (max-width: 1180px) {
  #incomeView,
  #transactionsView,
  #taxView,
  #settingsView,
  #incomeView .income-layout,
  #transactionsView .tool-row,
  #taxView .tax-report-toolbar,
  #settingsView .settings-layout {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #incomeView .income-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  #transactionsView .tool-row,
  #taxView .tax-report-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #transactionsView .tool-row > *,
  #taxView .tax-report-toolbar > * {
    min-width: 0;
  }

  #transactionsView .tool-actions {
    display: flex;
    grid-column: 1 / -1;
    align-items: stretch;
    justify-content: flex-start;
    width: 100%;
  }

  #transactionsView .tool-actions > :is(.button, .file-button) {
    flex: 1 1 150px;
    width: auto;
    max-width: 220px;
  }

  #taxView .tax-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  #taxView .tax-heading .button-row {
    justify-content: flex-start;
  }

  #settingsView .settings-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  #settingsView .settings-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    padding: 6px 6px 9px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    scrollbar-color: var(--accent) var(--surface-2);
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  #settingsView .settings-nav::-webkit-scrollbar {
    display: block;
    height: 6px;
  }

  #settingsView .settings-nav::-webkit-scrollbar-track {
    background: var(--surface-2);
    border-radius: 999px;
  }

  #settingsView .settings-nav::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 999px;
  }

  #settingsView .settings-nav-link {
    flex: 0 0 auto;
    min-width: max-content;
    min-height: 44px;
    padding-inline: 14px;
    text-align: center;
    white-space: nowrap;
    scroll-snap-align: start;
  }
}

@media (max-width: 760px) {
  #transactionsView .tool-row,
  #taxView .tax-report-toolbar {
    grid-template-columns: minmax(0, 1fr);
  }

  #transactionsView .tool-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  #transactionsView .tool-actions > :is(.button, .file-button) {
    width: 100%;
    max-width: none;
  }

  /* The legacy mobile transaction rule hides ordinary table cells. Tax rows
     intentionally use labelled cells instead of a duplicate mobile template. */
  #taxView .tax-table-shell {
    margin-inline: 0;
    overflow: visible;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  #taxView .tax-table-shell tr {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--surface-shadow);
  }

  #taxView .tax-table-shell tr:last-child {
    margin-bottom: 0;
  }

  #taxView .tax-table-shell td[data-label] {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 8px 0;
    overflow-wrap: anywhere;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
    text-align: right;
  }

  #taxView .tax-table-shell td[data-label]:last-child {
    border-bottom: 0;
  }

  #taxView .tax-table-shell td[data-label]::before {
    flex: 0 0 auto;
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.07em;
    text-align: left;
    text-transform: uppercase;
  }

  /* Long forms keep their context visible, but completion actions remain in
     normal flow after every field so they cannot cover or intercept inputs. */
  .modal-card:not(#dashboardCustomiseForm) > .modal-header {
    position: sticky;
    top: -16px;
    z-index: 12;
    margin: -16px -16px 14px;
    padding: 14px 16px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 20px -20px rgba(15, 23, 42, 0.72);
  }

  .modal-card:not(#dashboardCustomiseForm) > .modal-actions {
    position: static;
    bottom: auto;
    z-index: auto;
    margin: 18px 0 0;
    padding: 0 0 max(4px, var(--safe-bottom));
    background: transparent;
    border-top: 0;
    box-shadow: none;
  }

  /* Mobile actions follow their DOM order: cancel/back first, then the final
     primary or destructive submission at the true bottom of the form. */
  .modal-actions {
    flex-direction: column;
  }

  #dashboardCustomiseForm > .modal-actions,
  .wizard-actions {
    position: static;
    bottom: auto;
    z-index: auto;
    background: transparent;
  }

  /* Section guidance is most valuable on the narrow forms where controls
     stack. Keep it concise instead of removing it completely. */
  .form-section-heading p,
  .modal-card .form-section-heading p {
    display: -webkit-box;
    overflow: hidden;
    margin-top: 3px;
    font-size: 0.7rem;
    line-height: 1.3;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}

/* Touch targets remain comfortable without visually inflating every glyph. */
@media (hover: none) and (pointer: coarse) {
  .small-button,
  .text-button,
  .mobile-icon-button,
  .icon-button,
  .icon-toggle-button,
  .changelog-button,
  .user-settings-button,
  .field-help-button,
  .dashboard-size-options button,
  .dashboard-widget-move,
  .dashboard-widget-hide,
  .segmented-control button,
  .auth-tab {
    min-width: 44px;
    min-height: 44px;
  }
}

@media (max-width: 600px) {
  #settingsView .settings-nav {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow: visible;
  }

  #settingsView .settings-nav-link {
    width: 100%;
    min-width: 0;
    padding-inline: 10px;
    white-space: normal;
  }
}

@media (min-width: 601px) and (max-width: 1180px) {
  #settingsView .settings-nav {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow: visible;
  }

  #settingsView .settings-nav-link {
    width: 100%;
    min-width: 0;
    white-space: normal;
  }
}

@media (max-width: 1180px) {
  #transactionsView .table-shell {
    margin-inline: 0;
    overflow: visible;
    border-radius: var(--radius);
  }

  #transactionsView .table-shell table,
  #transactionsView .table-shell tbody,
  #transactionsView .table-shell tr {
    display: block;
    width: 100%;
    min-width: 0;
  }

  #transactionsView .table-shell thead {
    display: none;
  }

  #transactionsView .table-shell tr {
    border-bottom: 1px solid var(--line);
  }

  #transactionsView .table-shell tr:last-child {
    border-bottom: 0;
  }

  #transactionsView .table-shell td:not(.mobile-table-cell):not(.empty-table-cell) {
    display: none;
  }

  #transactionsView .mobile-table-cell,
  #transactionsView .empty-table-cell {
    display: block;
    width: 100%;
  }

  #transactionsView .mobile-table-cell {
    padding: 0;
    border-bottom: 0;
  }

  #transactionsView .mobile-transaction-list {
    display: grid;
    gap: 10px;
    padding: 10px 12px;
  }

  #transactionsView .mobile-transaction-card {
    display: grid;
    gap: 12px;
    min-width: 0;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }

  #transactionsView .mobile-transaction-card :is(strong, span) {
    display: block;
  }

  #transactionsView .mobile-transaction-card span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.82rem;
  }

  #transactionsView .mobile-transaction-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  #transactionsView .mobile-transaction-actions .action-group {
    min-width: 0;
  }
}

/* Honour OS motion preferences before a user profile can load its setting. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
  }

  .auth-word-rotator span {
    display: none;
    opacity: 0;
    transform: none;
  }

  .auth-word-rotator span:first-child {
    display: block;
    opacity: 1;
  }
}

@media (min-width: 1181px) and (max-height: 760px) {
  .auth-card {
    align-self: center;
    max-height: calc(100dvh - 40px);
    margin-block: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .auth-tabs {
    position: sticky;
    top: 0;
    z-index: 2;
  }
}

/* Form semantics and feedback are shared across every feature form. */
.field-label-row > .field-label-text {
  min-width: 0;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  line-height: inherit;
  cursor: pointer;
}

.field-label-row > .field-label-text:has(+ .icon-toggle) {
  flex: 1 1 auto;
}

.field-error {
  display: block;
  width: 100%;
  margin-top: 2px;
  color: var(--danger);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.35;
}

.field :is(input, select, textarea)[aria-invalid="true"] {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent) !important;
}

.field :is(input, select, textarea)[aria-invalid="true"]:focus-visible {
  outline-color: var(--danger) !important;
}

.security-grid-heading {
  grid-column: 1 / -1;
  display: grid;
  gap: 3px;
  margin-top: 8px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.security-grid-heading:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.security-grid-heading h4,
.security-grid-heading p {
  margin: 0;
}

.security-grid-heading p {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.goal-progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.goal-progress-heading strong {
  color: var(--ink);
  font-size: 0.78rem;
}

.metric-card[data-snapshot-detail]::after {
  display: block;
  margin-top: 10px;
  color: var(--accent-strong);
  content: "View details \2192";
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.settings-panel[hidden],
.settings-nav-link[hidden] {
  display: none !important;
}

@media (hover: none) and (pointer: coarse) {
  .field :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]), select, textarea),
  .period-control :is(input, select),
  .settings-nav-link,
  .setup-mode-card,
  .onboarding-actions .button,
  .auth-keyword-token {
    min-height: 44px;
  }
}

/* Navigation rail controls are desktop-only. The icon dimensions also keep the
   shared footer actions proportionate when the same markup moves below mobile
   content. */
#navigationRailToggle {
  display: none;
}

/* Side rails reserve the settings control beside the name, then give the
   household scope selector a full row so its label and value never collide. */
@media (min-width: 901px) {
  #primaryNavigationRail .user-card-row {
    display: grid;
    grid-template-areas:
      "avatar name settings"
      "avatar scope scope";
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 12px;
    row-gap: 6px;
  }

  #primaryNavigationRail .user-card-row > .avatar {
    grid-area: avatar;
  }

  #primaryNavigationRail .user-card-details {
    display: contents;
  }

  #primaryNavigationRail #activeUserName {
    grid-area: name;
  }

  #primaryNavigationRail .person-scope-control {
    grid-area: scope;
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
    min-width: 0;
    margin-top: 0;
  }

  #primaryNavigationRail .person-scope-control select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  #primaryNavigationRail .user-settings-button {
    grid-area: settings;
  }
}

.sidebar-action-icon {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

/* Full-height navigation stays on the left on desktop and can collapse to an
   icon rail without changing the established tablet header or phone tab bar. */
@media (min-width: 1181px) {
  :root {
    --desktop-navigation-rail-width: 304px;
  }

  :root[data-navigation-rail="collapsed"] {
    --desktop-navigation-rail-width: 88px;
  }

  :root[data-navigation-rail="expanded"] {
    --desktop-navigation-rail-width: 304px;
  }

  #appShell[data-navigation-collapsed] {
    grid-template-columns: var(--desktop-navigation-rail-width) minmax(0, 1fr);
    transition: grid-template-columns 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  #appShell[data-navigation-collapsed="false"] {
    --desktop-navigation-rail-width: 304px;
  }

  #appShell[data-navigation-collapsed="true"] {
    --desktop-navigation-rail-width: 88px;
  }

  #appShell[data-navigation-collapsed] > .workspace {
    grid-row: 1;
    grid-column: 2;
  }

  #appShell[data-navigation-collapsed] > #primaryNavigationRail {
    position: sticky;
    top: 0;
    z-index: 10;
    grid-row: 1;
    grid-column: 1;
    width: 100%;
    min-width: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 0;
  }

  #primaryNavigationRail > .nav-list {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
    scrollbar-width: thin;
  }

  #navigationRailToggle {
    position: absolute;
    top: max(24px, calc(var(--safe-top) + 18px));
    right: -22px;
    left: auto;
    z-index: 24;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    color: rgba(255, 255, 255, 0.82);
    background: color-mix(in srgb, var(--nav) 92%, var(--surface));
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(2, 6, 23, 0.28);
    cursor: pointer;
    transition:
      color 160ms ease,
      background-color 160ms ease,
      border-color 160ms ease,
      box-shadow 180ms ease,
      transform 180ms ease;
  }

  #navigationRailToggle:hover {
    color: #ffffff;
    background: color-mix(in srgb, var(--accent) 24%, var(--nav));
    border-color: color-mix(in srgb, var(--accent-glow) 46%, rgba(255, 255, 255, 0.18));
    box-shadow: 0 14px 32px rgba(2, 6, 23, 0.34);
    transform: translateX(1px);
  }

  #navigationRailToggle:focus-visible {
    color: #ffffff;
    outline: 3px solid color-mix(in srgb, var(--accent-glow) 72%, #ffffff);
    outline-offset: 3px;
  }

  #navigationRailToggle svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }

  #navigationRailToggle .navigation-rail-toggle-arrow {
    transform: rotate(180deg);
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  #appShell[data-navigation-collapsed="true"] #navigationRailToggle .navigation-rail-toggle-arrow {
    transform: rotate(0deg);
  }

  #primaryNavigationRail .sidebar-actions > .text-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  #appShell[data-navigation-collapsed="true"] > #primaryNavigationRail {
    padding-inline: 16px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .brand-button {
    justify-content: center;
    min-width: 0;
    height: 56px;
    padding: 6px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .brand-button > div:last-child {
    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;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail :is(.nav-label, .sidebar-action-label) {
    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;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .user-card {
    min-height: 0;
    margin: 16px 0 14px;
    padding: 5px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .user-card-row {
    grid-template-areas:
      "avatar"
      "settings";
    grid-template-columns: minmax(0, 1fr);
    justify-content: center;
    justify-items: center;
    gap: 8px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .user-card-details,
  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .user-card-email {
    display: none;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail :is(.avatar, .user-settings-button) {
    flex: 0 0 auto;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .user-settings-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .nav-list {
    width: 100%;
    min-width: 0;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .nav-link {
    position: relative;
    justify-content: center;
    gap: 0;
    width: 48px;
    min-width: 48px;
    min-height: 44px;
    margin-inline: auto;
    padding: 6px;
    text-align: center;
    overflow: visible;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .nav-icon {
    width: 32px;
    height: 32px;
    color: currentColor;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .nav-number {
    display: none;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .nav-symbol {
    display: block;
    width: 20px;
    height: 20px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .sidebar-footer {
    padding: 7px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .sidebar-footer > :is(.eyebrow, .mini-meter, strong, .app-version) {
    display: none;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .sidebar-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 6px;
    width: 100%;
    margin-top: 0;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .sidebar-actions > .text-button {
    justify-content: center;
    gap: 0;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 9px;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .sidebar-actions > .text-button:hover,
  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail .sidebar-actions > .text-button:focus-visible {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.13);
    border-color: color-mix(in srgb, var(--accent-glow) 34%, rgba(255, 255, 255, 0.14));
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail :is(
    .brand-button,
    .user-settings-button,
    .nav-link,
    .sidebar-actions > .text-button
  ) {
    position: relative;
    overflow: visible;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail :is(
    .brand-button,
    .user-settings-button,
    .nav-link,
    .sidebar-actions > .text-button
  )::before {
    position: absolute;
    top: 50%;
    right: auto;
    left: calc(100% + 12px);
    z-index: 40;
    width: max-content;
    max-width: 220px;
    padding: 7px 10px;
    color: #ffffff;
    background: color-mix(in srgb, var(--nav) 94%, #000000);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 9px;
    box-shadow: 0 10px 28px rgba(2, 6, 23, 0.28);
    content: attr(aria-label);
    font-size: 0.75rem;
    font-weight: 800;
    line-height: 1.2;
    opacity: 0;
    pointer-events: none;
    transform: translate(-6px, -50%);
    transition: opacity 140ms ease, transform 140ms ease;
    white-space: nowrap;
  }

  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail :is(
    .brand-button,
    .user-settings-button,
    .nav-link,
    .sidebar-actions > .text-button
  ):is(:hover, :focus-visible)::before {
    opacity: 1;
    transform: translate(0, -50%);
  }

  :root[data-motion="reduced"] #appShell[data-navigation-collapsed],
  :root[data-motion="reduced"] #navigationRailToggle,
  :root[data-motion="reduced"] #navigationRailToggle .navigation-rail-toggle-arrow,
  :root[data-motion="reduced"] #appShell[data-navigation-collapsed="true"] #primaryNavigationRail :is(
    .brand-button,
    .user-settings-button,
    .nav-link,
    .sidebar-actions > .text-button
  )::before {
    transition: none !important;
  }
}

@media (min-width: 1181px) and (prefers-reduced-motion: reduce) {
  #appShell[data-navigation-collapsed],
  #navigationRailToggle,
  #navigationRailToggle .navigation-rail-toggle-arrow,
  #appShell[data-navigation-collapsed="true"] #primaryNavigationRail :is(
    .brand-button,
    .user-settings-button,
    .nav-link,
    .sidebar-actions > .text-button
  )::before {
    transition: none !important;
  }
}

/*
  Authoritative phone layout for content-driven dashboard widgets.
  Intrinsic grid tracks prevent Safari from sizing a card before its rendered
  rows arrive, which previously let Prediction content escape under Goal Capacity.
*/
@media (max-width: 760px) {
  #dashboardView.active {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-auto-flow: row;
    grid-auto-rows: max-content;
    align-items: start;
  }

  #dashboardView.active > .prediction-widget,
  #dashboardView.active > .goal-capacity-widget {
    display: grid;
    grid-template-rows: max-content max-content;
    align-content: start;
    align-self: start;
    block-size: max-content !important;
    min-block-size: max-content !important;
    max-block-size: none !important;
    overflow: clip;
  }

  #dashboardView.active > .prediction-widget > .prediction-list,
  #dashboardView.active > .goal-capacity-widget > .goal-capacity {
    position: static;
    block-size: max-content !important;
    min-block-size: max-content;
  }

  #dashboardView.active > .prediction-widget .prediction-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 0;
    padding: 11px 12px;
  }

  #dashboardView.active > .prediction-widget .prediction-row span {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  #dashboardView.active > .prediction-widget .prediction-row strong {
    white-space: nowrap;
  }

  #dashboardView.active > .goal-capacity-widget .goal-capacity-hero {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr));
  }

  #dashboardView.active > .goal-capacity-widget .goal-capacity-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

@media (max-width: 340px) {
  #dashboardView.active > .prediction-widget .prediction-row,
  #dashboardView.active > .goal-capacity-widget .goal-capacity-row {
    grid-template-columns: minmax(0, 1fr);
  }

  #dashboardView.active > .prediction-widget .prediction-row strong,
  #dashboardView.active > .goal-capacity-widget .goal-capacity-row > strong {
    justify-self: start;
    text-align: left;
  }
}

/*
  Authoritative phone chrome and form-density pass.
  These rules intentionally live last: earlier responsive layers cover older
  layouts and must not be allowed to re-inflate current phone controls.
*/
.onboarding-card > .modal-header h2 {
  margin: 0;
}

@media (max-width: 760px) {
  :root {
    /* Includes the floating rail, its viewport inset, and breathing room. */
    --mobile-nav-height: 92px;
  }

  html {
    scroll-padding-top: calc(var(--mobile-shell-header-height, 76px) + var(--safe-top) + 12px);
    scroll-padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 12px);
  }

  #primaryNavigationRail {
    position: sticky;
    top: 0;
    z-index: 40;
    align-self: start;
    background: var(--nav);
    isolation: isolate;
  }

  #appShell:not(.hidden)::after {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 34;
    height: calc(var(--mobile-nav-height) + var(--safe-bottom) + 12px);
    background: linear-gradient(to bottom, transparent, var(--bg) 22px, var(--bg));
    content: "";
    pointer-events: none;
  }

  #appShell:not(.hidden) ~ .toast {
    bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 24px);
    z-index: 80;
  }

  .workspace {
    padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 26px);
  }

  .workspace :is(input, select, textarea, button, [tabindex]):not(.nav-link) {
    scroll-margin-top: calc(var(--mobile-shell-header-height, 76px) + var(--safe-top) + 12px);
    scroll-margin-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom) + 16px);
  }

  .onboarding-card > .modal-header {
    align-items: flex-start;
  }

  .onboarding-card > .modal-header > :first-child {
    min-width: 0;
  }

  .onboarding-card.setup-method-active {
    align-self: start;
    min-height: 0;
  }

  .onboarding-card.setup-method-active #onboardingBackBtn {
    display: none;
  }

  .onboarding-card.setup-method-active .setup-mode-panel {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-block: 8px;
    padding: 12px;
  }

  .onboarding-card.setup-method-active .setup-mode-orbit {
    height: 118px;
    margin-top: 12px;
  }

  .onboarding-card.setup-method-active .setup-mode-card {
    min-height: 82px;
    padding: 10px;
  }

  .onboarding-card .wizard-actions .button {
    min-height: 44px;
  }

  /* Preserve a compact visual control while its transparent pseudo area keeps
     the effective coarse-pointer target close to 44px. */
  .field-help-button,
  .modal-card .field-help-button,
  .onboarding-card .field-help-button {
    width: 28px;
    min-width: 28px;
    height: 28px;
    min-height: 28px;
    padding: 0;
    font-size: 0.7rem;
  }

  .field-help-button::after {
    position: absolute;
    inset: -8px;
    border-radius: 999px;
    content: "";
  }

  #settingsIncomeForm .field-label-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) repeat(3, auto);
    align-items: center;
    gap: 12px;
    min-width: 0;
    width: 100%;
  }

  #settingsIncomeForm .field-label-text {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  #settingsIncomeForm .field:has(> input[required]) > .field-label-row::after,
  #settingsIncomeForm .field:has(> select[required]) > .field-label-row::after,
  #settingsIncomeForm .field:has(> textarea[required]) > .field-label-row::after {
    width: 7px;
    min-width: 7px;
    height: 7px;
    min-height: 7px;
    padding: 0;
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-panel);
    content: "";
  }

  #settingsIncomeForm .checkbox-field {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    align-items: start;
    column-gap: 10px;
  }

  #settingsIncomeForm .checkbox-field > input {
    margin-top: 3px;
  }

  #settingsIncomeForm .checkbox-field > .field-label-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  #dashboardView > .metric-grid {
    border-left: 0 !important;
  }

  #dashboardView > .metric-grid .metric-card strong {
    max-width: 100%;
    font-size: clamp(0.96rem, 4.9vw, 1.38rem) !important;
    font-size: clamp(0.96rem, 10.4cqw, 1.38rem) !important;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.025em;
    overflow-wrap: normal;
    white-space: nowrap;
  }

  #cashFlowPanel {
    padding: 12px !important;
  }

  #cashFlowPanel > .panel-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  #cashFlowPanel .cash-flow-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 8px;
    width: 100%;
  }

  #cashFlowPanel .cash-flow-actions .segmented-control {
    width: 100%;
  }

  #cashFlowPanel #openCashFlowReportBtn {
    min-width: 104px;
    min-height: 44px;
  }

  #cashFlowPanel .cash-flow-controlbar {
    gap: 8px;
    padding: 10px;
  }

  #cashFlowPanel .chart-wrap,
  #dashboardView > .dashboard-cash-flow-widget[data-widget-size] .chart-wrap {
    height: clamp(220px, 58vw, 260px) !important;
  }
}

@media (max-width: 340px) {
  #cashFlowPanel .cash-flow-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  #dashboardView > .metric-grid,
  #dashboardView > .metric-grid[data-widget-size] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
