:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e3e3e0;
  --accent: #2f6f5e;
  --review: #b26a00;
  --review-bg: #fff3df;
  --danger: #b3261e;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1c1c1f;
    --text: #ececef;
    --muted: #9a9aa1;
    --line: #2c2c31;
    --accent: #7cc4ad;
    --review: #f0b660;
    --review-bg: #3a2c14;
    --danger: #f2827a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }

h1, h2 { margin: 0; font-weight: 600; }

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

button, input { font: inherit; color: inherit; }

button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

button[type="submit"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--muted); padding: 0; }

input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.error { color: var(--danger); margin: 0; }

/* Login */
.login { display: grid; gap: 12px; max-width: 320px; margin: 20vh auto 0; }
.login h1 { text-align: center; margin-bottom: 12px; }

/* Header */
.month-header { text-align: center; padding: 8px 0 16px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-nav a { font-size: 28px; padding: 0 12px; }
.month-nav h1 { font-size: 18px; }
.total { font-size: 34px; font-weight: 600; margin: 8px 0 12px; font-variant-numeric: tabular-nums; }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.switch {
  width: 30px; height: 18px; border-radius: 9px; background: var(--line); position: relative;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%; background: var(--surface);
  transition: transform 0.15s;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(12px); }

/* List */
.day h2 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 20px 4px 6px; }
.day ul { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 12px; overflow: hidden; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry.ignored, .entry.failed { opacity: 0.65; }

summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
.name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meta, .note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.note { font-style: italic; }
.badge {
  margin-left: 6px; padding: 1px 6px; border-radius: 6px;
  background: var(--review-bg); color: var(--review); font-size: 12px; font-weight: 500;
}

/* Detail */
.detail { padding: 0 14px 14px; display: grid; gap: 12px; }
.original { display: grid; gap: 4px; padding: 10px 12px; border-radius: 8px; background: var(--bg); font-size: 14px; }
.original > * { white-space: pre-wrap; }
.edit { display: grid; gap: 10px; }
.edit label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
/* iOS Safari gives date inputs an intrinsic minimum width that overflows narrow screens. */
.edit input { min-width: 0; }
.edit input[type="datetime-local"] { -webkit-appearance: none; appearance: none; min-height: 40px; text-align: left; }
.edit input[type="datetime-local"]::-webkit-date-and-time-value { text-align: left; }
.actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.loading, .empty { color: var(--muted); text-align: center; }

footer { margin-top: 32px; text-align: center; }
