:root {
  --bg: #f5f8fb;
  --card: #ffffff;
  --text: #14213d;
  --muted: #6b7a90;
  --border: #e6ebf1;
  --navy: #101c2e;
  --green: #1fa971;
  --green-dark: #178a5a;
  --green-bg: #eaf8f1;
  --red: #ef4444;
  --red-bg: #fff0f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  background: var(--navy);
  color: #fff;
}

.site-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
}

.brand b {
  color: #3ddc97;
}

.logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--green);
  border-radius: 15px;
}

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

.date {
  color: #b6c2d4;
  font-size: 0.9rem;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.greeting {
  margin-bottom: 24px;
}

.greeting h1 {
  margin: 0;
  font-size: 1.7rem;
}

.greeting p {
  margin: 6px 0 0;
  color: var(--muted);
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

.col-main,
.col-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
}

.stat p {
  margin: 0;
  font-size: 0.9rem;
}

.stat > div {
  min-width: 0;
}

.stat h2 {
  margin: 4px 0 0;
  font-size: 1.3rem;
  overflow-wrap: anywhere;
}

.stat-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  border-radius: 50%;
}

.stat-balance,
.stat-income {
  background: var(--green-bg);
  border-color: #cdeedd;
}

.stat-balance .stat-icon,
.stat-income .stat-icon {
  background: var(--green);
}

.stat-expense {
  background: var(--red-bg);
  border-color: #fcd9d9;
}

.stat-expense .stat-icon {
  background: var(--red);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 2px 10px rgba(16, 28, 46, 0.04);
}

.card h3 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

#tx-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#tx-form h3 {
  margin-bottom: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

input,
select {
  width: 100%;
  padding: 11px 13px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 169, 113, 0.18);
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.1s;
}

button:active {
  transform: scale(0.97);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.btn-primary {
  padding: 12px 22px;
  color: #fff;
  background: var(--green);
  border-radius: 10px;
}
.btn-primary:hover {
  background: var(--green-dark);
}

.edit-btn {
  color: #3b82f6;
}

.delete-btn {
  color: rgb(255, 53, 53);
}
.btn-ghost {
  padding: 12px 22px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.btn-ghost:hover {
  background: var(--bg);
}

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

.list-head h3 {
  margin: 0;
}

.list-tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tabs {
  display: flex;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tab {
  padding: 8px 16px;
  color: var(--muted);
  background: transparent;
  border-radius: 999px;
}

.tab.active {
  color: #fff;
  background: var(--green);
}

.search {
  width: 190px;
  border-radius: 999px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th {
  text-align: left;
  padding: 12px;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
}

th:first-child {
  border-radius: 10px 0 0 10px;
}

th:last-child {
  border-radius: 0 10px 10px 0;
}

td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

tbody tr:hover {
  background: var(--bg);
}

.badge {
  display: inline-block;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
}

.badge.Food {
  background: #ffedd9;
  color: #c2570c;
}
.badge.Bills {
  background: #dfeaff;
  color: #1d5fd1;
}
.badge.Transport {
  background: #ece4ff;
  color: #6d3fd1;
}
.badge.Shopping {
  background: #d9f3ee;
  color: #0f766e;
}

.badge.income {
  background: var(--green-bg);
  color: var(--green-dark);
}
.badge.expense {
  background: var(--red-bg);
  color: var(--red);
}

.amount-income {
  font-weight: 700;
  color: var(--green-dark);
}
.amount-expense {
  font-weight: 700;
  color: var(--red);
}

.btn-icon {
  width: 32px;
  height: 32px;
  margin-right: 4px;
  background: transparent;
  border-radius: 8px;
}
.btn-icon:hover {
  background: var(--border);
}
.empty {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 32px 0 8px;
  text-align: center;
}
.empty.show {
  display: flex;
}
.empty span {
  font-size: 2.4rem;
}
.empty p {
  margin: 8px 0 2px;
  font-weight: 600;
}
.empty small {
  color: var(--muted);
}

.donut {
  display: grid;
  place-items: center;
  width: 190px;
  height: 190px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: #e6ebf1;
}
.donut-hole {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 140px;
  background: var(--card);
  border-radius: 50%;
}
.donut-hole b {
  max-width: 100%;
  padding: 0 10px;
  font-size: 1.05rem;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}
.donut-hole small {
  color: var(--muted);
  font-size: 0.75rem;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.legend li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.legend .pct {
  min-width: 38px;
  text-align: right;
  color: var(--muted);
}

.custom-input {
  display: none;
  margin-top: 8px;
}
.cat-field:has(option[value="__new"]:checked) .custom-input {
  display: block;
}
.badge {
  background: #e8ecf1;
  color: #475569;
}
#tx-form:has(#type option[value="income"]:checked) .cat-field {
  display: none;
}

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

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.pagination button {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  color: var(--green-dark);
  cursor: pointer;
}

.pagination button.active {
  background: var(--green-dark);
  color: white;
  border-color: var(--green-dark);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  td.muted {
    display: none;
  }
}

@media (max-width: 1050px) {
  .content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .page {
    padding: 20px 16px 40px;
  }
  .site-header-inner {
    padding: 12px 16px;
  }
  .date {
    display: none;
  }
  .greeting h1 {
    font-size: 1.4rem;
  }

  .stats {
    grid-template-columns: 1fr;
  }
  .card {
    padding: 18px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
  input,
  select {
    font-size: 16px;
    padding: 13px 14px;
  }
  .btn-primary {
    width: 100%;
    padding: 14px;
  }
  .form-actions {
    justify-content: stretch;
  }

  .list-tools {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .tabs {
    width: 100%;
  }
  .tab {
    flex: 1;
  }
  .search {
    width: 100%;
  }

  .table-wrap {
    overflow-x: visible;
  }
  thead {
    display: none;
  }
  table,
  tbody {
    display: block;
  }

  tbody tr {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    grid-template-areas:
      "desc desc desc amount"
      "date date date actions"
      "cat  type .    actions";
    gap: 6px 8px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
  }
  tbody tr:last-child {
    border-bottom: none;
  }
  tbody tr:hover {
    background: transparent;
  }

  td {
    padding: 0;
    border: none;
    white-space: normal;
  }
  td:nth-child(1) {
    grid-area: date;
    font-size: 0.8rem;
    color: var(--muted);
  }
  td:nth-child(2) {
    grid-area: desc;
    font-weight: 600;
  }
  td:nth-child(3) {
    grid-area: cat;
  }
  td:nth-child(4) {
    grid-area: type;
  }
  td:nth-child(5) {
    grid-area: amount;
    justify-self: end;
  }
  td:nth-child(6) {
    grid-area: actions;
    justify-self: end;
    align-self: center;
  }

}

.currency {
  width: auto;
  padding: 8px 10px;
  font-size: 0.9rem;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
}
.currency option {
  color: var(--text);
}
@media (max-width: 700px) {
  .currency {
    font-size: 16px;
  }
}

@media (max-width: 700px) {
  .form-actions {
    flex-direction: column-reverse;
  }
  .btn-ghost {
    width: 100%;
    padding: 14px;
  }
}
