:root {
  --accent: #4f6df5;
  --accent-soft: #eef1fe;
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1c1e26;
  --muted: #767b8c;
  --line: #e6e8ef;
  --danger: #e5484d;
  --warn: #b98500;
  --ok: #2f9e63;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7b93ff;
    --accent-soft: #232a45;
    --bg: #101218;
    --card: #1b1e27;
    --text: #eceef4;
    --muted: #9aa0b2;
    --line: #2a2e3b;
    --danger: #ff6369;
    --warn: #e2b93b;
    --ok: #46c17e;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { font-size: 17px; }
body {
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

#header {
  padding: calc(14px + env(safe-area-inset-top)) 20px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
#today-date { font-size: 0.85rem; color: var(--muted); }
#today-summary { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }

main { padding: 14px 14px 0; max-width: 560px; margin: 0 auto; }

.group-title {
  font-size: 0.8rem; font-weight: 700; color: var(--muted);
  margin: 16px 6px 8px; letter-spacing: 0.05em;
}
.group-title.danger { color: var(--danger); }
.group-title.today { color: var(--accent); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
}
.card h3 { font-size: 1rem; margin-bottom: 10px; }

.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
}
.item.overdue { border-left: 4px solid var(--danger); }
.item.today { border-left: 4px solid var(--accent); }
.item.done .item-title { text-decoration: line-through; color: var(--muted); }

.check {
  width: 26px; height: 26px; min-width: 26px;
  border: 2px solid var(--line); border-radius: 50%;
  background: none; font-size: 15px; line-height: 1;
  color: transparent; cursor: pointer;
}
.item.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }

.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.item-sub { font-size: 0.95rem; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.item-sub .date { color: var(--text); font-weight: 700; }
.item-sub .late { color: var(--danger); font-weight: 700; }
.item-sub .soon { color: var(--warn); font-weight: 700; }

.item-actions { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: none; font-size: 1.05rem;
  padding: 6px; cursor: pointer; color: var(--muted);
}

.bill-amount { font-weight: 700; font-size: 1rem; white-space: nowrap; }
.paid-btn {
  border: 1.5px solid var(--accent); color: var(--accent); background: var(--accent-soft);
  border-radius: 10px; padding: 6px 10px; font-size: 0.85rem; font-weight: 700;
  white-space: nowrap; cursor: pointer;
}
.paid-btn.urgent { background: var(--danger); border-color: var(--danger); color: #fff; }
.paid-btn.done { background: var(--ok); border-color: var(--ok); color: #fff; }

.empty-hint { text-align: center; color: var(--muted); margin-top: 48px; line-height: 1.8; }

#fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 30px; border: none;
  box-shadow: 0 6px 18px rgba(79, 109, 245, 0.45);
  cursor: pointer; z-index: 6;
}

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: none; background: none; padding: 8px 0 6px;
  font-size: 0.72rem; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  position: relative;
}
.tab.active { color: var(--accent); font-weight: 700; }
.tab-icon { font-size: 1.35rem; }
.badge {
  position: absolute; top: 2px; right: calc(50% - 26px);
  background: var(--danger); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  min-width: 17px; height: 17px; line-height: 17px;
  border-radius: 9px; padding: 0 4px;
}

.btn {
  display: block; width: 100%;
  padding: 12px; margin-top: 8px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger-outline { color: #b42318; border-color: #f1b5b0; background: #fff7f6; margin-top: 10px; }
.notify-status.install-required {
  color: #b54708;
  background: #fff7e8;
  border: 1px solid #f3c780;
  border-radius: 12px;
  padding: 12px;
  line-height: 1.55;
}
.calendar-btn {
  display: inline-block;
  text-decoration: none;
  border: 1px solid #8fb0ff;
  background: #eef4ff;
  color: #3157c8;
  border-radius: 9px;
  padding: 7px 9px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  margin-top: 9px;
}
.btn:disabled { opacity: 0.5; }

.muted { color: var(--muted); font-size: 0.88rem; }
.small { font-size: 0.78rem; margin-top: 8px; }

dialog {
  border: none; border-radius: 18px;
  background: var(--card); color: var(--text);
  width: min(92vw, 420px);
  padding: 20px;
  margin: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h3 { margin-bottom: 14px; }
dialog label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
dialog input, dialog select {
  display: block; width: 100%; margin-top: 5px;
  padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
dialog label.check-row {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-weight: 500; cursor: pointer;
}
dialog label.check-row input {
  width: 20px; height: 20px; margin: 0; -webkit-appearance: checkbox; appearance: checkbox;
}
.custom-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.95rem; font-weight: 600;
  margin: -4px 0 12px;
  background: var(--accent-soft);
  border-radius: 10px; padding: 10px 12px;
}
.custom-row input, .custom-row select {
  width: auto; min-width: 64px; margin: 0;
  padding: 8px 10px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text);
}
.kind-tag {
  font-size: 0.68rem; font-weight: 700;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 5px; color: var(--muted); margin-right: 4px;
}
.dlg-actions { display: flex; gap: 10px; }
.dlg-actions .btn { margin-top: 6px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(100px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px;
  font-size: 0.88rem; font-weight: 600;
  z-index: 20; max-width: 88vw; text-align: center;
}
