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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
  padding: 24px 16px;
}

.container { max-width: 960px; margin: 0 auto; }

header {
  text-align: center;
  margin-bottom: 28px;
}
header h1 {
  font-size: 2rem;
  font-weight: 800;
  color: #1a1a2e;
  letter-spacing: -0.5px;
}
.subtitle { color: #666; margin-top: 4px; font-size: 1rem; }

.card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; color: #1a1a2e; }
.hidden { display: none !important; }

/* Week selector */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
select {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  cursor: pointer;
  min-width: 200px;
}
select:focus { outline: none; border-color: #2563eb; }

button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
  transition: background 0.15s;
  white-space: nowrap;
}
button:hover { background: #1d4ed8; }
button:disabled { background: #bbb; cursor: not-allowed; }
button.small { padding: 8px 14px; font-size: 0.82rem; background: #6b7280; }
button.small:hover { background: #4b5563; }
button.primary { margin-top: 16px; padding: 12px 28px; font-size: 1rem; background: #16a34a; }
button.primary:hover { background: #15803d; }

/* Inputs grid */
.inputs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
label { display: flex; flex-direction: column; font-size: 0.85rem; font-weight: 600; color: #374151; gap: 6px; }
input[type="number"] {
  padding: 10px 12px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 0.95rem;
  width: 100%;
}
input[type="number"]:focus { outline: none; border-color: #2563eb; }
.input-row { display: flex; gap: 6px; align-items: center; }
.input-row input { flex: 1; }
.note { font-size: 0.78rem; color: #6b7280; font-weight: 400; }

/* Mileage grid */
.mileage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.mileage-item label { font-size: 0.88rem; }

/* Results */
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.results-header h2 { margin: 0; }

.summary-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.summary-card {
  flex: 1;
  min-width: 140px;
  background: #f8fafc;
  border-radius: 10px;
  padding: 14px 18px;
  border: 1.5px solid #e5e7eb;
}
.summary-card .label { font-size: 0.78rem; color: #6b7280; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.summary-card .value { font-size: 1.4rem; font-weight: 800; margin-top: 4px; }
.summary-card.green .value { color: #16a34a; }
.summary-card.red .value { color: #dc2626; }
.summary-card.blue .value { color: #2563eb; }

.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  background: #f1f5f9;
  padding: 10px 14px;
  text-align: right;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  white-space: nowrap;
}
th:first-child { text-align: left; }
td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid #f1f5f9;
  font-variant-numeric: tabular-nums;
}
td:first-child { text-align: left; font-weight: 700; }
tr:last-child td { border-bottom: none; }

tr.profit td:last-child, tr.profit td:nth-last-child(2) { color: #16a34a; }
tr.loss { background: #fef2f2; }
tr.loss td:last-child, tr.loss td:nth-last-child(2) { color: #dc2626; font-weight: 700; }
tr.total-row td { font-weight: 700; background: #f1f5f9; border-top: 2px solid #e5e7eb; }

.error { color: #dc2626; font-size: 0.85rem; margin-top: 8px; }

/* Loading spinner */
.loading { display: inline-block; width: 16px; height: 16px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin 0.6s linear infinite; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) {
  .inputs-grid { grid-template-columns: 1fr 1fr; }
  .mileage-grid { grid-template-columns: 1fr 1fr; }
  th, td { padding: 8px 10px; }
}
