*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f8f8f8;
}

header {
  margin-bottom: 2rem;
}

header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

main {
  max-width: 42rem;
  margin: 0 auto;
}

section {
  margin-bottom: 2.5rem;
}

section h2 {
  margin: 0 0 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

/* Form */
.form-row {
  margin-bottom: 1rem;
  margin-right: 1rem;
}

.form-row label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  color: #444;
}

.form-row input {
  width: 100%;
  max-width: 18rem;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
}

.form-row input:focus {
  outline: none;
  border-color: #2d6ef8;
  box-shadow: 0 0 0 2px rgba(45, 110, 248, 0.2);
}

button[type="submit"] {
  margin-top: 0.5rem;
  padding: 0.5rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #fff;
  background: #2d6ef8;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

button[type="submit"]:hover {
  background: #255ed6;
}

button[type="submit"]:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(45, 110, 248, 0.4);
}

/* History */
#history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

#history-table th,
#history-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
}

#history-table th {
  font-weight: 600;
  color: #444;
}

#history-table tbody tr:hover {
  background: #f0f0f0;
}

.history-actions {
  display: flex;
  gap: 0.5rem;
}

.history-actions button {
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  color: #2d6ef8;
  background: transparent;
  border: 1px solid #2d6ef8;
  border-radius: 4px;
  cursor: pointer;
}

.history-actions button:hover {
  background: #e8eeff;
}

.history-actions button.delete {
  color: #c23030;
  border-color: #c23030;
}

.history-actions button.delete:hover {
  background: #ffebeb;
}

/* Empty state */
.empty-state {
  color: #666;
  font-size: 0.9375rem;
  margin: 0;
}

/* Charts */
.chart-controls {
  margin-bottom: 1rem;
}

.chart-controls label {
  margin-right: 0.5rem;
  font-size: 0.875rem;
  color: #444;
}

.chart-controls select {
  padding: 0.4rem 0.75rem;
  font-size: 0.9375rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
}

#chart-svg-wrap {
  margin-bottom: 1rem;
}

#chart-svg-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

#totals-container {
  font-size: 0.9375rem;
  color: #444;
}

#totals-container .totals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.75rem;
}

#totals-container .total-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid #e8e8e8;
}

#totals-container .total-item strong {
  display: block;
  font-size: 0.8125rem;
  color: #666;
  font-weight: 500;
}

#totals-container .total-item.deficit-surplus strong {
  color: #1a1a1a;
}

/* Data */
.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.data-actions button {
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #2d6ef8;
  background: #fff;
  border: 1px solid #2d6ef8;
  border-radius: 6px;
  cursor: pointer;
}

.data-actions button:hover {
  background: #e8eeff;
}

.data-actions button:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(45, 110, 248, 0.3);
}

@media (max-width: 480px) {
  body {
    padding: 0.75rem;
  }

  .form-row input {
    max-width: none;
  }

  #history-table th:nth-child(n+2),
  #history-table td:nth-child(n+2) {
    padding-left: 0.5rem;
  }
}
