:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1a1c24;
  --muted: #62677a;
  --line: #e2e5ee;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --danger: #c62828;
  --warn: #a15c00;
  --ok: #1b7a3d;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --card: #1c1f27;
    --ink: #e8eaf1;
    --muted: #a1a7b8;
    --line: #2c303b;
    --accent: #7b98ff;
    --accent-ink: #0d1020;
    --danger: #ff8a80;
    --warn: #ffc46b;
    --ok: #7ee2a8;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  max-width: 60rem;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
a { color: var(--accent); }
code { font-size: .9em; background: var(--line); padding: .05em .3em; border-radius: 4px; }
/* Author `display` rules (e.g. a.button) would otherwise win over the hidden attribute. */
[hidden] { display: none !important; }

.top { margin-bottom: 1rem; }
.tagline { color: var(--muted); margin: 0; }
.privacy { margin: .5rem 0 0; font-size: .88rem; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}

.totals-body { display: flex; flex-wrap: wrap; gap: 1rem; }
.total {
  flex: 1 1 12rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}
.total .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.total .value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.total .sub { color: var(--muted); font-size: .85rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .75rem; }

.quick-add {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .5rem 1rem;
  padding: .75rem;
  margin-bottom: 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.quick-add label { flex: 1 1 14rem; }
.quick-add p { flex: 2 1 16rem; margin: 0 0 .55rem; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--ink); margin-top: .75rem; }
label.inline { flex-direction: row; align-items: center; gap: .4rem; }
label .muted { font-weight: 400; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .6rem;
  width: 100%;
}
/* Keyboard focus: visible on every interactive element, in light and dark mode
   (--accent is redefined per colour scheme, so the ring stays high-contrast). */
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible,
a:focus-visible, .button:focus-visible, .button.file:focus-visible, .skip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input[type="checkbox"] { accent-color: var(--accent); width: 1.15rem; height: 1.15rem; }
input.small { width: 4.5rem; }
textarea { resize: vertical; }

/* Keyboard-only skip link: off-screen until focused. */
.skip {
  position: absolute;
  left: .5rem;
  top: -3rem;
  padding: .55rem .9rem;
  background: var(--card);
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  z-index: 10;
}
.skip:focus { top: .5rem; }

.actions { display: flex; gap: .6rem; align-items: center; margin-top: .9rem; }
.actions.wrap { flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }

button {
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .5rem .9rem;
  cursor: pointer;
}
button.secondary, .button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
button.danger-ghost { background: transparent; color: var(--danger); border-color: var(--line); margin-left: auto; }
.button.file { display: inline-flex; align-items: center; font-weight: 600; font-size: .95rem; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; color: var(--ink); }
a.button { display: inline-flex; align-items: center; font-weight: 600; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 9px; text-decoration: none; }
button:hover, .button.file:hover, a.button:hover { filter: brightness(1.08); }

.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }

.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .7rem .8rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .3rem .8rem;
}
.item .name { font-weight: 650; display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.item .meta { color: var(--muted); font-size: .85rem; grid-column: 1 / -1; overflow-wrap: anywhere; }
.item .price { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.item .when { text-align: right; font-size: .85rem; white-space: nowrap; }
.item .row-actions { grid-column: 1 / -1; display: flex; gap: .5rem; margin-top: .25rem; }
.item .row-actions button { padding: .3rem .6rem; font-size: .85rem; }
.item .flag { grid-column: 1 / -1; }
.item .flag label { display: inline-flex; align-items: center; gap: .4rem; font-size: .88rem; cursor: pointer; }
.item .flag input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); margin: 0; }
.item.flagged { border-color: var(--warn); }
.cancel-summary { margin: .6rem 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }

/* "Next 30 days" panel: one compact line per charge, then the per-currency total. */
.upcoming-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .15rem .8rem;
  padding: .5rem .1rem;
  border-bottom: 1px solid var(--line);
}
.upcoming-item:last-child { border-bottom: 0; }
.upcoming-item .name { font-weight: 650; overflow-wrap: anywhere; }
.upcoming-item .when { font-size: .85rem; color: var(--muted); grid-column: 1; white-space: nowrap; }
.upcoming-item .price {
  grid-column: 2; grid-row: 1 / span 2; align-self: center;
  text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap;
}
.upcoming-totals { font-weight: 650; margin: .6rem 0 0; font-variant-numeric: tabular-nums; }

.badge {
  font-size: .72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-radius: 999px;
  padding: .1rem .5rem;
  border: 1px solid currentColor;
}
.badge.trial { color: var(--accent); }
.badge.example { color: var(--muted); border-style: dashed; }
.badge.overdue { color: var(--danger); }
.badge.soon { color: var(--warn); }
.badge.ok { color: var(--muted); }
.badge.card-warning { color: var(--danger); border-style: dashed; }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .9rem; margin: .6rem 0 0; }
.notice { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: .6rem .8rem; font-size: .9rem; }
.empty { padding: 1rem 0 .25rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.1rem 0; }

footer { margin-top: 1.5rem; color: var(--muted); font-size: .85rem; }
footer p { margin: .3rem 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (max-width: 30rem) {
  .item { grid-template-columns: 1fr; }
  .item .price, .item .when { text-align: left; }
  .upcoming-item { grid-template-columns: 1fr; }
  .upcoming-item .price { grid-column: 1; grid-row: auto; text-align: left; }
  .upcoming-item .when { white-space: normal; }
}

/* ---------------------------------------------------------------- CSV ---- */

.muted.small { font-size: .85rem; }
h3 { font-size: .98rem; margin: 1.1rem 0 .4rem; }
.csv-errors { margin: .5rem 0 0; padding-left: 1.1rem; font-size: .88rem; color: var(--warn); }
.csv-errors li { margin: .15rem 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------- pricing ---- */

.plans { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .35rem; }
.plan {
  flex: 1 1 16rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}
.plan.pro { border-color: var(--accent); }
.plan h3 { margin-top: 0; }
.plan-price { font-size: 1.5rem; font-weight: 700; margin: 0 0 .5rem; }
.plan ul { margin: 0; padding-left: 1.1rem; font-size: .92rem; }
.plan li { margin: .25rem 0; }
.plan .muted.small { margin-top: auto; padding-top: .8rem; }
.plan button, .plan a.button { align-self: flex-start; }
.plan button[disabled] { opacity: .6; cursor: not-allowed; }

/* ------------------------------------------------- phone (360–400px) ---- */
/* One column everywhere, no horizontal overflow, and every tap target at
   least 44px tall (WCAG 2.5.5 asks for 44; the task's floor is 40). */

@media (max-width: 400px) {
  body { padding: 1rem .75rem 2.5rem; }

  .grid { grid-template-columns: 1fr; }
  .quick-add { padding: .6rem; }
  .actions { flex-wrap: wrap; }
  button.danger-ghost { margin-left: 0; }

  .item { grid-template-columns: 1fr; }
  .item .price, .item .when { text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .item .name { overflow-wrap: anywhere; }

  .plans { flex-direction: column; }
  .plan { flex: 1 1 auto; }

  button,
  .button,
  a.button,
  .button.file,
  input:not([type="checkbox"]),
  select,
  textarea { min-height: 44px; }

  label.check,
  label.inline { min-height: 44px; align-items: center; }
  .item .row-actions button { min-height: 44px; }
}
