:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #e2e5e9;
  --color-text: lch(0% 0 0);
  --color-text-muted: #161313;
  --color-primary: hwb(232 0% 0%);
  --color-primary-dark: #2456bf;
  --color-income: #16a34a;
  --color-used: #dc2626;
  --color-danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --header-height: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Cascadia Mono", "Consolas", "Courier New", monospace;
  background: var(--color-bg);
  color: var(--color-text);
}

/* Dashboard home page: slow animated gradient backdrop */
body.dashboard-page {
  background: linear-gradient(-45deg, #eef3ff, #f4f6f8, #eafbf2, #f4f0ff);
  background-size: 400% 400%;
  animation: dashboard-gradient-shift 22s ease infinite;
}

@keyframes dashboard-gradient-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@media (prefers-reduced-motion: reduce) {
  body.dashboard-page {
    animation: none;
  }
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* Header */
.site-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--color-text);
}

.brand span {
  color: var(--color-primary);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.site-nav a {
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.95rem;
}

.site-nav a:hover {
  color: var(--color-text);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  border-color: var(--color-primary);
}

.btn-danger {
  background: #fff;
  color: var(--color-danger);
  border-color: #fca5a5;
}

.btn-danger:hover {
  background: #fef2f2;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
}

/* Layout containers */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.page-narrow {
  max-width: 440px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.6rem;
}

.breadcrumb {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.module-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.module-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.12);
}

.module-card .icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #eef3ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.module-card h3 {
  margin: 0;
  font-size: 1.15rem;
}

.module-card p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.module-card.add-module {
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  border-style: dashed;
  cursor: default;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-error {
  background: #fef2f2;
  color: var(--color-danger);
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.form-success {
  background: #f0fdf4;
  color: var(--color-income);
  border: 1px solid #86efac;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.auth-card {
  margin-top: 60px;
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 40px rgba(16, 24, 40, 0.25);
}

.modal h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Money project list */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.project-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  cursor: pointer;
}

.project-card:hover {
  border-color: var(--color-primary);
}

.project-card h3 {
  margin: 0 0 6px;
}

.project-card .date {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

/* Money project dashboard */
.summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.summary-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.summary-tile .label {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.summary-tile .value {
  font-size: 1.4rem;
  font-weight: 700;
}

.summary-tile.income .value {
  color: var(--color-income);
}

.summary-tile.used .value {
  color: var(--color-used);
}

.money-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  align-items: start;
}

.money-layout > * {
  min-width: 0;
}

.chart-card {
  position: sticky;
  top: calc(var(--header-height) + 20px);
  text-align: center;
}

.money-chart-canvas {
  display: block;
  width: 100%;
  max-width: 160px;
  height: auto;
  margin: 0 auto;
}

.chart-legend {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.85rem;
}

.chart-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Tables */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

#tx-table-wrap,
#users-table-wrap {
  overflow-x: auto;
}

table.tx-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.tx-table th,
table.tx-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

table.tx-table th {
  background: #fafbfc;
  color: var(--color-text-muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

table.tx-table tbody tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.income {
  background: #f0fdf4;
  color: var(--color-income);
}

.badge.used {
  background: #fef2f2;
  color: var(--color-used);
}

.amount-cell.income {
  color: var(--color-income);
  font-weight: 600;
}

.amount-cell.used {
  color: var(--color-used);
  font-weight: 600;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
}

/* Gym */
.workout-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.workout-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.workout-item:hover {
  border-color: var(--color-primary);
}

.workout-item .count {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.exercise-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.exercise-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.exercise-item .name {
  font-weight: 600;
}

.exercise-item .details {
  color: var(--color-text-muted);
  font-size: 0.88rem;
}

/* Responsive */
@media (max-width: 860px) {
  .money-layout {
    grid-template-columns: 1fr;
  }

  .chart-card {
    position: static;
  }

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

@media (max-width: 600px) {
  .site-nav {
    gap: 12px;
  }

  .page {
    padding: 20px 14px 40px;
  }

  table.tx-table th:nth-child(4),
  table.tx-table td:nth-child(4) {
    display: none;
  }
}
