:root {
  color-scheme: light;
  --brand-green: #30ae49;
  --brand-cream: #dddcc4;
  --brand-teal: #4d9698;
  --brand-slate: #344b4c;
  --brand-yellow: #ffc846;
  --brand-orange: #f4512a;
  --bg: #f5f3e8;
  --panel: #ffffff;
  --ink: var(--brand-slate);
  --muted: #687676;
  --line: #d8d7c1;
  --soft: #ece9d3;
  --accent: var(--brand-green);
  --accent-dark: #26883b;
  --secondary: var(--brand-teal);
  --rose: var(--brand-orange);
  --gold: #b97910;
  --good: var(--brand-green);
  --shadow: 0 16px 38px rgba(52, 75, 76, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: inherit;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 2rem;
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
}

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

button,
.button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button:hover {
  background: var(--brand-slate);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost {
  background: var(--brand-cream);
  color: var(--brand-slate);
}

.ghost:hover {
  background: #cfccb0;
}

.danger {
  background: #fff0eb;
  color: var(--brand-orange);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-teal);
  box-shadow: 0 0 0 3px rgba(77, 150, 152, 0.18);
  outline: 0;
}

textarea {
  min-height: 180px;
  padding: 11px;
  resize: vertical;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.2;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(90deg, var(--brand-green) 0 33.33%, var(--brand-cream) 33.33% 66.66%, var(--brand-teal) 66.66% 100%) top / 100% 50% no-repeat,
    linear-gradient(90deg, var(--brand-slate) 0 33.33%, var(--brand-yellow) 33.33% 66.66%, var(--brand-orange) 66.66% 100%) bottom / 100% 50% no-repeat;
}

.login-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-logo {
  display: block;
  width: min(190px, 58vw);
  height: auto;
  justify-self: center;
  border-radius: 8px;
}

.brand-logo {
  display: block;
  width: 42px;
  height: 42px;
  object-fit: contain;
  object-position: center;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.login-error,
.notice.error {
  border: 1px solid #f7a98f;
  border-radius: 8px;
  background: #fff0eb;
  color: var(--brand-orange);
  padding: 11px 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: rgba(52, 75, 76, 0.97);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 0 18px;
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
}

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions,
.button-row,
.period-controls,
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.view-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sync-pill,
.count-chip,
.timezone-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  background: var(--brand-cream);
  color: var(--brand-slate);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.logout-link,
.text-link {
  color: var(--brand-teal);
  font-size: 0.86rem;
  font-weight: 700;
  text-decoration: none;
}

.logout-link:hover,
.text-link:hover {
  color: var(--brand-orange);
  text-decoration: underline;
}

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

.sidebar {
  position: sticky;
  top: 62px;
  align-self: start;
  height: calc(100vh - 62px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 0;
  background: var(--brand-slate);
  padding: 18px;
}

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

.nav-list a,
.mobile-nav a {
  min-height: 42px;
  display: flex;
  align-items: center;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 800;
  padding: 0 12px;
  text-decoration: none;
}

.nav-list a.active,
.mobile-nav a.active {
  background: var(--brand-green);
  color: #fff;
}

.workspace {
  width: 100%;
  margin: 0;
  padding: 32px 48px 90px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.view-head > div:first-child {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.eyebrow {
  color: var(--brand-teal);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.period-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px;
}

.period-controls label {
  min-width: 150px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(52, 75, 76, 0.06);
}

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

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  border-top: 5px solid var(--brand-green);
}

.metric:nth-child(2) {
  border-top-color: var(--brand-teal);
}

.metric:nth-child(3) {
  border-top-color: var(--brand-yellow);
}

.metric:nth-child(4) {
  border-top-color: var(--brand-orange);
}

.metric strong {
  display: block;
  margin-bottom: 5px;
  font-size: 1.6rem;
}

.metric span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.dashboard-grid,
.reports-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 14px;
  align-items: start;
}

.wide {
  grid-column: span 1;
}

.dashboard-grid > .wide:first-child,
.reports-grid > .wide:first-child {
  grid-column: 1 / -1;
}

.chart-frame {
  min-height: 286px;
  display: flex;
  align-items: end;
  gap: 10px;
  overflow: visible;
  padding: 14px 6px 4px;
}

.chart-frame.tall {
  min-height: 320px;
}

.month-bar {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  align-content: end;
  gap: 9px;
  height: 248px;
  color: var(--muted);
  text-align: center;
  font-size: 0.74rem;
  font-weight: 800;
}

.month-bar span {
  display: block;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-bar div {
  min-height: 4px;
  border-radius: 8px 8px 0 0;
  background: var(--brand-green);
}

.month-bar:nth-child(6n+2) div {
  background: var(--brand-teal);
}

.month-bar:nth-child(6n+3) div {
  background: var(--brand-yellow);
}

.month-bar:nth-child(6n+4) div {
  background: var(--brand-orange);
}

.month-bar:nth-child(6n+5) div {
  background: var(--brand-slate);
}

.month-bar:nth-child(6n+6) div {
  background: var(--brand-cream);
}

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(120px, 1.1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
}

.bar-label,
.bar-value {
  font-weight: 800;
}

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

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.compact-list {
  display: grid;
  gap: 8px;
}

.compact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.compact-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.compact-row strong {
  overflow-wrap: anywhere;
}

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

.import-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 14px;
}

.import-panel {
  display: grid;
  align-content: start;
  gap: 13px;
}

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

.transaction-grid {
  grid-template-columns:
    minmax(62px, 0.55fr)
    minmax(92px, 0.75fr)
    minmax(56px, 0.45fr)
    minmax(220px, 1.8fr)
    minmax(88px, 0.75fr)
    minmax(106px, 0.95fr)
    minmax(104px, 0.9fr)
    78px;
  align-items: end;
  gap: 8px;
}

.span-two {
  grid-column: span 2;
}

.review-panel,
.transaction-form,
.filters-panel {
  margin-top: 14px;
}

.transaction-form,
.filters-panel {
  padding: 12px 16px;
}

.transaction-form {
  display: grid;
  scroll-margin-top: 78px;
}

.transaction-form[hidden] {
  display: none;
}

.transaction-form label,
.filters-panel label {
  gap: 5px;
  font-size: 0.78rem;
}

.transaction-form input,
.transaction-form select,
.filters-panel input,
.filters-panel select {
  min-height: 38px;
  padding: 0 10px;
}

.filters-grid {
  grid-template-columns: 96px 112px minmax(140px, 1fr) minmax(140px, 1fr) minmax(180px, 1.15fr) 38px;
  gap: 8px 10px;
}

.filter-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  align-self: end;
}

.transaction-actions {
  display: flex;
  align-items: end;
  gap: 6px;
}

.icon-action {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 1.08rem;
  line-height: 1;
}

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

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

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

th {
  color: var(--brand-slate);
  background: #f2f0dd;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

td input,
td select {
  min-height: 38px;
}

.amount-cell {
  font-weight: 900;
  white-space: nowrap;
  color: var(--brand-slate);
}

.warning {
  color: var(--brand-orange);
  font-size: 0.78rem;
  font-weight: 800;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.82rem;
}

#transaction-table th,
#transaction-table td {
  padding: 7px 9px;
}

.sort-header {
  min-height: auto;
  width: 100%;
  justify-content: flex-start;
  gap: 6px;
  border-radius: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  text-align: left;
}

.sort-header:hover,
.sort-header.active {
  background: transparent;
  color: var(--brand-green);
}

.sort-header span {
  min-width: 14px;
  color: var(--brand-teal);
  font-size: 0.9rem;
  line-height: 1;
}

.legacy-summary {
  display: grid;
  gap: 7px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 60;
  max-width: calc(100vw - 28px);
  transform: translateX(-50%) translateY(16px);
  border-radius: 8px;
  background: var(--brand-slate);
  color: #fff;
  opacity: 0;
  padding: 11px 14px;
  pointer-events: none;
  transition: 160ms ease;
}

#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mobile-nav {
  display: none;
}

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

  .dashboard-grid,
  .reports-grid,
  .import-layout {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 780px) {
  .topbar {
    height: 58px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
  }

  .brand strong {
    max-width: 46vw;
  }

  .brand-logo {
    width: 36px;
    height: 36px;
  }

  .sync-pill {
    display: none;
  }

  .app-shell {
    display: block;
    min-height: auto;
  }

  .sidebar {
    display: none;
  }

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

  .view-head,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .period-controls,
  .button-row {
    justify-content: stretch;
  }

  .period-controls label,
  .button-row button,
  .button-row .button {
    flex: 1;
  }

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

  .span-two {
    grid-column: span 1;
  }

  .panel,
  .metric {
    padding: 13px;
  }

  .chart-frame {
    min-height: 270px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 16px;
  }

  .month-bar {
    min-width: 64px;
    height: 236px;
  }

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

  .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    border-top: 1px solid var(--line);
    background: rgba(52, 75, 76, 0.96);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 28px rgba(52, 75, 76, 0.18);
    backdrop-filter: blur(12px);
  }

  .mobile-nav a {
    justify-content: center;
    min-height: 42px;
    padding: 0 6px;
    font-size: 0.8rem;
  }

  table {
    min-width: 700px;
  }
}
