:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1e6fd9;
  --accent-text: #ffffff;
  --hero: var(--accent);
  --ok: #16a34a;
  --warn: #dc2626;
  --radius: 14px;
  color-scheme: light dark;
}
/* User colors from the settings are injected as <style id="theme">:root{...}</style>
   after this file and override both the light and the dark values above. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2a2f3a;
    --accent: #3b82f6;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  min-height: 100dvh;
}
.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.monthnav { display: flex; align-items: center; gap: 4px; flex: 1; }
h1 { font-size: 1.25rem; margin: 0; font-weight: 600; flex: 1; text-align: center; }
h2 { font-size: 1rem; margin: 0 0 8px; }
.nav, .icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; text-decoration: none;
  background: transparent; color: var(--text); font-size: 1.6rem; font-weight: 400; line-height: 1; cursor: pointer;
}
.nav:active, .icon:active { background: var(--line); }
@keyframes spin { to { transform: rotate(360deg); } }
.icon.htmx-request { animation: spin 0.8s linear infinite; }

/* Hero */
.hero {
  background: var(--hero); color: var(--accent-text);
  border-radius: var(--radius); padding: 22px 20px 18px; margin-bottom: 14px;
}
.hero.over { background: var(--warn); }
.hero p { margin: 0; }
.hero .label { font-size: 0.9rem; opacity: 0.85; }
.hero .remaining { font-size: 2.8rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin: 2px 0 12px; }
.hero .meta { font-size: 0.85rem; opacity: 0.9; margin-top: 8px; }
.bar { height: 8px; background: color-mix(in srgb, var(--accent-text) 30%, transparent); border-radius: 999px; overflow: hidden; }
.fill { height: 100%; background: var(--accent-text); border-radius: 999px; transition: width 0.3s ease; }

/* Cards & forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.row { display: flex; gap: 8px; }
.row + .row { margin-top: 8px; }
input, button, .button {
  font: inherit; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
  padding: 0 12px; background: var(--bg); color: var(--text); min-width: 0;
}
input { flex: 1; }
input.amount { flex: 0 0 34%; font-variant-numeric: tabular-nums; }
input[type="date"] { flex: 0 0 auto; max-width: 48%; }
button.wide { flex: 1; }
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
button, .button {
  background: var(--accent); color: var(--accent-text); border-color: transparent;
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
button:active, .button:active { filter: brightness(0.9); }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }
code { font-size: 0.8rem; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.error { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.notice { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }

/* Expense list */
.expenses { list-style: none; margin: 0 0 14px; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.expenses li { display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 14px; border-top: 1px solid var(--line); }
.expenses li:first-child { border-top: 0; }
.expenses .date { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; flex: 0 0 3.2em; }
.expenses .desc { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expenses .desc small { color: var(--muted); margin-left: 6px; }
.expenses .desc em { color: var(--muted); font-style: normal; }
.expenses .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.expenses .amt.refund { color: var(--ok); }
.expenses .empty { color: var(--muted); justify-content: center; padding: 20px; }
.expenses form { margin: 0; }
.del { background: transparent; color: var(--muted); border: 0; font-size: 1.4rem; min-height: 44px; width: 44px; padding: 0; }
.del:active { color: var(--warn); }

/* Color settings */
.colors { display: grid; grid-template-columns: 1fr 44px 7.5em; gap: 8px 10px; align-items: center; margin-bottom: 12px; }
.colors label { margin: 0; font-size: 0.95rem; color: var(--text); }
.colors input[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 44px; height: 44px; padding: 3px; flex: none; border-radius: 10px; cursor: pointer;
}
.colors input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.colors input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 7px; }
.colors input[type="color"]::-moz-color-swatch { border: 0; border-radius: 7px; }
.colors input.hex { padding: 0 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; }
.colors input.hex:invalid { border-color: var(--warn); }

/* Month override */
details.override summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; list-style: none; }
details.override summary::-webkit-details-marker { display: none; }
details.override[open] summary { margin-bottom: 10px; }

/* Login / error */
.login { text-align: center; padding-top: 18vh; }
.login img { border-radius: 22px; }
.login h1 { font-size: 1.6rem; margin: 12px 0 20px; }
.login .button { width: 100%; max-width: 320px; }

@media (max-width: 380px) {
  .hero .remaining { font-size: 2.3rem; }
  .row { flex-wrap: wrap; }
  input.amount { flex-basis: 40%; }
}
