:root {
  color-scheme: light;
  --paper: #f7f3ec;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #17201c;
  --muted: #6d746f;
  --line: #e1d8c9;
  --primary: #225e58;
  --primary-ink: #f8fffc;
  --accent: #d78a42;
  --coral: #c95543;
  --blue: #486c92;
  --green: #5a7f42;
  --shadow: 0 20px 60px rgba(60, 48, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(130deg, rgba(34, 94, 88, 0.08), transparent 36%),
    linear-gradient(310deg, rgba(215, 138, 66, 0.16), transparent 34%),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.78);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.28rem;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 3rem);
}

h3 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab,
.ghost-button,
.primary-button,
.icon-button {
  border: 0;
  border-radius: 8px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-tab.active {
  background: var(--ink);
  color: var(--paper);
  box-shadow: var(--shadow);
}

.sidebar-footer {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

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

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

.month-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sync-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  align-self: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.72);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.sync-pill.online {
  border-color: rgba(90, 127, 66, 0.28);
  background: rgba(90, 127, 66, 0.12);
  color: var(--green);
}

.sync-pill.error {
  border-color: rgba(201, 85, 67, 0.3);
  background: rgba(201, 85, 67, 0.1);
  color: var(--coral);
}

input,
select {
  min-height: 44px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34, 94, 88, 0.14);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-grid,
.content-grid,
.entry-layout,
.settings-grid {
  display: grid;
  gap: 18px;
}

.hero-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  margin-bottom: 18px;
}

.content-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
}

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

.wide-panel {
  grid-column: 1 / -1;
}

.panel,
.balance-panel,
.quick-entry,
.kpi-card {
  border: 1px solid rgba(225, 216, 201, 0.9);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 12px 32px rgba(60, 48, 31, 0.08);
}

.panel,
.quick-entry {
  padding: 20px;
}

.balance-panel {
  min-height: 320px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(22px, 4vw, 42px);
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(34, 94, 88, 0.96), rgba(23, 32, 28, 0.98)),
    var(--ink);
  color: var(--primary-ink);
}

.balance-panel .eyebrow,
.balance-panel .insight {
  color: rgba(248, 255, 252, 0.72);
}

.balance-panel strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(2.6rem, 7vw, 6rem);
  line-height: 0.95;
}

.balance-equation {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.balance-equation span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f4c15f, #7fd0a5);
  transition: width 220ms ease;
}

.insight {
  margin-bottom: 0;
  line-height: 1.6;
}

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

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  min-height: 118px;
  padding: 18px;
}

.kpi-card strong {
  display: block;
  margin: 10px 0 6px;
  font-size: 1.6rem;
}

.kpi-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.entry-form {
  display: grid;
  grid-template-columns: 150px 1fr 1fr 140px 1fr 112px 116px;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

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

.compact-form .primary-button {
  grid-column: span 2;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  white-space: nowrap;
}

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

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

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

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

.toggle-row {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.toggle-row input {
  min-height: auto;
  width: 18px;
  height: 18px;
}

.budget-bars,
.item-list,
.editable-list,
.weekly-summary {
  display: grid;
  gap: 10px;
}

.budget-row {
  display: grid;
  gap: 8px;
}

.budget-row-top,
.list-item,
.edit-row,
.weekly-row {
  display: grid;
  align-items: center;
  gap: 10px;
}

.budget-row-top {
  grid-template-columns: 1fr auto;
}

.budget-meter {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe4d8;
}

.budget-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.budget-meter.over span {
  background: var(--coral);
}

.list-item {
  grid-template-columns: 38px minmax(0, 1fr) auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.list-dot {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: rgba(34, 94, 88, 0.11);
  color: var(--primary);
  font-weight: 900;
}

.muted {
  color: var(--muted);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
}

tr:last-child td {
  border-bottom: 0;
}

.delete-button {
  border: 0;
  background: transparent;
  color: var(--coral);
  font-weight: 800;
}

.edit-row {
  grid-template-columns: minmax(130px, 1fr) 136px 44px;
}

.edit-row input {
  width: 100%;
}

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

.danger-text {
  color: var(--coral);
}

.settings-note {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

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

.calendar-head,
.calendar-day {
  border-radius: 8px;
}

.calendar-head {
  padding: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.calendar-day {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.calendar-day.empty {
  opacity: 0.28;
  background: transparent;
}

.day-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.day-number {
  font-weight: 900;
}

.day-tag {
  min-width: 30px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(72, 108, 146, 0.12);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 900;
}

.day-amount {
  margin-top: auto;
  font-weight: 900;
}

.day-nmd {
  color: var(--green);
}

.nmd-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(90, 127, 66, 0.13);
  color: var(--green);
  font-weight: 900;
}

.weekly-row {
  grid-template-columns: minmax(96px, 1fr) repeat(5, minmax(52px, 76px)) minmax(74px, 88px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  font-size: 0.9rem;
}

.weekly-row.header {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

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

#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 5;
  min-width: 220px;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.icon {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.chart-icon::before,
.chart-icon::after,
.plus-icon::before,
.plus-icon::after,
.calendar-icon::before,
.calendar-icon::after,
.sliders-icon::before,
.sliders-icon::after,
.download-icon::before,
.download-icon::after,
.upload-icon::before,
.upload-icon::after,
.refresh-icon::before,
.refresh-icon::after,
.trash-icon::before,
.trash-icon::after,
.chevron-left-icon::before,
.chevron-right-icon::before {
  content: "";
  position: absolute;
  display: block;
}

.plus-icon::before {
  top: 8px;
  left: 3px;
  width: 12px;
  height: 2px;
  background: currentColor;
}

.plus-icon::after {
  top: 3px;
  left: 8px;
  width: 2px;
  height: 12px;
  background: currentColor;
}

.chart-icon::before {
  inset: 2px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.chart-icon::after {
  left: 5px;
  bottom: 5px;
  width: 10px;
  height: 8px;
  border-left: 3px solid currentColor;
  border-right: 3px solid currentColor;
  background: currentColor;
  clip-path: polygon(0 60%, 30% 60%, 30% 20%, 65% 20%, 65% 0, 100% 0, 100% 100%, 0 100%);
}

.calendar-icon::before {
  inset: 2px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.calendar-icon::after {
  left: 4px;
  right: 4px;
  top: 7px;
  height: 2px;
  background: currentColor;
}

.sliders-icon::before {
  left: 3px;
  top: 4px;
  width: 12px;
  height: 10px;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.sliders-icon::after {
  left: 6px;
  top: 2px;
  width: 4px;
  height: 14px;
  border-top: 4px solid currentColor;
  border-bottom: 4px solid currentColor;
}

.download-icon::before,
.upload-icon::before {
  left: 8px;
  top: 2px;
  width: 2px;
  height: 10px;
  background: currentColor;
}

.download-icon::after,
.upload-icon::after {
  left: 4px;
  top: 8px;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.upload-icon::before {
  top: 6px;
}

.upload-icon::after {
  top: 2px;
  transform: rotate(225deg);
}

.refresh-icon::before {
  inset: 3px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
}

.refresh-icon::after {
  top: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(45deg);
}

.trash-icon::before {
  left: 5px;
  top: 6px;
  width: 8px;
  height: 9px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 2px 2px;
}

.trash-icon::after {
  left: 4px;
  top: 3px;
  width: 10px;
  height: 2px;
  background: currentColor;
  box-shadow: 3px -2px 0 -1px currentColor;
}

.chevron-left-icon::before,
.chevron-right-icon::before {
  top: 4px;
  width: 9px;
  height: 9px;
  border-top: 2px solid currentColor;
  border-left: 2px solid currentColor;
}

.chevron-left-icon::before {
  left: 6px;
  transform: rotate(-45deg);
}

.chevron-right-icon::before {
  right: 6px;
  transform: rotate(135deg);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .sidebar {
    padding: 20px 12px;
    align-items: center;
  }

  .brand {
    justify-content: center;
  }

  .brand div:last-child,
  .nav-tab span:last-child {
    display: none;
  }

  .nav-tab {
    justify-content: center;
    width: 56px;
    padding: 0;
  }

  .hero-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
    padding-bottom: 74px;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 4;
    height: 74px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .brand,
  .sidebar-footer {
    display: none;
  }

  .nav-tabs {
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
  }

  .nav-tab {
    width: auto;
    min-height: 52px;
  }

  .nav-tab span:last-child {
    display: inline;
    font-size: 0.76rem;
  }

  .main {
    padding: 18px 14px;
  }

  .topbar {
    display: grid;
  }

  .month-switcher {
    justify-content: space-between;
  }

  .sync-pill {
    justify-self: start;
  }

  #monthPicker {
    flex: 1;
  }

  .hero-grid,
  .entry-layout,
  .settings-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .balance-panel {
    min-height: 260px;
  }

  .entry-form,
  .compact-form,
  .data-actions {
    grid-template-columns: 1fr;
  }

  .compact-form .primary-button {
    grid-column: auto;
  }

  .calendar-grid {
    gap: 5px;
  }

  .calendar-day {
    min-height: 84px;
    padding: 8px;
    font-size: 0.8rem;
  }

  .day-tag {
    min-width: 24px;
    height: 21px;
  }

  .weekly-summary {
    overflow-x: auto;
  }

  .weekly-row {
    min-width: 620px;
  }
}
