:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #5b6575;
  --line: #d9dee6;
  --accent: #2457d6;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --soon: #8a5a00;
  --soon-bg: #fff1d6;
  --overdue-bg: #fde4e1;
  --later-bg: #e8eef9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --card: #1b212b;
    --text: #e8ecf2;
    --muted: #a3adbd;
    --line: #333c4a;
    --accent: #7ba3ff;
    --accent-text: #0d1320;
    --danger: #ff8a80;
    --soon: #ffd48a;
    --soon-bg: #3a2c10;
    --overdue-bg: #3c1f1c;
    --later-bg: #1f2a40;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.wrap { max-width: 640px; margin: 0 auto; padding: 20px 16px 48px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 8px 0 8px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.lead { margin: 0 0 8px; }
.privacy { margin: 0 0 16px; color: var(--muted); font-size: .92rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin: 0 0 16px;
}
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.totals div { min-width: 0; }
.totals dt { color: var(--muted); font-size: .85rem; }
.totals dd { margin: 0; font-size: 1.25rem; font-weight: 700; overflow-wrap: anywhere; }
.field { margin: 0 0 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: block; font-weight: 600; margin: 0 0 4px; font-size: .95rem; }
.opt { font-weight: 400; color: var(--muted); }
input, select, button { font: inherit; }
input[type="text"], input[type="date"], select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px; /* 16px stops iOS Safari from zooming on focus */
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.error { color: var(--danger); font-size: .88rem; margin: 4px 0 0; min-height: 0; }
.error:empty { display: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
button, .button {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
[hidden] { display: none !important; }
.list-head { display: block; }
.tools { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; margin-bottom: 4px; }
.tools label { margin: 0; }
.tools input[type="text"] { max-width: 120px; }
.empty { color: var(--muted); margin: 12px 0; }
.items { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.item-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.item-name { font-weight: 700; overflow-wrap: anywhere; }
.item-price { white-space: nowrap; font-weight: 600; }
.item-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.badge { display: inline-block; margin-top: 8px; padding: 2px 10px; border-radius: 999px; font-size: .85rem; background: var(--later-bg); }
.badge.soon { background: var(--soon-bg); color: var(--soon); }
.badge.overdue { background: var(--overdue-bg); color: var(--danger); }
.item-actions { display: flex; gap: 8px; margin-top: 10px; }
.item-actions button { min-height: 44px; flex: 1; }
footer { color: var(--muted); font-size: .85rem; }
@media (min-width: 560px) {
    .list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .list-head h2 { margin: 0; }
  .tools { display: flex; gap: 8px; }
  .tools select { width: auto; }
  .tools input[type="text"] { width: 72px; }
}

.content h2 { margin-bottom: 8px; }
.content h3 { font-size: 1rem; margin: 16px 0 4px; }
.content p { margin: 0 0 12px; }
.content ol, .content ul { margin: 0 0 12px; padding-left: 1.25rem; }
.content li { margin: 0 0 6px; }
noscript .card { margin-top: 0; }

.notice { margin: 0 0 8px; padding: 10px 12px; border-left: 4px solid var(--accent); background: var(--card); border-radius: 8px; font-size: .95rem; }
.banner { border-left: 4px solid var(--accent); }
.banner p { margin: 0 0 12px; }
.day { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0 0 12px; }
.day h3 { font-size: 1rem; margin: 0 0 8px; }
.day .none { color: var(--muted); margin: 0; font-size: .92rem; }
.acts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.act { border-top: 1px solid var(--line); padding-top: 8px; }
.act:first-child { border-top: 0; padding-top: 0; }
.act-top { display: flex; gap: 10px; align-items: baseline; }
.act-time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.2em; color: var(--accent); }
.act-title { font-weight: 600; overflow-wrap: anywhere; }
.act-note { color: var(--muted); font-size: .9rem; margin: 2px 0 0 calc(3.2em + 10px); overflow-wrap: anywhere; }
.act-actions { display: flex; gap: 8px; margin: 8px 0 0 calc(3.2em + 10px); }
.act-actions button { min-height: 44px; }
#link-out { width: 100%; min-height: 44px; padding: 8px 10px; margin: 4px 0 8px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 16px; }
#link-box { margin-top: 12px; }
@media print {
  body { background: #fff; color: #000; }
  .wrap { max-width: none; padding: 0; }
  #inputs-card, #share-card, #storage-note, #storage-status, .content, footer, .privacy, .notice, noscript, #shared-banner .actions, #link-error { display: none !important; }
  .card, .day { border: 0; box-shadow: none; padding: 0; }
  .day { border-top: 1px solid #999; padding-top: 8px; break-inside: avoid; }
  input { border: 0; padding: 0; }
  .act-time { color: #000; }
}

.people { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.person { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 999px; padding: 0 4px 0 12px; min-height: 44px; }
.person button { min-height: 36px; min-width: 36px; padding: 0 8px; border-radius: 999px; border: 0; background: transparent; color: var(--danger); }
.checks { border: 0; padding: 0; margin: 0 0 12px; }
.checks legend { font-weight: 600; font-size: .95rem; margin-bottom: 4px; padding: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0 12px 0 0; min-height: 44px; font-weight: 400; }
.table-wrap { overflow-x: auto; }
table.bal { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.bal th, table.bal td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.bal th:first-child, table.bal td:first-child { text-align: left; white-space: normal; overflow-wrap: anywhere; }
.pos { color: var(--accent); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }
.pays { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.pays li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-wrap: anywhere; }
.exp { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.exp-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.exp-title { font-weight: 700; overflow-wrap: anywhere; }
.exp-amt { white-space: nowrap; font-weight: 600; }
.exp-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; overflow-wrap: anywhere; }
.exp-actions { display: flex; gap: 8px; margin-top: 10px; }
.exp-actions button { min-height: 44px; flex: 1; }

.out { display: grid; gap: 8px; margin: 0 0 12px; }
.out div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 6px 0; }
.out dt { color: var(--muted); min-width: 0; }
.out dd { margin: 0; font-weight: 600; text-align: right; white-space: nowrap; }
.big { margin: 4px 0 12px; font-size: 1.9rem; font-weight: 700; line-height: 1.2; }
.big small { display: block; font-size: .9rem; font-weight: 400; color: var(--muted); }
.formula { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; }
