:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dfe3e6;
  --line-strong: #c8ced6;
  --green: #0f8b6f;
  --green-deep: #0a6d58;
  --blue: #2f6fdd;
  --rose: #c93852;
  --amber: #b7791f;
  --violet: #7251b5;
  --teal: #007c89;
  --shadow: 0 14px 42px rgba(32, 33, 36, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100svh;
  margin: 0;
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: progress;
  opacity: 0.72;
}

img,
svg {
  display: block;
}

.noscript {
  max-width: 560px;
  margin: 80px auto;
  padding: 24px;
}

.auth-screen {
  display: grid;
  min-height: 100svh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 430px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 58px;
  height: 58px;
  margin-bottom: 22px;
}

.auth-panel h1,
.topbar h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.auth-panel h1 {
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1;
}

.auth-copy {
  margin: 12px 0 24px;
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green-deep);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-shell {
  display: grid;
  min-height: 100svh;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100svh;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

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

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

.brand span {
  color: var(--muted);
  font-size: 0.88rem;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-button,
.quiet-button,
.icon-button,
.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.nav-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: var(--surface-soft);
  color: var(--green-deep);
}

.quiet-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  min-width: 42px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button:hover,
.quiet-button:hover,
.secondary-button:hover {
  border-color: var(--line-strong);
  background: #f9fafb;
}

.nav-button:focus-visible,
.quiet-button:focus-visible,
.icon-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.danger-button:focus-visible {
  outline: 3px solid rgba(15, 139, 111, 0.22);
  outline-offset: 2px;
}

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

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 1.05;
}

.top-actions,
.button-row,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.month-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}

.month-picker input {
  width: 132px;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.view {
  display: grid;
  gap: 18px;
}

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

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

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(32, 33, 36, 0.03);
}

.metric {
  min-height: 128px;
  padding: 18px;
  border-top-width: 4px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 12px 0 8px;
  font-size: clamp(1.55rem, 2.2vw, 2.25rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.accent-green {
  border-top-color: var(--green);
}

.accent-rose {
  border-top-color: var(--rose);
}

.accent-amber {
  border-top-color: var(--amber);
}

.accent-blue {
  border-top-color: var(--blue);
}

.content-grid {
  display: grid;
  gap: 18px;
}

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

.form-and-list {
  grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.1fr);
}

.panel {
  min-width: 0;
  padding: 18px;
}

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

.panel h2 {
  font-size: 1.08rem;
  line-height: 1.2;
}

.stacked-form,
.grid-form {
  display: grid;
  gap: 14px;
}

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

.form-field {
  display: grid;
  gap: 7px;
}

.form-field label,
.check-field,
.month-picker span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
}

.form-field textarea {
  min-height: 88px;
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.month-picker:focus-within {
  border-color: var(--green);
  outline: 3px solid rgba(15, 139, 111, 0.14);
}

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

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  max-width: 100%;
  padding: 0 16px;
  font-weight: 750;
  text-align: center;
  white-space: normal;
}

.primary-button {
  background: var(--green);
  color: white;
}

.primary-button:hover {
  background: var(--green-deep);
}

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

.danger-button {
  background: var(--rose);
  color: white;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.form-message {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--rose);
  font-weight: 650;
}

.auth-actions {
  display: flex;
  margin-top: 16px;
}

.chart-canvas {
  width: 100%;
  height: 280px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.legend-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.category-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 999px;
  background: #6b7280;
}

.transaction-list,
.investment-list,
.account-list,
.compact-list,
.progress-list {
  display: grid;
  gap: 10px;
}

.transaction-row,
.investment-row,
.account-row,
.compact-row,
.progress-item {
  position: relative;
  display: grid;
  align-items: center;
  min-height: 58px;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.transaction-row {
  grid-template-columns: 10px minmax(0, 1fr) auto 42px;
  padding: 10px;
}

.transaction-body,
.investment-row > div,
.account-row > div,
.progress-top > div {
  min-width: 0;
}

.transaction-body strong,
.transaction-body span,
.investment-row strong,
.investment-row span,
.account-row strong,
.account-row span,
.progress-top strong,
.progress-top span {
  display: block;
}

.transaction-body span,
.investment-row span,
.account-row span,
.progress-top span,
.subtle-note,
.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
}

.amount-positive {
  color: var(--green-deep);
}

.amount-negative {
  color: var(--rose);
}

.investment-row {
  grid-template-columns: minmax(0, 1fr) auto 42px;
  padding: 12px;
}

.account-row {
  grid-template-columns: 42px minmax(0, 1fr) auto 42px;
  padding: 12px;
}

.account-badge {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  color: var(--green-deep);
  background: var(--surface-soft);
}

.card-badge {
  color: var(--amber);
  background: #f8f0e4;
}

.account-value {
  text-align: right;
}

.account-value span {
  color: var(--muted);
  font-size: 0.86rem;
}

.account-snapshot {
  display: grid;
  gap: 10px;
}

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

.due-list span {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--green-deep);
  padding: 0 10px;
  font-size: 0.84rem;
  font-weight: 700;
}

.compact-row {
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px;
}

.compact-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-item {
  padding: 12px;
}

.progress-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.progress-status {
  text-align: right;
}

.row-remove {
  position: absolute;
  right: 10px;
  top: 10px;
}

.progress-item:has(.row-remove) {
  padding-right: 62px;
}

progress {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #e7eaee;
}

progress::-webkit-progress-bar {
  border-radius: 999px;
  background: #e7eaee;
}

progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--green);
}

progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--green);
}

.runway-panel {
  display: grid;
  gap: 12px;
}

.runway-panel strong {
  font-size: clamp(1.6rem, 3vw, 2.3rem);
}

.runway-panel span {
  color: var(--muted);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.security-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.cloud-panel,
.device-panel {
  display: grid;
  gap: 14px;
}

.cloud-status {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  padding: 12px;
}

.cloud-status span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.security-row p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.security-icon {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--green-deep);
}

.danger-panel {
  border-color: rgba(201, 56, 82, 0.4);
}

.empty-state {
  display: grid;
  min-height: 96px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfd;
  padding: 18px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.mobile-nav {
  display: none;
}

.category-housing {
  background: #2f6fdd;
}

.category-food {
  background: #0f8b6f;
}

.category-transportation {
  background: #b7791f;
}

.category-utilities {
  background: #007c89;
}

.category-healthcare {
  background: #c93852;
}

.category-insurance {
  background: #7251b5;
}

.category-debt {
  background: #8a5a44;
}

.category-entertainment {
  background: #d05b33;
}

.category-education {
  background: #356859;
}

.category-travel {
  background: #4169a8;
}

.category-investing {
  background: #0b6e4f;
}

.category-savings {
  background: #8f6b00;
}

.category-income {
  background: #277a48;
}

.category-other {
  background: #6b7280;
}

progress.category-housing::-webkit-progress-value { background: #2f6fdd; }
progress.category-food::-webkit-progress-value { background: #0f8b6f; }
progress.category-transportation::-webkit-progress-value { background: #b7791f; }
progress.category-utilities::-webkit-progress-value { background: #007c89; }
progress.category-healthcare::-webkit-progress-value { background: #c93852; }
progress.category-insurance::-webkit-progress-value { background: #7251b5; }
progress.category-debt::-webkit-progress-value { background: #8a5a44; }
progress.category-entertainment::-webkit-progress-value { background: #d05b33; }
progress.category-education::-webkit-progress-value { background: #356859; }
progress.category-travel::-webkit-progress-value { background: #4169a8; }
progress.category-investing::-webkit-progress-value { background: #0b6e4f; }
progress.category-savings::-webkit-progress-value { background: #8f6b00; }
progress.category-income::-webkit-progress-value { background: #277a48; }
progress.category-other::-webkit-progress-value { background: #6b7280; }

progress.category-housing::-moz-progress-bar { background: #2f6fdd; }
progress.category-food::-moz-progress-bar { background: #0f8b6f; }
progress.category-transportation::-moz-progress-bar { background: #b7791f; }
progress.category-utilities::-moz-progress-bar { background: #007c89; }
progress.category-healthcare::-moz-progress-bar { background: #c93852; }
progress.category-insurance::-moz-progress-bar { background: #7251b5; }
progress.category-debt::-moz-progress-bar { background: #8a5a44; }
progress.category-entertainment::-moz-progress-bar { background: #d05b33; }
progress.category-education::-moz-progress-bar { background: #356859; }
progress.category-travel::-moz-progress-bar { background: #4169a8; }
progress.category-investing::-moz-progress-bar { background: #0b6e4f; }
progress.category-savings::-moz-progress-bar { background: #8f6b00; }
progress.category-income::-moz-progress-bar { background: #277a48; }
progress.category-other::-moz-progress-bar { background: #6b7280; }

@media (max-width: 1080px) {
  .metric-grid,
  .metric-grid.three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-columns,
  .form-and-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
    min-height: 100svh;
  }

  .sidebar {
    display: none;
  }

  .workspace {
    padding: 18px 14px calc(86px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    align-items: flex-start;
    margin: -18px -14px 18px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(245, 246, 248, 0.96);
    backdrop-filter: blur(10px);
  }

  .topbar h1 {
    font-size: 1.65rem;
  }

  .top-actions {
    justify-content: flex-end;
  }

  .month-picker {
    width: 100%;
    justify-content: space-between;
  }

  .mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 2px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .mobile-nav .nav-button {
    min-height: 56px;
    flex-direction: column;
    gap: 3px;
    justify-content: center;
    padding: 4px 2px;
    font-size: 0.62rem;
    text-align: center;
  }

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

  .mobile-nav .icon {
    width: 19px;
    height: 19px;
  }

  .toast {
    right: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 620px) {
  .auth-screen {
    align-items: stretch;
    padding: 12px;
  }

  .auth-panel {
    align-self: center;
    padding: 22px;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px 42px;
    width: 100%;
  }

  .metric-grid,
  .metric-grid.three,
  .grid-form {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 112px;
  }

  .panel {
    padding: 14px;
  }

  .transaction-row {
    grid-template-columns: 10px minmax(0, 1fr) 42px;
  }

  .transaction-row > .amount-positive,
  .transaction-row > .amount-negative {
    grid-column: 2;
  }

  .transaction-row > .icon-button {
    grid-column: 3;
    grid-row: 1 / span 2;
  }

  .investment-row {
    grid-template-columns: minmax(0, 1fr) 42px;
  }

  .investment-row > strong {
    grid-column: 1;
  }

  .account-row {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
  }

  .account-value {
    grid-column: 2;
    text-align: left;
  }

  .account-row > .icon-button {
    grid-column: 3;
    grid-row: 1 / span 2;
  }

  .compact-row,
  .progress-top {
    grid-template-columns: 1fr;
  }

  .progress-status {
    text-align: left;
  }

  .button-row,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row > *,
  .form-actions > *,
  .primary-button,
  .secondary-button,
  .danger-button {
    width: 100%;
  }
}
