*, *::before, *::after { box-sizing: border-box; }

:root {
  color-scheme: light;

  /* White base */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --surface-3: #f0f4f9;
  --line: #e6eaf0;
  --line-strong: #d3d9e1;

  --text: #1f1f1f;
  --text-2: #444746;
  --text-3: #6f7378;

  /* Google accents */
  --primary: #0b57d0;
  --primary-hover: #0a4cb8;
  --primary-tint: #d3e3fd;
  --on-primary-tint: #041e49;
  --blue: #1a73e8;
  --red: #d93025;
  --yellow: #f9ab00;
  --green: #1e8e3e;

  --radius-lg: 24px;
  --radius: 16px;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, .14), 0 1px 3px 1px rgba(60, 64, 67, .08);
  --shadow-3: 0 12px 40px rgba(60, 64, 67, .22);
  --font: "Google Sans Flex", "Google Sans", Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--primary); text-decoration: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[data-icon] { display: inline-grid; place-items: center; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: 64px; padding: 0 24px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); font-size: 20px; font-weight: 500; letter-spacing: -.01em; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 10px); gap: 3px; }
.brand-mark i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px 0 12px; border-radius: 999px;
  color: var(--text-2); font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--surface-3); }
.tab.is-active { background: var(--primary-tint); color: var(--on-primary-tint); }
.bottom-nav { display: none; }

/* ---------- Page ---------- */
main { padding: 32px 24px 64px; }
.page { max-width: 1200px; margin: 0 auto; }
.page-narrow { max-width: 640px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { margin: 0; font-size: 32px; line-height: 1.2; font-weight: 400; letter-spacing: -.02em; }
.page-sub { margin: 6px 0 0; color: var(--text-2); }
.head-actions { display: flex; align-items: center; gap: 4px; }
.head-actions .btn { margin-right: 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 20px; border-radius: 999px;
  font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, box-shadow .15s, color .15s, border-color .15s;
}
.btn svg.i { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-1); }
.btn-primary:disabled { background: #ebedf0; color: #9aa0a6; box-shadow: none; cursor: default; }
.btn-tonal { background: var(--primary-tint); color: var(--on-primary-tint); }
.btn-tonal:hover { background: #c3d7fb; }
.btn-outline { background: #fff; border: 1px solid var(--line-strong); color: var(--primary); }
.btn-outline:hover { background: #f5f8fe; }
.btn-lg { height: 52px; font-size: 16px; }
.btn-sm { height: 36px; padding: 0 14px 0 10px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--text-2); transition: background .15s, color .15s; flex: none; }
.icon-btn:hover { background: var(--surface-3); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon-btn.subtle { color: var(--text-3); }
.icon-btn.subtle:hover { color: var(--red); background: #fdf3f2; }

/* ---------- Log form ---------- */
.form-card { padding: 4px 24px 24px; }
.field { padding: 20px 0; border-bottom: 1px solid var(--line); }
.field.no-line { border-bottom: 0; }
.field-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 12px; font-size: 14px; font-weight: 500; }
.hint { font-size: 13px; font-weight: 400; color: var(--text-3); }

.date-stepper { display: flex; align-items: center; gap: 8px; }
.date-display {
  position: relative; flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  height: 52px; border: 1px solid var(--line-strong); border-radius: 14px;
  font-size: 16px; font-weight: 500; cursor: pointer; transition: background .15s;
}
.date-display:hover { background: var(--surface-2); }
.date-long, .date-short { white-space: nowrap; }
.date-short { display: none; }
.date-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; cursor: pointer; }
.date-input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; background: var(--primary-tint); color: var(--on-primary-tint); font-size: 12px; font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: #fff; color: var(--text-2); font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { background: var(--surface-2); }
.chip.is-on { background: var(--primary-tint); border-color: transparent; color: var(--on-primary-tint); }
.chip-person { padding-left: 6px; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.chip-cat { --ink: color-mix(in srgb, var(--c) 58%, #000); padding-left: 12px; }
.chip-check { display: none; color: var(--ink); }
.chip-check svg.i { width: 18px; height: 18px; stroke-width: 2.6; }
.chip-cat.is-on { background: color-mix(in srgb, var(--c) 14%, #fff); border-color: color-mix(in srgb, var(--c) 45%, #fff); color: var(--ink); padding-left: 8px; }
.chip-cat.is-on .dot { display: none; }
.chip-cat.is-on .chip-check { display: inline-flex; }

.textarea, .input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 12px; background: #fff;
  font-size: 15px; transition: border-color .15s, box-shadow .15s;
}
.textarea { padding: 12px 14px; resize: vertical; min-height: 88px; }
.input { height: 44px; padding: 0 14px; }
.textarea:focus, .input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.textarea::placeholder, .input::placeholder { color: #9aa0a6; }

.notice { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: #e6f4ea; color: #0d652d; font-size: 13px; }
.notice svg.i { width: 18px; height: 18px; }
.form-actions { padding-top: 8px; }
.help { margin: 10px 0 0; color: var(--text-3); font-size: 13px; }
.help.center { text-align: center; }

.field-label .link-btn { margin-left: auto; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; margin: -6px -8px -6px 0; padding: 0 12px; border-radius: 999px; color: var(--primary); font-size: 14px; font-weight: 500; white-space: nowrap; transition: background .15s; }
.link-btn svg.i { width: 18px; height: 18px; }
.link-btn:hover { background: #eef3fd; }

.chip-add { border-style: dashed; color: var(--primary); padding: 0 16px 0 10px; }
.chip-add svg.i { width: 18px; height: 18px; }
.chip.is-editing, .chip.is-editing:hover { padding-right: 4px; background: #fff; cursor: default; }
.chip-remove { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: var(--text-3); transition: background .15s, color .15s; }
.chip-remove:hover { background: #fce8e6; color: var(--red); }
.chip-remove svg.i { width: 16px; height: 16px; stroke-width: 2.2; }
.chip-form { display: flex; align-items: center; gap: 6px; flex: 1 1 260px; max-width: 380px; }
.chip-form .input { height: 40px; border-radius: 10px; }

.log-list { margin-top: 16px; padding: 20px 24px 24px; }
.log-list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.log-list-head h2 { margin: 0; font-size: 16px; font-weight: 500; }
.btn-delete { display: inline-flex; align-items: center; align-self: flex-start; gap: 6px; height: 32px; margin: -4px -4px 0 0; padding: 0 12px 0 8px; border-radius: 999px; color: var(--red); font-size: 13px; font-weight: 500; transition: background .15s; }
.btn-delete:hover { background: #fce8e6; }
.btn-delete svg.i { width: 16px; height: 16px; }
/* Delete sits in the top-right corner so the paid rows can use the card's full width */
.entry { position: relative; }
.entry > .btn-delete, .entry > .icon-btn.subtle { position: absolute; top: 10px; right: 10px; margin: 0; }
.entry-top { padding-right: 34px; }
.entry:has(> .btn-delete) .entry-top { padding-right: 84px; }.empty-link { color: var(--text-3); font-size: 14px; }

/* ---------- Avatars / tags / entries ---------- */
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--c); color: #fff; font-size: 14px; font-weight: 500; flex: none; letter-spacing: .02em; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.xs { width: 22px; height: 22px; font-size: 10px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 6px; background: color-mix(in srgb, var(--c) 14%, #fff); color: color-mix(in srgb, var(--c) 58%, #000); font-size: 12px; font-weight: 500; }

.entry-list { display: flex; flex-direction: column; gap: 10px; }
.entry { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.entry-body { flex: 1; min-width: 0; }
.entry-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.entry-name { font-weight: 500; }
.entry-time { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.entry-note { margin: 8px 0 0; color: var(--text-2); font-size: 14px; overflow-wrap: anywhere; }
.entry .icon-btn { width: 34px; height: 34px; margin: -6px -6px 0 0; }
.entry .icon-btn svg.i { width: 18px; height: 18px; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 28px 12px; color: var(--text-3); }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 10px; border-radius: 50%; background: var(--surface-3); }
.empty strong { color: var(--text-2); font-weight: 500; }
.empty p { margin: 4px 0 0; font-size: 14px; }

/* ---------- Calendar ---------- */
.filter-row { display: flex; gap: 8px; margin-bottom: 16px; padding-bottom: 2px; overflow-x: auto; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-row .chip { flex: none; height: 34px; padding: 0 12px; }
.filter-row .chip-person { padding-left: 5px; }

.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.cal-card { overflow: hidden; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow { padding: 12px 12px 8px; color: var(--text-3); font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.cal-cell {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 6px;
  min-height: 108px; padding: 8px; text-align: left;
  border-top: 1px solid var(--line); border-left: 1px solid var(--line);
  transition: background .12s;
}
.cal-cell:nth-child(7n + 1) { border-left: 0; }
.cal-cell:hover { background: var(--surface-2); }
.cal-cell.is-out { background: #fcfdfe; }
.cal-cell.is-out .cal-num { color: #b3b8be; }
.cal-num { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: var(--text-2); font-size: 13px; font-weight: 500; }
.cal-cell.is-today .cal-num { background: var(--primary); color: #fff; }
.cal-cell.is-selected { background: #f1f6fe; box-shadow: inset 0 0 0 2px var(--primary); }
.cal-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 4px; }
.cal-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.cal-count { color: var(--text-3); font-size: 12px; white-space: nowrap; }
.cal-cell { position: relative; }
.cal-del {
  position: absolute; top: 10px; right: 8px;
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px 0 6px; border-radius: 999px;
  background: #fce8e6; color: #b3261e; font-size: 11px; font-weight: 500; white-space: nowrap;
}
.cal-del svg.i { width: 12px; height: 12px; stroke-width: 2.2; }

.deleted { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.deleted-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; color: #b3261e; font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.deleted-head svg.i { width: 14px; height: 14px; }
.deleted-row { padding: 10px 12px; border: 1px dashed #f3c5c1; border-radius: 12px; background: #fffafa; }
.deleted-row + .deleted-row { margin-top: 8px; }
.deleted-main { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; }
.deleted-title { color: var(--text-2); font-size: 14px; font-weight: 500; }
.deleted-time { color: var(--text-3); font-size: 12px; }
.tag.is-deleted { opacity: .7; text-decoration: line-through; }

/* ---------- Paid / unpaid ---------- */
.pay-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.pay-row { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.pay-check {
  position: relative; display: grid; place-items: center; flex: none;
  width: 24px; height: 24px; border: 2px solid var(--line-strong); border-radius: 50%;
  color: transparent; transition: background .15s, border-color .15s, color .15s;
}
.pay-check::before { content: ""; position: absolute; inset: -6px -4px; }
.pay-check svg.i { width: 14px; height: 14px; stroke-width: 3; }
.pay-check:hover { border-color: var(--green); color: color-mix(in srgb, var(--green) 45%, #fff); }
.pay-check.is-paid { background: var(--green); border-color: var(--green); color: #fff; }
.pay-status { margin-left: auto; padding: 4px 6px; border-radius: 6px; color: var(--text-3); font-size: 12px; font-weight: 500; }
.pay-status.is-paid { color: #137333; }
.pay-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.pay-pill { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 10px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 500; }
.pay-pill svg.i { width: 13px; height: 13px; stroke-width: 2.6; }
.pay-pill.is-paid { background: #e6f4ea; color: #137333; }
.pay-pill.is-unpaid { background: #fef7e0; color: #8a5a00; }
.block.is-paid { display: flex; align-items: center; gap: 4px; }
.block svg.i { width: 12px; height: 12px; flex: none; stroke-width: 2.8; }
.block-name { overflow: hidden; text-overflow: ellipsis; }

.pay-check.is-static { cursor: default; }
.pay-check.is-static::before { content: none; }
.pay-check.is-static:hover { border-color: var(--line-strong); color: transparent; }
.pay-check.is-static.is-paid:hover { border-color: var(--green); color: #fff; }

/* ---------- Sign-in + sync status ---------- */
body.is-gated .tabs, body.is-gated .bottom-nav { display: none; }
body.is-gated main { padding-bottom: 64px; }
.sync-pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.sync-pill.is-saved { background: #e6f4ea; color: #137333; }
.sync-pill.is-offline { background: #fef7e0; color: #8a5a00; }
.sync-pill.is-error { background: #fce8e6; color: #b3261e; }
.login-mark { display: inline-grid; grid-template-columns: repeat(2, 16px); gap: 4px; }
.login-mark i { width: 16px; height: 16px; border-radius: 5px; background: var(--c); }
.account-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.account-user { font-weight: 500; overflow-wrap: anywhere; }
.loading-page { display: grid; place-items: center; gap: 12px; min-height: 50vh; color: var(--text-3); text-align: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.mgr-stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Manager ---------- */
.page-mid { max-width: 980px; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 999px; background: #fff; }
.seg button { height: 32px; padding: 0 14px; border-radius: 999px; color: var(--text-2); font-size: 13px; font-weight: 500; white-space: nowrap; transition: background .15s, color .15s; }
.seg button:hover { background: var(--surface-3); }
.seg button.is-on { background: var(--primary-tint); color: var(--on-primary-tint); }
.seg b { margin-left: 4px; font-weight: 500; opacity: .7; }

.lock-page { display: grid; justify-items: center; padding-top: 24px; }
.lock-card { width: min(420px, 100%); padding: 32px 28px 28px; text-align: center; }
.lock-icon { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--primary-tint); color: var(--on-primary-tint); }
.lock-icon svg.i { width: 26px; height: 26px; }
.lock-title { margin: 14px 0 6px; font-size: 26px; font-weight: 400; }
.lock-text { margin: 0 0 20px; color: var(--text-2); }
.lock-form, .pw-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.lock-form .btn, .pw-form .btn { margin-top: 12px; }
.pw-form .btn { align-self: flex-start; }
.form-error { margin: 6px 0 0; padding: 8px 12px; border-radius: 10px; background: #fce8e6; color: #b3261e; font-size: 13px; }

.money-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.money-card { position: relative; overflow: hidden; padding: 22px; }
.money-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--accent); }
.money-card.is-unpaid { --accent: #f9ab00; --accent-ink: #8a5a00; --accent-bg: #fef7e0; }
.money-card.is-paid { --accent: #1e8e3e; --accent-ink: #137333; --accent-bg: #e6f4ea; }
.money-head { display: flex; align-items: center; gap: 10px; }
.money-head h2 { margin: 0; font-size: 16px; font-weight: 500; }
.money-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-bg); color: var(--accent-ink); }
.money-icon svg.i { width: 18px; height: 18px; }
.money-total { margin-top: 12px; font-size: 36px; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.money-sub { margin-top: 4px; color: var(--text-3); font-size: 13px; }
.money-group { margin-top: 16px; }
.money-group .eyebrow { margin-bottom: 2px; }
.money-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.money-row:last-child { border-bottom: 0; }
.money-label { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; }
.money-label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.money-dot { flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.money-count { color: var(--text-3); font-size: 12px; white-space: nowrap; }
.money-amt { min-width: 76px; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
.money-empty { margin: 16px 0 0; color: var(--text-3); font-size: 14px; }

.ledger-card { margin-bottom: 16px; padding: 20px 22px; }
.ledger-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.ledger-list { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; }
.ledger-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.ledger-row:last-child { border-bottom: 0; }
.ledger-main { flex: 1; min-width: 0; }
.ledger-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.ledger-name { font-size: 14px; font-weight: 500; }
.ledger-sub { margin-top: 2px; overflow: hidden; color: var(--text-3); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.ledger-amt { font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger-amt.is-none { color: var(--text-3); font-size: 12px; font-weight: 400; }
.ledger-more { margin-top: 12px; }

.mgr-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; margin-bottom: 16px; }
.rate-name { flex: 1; min-width: 0; font-weight: 500; }
.money-input { display: inline-flex; align-items: center; gap: 4px; width: 128px; height: 40px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--text-3); }
.money-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.money-input input { width: 100%; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; text-align: right; }

[hidden] { display: none !important; }
.rate-picker { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.rate-picker .desc-label { margin-top: 0; }
.select-wrap { position: relative; display: block; }
.select { width: 100%; height: 44px; padding: 0 40px 0 14px; border: 1px solid var(--line-strong); border-radius: 12px; background: #fff; color: var(--text); font-size: 15px; font-weight: 500; cursor: pointer; appearance: none; -webkit-appearance: none; }
.select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.select-wrap svg.i { position: absolute; top: 50%; right: 12px; color: var(--text-3); pointer-events: none; transform: translateY(-50%); }
.rate-main { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.rate-main .rate-name { flex: none; }
.rate-note { color: var(--text-3); font-size: 12px; }
.rate-note.is-own { color: var(--primary); }
.rate-note.is-up { color: #137333; font-weight: 500; }
.rate-note.is-down { color: #b3261e; font-weight: 500; }
.money-input.is-custom { border-color: var(--primary); background: #f5f8fe; }
.rate-reset.is-hidden { visibility: hidden; }
.icon-btn.rate-reset:hover { background: #eef3fd; color: var(--primary); }
.ledger-amt { display: flex; flex-direction: column; align-items: flex-end; }
.ledger-own { color: var(--primary); font-size: 11px; font-weight: 500; }

.bin-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 14px; border-bottom: 1px solid var(--line); }
.bin-row:last-child { border-bottom: 0; }
.bin-kind { flex: none; width: 72px; color: var(--text-3); font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.bin-main { flex: 1; min-width: 0; }
.bin-title { font-size: 14px; font-weight: 500; }
.bin-sub { color: var(--text-3); font-size: 12px; }
.bin-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px; }
.bin-actions .btn-delete { margin: 0; }
.bin-note { color: var(--text-3); font-size: 12px; }

.dialog-body { margin: 8px 0 0; color: var(--text-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.btn-text { color: var(--primary); }
.btn-text:hover { background: #eef3fd; }
.btn-danger-fill { background: var(--red); color: #fff; }
.btn-danger-fill:hover { background: #c5221f; box-shadow: var(--shadow-1); }
.btn-danger-fill:disabled { background: #ebedf0; color: #9aa0a6; box-shadow: none; cursor: default; }
.danger-card { margin-bottom: 16px; border-color: #f3d3cf; }
.danger-card .settings-head h2 { color: #b3261e; }
.date-range { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 520px; margin-top: 14px; }
.date-field { display: flex; flex-direction: column; gap: 4px; }
.date-field .desc-label { margin-top: 0; }
.reset-preview { margin: 14px 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 14px; }
.reset-preview.is-error { background: #fce8e6; color: #b3261e; }
.dialog .desc-label { margin-top: 16px; }
.dialog .input { margin-top: 4px; }

/* ---------- Category descriptions ---------- */
button.tag { cursor: pointer; transition: background .15s; }
button.tag:hover { background: color-mix(in srgb, var(--c) 26%, #fff); }
.cat-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--c); flex: none; }
.desc-list { display: flex; flex-direction: column; gap: 10px; }
.desc-card { padding: 14px 16px 14px 16px; border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 16px; background: #fff; }
.desc-name { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 500; }
.desc-name .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.desc-visible { margin: 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--c) 11%, #fff); color: var(--text); font-size: 15px; font-weight: 500; line-height: 1.45; }
.desc-visible.is-empty { background: var(--surface-2); color: var(--text-3); font-weight: 400; }
.desc-toggle { display: inline-flex; align-items: center; gap: 4px; height: 36px; margin: 6px 0 0 -6px; padding: 0 10px; border-radius: 999px; color: var(--primary); font-size: 14px; font-weight: 500; transition: background .15s; }
.desc-toggle:hover { background: #eef3fd; }
.desc-toggle svg.i { width: 18px; height: 18px; transition: transform .2s; }
.desc-toggle[aria-expanded="true"] svg.i { transform: rotate(180deg); }
.desc-hidden { margin: 4px 2px 2px; color: var(--text-2); font-size: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet-foot { display: flex; justify-content: flex-end; margin-top: 14px; }

.cat-item + .cat-item { border-top: 1px solid var(--line); }
.cat-item .list-row { border-bottom: 0; }
.cat-main { flex: 1; min-width: 0; }
.cat-main .inline-input { display: block; width: calc(100% + 8px); height: 32px; }
.cat-sub { overflow: hidden; color: var(--text-2); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.cat-sub.is-empty { color: var(--text-3); }
.icon-btn.is-on { background: var(--primary-tint); color: var(--on-primary-tint); }
.cat-desc { display: flex; flex-direction: column; gap: 6px; padding: 0 16px 16px 54px; }
.desc-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin-top: 8px; font-size: 13px; font-weight: 500; }
.cat-desc .link-btn { align-self: flex-start; margin: 6px 0 0 -12px; }

@media (max-width: 1100px) {
  .cal-del { padding: 0 5px; }
  .cal-del-text { display: none; }
}

.day-panel { position: sticky; top: 84px; padding: 20px; scroll-margin-top: 72px; }
.day-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.eyebrow { color: var(--text-3); font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.day-title { margin: 2px 0 0; font-size: 22px; font-weight: 400; letter-spacing: -.01em; }
.missing { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 13px; }
.missing strong { color: var(--text-2); font-weight: 500; }

/* ---------- Week board ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 16px 18px; border: 1px solid var(--line); border-radius: 20px; }
.stat-label { color: var(--text-3); font-size: 13px; }
.stat-value { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value small { color: var(--text-3); font-size: 15px; letter-spacing: 0; }
.stat-value .dot { width: 12px; height: 12px; border-radius: 4px; background: var(--c); flex: none; }
.stat-value .txt { overflow: hidden; text-overflow: ellipsis; }

.board-card { overflow: hidden; }
.board-scroll { overflow-x: auto; }
.board { width: 100%; min-width: 900px; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.board th, .board td { padding: 0; vertical-align: top; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); }
.board tbody tr:last-child th, .board tbody tr:last-child td { border-bottom: 0; }
.board thead th { padding: 12px 10px 10px; background: #fff; color: var(--text-3); font-size: 12px; font-weight: 500; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
.board thead .dnum { display: grid; place-items: center; width: 34px; height: 34px; margin: 2px 0 0 -6px; border-radius: 50%; color: var(--text); font-size: 20px; font-weight: 400; letter-spacing: 0; }
.board thead th.is-today { color: var(--primary); }
.board thead th.is-today .dnum { background: var(--primary); color: #fff; }
.board .col-person { position: sticky; left: 0; z-index: 1; width: 210px; background: #fff; border-left: 0; }
.board thead .col-person { vertical-align: bottom; }
.board-person { display: flex; align-items: center; gap: 10px; min-height: 92px; padding: 12px 14px; }
.board-person .name { font-size: 14px; font-weight: 500; line-height: 1.3; color: var(--text); }
.board-person .sub { color: var(--text-3); font-size: 12px; font-weight: 400; }
.board td.is-today { background: #f7faff; }
.board-cell { display: flex; flex-direction: column; gap: 4px; width: 100%; min-height: 92px; padding: 8px; text-align: left; transition: background .12s; }
.board-cell:hover { background: rgba(11, 87, 208, .045); }
.block {
  display: block; padding: 5px 8px; border-radius: 8px; border-left: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 12%, #fff); color: color-mix(in srgb, var(--c) 58%, #000);
  font-size: 12px; font-weight: 500; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cell-note { display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; color: var(--text-3); font-size: 11px; }
.cell-note svg.i { width: 13px; height: 13px; }
.cell-empty { display: block; width: 14px; height: 2px; margin: 12px 0 0 4px; border-radius: 2px; background: var(--line-strong); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 16px; color: var(--text-2); font-size: 13px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; margin: -4px -8px; padding: 4px 8px; border-radius: 8px; color: inherit; font-size: inherit; transition: background .15s; }
.legend-item:hover { background: var(--surface-3); }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.legend b { color: var(--text-3); font-weight: 400; }

/* ---------- Settings ---------- */
.settings-stack { display: flex; flex-direction: column; gap: 16px; }
.settings-card { padding: 24px; }
.settings-head { margin-bottom: 16px; }
.settings-head h2 { margin: 0; font-size: 18px; font-weight: 500; }
.settings-head p { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }
.qr-wrap { display: grid; grid-template-columns: 184px minmax(0, 1fr); gap: 24px; align-items: start; }
.qr { width: 184px; height: 184px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.qr svg { display: block; width: 100%; height: 100%; }
.qr-side .btn-row { margin-top: 16px; }
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.inline-input { flex: 1; min-width: 0; height: 36px; margin-left: -8px; padding: 0 8px; border: 1px solid transparent; border-radius: 8px; background: transparent; font-weight: 500; transition: border-color .15s; }
.inline-input:hover { border-color: var(--line); }
.inline-input:focus { outline: none; border-color: var(--primary); background: #fff; }
.row-meta { color: var(--text-3); font-size: 13px; white-space: nowrap; }
.swatch { width: 28px; height: 28px; border-radius: 8px; background: var(--c); flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); transition: transform .12s; }
.swatch:hover { transform: scale(1.08); }
.add-row { display: flex; gap: 8px; margin-top: 12px; }
.add-row .input { flex: 1; }
.print-only { display: none; }

/* ---------- Sheet / toast ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(32, 33, 36, .32); opacity: 0; transition: opacity .2s; }
.sheet-backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed; left: 50%; top: 50%; z-index: 41;
  width: min(480px, calc(100vw - 32px)); max-height: min(660px, calc(100vh - 48px)); overflow: auto;
  padding: 20px; background: #fff; border-radius: 28px; box-shadow: var(--shadow-3);
  opacity: 0; transform: translate(-50%, -47%) scale(.98); transition: opacity .2s, transform .2s ease;
}
.sheet.is-open { opacity: 1; transform: translate(-50%, -50%); }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.sheet-title-wrap { flex: 1; min-width: 0; }
.sheet-title { margin: 0; font-size: 20px; font-weight: 500; }
.sheet-sub { color: var(--text-3); font-size: 14px; }
.sheet-cta { margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  display: flex; align-items: center; gap: 12px; min-height: 48px; max-width: calc(100vw - 32px);
  padding: 6px 8px 6px 16px; border-radius: 10px; background: #2d2f31; color: #f2f2f2; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
  opacity: 0; transform: translate(-50%, 12px); transition: opacity .2s, transform .2s;
}
.toast.is-open { opacity: 1; transform: translate(-50%, 0); }
/* Let taps fall through the toast to buttons underneath; only its action button is tappable */
.toast { pointer-events: none; }
.toast-action { pointer-events: auto; }
.toast > span { padding-right: 8px; }
.toast-action { padding: 8px 10px; border-radius: 6px; color: #a8c7fa; font-weight: 500; }
.toast-action:hover { background: rgba(168, 199, 250, .12); }

/* ---------- Mobile ---------- */
@media (max-width: 759px) {
  .topbar { height: 56px; padding: 0 16px; }
  .tabs { display: none; }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    background: #fff; border-top: 1px solid var(--line);
  }
  .bnav { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-2); font-size: 12px; font-weight: 500; }
  .bnav-icon { width: 56px; height: 30px; border-radius: 999px; transition: background .15s; }
  .bnav.is-active { color: var(--text); }
  .bnav.is-active .bnav-icon { background: var(--primary-tint); color: var(--on-primary-tint); }

  main { padding: 20px 16px calc(100px + env(safe-area-inset-bottom)); }
  /* Keep scrolled-to/focused controls clear of the sticky top bar and fixed bottom nav */
  html { scroll-padding: 64px 0 calc(96px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 26px; }
  .page-head { align-items: center; margin-bottom: 16px; }
  .form-card { padding: 0 16px 16px; border-radius: 20px; }
  .date-long { display: none; }
  .date-short { display: inline; }
  .log-list { padding: 16px; border-radius: 20px; }
  .cat-item .row-meta { display: none; }
  .cat-item .list-row { gap: 8px; }
  .cat-desc { padding: 0 14px 16px; }
  .bnav { font-size: 11px; }
  .bnav-icon { width: 48px; }
  .money-grid, .mgr-grid { grid-template-columns: 1fr; gap: 12px; }
  .money-card { padding: 18px; }
  .money-total { font-size: 30px; }
  .ledger-card { padding: 16px; }
  .ledger-row { gap: 10px; padding: 10px 12px; }
  .seg button { padding: 0 10px; }
  .bin-row { flex-wrap: wrap; }
  .bin-kind { width: auto; }
  .bin-actions { justify-content: flex-start; width: 100%; }
  .lock-card { padding: 28px 20px 22px; }
  .date-range { grid-template-columns: 1fr; }

  .cal-layout { grid-template-columns: 1fr; gap: 16px; }
  .cal-dow { padding: 10px 0 6px; font-size: 11px; text-align: center; }
  .cal-cell { align-items: center; justify-content: flex-start; gap: 4px; min-height: 60px; padding: 5px 2px; }
  .cal-meta { justify-content: center; }
  .cal-dots { justify-content: center; gap: 3px; }
  .cal-dots i { width: 6px; height: 6px; }
  .cal-count { display: none; }
  .cal-cell { min-height: 68px; }
  .cal-del { position: static; height: auto; padding: 0; background: none; }
  .cal-del svg.i { width: 12px; height: 12px; }
  .day-panel { position: static; padding: 16px; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 12px; border-radius: 16px; }
  .stat-label { font-size: 12px; }
  .stat-value { font-size: 22px; }
  .stat-value small { font-size: 13px; }
  .board { min-width: 820px; }
  .board .col-person { width: 150px; }
  .board-person { padding: 10px; }

  .settings-card { padding: 18px; }
  .qr-wrap { grid-template-columns: 1fr; }
  .qr { margin: 0 auto; }

  .sheet {
    left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 86vh;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-radius: 28px 28px 0 0; transform: translateY(24px);
  }
  .sheet.is-open { transform: none; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* ---------- Print (QR poster) ---------- */
@media print {
  @page { margin: 0; }
  body * { visibility: hidden; }
  .qr-print, .qr-print * { visibility: visible; }
  .qr-print { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 0; }
  .qr-print .settings-head, .qr-print .qr-side { display: none; }
  .qr-print .qr-wrap { display: block; }
  .qr-print .qr { width: 10cm; height: 10cm; border: 0; }
  .qr-print .print-only { display: block; margin-top: 1cm; text-align: center; }
  .print-title { font-size: 30pt; font-weight: 500; }
  .print-sub { margin-top: 4pt; color: #444; font-size: 16pt; }
}
