:root {
  --bg: #f8f4ed;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #2f3a40;
  --muted: #858176;
  --line: #dfd8cc;
  --accent: #7e8b7c;
  --accent-dark: #5f6d61;
  --accent-soft: #eff2ed;
  --roof: #a0998e;
  --warning: #a77a4b;
  --danger: #9b4a45;
  --blue: #42515a;
  --green: #7e8b7c;
  --orange: #b3956d;
  --rose: #9b7777;
  --shadow: 0 18px 44px rgba(64, 56, 46, 0.08);
  --radius: 8px;
  --display-font: "Cormorant Garamond", Baskerville, "Libre Baskerville", Georgia, "Times New Roman", serif;
  --body-font: Optima, "Avenir Next", Avenir, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-family: var(--body-font);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(126, 139, 124, 0.14), transparent 34%),
    radial-gradient(circle at 88% 10%, rgba(160, 153, 142, 0.14), transparent 30%),
    linear-gradient(135deg, rgba(179, 149, 109, 0.08), transparent 48%),
    var(--bg);
  color: var(--ink);
}

body.auth-locked {
  min-height: 100vh;
}

body.auth-locked .app-shell {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    border-color 150ms ease,
    background 150ms ease;
}

button:hover,
.file-button:hover {
  transform: translateY(-1px);
}

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

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

.auth-screen[hidden] {
  display: none;
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(280px, 1fr);
  width: min(900px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(253, 251, 246, 0.96);
  box-shadow: 0 28px 80px rgba(47, 58, 64, 0.16);
}

.auth-brand {
  align-content: center;
  margin: 0;
  padding: 34px 28px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(126, 139, 124, 0.1), transparent),
    #f5f0e7;
}

.auth-form {
  display: grid;
  gap: 16px;
  align-content: center;
  padding: 38px;
}

.auth-form h2 {
  margin: 5px 0 0;
  font-family: var(--display-font);
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 400;
  line-height: 1;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 0.84rem;
  font-weight: 800;
}

.security-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.link-button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(47, 58, 64, 0.34);
  backdrop-filter: blur(10px);
}

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

.modal-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
  box-shadow: 0 28px 70px rgba(47, 58, 64, 0.18);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  align-self: start;
  min-height: 100vh;
  padding: 26px 22px;
  border-right: 1px solid var(--line);
  background: rgba(253, 251, 246, 0.9);
  backdrop-filter: blur(16px);
}

.brand {
  display: grid;
  justify-items: center;
  gap: 12px;
  margin-bottom: 26px;
  text-align: center;
}

.logo-mark {
  position: relative;
  display: grid;
  width: 124px;
  height: 108px;
  place-items: center;
  color: var(--ink);
}

.logo-mark strong {
  margin-top: 18px;
  font-family: var(--display-font);
  font-size: 4.9rem;
  font-weight: 500;
  letter-spacing: -0.08em;
  line-height: 0.85;
}

.roof,
.roof::after {
  position: absolute;
  top: 13px;
  left: 22px;
  width: 55px;
  height: 5px;
  border-radius: 999px;
  background: var(--roof);
  content: "";
  transform: rotate(-39deg);
  transform-origin: right center;
}

.roof::after {
  top: 0;
  left: 51px;
  width: 58px;
  transform: rotate(78deg);
  transform-origin: left center;
}

.chimney {
  position: absolute;
  top: 18px;
  right: 24px;
  width: 15px;
  height: 28px;
  background: var(--roof);
  border-radius: 2px 2px 0 0;
}

.sprig {
  position: absolute;
  right: 14px;
  bottom: 16px;
  width: 54px;
  height: 28px;
  border-bottom: 3px solid var(--accent);
  border-radius: 0 0 999px 999px;
  transform: rotate(-24deg);
}

.sprig::before,
.sprig::after {
  position: absolute;
  width: 16px;
  height: 8px;
  border-radius: 100% 0 100% 0;
  background: var(--accent);
  content: "";
  opacity: 0.86;
}

.sprig::before {
  right: 12px;
  bottom: 6px;
  transform: rotate(-20deg);
}

.sprig::after {
  right: -4px;
  bottom: 14px;
  transform: rotate(-58deg);
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h2,
.panel p {
  margin: 0;
}

.brand h1 {
  font-family: var(--display-font);
  font-size: 2.3rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.brand h1 span:first-child {
  color: var(--ink);
}

.brand h1 span:last-child {
  color: var(--accent);
}

.brand p,
.muted,
.summary-tile span,
.panel-heading span,
.select-field span,
.field span,
.expense-copy span {
  color: var(--muted);
}

.period-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 20px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ece7dc;
}

.period-tab {
  display: grid;
  gap: 2px;
  min-height: 52px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  text-align: center;
  padding: 8px 10px;
}

.period-tab span {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.period-tab b {
  color: inherit;
}

.period-tab.active,
.period-tab:hover {
  border-color: transparent;
  background: var(--surface-strong);
  color: var(--ink);
  box-shadow: 0 10px 24px rgba(17, 24, 39, 0.09);
}

.main-content {
  min-width: 0;
  padding: 28px 32px 34px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h2 {
  margin-top: 4px;
  font-family: var(--display-font);
  font-size: clamp(2rem, 4vw, 3.7rem);
  font-weight: 400;
  line-height: 1;
}

.topbar-actions,
.tool-row,
.filters,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.ledger-overview {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 14px;
  margin-bottom: 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.summary-tile,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(253, 251, 246, 0.94);
  box-shadow: var(--shadow);
}

.summary-tile {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(82, 109, 90, 0.08), transparent),
    var(--surface-strong);
}

.summary-tile.hero-total {
  grid-column: span 2;
  min-height: 132px;
  background:
    linear-gradient(135deg, rgba(126, 139, 124, 0.16), transparent),
    var(--surface-strong);
}

.summary-tile.hero-total strong {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.summary-tile:nth-child(2) {
  background:
    linear-gradient(180deg, rgba(102, 124, 92, 0.1), transparent),
    var(--surface-strong);
}

.summary-tile:nth-child(3) {
  background:
    linear-gradient(180deg, rgba(83, 97, 111, 0.09), transparent),
    var(--surface-strong);
}

.summary-tile:nth-child(4) {
  background:
    linear-gradient(180deg, rgba(169, 131, 82, 0.1), transparent),
    var(--surface-strong);
}

.summary-tile:nth-child(5) {
  background:
    linear-gradient(180deg, rgba(155, 106, 111, 0.08), transparent),
    var(--surface-strong);
}

.summary-tile:nth-child(6) {
  background:
    linear-gradient(180deg, rgba(31, 37, 34, 0.05), transparent),
    var(--surface-strong);
}

.summary-tile strong {
  overflow-wrap: anywhere;
  font-family: var(--display-font);
  font-size: clamp(1.3rem, 2vw, 1.8rem);
}

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

.insight-card {
  display: grid;
  gap: 6px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(253, 251, 246, 0.94);
  box-shadow: var(--shadow);
  padding: 14px;
}

.insight-card span,
.insight-card p {
  color: var(--muted);
}

.insight-card span {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.insight-card strong {
  overflow-wrap: anywhere;
  font-family: var(--display-font);
  font-size: 1.35rem;
}

.insight-card p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.35;
}

.panel {
  padding: 18px;
}

.compact-panel {
  margin-bottom: 14px;
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.05);
}

.tools-panel {
  margin-top: auto;
  margin-bottom: 0;
}

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

.panel-heading h2 {
  font-family: var(--display-font);
  font-size: 1rem;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(340px, 1.05fr) minmax(320px, 0.95fr);
  gap: 14px;
  margin-bottom: 14px;
}

.main-workspace {
  grid-template-columns: minmax(360px, 0.78fr) minmax(440px, 1.22fr);
  align-items: start;
}

.visual-grid {
  grid-template-columns: minmax(440px, 1.2fr) minmax(340px, 0.8fr);
}

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

.field,
.select-field {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 650;
}

.field input,
.field select,
.select-field input,
.select-field select,
.filters input,
.filters select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus,
.select-field input:focus,
.select-field select:focus,
.filters input:focus,
.filters select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(82, 109, 90, 0.12);
}

.budget-total {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.budget-total span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.budget-total strong {
  font-family: var(--display-font);
  font-size: 1.55rem;
}

.select-field {
  min-width: 136px;
}

.merchant-quick,
.quick-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.merchant-quick {
  margin: 16px 0 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.quick-categories {
  margin: 16px 0;
}

.merchant-button,
.quick-category {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

.merchant-button {
  border-color: rgba(126, 139, 124, 0.35);
  background: linear-gradient(180deg, #ffffff, #f3f0e9);
  color: var(--accent-dark);
  font-weight: 800;
}

.quick-category.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 750;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: var(--radius);
  padding: 0 16px;
  font-weight: 750;
}

.primary-button {
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: white;
  box-shadow: 0 12px 24px rgba(82, 109, 90, 0.2);
}

.primary-button:hover {
  box-shadow: 0 16px 28px rgba(83, 97, 111, 0.2);
}

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

.tool-button {
  display: grid;
  min-width: 76px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 850;
}

.tool-button:hover,
.secondary-button:hover,
.merchant-button:hover,
.quick-category:hover {
  border-color: #b7c3d6;
  box-shadow: 0 10px 22px rgba(17, 24, 39, 0.08);
}

.tool-button.danger {
  border-color: rgba(185, 28, 28, 0.2);
  background: #fff5f5;
  color: var(--danger);
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.meter {
  overflow: hidden;
  height: 10px;
  margin: 12px 0 8px;
  border-radius: 999px;
  background: #eee9de;
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 180ms ease;
}

.category-chart,
.trend-chart {
  display: grid;
  gap: 12px;
}

.budget-panel {
  margin-bottom: 14px;
}

.category-budget-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 10px;
}

.category-budget-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  padding: 10px;
}

.category-budget-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.category-budget-copy b,
.category-budget-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-budget-copy small {
  color: var(--muted);
  font-size: 0.75rem;
}

.category-budget-card input {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

.category-budget-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(82, 109, 90, 0.12);
}

.category-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.stacked-bar {
  display: flex;
  overflow: hidden;
  height: 28px;
  border-radius: 999px;
  background: #eee9de;
}

.stacked-bar span {
  min-width: 8px;
}

.stack-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stack-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  padding: 0 9px;
  font-size: 0.76rem;
  font-weight: 750;
}

.stack-legend i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.stack-legend b {
  color: var(--ink);
}

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

.category-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 12px;
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.04);
}

.category-card.is-empty {
  opacity: 0.45;
}

.category-card-top {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.category-card-top div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.category-card-top strong,
.category-card-top small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-card-top small {
  color: var(--muted);
  font-size: 0.78rem;
}

.category-card b {
  font-family: var(--display-font);
  font-size: 1.12rem;
}

.budget-note {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.category-icon {
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: var(--radius);
  color: white;
  font-size: 0.72rem;
  font-weight: 900;
}

.category-track {
  height: 9px;
}

.spark-bars {
  display: grid;
  grid-template-columns: repeat(12, minmax(3px, 1fr));
  align-items: end;
  min-height: 44px;
  gap: 3px;
}

.spark-bars span {
  display: block;
  min-height: 4px;
  border-radius: 6px 6px 2px 2px;
  opacity: 0.82;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(96px, 0.85fr) minmax(120px, 1.4fr) auto;
  gap: 10px;
  align-items: center;
}

.chart-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  overflow: hidden;
  height: 12px;
  border-radius: 999px;
  background: #eee9de;
}

.bar-fill {
  display: block;
  min-width: 3px;
  height: 100%;
  border-radius: inherit;
}

.bar-value {
  min-width: 84px;
  font-weight: 750;
  text-align: right;
}

.trend-chart {
  grid-template-columns: repeat(14, minmax(14px, 1fr));
  align-items: end;
  min-height: 228px;
  padding-top: 10px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(236, 231, 220, 0.55));
  padding-inline: 10px;
}

.trend-bar {
  display: grid;
  align-content: end;
  gap: 6px;
  min-width: 0;
  height: 208px;
}

.trend-bar span {
  display: block;
  min-height: 3px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--rose), var(--blue) 48%, var(--accent));
}

.trend-bar small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
  text-overflow: ellipsis;
}

.filters {
  margin-bottom: 12px;
}

.expense-list {
  display: grid;
  max-height: 430px;
  overflow: auto;
  padding-right: 4px;
  gap: 8px;
}

.expense-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 10px;
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.04);
}

.expense-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: var(--radius);
  color: white;
  font-size: 0.78rem;
  font-weight: 850;
}

.expense-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.expense-copy strong,
.expense-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-meta {
  display: flex;
  gap: 8px;
  align-items: center;
}

.delete-button {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff5f5;
  color: var(--danger);
  font-weight: 800;
}

.empty-state {
  display: grid;
  min-height: 120px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .period-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .auth-brand {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .period-tab {
    text-align: center;
  }

  .summary-grid,
  .ledger-overview,
  .insight-grid,
  .content-grid,
  .main-workspace,
  .visual-grid,
  .category-budget-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .category-chart {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main-content,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .topbar-actions,
  .form-actions,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .ledger-overview,
  .insight-grid,
  .content-grid,
  .main-workspace,
  .visual-grid,
  .form-grid,
  .category-chart,
  .category-budget-grid {
    grid-template-columns: 1fr;
  }

  .summary-tile.hero-total {
    grid-column: span 1;
  }

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

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

  .bar-value {
    text-align: left;
  }

  .trend-chart {
    grid-template-columns: repeat(7, minmax(18px, 1fr));
  }
}
