:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --panel: #f9fafb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --fg: #e8e8e8;
    --muted: #9ca3af;
    --border: #2a2e37;
    --accent: #60a5fa;
    --panel: #1a1d24;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
}

header {
  padding: 2rem 1.5rem 1rem;
  text-align: center;
}

header h1 { margin: 0; }
.subtitle { color: var(--muted); margin: 0.25rem 0 0; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

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

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}

.stat-card .value { font-size: 1.5rem; font-weight: 600; }
.stat-card .label { color: var(--muted); font-size: 0.8rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.panel h2 { margin-top: 0; font-size: 1.05rem; }

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#measurementFields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

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

.field-row.full { grid-column: 1 / -1; }

.field-row-pair {
  display: flex;
  gap: 1rem;
}

.field-row-pair .field-row { flex: 1; }

.field-row label {
  font-size: 0.8rem;
  color: var(--muted);
}

.field-row > input {
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
}

.stepper {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
}

.stepper input {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}

.step-btn {
  flex: none;
  width: 3rem;
  min-height: 3rem;
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  padding: 0;
}

.step-btn:active { background: var(--accent); color: white; }

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

.form-actions button { flex: 1; }

button {
  padding: 0.75rem 1.1rem;
  min-height: 3rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

button#cancelEdit {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

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

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }

td.actions { display: flex; gap: 0.4rem; }
td.actions button { padding: 0.3rem 0.6rem; min-height: auto; font-size: 0.8rem; }
td.actions button.delete { background: #dc2626; }
