:root {
  --bg: #f7f4ec;
  --ink: #1f2430;
  --accent: #0f766e;
  --accent-2: #c2410c;
  --panel: rgba(255, 255, 255, 0.85);
  --border: rgba(31, 36, 48, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top right, #ffedd5, transparent 45%), var(--bg);
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: "Space Grotesk", sans-serif;
  margin-top: 0;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(50px);
}

.bg-shape-a {
  width: 250px;
  height: 250px;
  background: rgba(15, 118, 110, 0.2);
  top: -40px;
  left: -40px;
}

.bg-shape-b {
  width: 300px;
  height: 300px;
  background: rgba(194, 65, 12, 0.18);
  right: -100px;
  bottom: -80px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
}

.brand {
  font-size: 1.25rem;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.brand-user {
  margin: 0;
  font-size: 0.85rem;
  color: #4b5563;
  font-weight: 600;
}

nav {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

a, .link-btn {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.link-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.logout-btn {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: rgba(185, 28, 28, 0.12);
  color: #991b1b;
  border: 1px solid rgba(185, 28, 28, 0.35);
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.logout-btn:hover,
.logout-btn:focus-visible {
  background: #b91c1c;
  color: #fff;
  border-color: #b91c1c;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
  margin-bottom: 1rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.grid {
  display: grid;
  gap: 1rem;
}

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

.form-grid p,
.form-inline p {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.8rem;
}

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

.entry-form-grid button {
  grid-column: 1 / 2;
  align-self: flex-end;
}

.entry-form-grid .entry-form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.entry-form-grid .entry-form-actions .btn {
  width: fit-content;
}

.form-action-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.entry-form-grid p {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.8rem;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.btn.btn-alt {
  background: #374151;
}

.btn.danger {
  background: #b91c1c;
}

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  margin-bottom: 0.8rem;
}

.flash.success {
  background: rgba(34, 197, 94, 0.2);
}

.flash.error {
  background: rgba(220, 38, 38, 0.2);
}

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

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

th, td {
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.ledger-table thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.ledger-table tfoot th,
.ledger-table tfoot td {
  background: rgba(15, 118, 110, 0.08);
  font-weight: 800;
}

.ledger-actions-cell {
  white-space: nowrap;
  vertical-align: middle;
}

.ledger-actions-wrap {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
}

.ledger-action-btn {
  padding: 0.18rem 0.4rem;
  font-size: 0.68rem;
  line-height: 1.1;
  border-radius: 7px;
  min-height: 0;
}

.user-actions-cell {
  white-space: nowrap;
}

.user-actions-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.user-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0.35rem 0.7rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.user-action-btn:hover,
.user-action-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
}

.user-action-edit {
  background: rgba(15, 118, 110, 0.12);
  color: #0f766e;
  border-color: rgba(15, 118, 110, 0.35);
}

.user-action-edit:hover,
.user-action-edit:focus-visible {
  background: #0f766e;
  color: #ffffff;
  border-color: #0f766e;
}

.user-action-delete {
  background: rgba(185, 28, 28, 0.12);
  color: #991b1b;
  border-color: rgba(185, 28, 28, 0.35);
}

.user-action-delete:hover,
.user-action-delete:focus-visible {
  background: #b91c1c;
  color: #ffffff;
  border-color: #b91c1c;
}

.big {
  font-size: 2rem;
  font-weight: 700;
}

.compact-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.compact-list li {
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--border);
}

.muted {
  color: #475569;
  font-size: 0.92rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.report-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, max-content));
  justify-content: start;
  gap: 0.5rem;
}

.report-actions .btn {
  width: 100%;
  min-height: 44px;
  display: inline-flex;
  gap: 0.45rem;
  justify-content: flex-start;
  align-items: center;
  padding: 0.6rem 0.8rem;
}

.report-subtitle {
  margin: 0.25rem 0 0;
}

.report-meta-row {
  margin-top: 0.8rem;
}

.report-balance-note,
.report-bank-hint {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

.report-metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.metric-card {
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(100, 116, 139, 0.25);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
}

.metric-label {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 700;
  color: #475569;
}

.metric-value {
  margin: 0.35rem 0 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.15;
}

.metric-card-highlight {
  border-width: 2px;
}

.metric-card-profit {
  border-color: rgba(22, 163, 74, 0.5);
  background: rgba(220, 252, 231, 0.6);
}

.metric-card-loss {
  border-color: rgba(220, 38, 38, 0.55);
  background: rgba(254, 226, 226, 0.65);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}

.chip {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.15);
  font-weight: 600;
}

.chart-panel {
  min-height: 300px;
}

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

.chart-wrap {
  position: relative;
  height: clamp(139px, 25.2vw, 227px);
  width: 100%;
}

.trend-wrap {
  height: clamp(151px, 26.5vw, 239px);
}

.report-chart-grid {
  align-items: stretch;
}

.report-filter-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 210px));
  gap: 0.75rem;
  align-items: end;
  justify-content: start;
  margin-top: 0.8rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.filter-field label {
  font-size: 0.85rem;
  font-weight: 700;
}

.filter-field ul.errorlist,
.filter-errors ul.errorlist {
  margin: 0.15rem 0 0;
  padding-left: 1rem;
  color: #b91c1c;
  font-size: 0.8rem;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: nowrap;
}

.filter-actions .btn {
  min-width: 120px;
  flex: 1;
  white-space: nowrap;
}

.filter-errors {
  grid-column: 1 / -1;
}

.three-col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.report-chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.4rem;
  margin-bottom: 1rem;
}

.report-chart-board {
  display: grid;
  grid-template-rows: repeat(2, minmax(151px, auto));
  grid-auto-flow: column;
  grid-auto-columns: minmax(202px, 1fr);
  gap: 0.65rem;
  min-width: max(100%, 655px);
}

.compact-chart-panel {
  margin-bottom: 0;
  min-height: 164px;
}

.compact-chart-panel h3 {
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
}

.chart-category-tag {
  display: inline-block;
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #334155;
  background: rgba(148, 163, 184, 0.18);
  border: 1px solid rgba(100, 116, 139, 0.28);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
}

.auth-panel {
  max-width: 420px;
  margin: 3rem auto;
}

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

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

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  table {
    min-width: 620px;
  }

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

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

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

  .report-chart-board {
    grid-auto-columns: minmax(189px, 1fr);
    min-width: 605px;
  }

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

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

  .filter-actions {
    grid-column: 1 / -1;
  }

  .report-actions {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    width: 100%;
  }

  .report-head {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 520px) {
  .stats-row {
    grid-template-columns: 1fr;
  }

  .chart-wrap,
  .trend-wrap {
    height: 139px;
  }

  .report-filter-grid,
  .entry-form-grid,
  .three-col {
    grid-template-columns: 1fr;
  }

  .report-metric-grid {
    grid-template-columns: 1fr;
  }

  .report-chart-scroll {
    overflow-x: visible;
  }

  .report-chart-board {
    grid-template-rows: none;
    grid-auto-flow: row;
    grid-auto-columns: auto;
    min-width: 100%;
    grid-template-columns: 1fr;
  }

  .filter-actions .btn {
    width: 100%;
  }
}
