﻿:root {
  --bg: #f4f7f2;
  --card: #ffffff;
  --ink: #1b2b24;
  --muted: #486357;
  --accent: #248e67;
  --warn: #c24b3d;
  --border: #d3ddd8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top, #e8f5ea, var(--bg));
  color: var(--ink);
}

.app {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem 2rem;
}

h1 { margin-bottom: 0.2rem; }
.sub { color: var(--muted); margin-top: 0; }

h1,
.sub {
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

.layout {
  display: grid;
  grid-template-columns: repeat(2, 420px);
  gap: 1rem;
  align-items: stretch;
  justify-content: center;
}

.left-column,
.right-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}

.status,
.entries-card {
  flex: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-top: 0;
}

.log-spend-card {
  align-items: flex-start;
}

.status,
.entries-card {
  display: flex;
  flex-direction: column;
}

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

.setup-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.inline-form {
  display: grid;
  grid-template-columns: 152px 92px minmax(120px, 180px);
  gap: 0.6rem;
  align-items: center;
  justify-content: start;
  width: fit-content;
}

#spend-date {
  width: 152px;
  max-width: 100%;
  min-width: 0;
}

#spend-amount {
  width: 92px;
  max-width: 100%;
  min-width: 0;
}

#spend-note {
  width: 160px;
  max-width: 100%;
  min-width: 0;
  justify-self: start;
}

.pending-toggle {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
  white-space: nowrap;
  justify-self: start;
  margin-left: 0.5rem;
}

.pending-toggle input {
  margin: 0;
  width: 0.78rem;
  height: 0.78rem;
  accent-color: var(--accent);
}

.pending-label-text {
  position: relative;
  top: -1px;
}

.inline-form > button,
.inline-form > .pending-toggle {
  grid-row: 2;
}

.inline-form > button[type="submit"] {
  grid-column: 1;
}

.inline-form > .pending-toggle {
  grid-column: 2;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
}

input, button {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
}

.grid-form input,
.grid-form button,
.grid-form .setup-actions {
  width: 100%;
}

.card {
  width: 100%;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
}

button:hover { filter: brightness(0.95); }

button.danger {
  background: var(--warn);
  border: 1px solid #9f3b31;
}

button.secondary {
  background: #e4ebe7;
  color: #1b2b24;
  border: 1px solid var(--border);
}

#reset-day-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.entries-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  width: fit-content;
  min-width: 380px;
  max-width: 100%;
}

#export-btn,
#import-btn,
#reset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  line-height: 1.2;
}

#reset-btn {
  margin-left: auto;
}

.meter-panel {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  column-gap: 1.2rem;
  row-gap: 0.45rem;
  height: 280px;
  margin-top: 0.5rem;
  width: fit-content;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.meter-wrap {
  width: 132px;
  min-width: 132px;
  height: 100%;
  background: #ebf0ec;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  display: flex;
  align-items: flex-end;
}

.meter-trend {
  grid-column: 1;
  grid-row: 1;
  width: 132px;
  margin: 0;
  display: grid;
  grid-template-columns: 1ch auto 1ch;
  justify-content: center;
  align-items: center;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.meter-wrap {
  grid-column: 1;
  grid-row: 2;
}

.meter-trend .trend-sign {
  display: inline-block;
  width: 1ch;
  text-align: center;
  font: inherit;
}

.meter-trend .trend-sign-empty {
  width: 0;
}

.meter-trend .trend-value {
  display: inline-block;
  text-align: center;
}

.meter-trend .trend-sign[aria-hidden="true"] {
  visibility: hidden;
}

.meter-fill {
  width: 100%;
  height: 0%;
  background: linear-gradient(0deg, #d67f35, #b94c38);
  transition: height 0.35s ease;
}

.meter-ticks {
  grid-column: 2;
  grid-row: 2;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: repeat(14, minmax(0, 1fr));
  gap: 0;
  min-width: 0;
  width: max-content;
}

.tick-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 0;
  padding: 0.1rem 0;
}

.tick {
  display: inline-block;
  width: 18px;
  height: 6px;
  border-radius: 999px;
  background: #c7d5ce;
  flex: 0 0 auto;
}

.tick-label {
  font-size: 0.78rem;
  line-height: 1;
  white-space: nowrap;
  color: var(--muted);
}

.tick-row.past .tick {
  background: #7aa996;
}

.tick-row.today .tick {
  width: 18px;
  height: 10px;
  background: #1c6f52;
  box-shadow: 0 0 0 2px #d7efe4;
}

.tick-row.today .tick-label {
  color: #1b2b24;
  font-weight: 700;
}

.stats {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 0.6rem;
  gap: 0.05rem;
}

.stats p {
  margin: 0;
}

.meter-trend.trend-positive {
  color: #1c6f52;
}

.meter-trend.trend-negative {
  color: #c24b3d;
}

.meter-trend.trend-neutral {
  color: #1b2b24;
}

.entries-table-wrap {
  overflow: auto;
  display: flex;
  justify-content: flex-start;
}

.entries-help {
  display: block;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.pane-help {
  display: block;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.entries-table {
  width: auto;
  border-collapse: collapse;
  table-layout: auto;
  min-width: 380px;
}

.entries-table th,
.entries-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
  text-align: left;
}

.entries-table th:nth-child(1),
.entries-table td:nth-child(1) {
  width: 34px;
}

.entries-table th:nth-child(2),
.entries-table td:nth-child(2) {
  width: 94px;
  white-space: nowrap;
}

.entries-table th:nth-child(3),
.entries-table td:nth-child(3) {
  width: 92px;
  text-align: right;
}

.entries-table th:nth-child(4),
.entries-table td:nth-child(4) {
  width: 100px;
  text-align: right;
}

.entry-date-cell {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.entries-table thead th {
  position: sticky;
  top: 0;
  background: #f9fbf9;
}

.day-toggle {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--ink);
  border: none;
  padding: 0;
  font: inherit;
}

.day-toggle:hover {
  filter: none;
  color: var(--accent);
}

.day-toggle-marker {
  width: auto;
  text-align: center;
  font-weight: 700;
}

.entry-detail-row td {
  padding: 0;
  background: #f9fbf9;
}

.transactions-panel {
  padding: 0.5rem 0.6rem 0.7rem 1rem;
}

.transactions-empty {
  color: var(--muted);
  font-size: 0.8rem;
}

.transactions-table {
  width: auto;
  border-collapse: collapse;
  table-layout: auto;
}

.transactions-table th,
.transactions-table td {
  padding: 0.3rem 0.25rem;
  border-bottom: 1px solid #e5ece8;
  font-size: 0.8rem;
  text-align: left;
  white-space: nowrap;
}

.transactions-table th:nth-child(1),
.transactions-table td:nth-child(1) {
  width: 1%;
}

.transactions-table th:nth-child(2),
.transactions-table td:nth-child(2) {
  text-align: right;
}

.transactions-table th:nth-child(3),
.transactions-table td:nth-child(3) {
  text-align: center;
}

.transactions-table th:nth-child(4),
.transactions-table td:nth-child(4) {
  text-align: right;
}

.transactions-table th:nth-child(4) {
  text-align: center;
}

.transaction-actions {
  white-space: nowrap;
}

.transaction-btn {
  padding: 0.2rem 0.45rem;
  font-size: 0.74rem;
  margin-left: 0.25rem;
}

.edit-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  max-width: 340px;
  width: calc(100% - 2rem);
}

.edit-dialog::backdrop {
  background: rgba(27, 43, 36, 0.28);
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
}

.edit-form h2 {
  margin: 0;
}

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

#edit-pending-toggle-btn {
  margin-right: auto;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
}

.pending-chip {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
}

.pending-chip-button {
  border: none;
  cursor: pointer;
}

.pending-chip-button:hover {
  filter: brightness(0.98);
}

.transaction-amount-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}

.transaction-note {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.pending-chip.is-pending {
  background: #f5e7c8;
  color: #7a5712;
}

.pending-chip.is-cleared {
  background: #e2eee8;
  color: #345f4d;
}

.entries-table td.spend-under {
  color: #1c6f52;
}

.entries-table td.spend-over {
  color: #c24b3d;
}

.entries-table td.spend-on {
  color: #1b2b24;
}

.entries-table td.delta-positive {
  color: #1c6f52;
}

.entries-table td.delta-negative {
  color: #c24b3d;
}

.entries-table td.delta-neutral {
  color: #1b2b24;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .left-column,
  .right-column {
    height: auto;
  }

  .status,
  .entries-card {
    flex: unset;
  }

  .meter-panel {
    height: 250px;
  }

  .meter-panel {
    grid-template-columns: 88px 1fr;
  }

  .meter-wrap {
    width: 88px;
    min-width: 88px;
  }

  .meter-trend {
    width: 88px;
  }

  .tick-label {
    font-size: 0.68rem;
  }
}

@media (max-width: 760px) {
  .log-spend-card {
    align-items: stretch;
  }

  .inline-form {
    display: grid;
    grid-template-columns: 140px 84px minmax(72px, 1fr);
    width: 100%;
  }

  #spend-date {
    width: 140px;
  }

  #spend-amount {
    width: 84px;
  }

  #spend-note {
    width: 100%;
    justify-self: stretch;
  }
}

@media (max-width: 620px) {
  .inline-form {
    grid-template-columns: 132px 80px minmax(0, 1fr);
    width: 100%;
  }

  #spend-date {
    width: 132px;
  }

  #spend-amount {
    width: 80px;
  }

  #spend-note {
    width: 100%;
    justify-self: stretch;
  }
}


.entries-table tbody tr.today-row td {
  font-weight: 700;
}


