.theme-toggle { width: 42px; height: 42px; display: inline-grid; place-items: center; flex: 0 0 42px; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font-size: 20px; line-height: 1; }
.brand-home { color: inherit; text-decoration: none; }
.theme-toggle:hover { border-color: var(--green); color: var(--green); }
.auth-theme-toggle { position: fixed; z-index: 5; top: 22px; right: 22px; box-shadow: 0 8px 25px rgba(24,51,45,.1); }
body, .ledger, .stats article, .auth-card, .login-shell, input, select, dialog { transition: background-color .2s ease, border-color .2s ease, color .2s ease; }

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8f1ed;
  --muted: #9eb0aa;
  --paper: #101815;
  --card: #19231f;
  --green: #70c2a7;
  --lime: #d7ee79;
  --red: #ee8178;
  --line: #33413c;
}
html[data-theme="dark"] select,
html[data-theme="dark"] input,
html[data-theme="dark"] .controls .household-name,
html[data-theme="dark"] .controls input[type="month"],
html[data-theme="dark"] .controls select { background: #202d28; color: var(--ink); }
html[data-theme="dark"] th,
html[data-theme="dark"] td { border-bottom-color: #2a3732; }
html[data-theme="dark"] .avatar { background: #263d35; }
html[data-theme="dark"] .category,
html[data-theme="dark"] .close,
html[data-theme="dark"] .type-toggle { background: #25322d; }
html[data-theme="dark"] .type-toggle input:checked + span { background: #34443e; color: var(--ink); }
html[data-theme="dark"] .empty { background: var(--card); }
html[data-theme="dark"] dialog { background: var(--card); color: var(--ink); }
html[data-theme="dark"] .pill.income { background: #29432d; color: #a9db97; }
html[data-theme="dark"] .pill.expense { background: #4a2d2a; color: #f1aaa3; }
html[data-theme="dark"] .stats i.income { background: #29432d; color: #a9db97; }
html[data-theme="dark"] .stats i.expense { background: #4a2d2a; color: #f1aaa3; }
html[data-theme="dark"] .auth-error { background: #4a2d2a; color: #f1aaa3; }
html[data-theme="dark"] .security-message { background: #29432d; color: #a9db97; }
html[data-theme="dark"] button:where(:not(.ghost):not(.icon):not(.close):not(.theme-toggle):not(.danger-link):not(.danger-button)) { background: #397d69; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    radial-gradient(circle at 15% 15%, rgba(207, 232, 108, .2), transparent 28%),
    radial-gradient(circle at 85% 80%, rgba(39, 114, 95, .12), transparent 30%),
    var(--paper);
}

.login-shell {
  width: min(920px, 100%);
  min-height: 570px;
  display: grid;
  grid-template-columns: .9fr 1.1fr;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 30px 90px rgba(24, 51, 45, .16);
}

.login-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 48px;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(145deg, #153c32, #27725f);
}

.login-brand > div:nth-child(2) { margin-top: 22px; }
.login-brand .eyebrow { color: #b9d2ca; }
.login-brand h1 { color: #fff; }
.login-brand h1 em { color: var(--lime); }
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--lime);
  color: var(--ink);
  font-family: 'Playfair Display', serif;
  font-size: 25px;
  font-style: italic;
  font-weight: 700;
}
.brand-message { position: relative; z-index: 1; margin-top: auto; }
.brand-message h2 { margin-bottom: 14px; font-size: 30px; line-height: 1.15; }
.brand-message p { max-width: 290px; color: #c9ddd6; font-size: 14px; line-height: 1.65; }
.brand-decoration { position: absolute; right: -50px; top: 95px; color: rgba(255,255,255,.06); font-size: 260px; }

.login-form-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 58px 68px;
}
.login-form-panel > .eyebrow { color: var(--green); }
.login-form-panel h2 { margin: 4px 0 8px; font-size: 28px; letter-spacing: -.5px; }
.login-subtitle { margin-bottom: 18px; color: var(--muted); font-size: 14px; }
.login-form-panel label { display: block; margin: 17px 0; color: var(--ink); font-size: 12px; font-weight: 700; }
.login-form-panel input { display: block; width: 100%; margin-top: 7px; padding: 13px 14px; }
.login-form-panel button { width: 100%; margin-top: 8px; padding: 14px; }
.login-form-panel button .button-spinner { display: none; width: 16px; height: 16px; margin-left: 9px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: button-spin .7s linear infinite; }
.login-form-panel button.is-loading { display: flex; align-items: center; justify-content: center; opacity: .68; cursor: wait; }
.login-form-panel button.is-loading .button-spinner { display: inline-block; }
@keyframes button-spin { to { transform: rotate(360deg); } }
.invite-prompt { display: flex; justify-content: center; gap: 6px; margin-top: 26px; color: var(--muted); font-size: 13px; }
.invite-prompt a { color: var(--green); font-weight: 700; text-decoration: none; }
.invite-prompt a:hover { text-decoration: underline; }
.mobile-brand { display: none; }
.recurring { display:inline-block; margin-left:8px; color:var(--green); font-size:10px; font-weight:700 }
.check-row { display:flex; align-items:center; gap:10px; padding:12px; border:1px solid var(--line); border-radius:10px }
.check-row input { width:auto; margin:0 }
.check-row span, .check-row small { display:block }
.check-row strong { color:var(--ink) }
.check-row small { margin-top:2px; font-weight:500 }
#entryRepeat[hidden], #entryMonthNote[hidden] { display: none; }
.entry-month-note { color: var(--muted); font-size: 13px; line-height: 1.5; margin: -8px 0 18px; }

header .account-menu { display: flex; align-items: center; gap: 9px; }
header .account-menu form { display: flex; align-items: center; margin: 0; }
header .account-menu button { height: 42px; display: inline-flex; align-items: center; justify-content: center; margin: 0; padding: 0 15px; white-space: nowrap; }
header .account-menu > span { display: inline-flex; align-items: center; height: 42px; padding: 0 5px; }
.header-link { height: 42px; display: inline-flex; align-items: center; justify-content: center; padding: 0 15px; border: 1px solid #b9cec5; border-radius: 12px; color: var(--green); font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.security-shell { padding-bottom: 60px; }
.security-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.security-card { margin-bottom: 18px; padding: 25px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.security-card h2 { margin-bottom: 6px; font-size: 21px; }
.security-card > p { margin-bottom: 18px; color: var(--muted); font-size: 13px; }
.security-card label { display: block; margin: 14px 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.security-card label input { display: block; width: 100%; margin-top: 6px; }
.security-message { margin-bottom: 18px; padding: 12px 15px; border-radius: 10px; background: #e8f5d2; color: #477236; }
.security-list > div { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid #edf0ed; }
.security-list > div:last-child { border-bottom: 0; }
.security-list span,.security-list small { display: block; }
.security-list small { margin-top: 3px; color: var(--muted); }
.danger-button { background: var(--red); }
.danger-link { padding: 8px 10px; background: transparent; color: var(--red); }

.controls > form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 260px minmax(140px, 1fr);
  align-items: center;
  gap: 9px;
}
.controls .household-name,
.controls input[type="month"],
.controls select {
  width: 100%;
  height: 42px;
  min-height: 42px;
  margin: 0;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: 500 14px 'DM Sans', sans-serif;
}
.controls .household-name {
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.controls > .ghost { height: 42px; display: inline-flex; align-items: center; justify-content: center; margin: 0; }
.month-navigation { display: flex; align-items: center; gap: 5px; min-width: 0; }
.controls .month-navigation input { flex: 1; min-width: 0; padding: 0 8px; text-align: center; }
.controls .month-step { flex: 0 0 42px; height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--green); font-size: 20px; }
.controls .month-step:hover { border-color: var(--green); }
.controls .month-step:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
@media (min-width: 721px) and (max-width: 900px) {
  .controls { flex-wrap: wrap; gap: 12px; }
  .controls > form { width: 100%; }
  .controls > .ghost { margin-left: auto; }
}

@media (max-width: 720px) {
  .auth-page { padding: 18px; }
  .login-shell { min-height: 0; grid-template-columns: 1fr; border-radius: 22px; }
  .login-brand { display: none; }
  .login-form-panel { padding: 40px 30px; }
  .mobile-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
  .mobile-brand .brand-mark { width: 42px; height: 42px; border-radius: 13px; font-size: 22px; }
  .mobile-brand h1 { font-size: 24px; }
  .invite-prompt { flex-direction: column; align-items: center; }
  header { height: auto; min-height: 95px; gap: 14px; }
  header .account-menu { gap: 6px; }
  header .account-menu > span { display: none; }
  header .account-menu button { height: 39px; padding: 0 11px; font-size: 12px; }
  header .header-link { height: 39px; padding: 0 11px; font-size: 12px; }
  .security-grid { grid-template-columns: 1fr; }
  .controls { flex-direction: column; align-items: stretch; }
  .controls > form { width: 100%; grid-template-columns: 1fr; }
  .controls > .ghost { align-self: flex-end; }
}

@media (max-width: 430px) {
  header { align-items: flex-start; flex-direction: column; padding: 20px 0; }
  header .account-menu { width: 100%; justify-content: flex-end; }
}

.app-tabs { display:flex; gap:5px; width:max-content; margin:0 0 22px; padding:5px; border:1px solid var(--line); border-radius:13px; background:var(--card); }
.app-tabs a { padding:9px 15px; border-radius:9px; color:var(--muted); font-size:13px; font-weight:700; text-decoration:none; }
.app-tabs a.active { background:var(--ink); color:var(--card); }
.grocery-hero { display:flex; align-items:center; justify-content:space-between; gap:28px; margin-bottom:18px; padding:28px 30px; border-radius:20px; color:#fff; background:linear-gradient(120deg,#173f35,#296c5b); }
.grocery-hero .eyebrow { color:#b9d2ca; }
.grocery-hero h2 { margin-bottom:5px; font-size:30px; }
.grocery-hero p:last-child { color:#c9ddd6; font-size:13px; }
.grocery-add-form { display:flex; gap:8px; width:min(480px,52%); }
.grocery-add-form input { flex:1; min-width:0; border-color:transparent; }
.grocery-add-form button { white-space:nowrap; background:var(--lime); color:#18332d; }
.grocery-ledger { min-height:300px; }
.grocery-actions { min-width:74px; }
.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; }
html[data-theme="dark"] .app-tabs a.active { background:#397d69; color:#fff; }
@media(max-width:650px) {
  .app-tabs { width:100%; }
  .app-tabs a { flex:1; text-align:center; }
  .grocery-hero { align-items:stretch; flex-direction:column; padding:24px; }
  .grocery-add-form { width:100%; }
}
@media(max-width:430px) {
  .grocery-add-form { flex-direction:column; }
}

/* Shared visual rhythm. Keep these after the legacy responsive rules. */
body { font-size: 16px; line-height: 1.5; }
button, input, select, textarea { font-family: inherit; font-weight: 500; font-size: 14px; line-height: 1.4; }
button { font-weight: 600; }
button, .header-link, .app-tabs a { min-height: 44px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select { min-height: 44px; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
:where(button, a, input, select, textarea):focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
button:not(:disabled):hover, .header-link:hover { filter: brightness(.94); }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: clamp(25px, 3vw, 29px); }
.eyebrow { font-size: 11px; letter-spacing: 1.5px; color: var(--muted); }
.section-title h2, .security-card h2, dialog h2 { font-size: clamp(22px, 2.5vw, 26px); }
.hero h2 { font-size: clamp(32px, 5vw, 52px); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stats strong, .amount { font-variant-numeric: tabular-nums; }
.stats article, .stats article > div, .controls > form, .security-card { min-width: 0; }
.stats strong { overflow-wrap: anywhere; }
.stats i { flex-shrink: 0; }
.category, .pill, .recurring { font-size: 12px; }
.category { white-space: normal; }
.login-form-panel label, .auth-card label, .security-card label, dialog label { font-size: 14px; }
.login-subtitle, .security-card > p, .grocery-hero p:last-child { font-size: 15px; line-height: 1.6; }
header { gap: 20px; }
header .account-menu { flex-wrap: wrap; justify-content: flex-end; }
header .account-menu button, header .header-link { height: 44px; }
header .account-menu .theme-toggle { padding: 0; }
.controls { gap: 12px; }
.controls .household-name, .controls input[type="month"], .controls select { height: 44px; }
.controls .month-step { flex-basis: 44px; height: 44px; }
.app-tabs a { display: flex; align-items: center; justify-content: center; font-size: 14px; }
.section-title { gap: 16px; }
.section-title > button { flex-shrink: 0; }
td { vertical-align: middle; }
.amount { white-space: nowrap; }
/* Keep table cells in table layout; flex only the controls inside them. */
td.actions { display: table-cell; vertical-align: middle; text-align: right; }
.action-buttons { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; }
.actions .icon { min-width: 44px; min-height: 44px; color: var(--muted); }
.complete-toggle { width: 28px; height: 28px; }
.complete-cell { padding-top: 8px; padding-bottom: 8px; }
.complete-cell form { min-height: 44px; display: flex; align-items: center; justify-content: center; }
.completed td:not(.actions):not(.complete-cell) { opacity: .75; }
.security-list > div { padding: 12px 0; border-color: var(--line); }
.security-list span { min-width: 0; overflow-wrap: anywhere; }
.security-list button { flex-shrink: 0; }
dialog { max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; }
dialog h2 { padding-right: 36px; }
.close { width: 44px; height: 44px; top: 14px; right: 14px; }
.auth-page { min-height: 100dvh; }
.auth-card { overflow-wrap: anywhere; }
.brand-mark { color: #18332d; }
html[data-theme="dark"] .amount.income { color: #a9db97; }
html[data-theme="dark"] .controls .month-step { background: var(--card); color: var(--green); }
html[data-theme="dark"] .grocery-add-form button { background: var(--lime); color: #18332d; }
@media (max-width: 900px) {
  header { height: auto; min-height: 105px; padding: 20px 0; flex-wrap: wrap; }
  .controls { flex-wrap: wrap; }
  .controls > form { width: 100%; }
  .controls > .ghost { margin-left: auto; }
}
@media (max-width: 720px) {
  .shell { width: calc(100% - 28px); }
  header .account-menu { gap: 6px; }
  header .account-menu button, header .header-link { font-size: 14px; padding: 0 10px; }
  input:not([type="checkbox"]):not([type="radio"]), select,
  .controls input[type="month"], .controls select { font-size: 16px; }
  .ledger, .security-card { padding: 18px; }
  .hero, .grocery-hero { padding: 24px; }
  .login-form-panel { padding: 36px 24px; }
  .auth-card { padding: 28px 24px; }
  .auth-theme-toggle { top: 12px; right: 12px; }
  .auth-page { padding: 72px 16px 24px; }
  dialog > form { padding: 26px 22px; }
  .table-wrap { margin: 0 -6px; }
  th, td { padding: 12px 6px; }
}
@media (max-width: 430px) {
  .section-title { flex-wrap: wrap; }
  .ledger { padding: 16px 12px; }
  .complete-heading, .complete-cell { width: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

/* Interaction components. Responsive visibility uses named cells, not column numbers. */
[hidden] { display: none !important; }
.account-dropdown { position: relative; }
.account-dropdown summary { cursor: pointer; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; font-weight: 600; list-style: none; }
.account-dropdown summary::-webkit-details-marker { display: none; }
.account-dropdown summary:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.account-panel { position: absolute; z-index: 10; right: 0; top: calc(100% + 8px); width: 230px; max-width: calc(100vw - 28px); padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); box-shadow: 0 12px 36px #102b2520; }
.account-panel .account-name { padding: 8px; overflow-wrap: anywhere; font-size: 14px; color: var(--muted); }
header .account-panel form, header .account-panel button, header .account-panel a { width: 100%; }
header .account-panel a, header .account-panel form { margin-top: 6px; }
.controls { flex-wrap: wrap; }
.controls > form { flex: 1; grid-template-columns: 270px minmax(140px, 1fr); }
.month-display { position: relative; flex: 1; min-width: 0; text-align: center; padding: 10px 2px; font-size: 15px; font-weight: 600; }
.month-display input[type="month"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.month-display:focus-within { outline: 3px solid var(--green); outline-offset: 2px; border-radius: 8px; }
.this-month { display: inline-flex; align-items: center; min-height: 44px; color: var(--green); font-size: 14px; font-weight: 600; }
.onboarding-note, .list-empty { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.onboarding-note .ghost { margin: 8px; }
.type-toggle label { position: relative; }
.type-toggle input:focus-visible + span { outline: 3px solid var(--green); outline-offset: 2px; }
.type-toggle span { min-height: 44px; }
.mobile-meta { display: none; }
.recurring { margin-left: 0; margin-right: 3px; }
.date-cell { white-space: nowrap; }
.dialog-delete { width: 100%; margin-top: 14px; background: #b83e36; color: #fff; }
html[data-theme="dark"] .dialog-delete { background: #b83e36; color: #fff; }
.completed-heading td { padding: 18px 0 8px; border: 0; }
.completed-disclosure { background: transparent; color: var(--green); padding: 10px; font-size: 14px; text-align: left; }
html[data-theme="dark"] button.completed-disclosure { background: transparent; }
.feedback { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 16px; margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.feedback > span { flex: 1; min-width: 120px; }
.feedback button { flex: 0 0 44px; width: 44px; min-height: 44px; padding: 0; margin: 0; background: transparent; color: var(--ink); font-size: 20px; }
.feedback a { color: var(--green); font-weight: 600; text-decoration: underline; }
.feedback button.refresh-session { flex: 0 1 auto; width: auto; padding: 8px; font-size: 14px; }
.feedback-error { border-color: var(--red); }
body > .feedback { position: fixed; z-index: 20; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(580px, calc(100% - 28px)); box-shadow: 0 8px 32px #102b2526; }
.grocery-add-form { flex-wrap: wrap; }
.grocery-add-form .feedback { flex-basis: 100%; }
button.is-loading::after { content: ''; display: inline-block; vertical-align: middle; width: 16px; height: 16px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: button-spin .7s linear infinite; }
button.is-loading { opacity: .65; cursor: wait; }
.confirm-content { padding: 28px; }
.confirm-content p { color: var(--muted); }
.confirm-controls { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
@media (max-width: 720px) {
  header { flex-direction: row; align-items: center; min-height: 90px; }
  header .account-menu { width: auto; }
  .controls { display: grid; grid-template-columns: 1fr auto; }
  .controls > form { grid-column: 1 / -1; }
  .controls > form { grid-template-columns: 1fr; }
  .controls > .ghost { margin-left: 0; grid-column: 2; grid-row: 2; }
  .controls .this-month { grid-column: 1; grid-row: 2; align-self: center; }
}
@media (max-width: 650px) {
  .activity-table, .activity-table tbody { display: block; width: 100%; }
  .activity-table thead { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .activity-table tr { display: grid; grid-template-columns: 36px minmax(0, 1fr) 44px; gap: 4px 10px; padding: 16px 0; border-bottom: 1px solid var(--line); }
  .activity-table td { border: 0; padding: 0; min-width: 0; }
  .activity-table .complete-cell { grid-column: 1; grid-row: 1 / span 2; width: auto; align-self: center; }
  .activity-table .description-cell { grid-column: 2; grid-row: 1; align-self: center; }
  .activity-table .category-cell, .activity-table .person-cell, .activity-table .date-cell, .activity-table .type-column { display: none; }
  .mobile-meta { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
  .activity-table .amount { grid-column: 2; grid-row: 2; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .activity-table .actions { grid-column: 3; grid-row: 1 / span 2; align-self: center; min-width: 0; }
  .activity-table .action-buttons { flex-direction: column; gap: 0; }
  .activity-table .completed-heading { display: block; border: 0; padding-bottom: 0; }
  .activity-table .completed-heading td { display: block; }
  .grocery-table .description-cell { grid-row: 1 / span 2; }
  .budget-table tr { grid-template-columns: 32px minmax(0, 1fr) minmax(65px, max-content) 44px; gap: 8px; align-items: center; }
  .budget-table .complete-cell, .budget-table .description-cell, .budget-table .amount, .budget-table .actions { grid-row: 1; }
  .budget-table .amount { grid-column: 3; text-align: right; white-space: nowrap; }
  .budget-table .actions { grid-column: 4; }
  .budget-table .actions form { display: none; }
  .budget-table .recurring-label { display: none; }
  .budget-table .recurring { margin: 0; font-size: 14px; }
}
