:root {
  --bg: #f5f6fa; --card: #ffffff; --text: #14161c; --muted: #6b7280; --line: #e5e7ee;
  --accent: #4f46e5; --accent-soft: #e8e7fd; --warn: #b45309; --warn-bg: #fef3c7; --now: #16a34a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b22; --text: #eef0f5; --muted: #9aa1b0; --line: #262a34;
    --accent: #8b87ff; --accent-soft: #25254a; --warn: #fbbf24; --warn-bg: #2d2410; --now: #4ade80;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* perquè cap display d'autor anul·li l'atribut hidden */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 640px; margin-inline: auto;
}
.top { display: flex; justify-content: space-between; align-items: flex-end; padding: 20px 0 12px; }
.greeting { margin: 0; color: var(--muted); font-size: 14px; }
.today { margin: 2px 0 0; font-size: 26px; }
.today::first-letter { text-transform: uppercase; }
.icon-btn {
  appearance: none; border: 0; background: var(--card); color: var(--text);
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  box-shadow: 0 0 0 1px var(--line);
}
.icon-btn.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }
.card { background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 14px; box-shadow: 0 0 0 1px var(--line); }
.card h2 { margin: 0 0 8px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.pill { text-transform: none; background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; padding: 1px 8px; letter-spacing: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.empty { color: var(--muted); font-size: 15px; padding: 6px 0; }
.warn { color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; font-size: 13px; margin-bottom: 6px; }

.ev { display: grid; grid-template-columns: 64px 1fr; gap: 10px; }
.ev .time { white-space: pre-line; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; padding-top: 1px; }
.ev .title { font-weight: 600; }
.ev .meta { color: var(--muted); font-size: 13px; }
.ev.past { opacity: .5; }
.ev.now { border-left: 3px solid var(--now); padding-left: 8px; margin-left: -11px; }
.ev.next .title::after { content: "properament"; margin-left: 8px; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 999px; }
.ev.now .title::after { content: "ara"; margin-left: 8px; font-size: 11px; font-weight: 700; color: #fff; background: var(--now); padding: 1px 7px; border-radius: 999px; text-transform: uppercase; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; margin-left: 6px; }

.mail a, .notice { color: inherit; text-decoration: none; display: block; }
.mail .from { font-weight: 600; }
.mail .subject { color: var(--text); }
.mail .meta, .notice .meta { color: var(--muted); font-size: 13px; }
.notice .title { font-weight: 600; }

.foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; padding: 4px 4px 0; }
.foot form { margin: 0; }
.link { appearance: none; background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; padding: 8px; }

body.login { display: grid; place-items: center; min-height: 100dvh; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-box .logo { border-radius: 16px; }
.login-box h1 { font-size: 22px; margin: 12px 0 20px; }
.login-box form { text-align: left; display: grid; gap: 10px; }
.login-box label { font-size: 14px; color: var(--muted); }
.login-box input { font: inherit; font-size: 17px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.login-box button { font: inherit; font-weight: 600; padding: 12px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; }
.form-error { color: #dc2626; margin: 0; font-size: 14px; }
a.plain { color: inherit; text-decoration: none; }
.notice-row { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.notice .body { white-space: pre-line; }
.dismiss { appearance: none; border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; padding: 2px 10px; margin: -4px -8px 0 0; }

/* ---- Finances ---- */
.muted { color: var(--muted); }
.small { font-size: 13px; margin: 6px 0 0; }
.card h3.sub { margin: 16px 0 4px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.fin-head { display: flex; justify-content: space-between; align-items: center; }
.fin-head h2 { margin: 0; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-label { min-width: 110px; text-align: center; font-size: 14px; }
.month-label::first-letter { text-transform: uppercase; }
.mini { appearance: none; border: 0; background: var(--bg); color: var(--text); width: 36px; height: 36px; border-radius: 50%; font-size: 20px; line-height: 1; }
.mini:disabled { opacity: .3; }
.fin-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 4px; }
.fin-totals div { background: var(--bg); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; }
.fin-totals div:nth-child(3) { grid-column: 1 / -1; order: -1; } /* el balanç, gran i a dalt */
.fin-totals .lab { font-size: 12px; color: var(--muted); }
.fin-totals .val { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fin-totals div:nth-child(3) .val { font-size: 28px; }
.pos { color: var(--now); }
.neg { color: #dc2626; }
@media (prefers-color-scheme: dark) { .neg { color: #f87171; } }
.fin-actions { display: flex; gap: 8px; margin: 12px 0 0; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; min-height: 44px; padding: 0 16px; border-radius: 12px; flex: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; }
.cats { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cats li { display: grid; gap: 4px; }
.cats .row { display: flex; justify-content: space-between; font-size: 14px; }
.cats .track { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.cats .bar { height: 100%; background: var(--accent); border-radius: 3px; }
.mv { display: grid; grid-template-columns: 44px 1fr auto auto; gap: 8px; align-items: center; }
.mv .when { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.mv .what { min-width: 0; }
.mv .what .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv .what .c { color: var(--muted); font-size: 12px; }
.mv .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.mv .amt.in { color: var(--now); }
.mv.paused { opacity: .55; }
.fixed-box { margin-top: 14px; }
.fixed-box summary { cursor: pointer; color: var(--muted); font-size: 13px; letter-spacing: .06em; text-transform: uppercase; padding: 6px 0; }
.fixed-box .btn { width: 100%; margin-top: 10px; }
.fx { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.fx .tools { display: flex; gap: 2px; grid-row: span 2; }
.fx .tools button { appearance: none; border: 0; background: none; color: var(--muted); font-size: 18px; min-width: 40px; min-height: 40px; }

dialog { border: 0; border-radius: 18px; padding: 20px; width: min(92vw, 420px); background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin: 0 0 12px; font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
dialog input, dialog select { font: inherit; font-size: 17px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 100%; }
.dlg-actions { display: flex; gap: 8px; margin-top: 4px; }
