:root {
  --bg: #f4efe6;
  --bg-strong: #e7dcc8;
  --surface: #fffdfa;
  --surface-soft: #f8f2e8;
  --line: #d9ccb6;
  --ink: #1d1a16;
  --muted: #6b6257;
  --primary: #0c6d64;
  --primary-strong: #0a564f;
  --accent: #e58a39;
  --danger: #9f3f2f;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow: 0 22px 48px rgba(40, 26, 8, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 12%, rgba(229, 138, 57, 0.26), transparent 38%),
    radial-gradient(circle at 88% 8%, rgba(12, 109, 100, 0.2), transparent 34%),
    radial-gradient(circle at 50% 115%, rgba(229, 138, 57, 0.16), transparent 35%),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.42;
  background-image: linear-gradient(rgba(80, 63, 36, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(80, 63, 36, 0.05) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at center, #000 30%, transparent 100%);
}

body.modal-open {
  overflow: hidden;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  letter-spacing: 0.01em;
}

h1 {
  font-size: clamp(1.5rem, 1.8vw, 2.15rem);
}

h2 {
  font-size: clamp(1.3rem, 1.5vw, 1.65rem);
}

h3 {
  font-size: 0.95rem;
}

label {
  display: grid;
  gap: 0.35rem;
}

input,
select,
button {
  font: inherit;
}

input:not([type="checkbox"]),
select {
  width: 100%;
  min-height: 50px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0.55rem 0.75rem;
  background: #fff;
  color: var(--ink);
}

input:not([type="checkbox"]):focus,
select:focus,
button:focus {
  outline: 2px solid rgba(12, 109, 100, 0.35);
  outline-offset: 2px;
}

.app-shell {
  position: relative;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.05rem;
  display: grid;
  gap: 1rem;
  z-index: 1;
}

.card {
  background: linear-gradient(150deg, rgba(255, 253, 250, 0.95), rgba(245, 236, 221, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand-block {
  display: grid;
  gap: 0.25rem;
}

.eyebrow {
  color: var(--primary);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
}

.date-context {
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 0.62rem 1rem;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

.btn-primary {
  background: linear-gradient(160deg, var(--primary), var(--primary-strong));
  color: #fff;
  box-shadow: 0 12px 22px rgba(10, 86, 79, 0.24);
}

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

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  padding: 0.75rem;
}

.tab-btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f2eadc;
  color: var(--ink);
  font-weight: 600;
  padding: 0.78rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.tab-btn.active {
  background: linear-gradient(160deg, var(--primary), #0f7f75);
  color: #fff;
  border-color: transparent;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.72);
}

.tab-btn:hover {
  transform: translateY(-1px);
}

.status {
  min-height: 1.45rem;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
  padding-left: 0.2rem;
}

.status.error {
  color: var(--danger);
}

.delight-banner {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  border: 1px solid rgba(12, 109, 100, 0.28);
  color: #083e39;
  font-weight: 600;
  background: linear-gradient(120deg, rgba(12, 109, 100, 0.18), rgba(229, 138, 57, 0.2));
  animation: banner-in 320ms ease;
}

.delight-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.34), transparent);
  transform: translateX(-120%);
  animation: sheen 2.8s ease-in-out infinite;
}

.available-card {
  display: grid;
  gap: 0.28rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(145deg, rgba(12, 109, 100, 0.16), rgba(255, 253, 250, 0.95));
}

.available-label {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #0a534c;
  font-weight: 700;
}

.available-amount {
  font-family: "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  font-size: clamp(2rem, 4.2vw, 3rem);
  line-height: 1.05;
  font-weight: 700;
}

.available-detail {
  color: var(--muted);
  font-size: 0.92rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.metrics {
  animation: rise-in 420ms ease;
}

.metric-list {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 0.7rem;
}

.metric-list article {
  background: linear-gradient(160deg, #f2eadc, #efe4d4);
  border: 1px solid #dfd0b8;
  border-radius: var(--radius-md);
  padding: 0.72rem;
}

.metric-list h3 {
  color: var(--muted);
  font-weight: 600;
}

.metric-list p {
  margin-top: 0.2rem;
  font-size: 1.28rem;
  font-weight: 700;
}

.story-card,
.pace-card,
.trend-panel {
  animation: rise-in 460ms ease;
}

.story-headline {
  margin-top: 0.7rem;
  font-size: clamp(1.05rem, 1.35vw, 1.35rem);
  font-weight: 700;
}

.story-subhead {
  margin-top: 0.55rem;
  color: var(--muted);
}

.progress-row {
  margin-top: 0.95rem;
  display: grid;
  gap: 0.5rem;
}

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

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.28s ease;
}

.progress-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.pace-title {
  margin-top: 0.7rem;
  font-size: 1.08rem;
  font-weight: 700;
}

.pace-description {
  margin-top: 0.5rem;
  color: var(--muted);
}

.pace-detail {
  margin-top: 0.7rem;
  font-weight: 700;
  color: #093f3b;
}

.trend-wrapper {
  margin-top: 0.85rem;
  min-height: 220px;
  border-radius: var(--radius-md);
  border: 1px solid #e2d7c6;
  background: rgba(255, 255, 255, 0.68);
  padding: 0.4rem;
}

#spend-trend {
  width: 100%;
  height: 220px;
}

.pie-wrapper {
  margin-top: 0.85rem;
  min-height: 260px;
  display: grid;
  place-items: center;
}

.legend {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.legend li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.92rem;
}

.legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  display: inline-block;
  margin-right: 0.42rem;
}

.inline-form {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
}

.category-list,
.transactions {
  margin-top: 0.85rem;
}

.category-list {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid #e3d7c7;
  background: #fff;
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
}

.category-item button {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 600;
}

.transactions-toolbar {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 0.65rem;
}

.transactions-search,
.transactions-sort {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
}

.transactions-search input,
.transactions-sort select {
  min-height: 46px;
}

.transactions-filter {
  margin-top: 0.55rem;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
}

.transactions-filter input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--primary);
}

.transactions-meta {
  margin-top: 0.45rem;
}

.transactions {
  max-height: 520px;
  display: grid;
  gap: 0.62rem;
  overflow: auto;
  padding-right: 0.2rem;
}

.tx-row {
  border: 1px solid #ddcfb9;
  border-radius: 14px;
  padding: 0.72rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 310px);
  gap: 0.8rem 1rem;
  background: linear-gradient(160deg, #fffdf8, #fbf5e9);
  position: relative;
  z-index: 0;
  animation: tx-rise 320ms ease both;
  animation-delay: var(--delay, 0ms);
}

.tx-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  border-radius: 14px 0 0 14px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  opacity: 0.32;
}

.tx-row.picker-open {
  z-index: 30;
}

.tx-payee {
  font-weight: 700;
}

.tx-payee.has-raw-name {
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-underline-offset: 0.18em;
  cursor: help;
}

.tx-date,
.tx-memo {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 0.2rem;
}

.tx-meta {
  display: grid;
  gap: 0.5rem;
}

.tx-amount {
  font-size: 1.02rem;
  font-weight: 700;
  text-align: right;
}

.tx-category-picker {
  position: relative;
}

.tx-category-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.58rem 0.68rem;
  background: #fff;
}

.tx-category-listbox {
  position: absolute;
  top: calc(100% + 0.36rem);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 18px 30px rgba(40, 26, 8, 0.16);
  padding: 0.35rem;
  display: grid;
  gap: 0.2rem;
  z-index: 40;
}

.tx-category-listbox[hidden] {
  display: none;
}

.tx-category-option {
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  color: var(--ink);
  padding: 0.48rem 0.52rem;
  cursor: pointer;
}

.tx-category-option[data-active="true"] {
  background: #e4f0ee;
}

.tx-category-option[data-selected="true"] {
  font-weight: 700;
}

.tx-category-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0.45rem 0.5rem;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 12, 8, 0.38);
  backdrop-filter: blur(3px);
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: min(1040px, 100%);
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  background: linear-gradient(170deg, #fffdfa, #f7eddc);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 46px rgba(18, 11, 5, 0.25);
  padding: 1rem;
}

.auth-modal {
  width: min(460px, 100%);
}

.auth-form {
  grid-template-columns: 1fr;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.1rem;
}

.settings-field {
  font-size: 1rem;
  font-weight: 600;
  gap: 0.5rem;
}

.settings-field input,
.settings-field select,
.field-with-action .btn {
  min-height: 54px;
}

.field-with-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.62rem;
}

.settings-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.72rem;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tx-rise {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.995);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes banner-in {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sheen {
  to {
    transform: translateX(120%);
  }
}

@media (min-width: 1080px) {
  .dashboard-grid {
    grid-template-columns: 1.2fr 0.8fr;
  }

  .metrics,
  .trend-panel,
  .transactions-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

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

  .field-with-action {
    grid-template-columns: 1fr;
  }

  .field-with-action .btn {
    width: 100%;
  }

  .transactions-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 0.72rem;
  }

  .card {
    border-radius: 18px;
    padding: 0.82rem;
  }

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

  .tx-row {
    grid-template-columns: 1fr;
  }

  .tx-amount {
    text-align: left;
  }
}
