/* Paydar base styles. Mobile first; dark mode follows the system setting. */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --border: #deded8;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #e3f1ec;
  --danger: #b3261e;
  --warn-bg: #fff4e0;
  --warn-text: #7a4b00;
  --ok-bg: #e6f4ea;
  --ok-text: #1e5e2e;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1e1e1c;
    --text: #ecece8;
    --muted: #9c9c95;
    --border: #34342f;
    --accent: #4fb39a;
    --accent-text: #0e1f1a;
    --accent-soft: #1d332d;
    --danger: #f2b8b5;
    --warn-bg: #3a2c12;
    --warn-text: #f5d39a;
    --ok-bg: #173022;
    --ok-text: #a8dbb5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 42rem; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.4rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 0.5rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header and navigation */
.wordmark { font-weight: 700; letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 42rem; margin: 0 auto; padding: 0.75rem 1rem 0.25rem;
}
.topbar .wordmark { font-size: 1.25rem; }
.topbar form { margin: 0; }
.tabs {
  display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none;
  max-width: 42rem; margin: 0 auto; padding: 0.25rem 1rem; border-bottom: 1px solid var(--border);
}
.tabs a {
  flex: none; padding: 0.4rem 0.7rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 0.95rem;
}
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }

/* Landing */
.landing { min-height: 100svh; display: flex; flex-direction: column; justify-content: center; }
.landing .wordmark { font-size: 2.5rem; text-align: center; margin: 0 0 1.5rem; }
.login { width: 100%; max-width: 22rem; margin: 0 auto; }

/* Cards and sections */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.25rem; }
.section-head h1, .section-head h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 0.5rem; }

/* Lists of paychecks, bills, adjustments */
.items { list-style: none; margin: 0; padding: 0; }
.items.card { padding: 0 1rem; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "check main amount" "check more more";
  column-gap: 0.75rem; align-items: start; padding: 0.65rem 0; border-top: 1px solid var(--border);
}
.items > .item:first-child { border-top: 0; }
.item:not(:has(> .item-check)) { grid-template-columns: 1fr auto; grid-template-areas: "main amount" "more more"; }
.item-check { grid-area: check; padding-top: 0.1rem; }
.item-main { grid-area: main; display: flex; flex-direction: column; min-width: 0; }
.item-name { font-weight: 500; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
a.item-name:hover { text-decoration: underline; }
.item-meta { font-size: 0.85rem; color: var(--muted); }
.item-meta.warn { color: var(--warn-text); }
.item-amount { grid-area: amount; text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.item-form, .item-more { grid-area: more; margin-top: 0.4rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.item-more { display: block; }
.item.skipped .item-name, .item.skipped .item-amount .money { text-decoration: line-through; color: var(--muted); }
.item.overdue .item-meta { color: var(--warn-text); }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.neg { color: inherit; }
.tag, .badge {
  display: inline-block; font-size: 0.72rem; line-height: 1.4; padding: 0 0.4rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--muted); white-space: nowrap;
}
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }

/* The paid checkbox is a button so it works without JavaScript. */
button.check {
  width: 1.9rem; height: 1.9rem; padding: 0; border-radius: 8px; font-size: 1.1rem; line-height: 1;
  background: transparent; border: 2px solid var(--border); color: var(--accent-text);
}
button.check.on { background: var(--accent); border-color: var(--accent); }

/* Period math */
.math { display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 1rem; margin: 1rem 0 0; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.math dt { color: var(--muted); }
.math dd { margin: 0; text-align: right; }
.math .total { font-weight: 700; color: var(--text); font-size: 1.1rem; padding-top: 0.25rem; }

/* Period summary cards */
a.summary { display: block; text-decoration: none; color: var(--text); margin: 0; }
a.summary.warn { border-color: var(--warn-text); }
.summary-head { display: flex; justify-content: space-between; font-weight: 600; }
.summary-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; font-size: 0.85rem; color: var(--muted); margin-top: 0.15rem; }
.current-marker { position: relative; }
.current-marker > .badge { position: absolute; top: -0.5rem; right: 0.75rem; background: var(--accent); color: var(--accent-text); }
.pager { display: flex; justify-content: space-between; margin-bottom: 0.75rem; }

/* Notices */
.notice { border-radius: 10px; padding: 0.7rem 0.9rem; margin-bottom: 0.75rem; background: var(--accent-soft); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); }
.notice a { color: inherit; font-weight: 600; }
.error { color: var(--danger); margin: 0; }
.error ul { margin: 0; padding-left: 1.2rem; }

/* Forms */
.stack-form { display: flex; flex-direction: column; gap: 0.9rem; }
.row-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; }
.row-form + .row-form, .item-more .row-form { margin-top: 0.5rem; }
form.inline { display: inline; margin: 0; }
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
label.check-label { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.5rem; color: var(--text); }
label.check-label .hint { flex-basis: 100%; }
.hint { font-size: 0.8rem; color: var(--muted); }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0; padding: 0.5rem 0.75rem 0.75rem; }
legend { font-size: 0.9rem; color: var(--muted); padding: 0 0.25rem; }
details summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; }
details.add { margin: 0.75rem 0; }
details.add[open] summary { margin-bottom: 0.75rem; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; min-width: 0;
}
input[type="checkbox"] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

button, a.button {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 0.7rem 1rem;
  background: var(--accent); color: var(--accent-text); cursor: pointer; text-decoration: none; display: inline-block;
}
button.small { padding: 0.45rem 0.75rem; font-size: 0.9rem; }
button.secondary, a.button.secondary { background: var(--accent-soft); color: var(--text); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.link { background: none; color: var(--accent); padding: 0.25rem 0; font-weight: 500; }

@media (min-width: 40rem) {
  main { padding: 1.5rem 1rem; }
}

/* Error toast (public/app.js) */
.toast {
  position: fixed; left: 1rem; right: 1rem; bottom: 1rem; max-width: 30rem; margin: 0 auto;
  padding: 0.8rem 1rem; border-radius: 10px; background: var(--danger); color: var(--surface);
  font-weight: 600; opacity: 0; transform: translateY(1rem); transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.visible { opacity: 1; transform: none; }

/* Everyone / Mine filter */
.filter { display: inline-flex; gap: 0.15rem; padding: 0.15rem; border-radius: 999px; background: var(--accent-soft); margin: 0.25rem 0 0.75rem; }
.filter a { padding: 0.25rem 0.8rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 0.9rem; }
.filter a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; }
.tag.who { vertical-align: 0.1em; }
.export-links { margin: 1rem 0 0; line-height: 2; }
.math .aside { font-size: 0.85rem; color: var(--muted); font-weight: 400; }
label.check-label > .text { flex: 1 1 0; min-width: 0; }
label.check-label + .row-form { margin-top: 0.5rem; }

/* Calendar */
.calendar { width: 100%; border-collapse: collapse; table-layout: fixed; margin-bottom: 0.5rem; }
.calendar th { font-size: 0.75rem; font-weight: 500; color: var(--muted); padding: 0.25rem 0; }
.calendar td { height: 3.1rem; padding: 0; border: 1px solid var(--border); vertical-align: top; background: var(--surface); }
.calendar td.blank { background: transparent; border-color: transparent; }
.calendar td .num { display: block; padding: 0.2rem 0.3rem 0; font-size: 0.85rem; }
.calendar td a { display: block; height: 100%; color: var(--text); text-decoration: none; }
.calendar td.has-items a:hover, .calendar td.has-items a:focus-visible { background: var(--accent-soft); }
.calendar td[aria-current="date"] .num { font-weight: 700; color: var(--accent); }
.calendar .dots { display: flex; gap: 0.2rem; padding: 0.15rem 0.3rem; }
.dot { display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%; vertical-align: middle; }
.dot.pay { background: var(--accent); }
.dot.bill { background: var(--muted); }
.dot.bill.late { background: var(--warn-text); }
.legend { font-size: 0.8rem; display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; align-items: center; }
.card.day:target { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.day { scroll-margin-top: 0.75rem; }
.day-link { margin: 0.5rem 0 0; font-size: 0.9rem; }
