:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #1f2937;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

.hero {
  background: linear-gradient(120deg, #1d4ed8, #2563eb, #38bdf8);
  color: #fff;
  padding: 2.5rem 1.5rem;
  text-align: center;
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  font-size: 1rem;
  opacity: 0.95;
}

.container {
  max-width: 1200px;
  margin: -40px auto 60px;
  padding: 0 1rem 1rem;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

.card h2,
.card h3 {
  margin-top: 0;
}

.input-card {
  position: relative;
  z-index: 2;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}

input,
select,
button {
  font: inherit;
}

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

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

button:active {
  transform: translateY(1px);
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 18px rgba(37, 99, 235, 0.25);
}

.secondary-btn {
  background: #0ea5e9;
  color: #fff;
  box-shadow: 0 12px 18px rgba(14, 165, 233, 0.25);
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
  font-weight: 600;
}

.summary span {
  background: var(--accent-soft);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.chart-card {
  min-height: 320px;
}

.flow-chart {
  width: 100%;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.flow-chart canvas {
  width: 100% !important;
  height: 100% !important;
}

.table-card .table-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

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

.table-wrapper.compact table {
  min-width: 0;
}

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

table thead {
  background: var(--accent-soft);
}

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

th {
  font-weight: 700;
  font-size: 0.95rem;
}

.status-within {
  color: var(--success);
  font-weight: 700;
}

.status-above {
  color: var(--danger);
  font-weight: 700;
}

.status-below {
  color: var(--warning);
  font-weight: 700;
}

.input-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 0.35rem;
  align-items: center;
}

.input-controls input {
  width: 100%;
  padding: 0.4rem 0.45rem;
}

.small-btn {
  padding: 0.4rem 0.6rem;
  background: #e5e7eb;
  border: 1px solid var(--border);
}

.remove-btn {
  background: #fee2e2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.allocation-message {
  color: var(--danger);
  margin: 0;
  font-weight: 600;
}

.helper-text {
  color: var(--muted);
  font-size: 0.9rem;
}

.add-card {
  background: #ecfeff;
  border: 1px solid #bae6fd;
}

.add-form {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.savings-card canvas {
  width: 100% !important;
  max-height: 320px;
}

.savings-summary {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  font-weight: 600;
}

.score-card {
  text-align: center;
}

.score-value {
  font-size: 2rem;
  font-weight: 800;
}

.score-message {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .summary {
    flex-direction: column;
  }

  .control-group {
    grid-template-columns: repeat(4, minmax(50px, 1fr));
  }

  table {
    min-width: 0;
  }

  .savings-summary {
    flex-direction: column;
  }
}
