/* PlanLo 訂閱追蹤｜SubTracker — P9 UI revamp (Wave 1).
 * Shared tokens + base components come from /shared/design/ (tokens.css, base.css).
 * Only SubTracker-specific layout lives here. Tokens only for colour. */

:root {
  /* SubTracker-only tokens (kept out of shared/design/tokens.css). */
  --avatar-ink: #fffdf8;
  --avatar-gold-ink: #2c261d;
  --sheet-scrim: rgba(20, 16, 10, 0.45);
}

.notebook {
  max-width: 620px;
}

@media (min-width: 640px) {
  .notebook {
    max-width: 680px;
  }
}

/* —— Masthead (family style: serif title + tools) —— */

.masthead {
  text-align: left;
  margin-bottom: 1.1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px dashed var(--rule-strong);
}

.masthead-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.masthead-title {
  min-width: 0;
}

.brand-kana {
  margin: 0 0 0.2rem;
  font-size: 0.875rem;
  letter-spacing: 0.28em;
  color: var(--seal);
  font-weight: 600;
}

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: var(--ink);
  line-height: 1.2;
}

.masthead-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-left: auto;
}

/* Account (login in header) */

.account {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.account-in {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.account-email {
  font-size: 0.875rem;
  color: var(--ink-soft);
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-header {
  min-height: 36px;
  padding: 0.4rem 0.8rem;
  font-size: 0.875rem;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  border: 1px solid var(--rule-strong);
}

.btn-header:hover {
  background: var(--paper-deep);
}

/* Guest banner (single thin line) */

.guest-banner {
  margin: 0 0 1rem;
  padding: 0.45rem 0.7rem;
  border: 1px dashed var(--rule-strong);
  border-radius: 8px;
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-size: 0.875rem;
  line-height: 1.45;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  text-align: center;
}

.guest-banner.is-warn {
  border-style: solid;
  border-color: var(--rule-strong);
  background: var(--paper-deep);
  color: var(--ink);
}

.link-btn {
  font: inherit;
  font-size: inherit;
  border: 0;
  background: transparent;
  color: var(--seal);
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.link-btn:hover {
  text-decoration-style: solid;
}

/* —— Layout stack —— */

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 0.5rem;
}

/* —— Overview card —— */

.overview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
  flex-wrap: wrap;
}

.overview-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.period-toggle {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-inline-size: 0;
  max-inline-size: 100%;
  box-sizing: border-box;
  border: 1px solid var(--muted);
  border-radius: 24px;
  background: var(--paper-deep);
  padding: 2px;
}

.period-btn {
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.2;
  min-inline-size: 44px;
  min-block-size: 44px;
  padding: 0.3rem 0.6rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  overflow-wrap: normal;
  flex: 0 0 auto;
  text-align: center;
}

.period-btn.is-active {
  background: var(--seal);
  color: var(--avatar-ink);
  font-weight: 600;
}

.total-row {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin: 0.1rem 0;
}

.total-amount {
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.total-period {
  font-size: 0.875rem;
  color: var(--muted);
}

.overview-sub {
  margin: 0.45rem 0 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* —— Upcoming renewals —— */

.upcoming-track {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.upcoming-card {
  flex: 0 0 auto;
  min-width: 158px;
  scroll-snap-align: start;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  padding: 0.55rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.upcoming-top {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.upcoming-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upcoming-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.upcoming-amount {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

@media (min-width: 761px) {
  .upcoming-track {
    flex-wrap: wrap;
    overflow: visible;
    padding-bottom: 0;
  }
  .upcoming-card {
    flex: 1 1 180px;
  }
}

/* Chips */

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 0.875rem;
  line-height: 1.2;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink-soft);
  white-space: nowrap;
}

.chip-seal {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--avatar-ink);
  font-weight: 600;
}

.chip-gold {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--avatar-gold-ink);
  font-weight: 600;
}

.chip-muted {
  background: var(--paper);
  border-color: var(--rule);
  color: var(--muted);
}

/* —— Subscription list —— */

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.list-head .card-title {
  margin: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.sub-count {
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.btn-add {
  min-height: 40px;
  padding: 0.45rem 0.95rem;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.empty-state {
  margin: 0.35rem 0 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.hot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.2rem 0 0.4rem;
}

.hot-chip {
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.2;
  padding: 0.35rem 0.7rem;
  min-height: 36px;
  border-radius: 999px;
  border: 1px dashed var(--rule-strong);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}

.hot-chip:hover {
  border-style: solid;
  color: var(--ink);
  background: var(--paper-deep);
}

.sub-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}

@media (min-width: 761px) {
  .sub-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.sub-item {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0.15rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
}

.sub-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem 0.45rem 0.45rem;
  background: transparent;
  border: 0;
  border-radius: 10px 0 0 10px;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.sub-open:hover {
  background: var(--paper-deep);
}

.sub-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.sub-title-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  width: 100%;
  min-width: 0;
}

.sub-title-row .sub-name {
  flex: 1 1 0;
  min-width: 0;
}

.sub-title-row .sub-amount {
  flex: 0 0 auto;
}

.sub-name {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub-meta {
  font-size: 0.875rem;
  color: var(--ink-soft);
  line-height: 1.25;
}

.sub-approx {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.25;
}

.sub-remind {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--moss);
  line-height: 1.25;
}

.sub-remind.is-off {
  color: var(--muted);
}

.sub-remind .icon {
  flex-shrink: 0;
}

.sub-amount {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 700;
  color: var(--seal);
  white-space: nowrap;
}

/* ⋮ menu */

.sub-menu-wrap {
  position: relative;
  display: flex;
  align-items: flex-start;
  padding: 0.15rem 0.2rem 0 0;
}

.more-btn {
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 0.4rem;
  cursor: pointer;
}

.more-btn:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

.sub-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  min-width: 126px;
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.sub-menu button {
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.sub-menu button:hover {
  background: var(--paper-deep);
}

.sub-menu .menu-danger {
  color: var(--seal);
}

/* —— Initials avatar —— */

.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--seal);
  color: var(--avatar-ink);
  user-select: none;
  -webkit-user-select: none;
}

.sub-open > .avatar:not(.avatar-sm) {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
}

.avatar.c1 {
  background: var(--moss);
}

.avatar.c2 {
  background: var(--gold);
  color: var(--avatar-gold-ink);
}

.avatar.c3 {
  background: var(--ink);
  color: var(--card);
}

.avatar-sm {
  width: 32px;
  height: 32px;
  flex-basis: 32px;
  border-radius: 8px;
  font-size: 0.875rem;
}

/* —— Form (inside sheet) —— */

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
}

.field-label {
  font-size: 0.875rem;
}

.remind-box {
  margin: 0;
  padding: 0.7rem 0.8rem 0.8rem;
  border: 1px dashed var(--rule-strong);
  border-radius: 10px;
  min-width: 0;
}

.remind-box legend {
  padding: 0 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
}

.switch-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 0;
  padding: 0;
  margin: 0;
  accent-color: var(--seal);
  flex-shrink: 0;
  cursor: pointer;
}

.phase-note {
  margin: 0.6rem 0 0;
  font-size: 0.875rem;
  color: var(--seal);
  line-height: 1.5;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.form-actions .btn {
  flex: 1 1 8rem;
}

/* —— Sheet: modal on desktop, bottom sheet on mobile —— */

body.sheet-open {
  overflow: hidden;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: var(--sheet-scrim);
}

.sheet-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  padding: 1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
}

.sheet-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.sheet-close {
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  cursor: pointer;
}

.sheet-close:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

#hotChipsForm {
  margin: 0 0 0.85rem;
}

@media (min-width: 761px) {
  .sheet {
    align-items: center;
  }
  .sheet-panel {
    max-width: 560px;
    margin: 1.5rem;
    border-bottom: 1px solid var(--rule-strong);
    border-radius: 14px;
    max-height: calc(100vh - 3rem);
    box-shadow: var(--shadow);
  }
}

/* —— Footer —— */

.foot p {
  font-size: 0.875rem;
}

@media (max-width: 420px) {
  .field-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.85rem;
  }
  .masthead h1 {
    font-size: 1.6rem;
  }
  .total-amount {
    font-size: 1.8rem;
  }
}

/* Categories use the same paper, rule and muted tokens in both themes. */
.category-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; min-width: 0; }
.category-filters { display: flex; flex: 1; gap: .5rem; overflow-x: auto; flex-wrap: nowrap; min-width: 0; padding-bottom: .35rem; }
.category-filters button { flex: 0 0 auto; }
.category-filters [aria-pressed="true"] { border-color: var(--ink-soft); color: var(--ink); background: var(--paper-deep); }
.category-chip { display: inline-block; width: fit-content; border: 1px solid var(--rule); border-radius: 999px; padding: .1rem .45rem; color: var(--muted); font-size: .875rem; }
.category-row { display: flex; align-items: center; gap: .75rem; border-bottom: 1px solid var(--rule); padding: .7rem 0; }
.category-row span { flex: 1; overflow-wrap: anywhere; }
#categorySheet { z-index: 90; }
#categoryForm { margin-top: 1rem; }
.gate { display: grid; gap: 1rem; justify-items: start; }

/* Masthead controls copied from hub; owned locally by SubTracker. */
.has-theme-toggle { position: relative; }
/* 20261024themeAuto1：主題掣改為下拉（跟系統／淺色／深色） */
.theme-quick {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
}
.theme-quick > summary { list-style: none; }
.theme-quick > summary::-webkit-details-marker { display: none; }
.theme-toggle,
.theme-quick-btn {
  position: relative;
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1;
  -webkit-appearance: none;
  appearance: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle::after,
.theme-quick-btn::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
}
.theme-toggle:hover,
.theme-quick-btn:hover { color: var(--seal); border-color: var(--seal); }
.theme-toggle:focus-visible,
.theme-quick-btn:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }
.theme-toggle svg,
.theme-quick-btn svg { display: block; pointer-events: none; }
.theme-toggle .ico-sun,
.theme-quick-btn .ico-sun { display: none; }
html[data-theme="dark"] .theme-toggle .ico-moon,
html[data-theme="dark"] .theme-quick-btn .ico-moon { display: none; }
html[data-theme="dark"] .theme-toggle .ico-sun,
html[data-theme="dark"] .theme-quick-btn .ico-sun { display: block; }
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .theme-quick-btn { background: #322c25; color: #d9cfc0; border-color: #6d6254; }
html[data-theme="dark"] .theme-toggle:hover,
html[data-theme="dark"] .theme-quick-btn:hover { color: #f6f1e7; border-color: #b7ab9b; }
.theme-quick-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  min-width: 9.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.35rem;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: var(--card, #fffdf8);
  box-shadow: 0 8px 20px rgba(40, 30, 20, 0.12);
  z-index: 20;
}
.theme-quick:not([open]) > .theme-quick-panel { display: none; }
.theme-quick-opt {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.875rem; /* ≥14px@16；網頁版字級地板 */
  font-weight: 500;
  padding: 0.42rem 0.55rem;
  cursor: pointer;
  min-height: 2rem;
  line-height: 1.3;
}
.theme-quick-opt:hover {
  border-color: var(--rule-strong);
  background: var(--paper-deep, #f3ead8);
}
.theme-quick-opt.is-active {
  border-color: var(--seal);
  color: var(--seal);
  font-weight: 700;
  background: rgba(181, 74, 60, 0.08);
}
html[data-theme="dark"] .theme-quick-panel {
  background: #2a251f;
  border-color: #6d6254;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
html[data-theme="dark"] .theme-quick-opt { color: #e8dfd0; }
html[data-theme="dark"] .theme-quick-opt:hover {
  background: #3a3229;
  border-color: #6d6254;
}
html[data-theme="dark"] .theme-quick-opt.is-active {
  color: #f0d9a8;
  border-color: #c4a36a;
  background: rgba(196, 163, 106, 0.12);
}
.has-locale-picker { position: relative; }
.locale-picker {
  position: absolute;
  top: 0;
  right: 38px;
  z-index: 3;
}
.locale-toggle {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  -webkit-appearance: none;
  appearance: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.locale-toggle::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
}
.locale-toggle { position: relative; }
.locale-toggle:hover { color: var(--seal); border-color: var(--seal); }
.locale-toggle:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }
.locale-toggle-text { pointer-events: none; }
html[data-theme="dark"] .locale-toggle {
  background: #322c25;
  color: #d9cfc0;
  border-color: #6d6254;
}
html[data-theme="dark"] .locale-toggle:hover {
  color: #f6f1e7;
  border-color: #b7ab9b;
}
.locale-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 10.75rem;
  margin: 0;
  padding: 0.4rem 0;
  list-style: none;
  background: var(--card, #fbf6ec);
  border: 1px solid var(--rule-strong, #cfc3b0);
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(44, 38, 29, 0.14);
  z-index: 20;
}
html[data-theme="dark"] .locale-menu {
  background: #322c25;
  border-color: #6d6254;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}
.locale-menu a {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.58rem 1rem;
  color: var(--ink, #2c261d);
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.35;
  white-space: nowrap;
}
html[data-theme="dark"] .locale-menu a { color: #f6f1e7; }
.locale-menu a:hover,
.locale-menu a:focus-visible {
  background: rgba(181, 74, 60, 0.08);
  outline: none;
}
html[data-theme="dark"] .locale-menu a:hover,
html[data-theme="dark"] .locale-menu a:focus-visible {
  background: rgba(246, 241, 231, 0.08);
}
.locale-menu a[aria-selected="true"] { font-weight: 600; }
.locale-check {
  display: inline-block;
  width: 1em;
  text-align: center;
  color: var(--seal, #b54a3c);
  flex: 0 0 auto;
}

.masthead-title { padding-right: 78px; }
.masthead-tools { padding-top: 38px; }
.locale-menu[hidden] { display: none; }
.remind-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.remind-chips label { display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; }
.remind-chips label[hidden] { display: none; }
.remind-chips input { width: auto; margin: 0; }
.remind-chips label:has(:disabled) { opacity: .55; }
[dir="rtl"] .masthead-title { padding-right: 0; padding-left: 78px; }
[dir="rtl"] .theme-quick { right: auto; left: 0; }
[dir="rtl"] .locale-picker { right: auto; left: 38px; }
[dir="rtl"] .locale-menu, [dir="rtl"] .theme-quick-panel { right: auto; left: 0; }
[dir="rtl"] .theme-quick-opt { text-align: right; }

.sub-menu { right: auto; inset-inline-end: 0; max-width: calc(100vw - 2rem); }
.sub-menu button { text-align: start; }

/* Calendar export picker: normal checkbox order also follows RTL. */
.export-bulk, .export-cats > div { display: flex; flex-wrap: wrap; gap: .5rem; }
.export-cats, .export-items { min-width: 0; margin-block: .75rem; }
.export-cats .hot-chip { display: inline-flex; align-items: center; gap: .35rem; max-width: 100%; white-space: normal; }
.export-row { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; padding-block: .5rem; min-width: 0; }
.export-row input, .export-cats input { flex-shrink: 0; width: auto; }
.export-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-missing { flex-basis: 100%; color: var(--ink-soft); font-size: .85rem; }
.export-footer { position: sticky; bottom: 0; background: var(--card); padding-block: .75rem; z-index: 2; }

/* ————— ST-V: tool-site structure + shared paper palette (D1=B, D2=A, D3=A) ————— */

.visually-hidden {
  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"] {
  --paper: #1b1916;
  --paper-deep: #24211c;
  --card: #2a261f;
  --ink: #f6f1e7;
  --ink-soft: #e4d8c6;
  --muted: #b7ab9b;
  --rule: #4a4338;
  --rule-strong: #6d6254;
  --seal: #e08b7d;
  --seal-deep: #f3c2b8;
  --moss: #9dccb2;
  --gold: #e2c78a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] body {
  background: #141311;
  color: var(--ink);
}

html[data-theme="dark"] .notebook,
html[data-theme="dark"] .page {
  background: var(--paper);
  color: var(--ink);
}

/* Masthead: title + quick controls on the first row, account on the second. */

.masthead {
  text-align: start;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1.5px solid var(--ink);
}

.masthead-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}

.masthead-title {
  min-width: 0;
  padding-right: 0;
}

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.05rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.masthead-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.masthead-account {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
  min-width: 0;
}

.masthead-tools {
  margin-left: 0;
  padding-top: 0;
}

.account {
  min-width: 0;
  justify-content: flex-end;
}

.account-email {
  max-width: 14rem;
}

.locale-picker,
.theme-quick {
  position: relative;
  top: auto;
  right: auto;
  inset-inline-end: auto;
  z-index: 2;
  margin: 0;
}

.locale-toggle,
.theme-toggle,
.theme-quick-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
}

.locale-toggle svg,
.theme-toggle svg,
.theme-quick-btn svg {
  width: 16px;
  height: 16px;
}

.locale-menu,
.theme-quick-panel {
  top: calc(100% + 8px);
  right: auto;
  inset-inline-end: 0;
  border-radius: 10px;
  max-width: calc(100vw - 24px);
}

.theme-quick-panel {
  min-width: min(9.5rem, calc(100vw - 24px));
}

.locale-menu a {
  overflow-wrap: anywhere;
}

[dir="rtl"] .masthead-title {
  padding-right: 0;
  padding-left: 0;
}

[dir="rtl"] .locale-picker,
[dir="rtl"] .theme-quick {
  right: auto;
  left: auto;
}

/* Container / spacing: keep the SubTracker width, align rhythm only. */

.page {
  padding: 16px;
}

.stack {
  gap: 16px;
}

.card {
  padding: 16px;
}

.overview-head,
.list-head,
.sheet-head {
  gap: 8px;
}

.form-stack {
  gap: 1rem;
}

@media (min-width: 640px) {
  .page {
    padding: 24px;
  }
}

/* Cards / list items */

.sub-item,
.sub-open {
  border-radius: 8px;
}

.sub-open {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.upcoming-card {
  border-radius: 8px;
}

/* Buttons and period control */

.btn {
  border-radius: 999px;
  min-height: 44px;
  padding-inline: 0.8rem;
  font-size: 0.9rem;
}

.btn-primary {
  background: var(--seal);
  color: #fff8f2;
  border-color: var(--seal-deep);
  box-shadow: none;
}

.btn-secondary {
  border-radius: 999px;
}

.btn-header,
.btn-add {
  min-height: 44px;
}

.period-toggle {
  border-radius: 999px;
}

.period-btn {
  min-height: 44px;
  padding-inline: 0.6rem;
  font-size: 0.875rem;
}

html[data-theme="dark"] .btn-primary {
  background: #e08b7d;
  color: #2c261d;
  border-color: #e08b7d;
}

/* Banner and separators */

.guest-banner {
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  padding: 8px 12px;
}

.guest-banner.is-warn {
  border-style: solid;
}

/* Multi-select category chips */

.category-toolbar {
  gap: 8px;
  margin-bottom: 16px;
}

.category-filters {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 8px;
  overflow: visible;
  min-width: 0;
  padding-bottom: 0;
}

.category-filters .hot-chip {
  flex: 0 1 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.45rem 0.8rem;
  border-style: solid;
  border-radius: 999px;
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: 100%;
  text-align: start;
}

.category-filters .filter-check {
  display: inline-block;
  width: 1em;
  flex: 0 0 auto;
  text-align: center;
}

.category-filters [aria-pressed="true"] {
  border-width: 2px;
  border-style: solid;
  border-color: var(--ink-soft);
  color: var(--ink);
  background: var(--paper-deep);
  font-weight: 600;
}

.category-toolbar > .link-btn {
  flex: 0 0 auto;
}

.filter-empty {
  text-align: center;
  padding: 0.35rem 0 0.5rem;
}

.filter-empty .btn {
  width: auto;
  margin-top: 0.5rem;
}

@media (max-width: 760px) {
  .category-filters {
    flex-basis: 100%;
  }
}

@media (max-width: 420px) {
  .masthead h1 {
    font-size: 1.6rem;
  }
}

/* Dark popup surfaces now consume the local tokens. */

html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .theme-quick-btn,
html[data-theme="dark"] .locale-toggle {
  background: var(--card);
  color: var(--ink-soft);
  border-color: var(--rule-strong);
}

html[data-theme="dark"] .theme-toggle:hover,
html[data-theme="dark"] .theme-quick-btn:hover,
html[data-theme="dark"] .locale-toggle:hover {
  color: var(--ink);
  border-color: var(--muted);
}

html[data-theme="dark"] .theme-quick-panel,
html[data-theme="dark"] .locale-menu {
  background: var(--card);
  border-color: var(--rule-strong);
  box-shadow: var(--shadow);
}

html[data-theme="dark"] .theme-quick-opt,
html[data-theme="dark"] .locale-menu a {
  color: var(--ink);
}

html[data-theme="dark"] .theme-quick-opt:hover,
html[data-theme="dark"] .locale-menu a:hover,
html[data-theme="dark"] .locale-menu a:focus-visible {
  background: var(--paper-deep);
  border-color: var(--rule-strong);
}

html[data-theme="dark"] .theme-quick-opt.is-active {
  color: var(--gold);
  border-color: var(--gold);
  background: rgba(226, 199, 138, 0.12);
}

/* Keep text actions reachable on touch screens, including wrapped translations. */
.link-btn { min-width: 44px; min-height: 44px; }

/* Allow translated action labels to wrap at enlarged text sizes. */
.category-toolbar > .link-btn {
  max-inline-size: 100%;
  min-inline-size: 44px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.sub-meta .category-chip,
.category-chip {
  max-inline-size: 100%;
  min-inline-size: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}
.btn-add,
.period-toggle {
  max-inline-size: 100%;
  min-inline-size: 0;
}
.btn-add {
  white-space: normal;
  overflow-wrap: anywhere;
}
.period-btn {
  min-inline-size: 44px;
  min-block-size: 44px;
  white-space: nowrap;
  overflow-wrap: normal;
  flex: 0 0 auto;
}
.masthead-top {
  flex-wrap: wrap;
}
.masthead-title {
  flex: 1 0 auto;
  max-inline-size: 100%;
}
.masthead h1 {
  overflow-wrap: anywhere;
}

/* Keep subscription text readable when font enlargement consumes the row. */
.sub-open {
  flex-wrap: wrap;
}
.sub-text {
  flex: 1 1 8rem;
}
.sub-name {
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
}
.sub-title-row .sub-amount {
  max-inline-size: 100%;
  white-space: nowrap;
}

/* ST-V r3 :144 contrast fixes (local tokens only; shared/ untouched).
   Interactive boundaries >= 3:1, active period text, banner link text. */
:root { --ctl-border: #857860; }
html[data-theme="dark"] { --ctl-border: #8f8473; }
.locale-toggle,
.theme-quick-btn,
.btn-header,
.period-toggle,
.category-filters button,
.hot-chip { border-color: var(--ctl-border); }
html[data-theme="dark"] .locale-toggle,
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .theme-quick-btn { border-color: var(--ctl-border); }
.category-filters [aria-pressed="true"] { border-color: var(--ink-soft); }
html[data-theme="dark"] .period-btn.is-active { color: #1b1916; }
.guest-banner .link-btn { color: var(--seal-deep); }

/* ST-F payment method + notes. Only collapsed notes text may clamp. */
.stf-card {
  flex: 1 0 100%;
  padding: 0 0.75rem 0.7rem;
  min-width: 0;
}
.sub-item { flex-wrap: wrap; }
.stf-card-payment,
.stf-card-notes { margin: 0.15rem 0 0; }
.stf-card-label { color: var(--ink-soft); margin-inline-end: 0.35rem; }
.stf-card-value,
.stf-notes-text {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.stf-notes-text { white-space: pre-wrap; }
.stf-notes-body.is-clamped .stf-notes-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.stf-notes-toggle {
  min-width: 44px;
  min-height: 44px;
  margin-top: 0.2rem;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.875rem;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.stf-notes-toggle[hidden] { display: none; }
#subNotes { min-height: 4.5rem; resize: vertical; width: 100%; }

/* ST-FILTER: shared dialog and page entries. */
.overview-head, .list-head { flex-wrap: wrap; gap: 12px; }
.list-head .card-title, .overview-head .overview-title { margin-inline-end: auto; }
/* ST-FILTER r6.2.2: D-R6-4=A constants, local to the two triggers. */
.filter-trigger {
  gap: 6px; block-size: 44px; min-block-size: 44px; min-inline-size: 44px;
  padding: 0 0.9rem; border-radius: 999px; font-size: 0.875rem; line-height: 1.2; border-color: var(--muted);
}
.list-head .filter-trigger {
  flex: 0 0 auto;
  inline-size: auto;
  width: auto;
  min-inline-size: 44px;
  min-block-size: 44px;
  box-sizing: border-box;
  white-space: nowrap;
}
.filter-badge { border: 1px solid currentColor; border-radius: 999px; padding-inline: 6px; }
.filter-status-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; }
.filter-status-bar p { flex: 1 1 200px; margin: 0; overflow-wrap: anywhere; }
.filter-status-bar button, .filter-panel button { min-block-size: 44px; min-inline-size: 44px; font-size: 14px; white-space: normal; }
.filter-panel { max-block-size: 92dvh; overflow-y: auto; overscroll-behavior: contain; font-size: 14px; }
.filter-panel fieldset { min-inline-size: 0; margin-block: 16px; padding: 8px; border: 1px solid var(--border, #aaa); border-radius: 12px; }
.filter-panel legend { padding-inline: 6px; }
.filter-option { display: flex; align-items: center; gap: 10px; min-block-size: 44px; cursor: pointer; padding: 4px 8px; }
.filter-option input { flex: 0 0 auto; inline-size: 20px; block-size: 20px; }
.filter-option-name { flex: 1; min-inline-size: 0; overflow-wrap: anywhere; }
.filter-option-count { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.filter-panel :focus-visible, .filter-trigger:focus-visible { outline: 3px solid currentColor; outline-offset: 2px; }
.filter-panel p { overflow-wrap: anywhere; }
@media (min-width: 761px) { .filter-panel { max-inline-size: 560px; } }

.filter-badge { font-size: 0.75rem; line-height: 1.2; padding-inline: 4px; }
#filterModalClose {
  inline-size: 44px; block-size: 44px; flex: 0 0 44px; border-radius: 8px;
  border: 1px solid var(--muted); background: var(--card); color: var(--ink); font-size: 1.5rem;
}
#filterModal fieldset { border: 0; padding: 0; }
#filterModal legend { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; inline-size: 100%; font-size: 14px; font-weight: 600; padding: 0; }
#filterModal legend .link-btn { margin-inline-start: auto; }
#filterModal [id$="Rows"] { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 8px; }
#filterModal .filter-option {
  position: relative; display: inline-flex; gap: 6px; border: 1px solid var(--muted);
  border-radius: 999px; background: var(--card); color: var(--ink); padding: 8px 12px;
  max-inline-size: 100%; box-sizing: border-box;
}
#filterModal .filter-option[hidden] { display: none; }
#filterModal .filter-option input {
  position: absolute; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); clip: rect(0,0,0,0); white-space: nowrap;
}
#filterModal .filter-option:has(input:checked) { background: var(--seal); color: var(--avatar-ink); border-color: var(--seal); }
html[data-theme="dark"] #filterModal .filter-option:has(input:checked) { color: var(--paper-deep); }
#filterModal .filter-option:has(input:checked)::before { content: "✓"; }
#filterModal .filter-option:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: 3px; }
#filterModal .filter-option-count { border: 1px solid currentColor; border-radius: 999px; padding-inline: 5px; }
#filterModal .filter-selected-count { margin-inline-start: auto; font-weight: 400; }
#filterModal legend:has(.filter-selected-count:not([hidden])) .link-btn { margin-inline-start: 0; }
#filterModal .filter-search { display: flex; gap: 8px; margin-block: 12px; }
#filterModal .filter-search input { min-inline-size: 0; flex: 1; min-block-size: 44px; border: 1px solid var(--muted); background: var(--card); color: var(--ink); border-radius: 8px; padding: 8px; font: inherit; }
#filterModal .filter-search input::placeholder { color: var(--ink-soft); opacity: 1; }
#filterSearchClear, #filterSelectedChips button { border: 1px solid var(--muted); background: var(--card); color: var(--ink); border-radius: 999px; padding: 8px 12px; }
#filterSelectedTitle { font-size: 14px; margin-block: 8px; }
#filterSelectedChips { display: flex; flex-wrap: wrap; gap: 8px; }
#filterSelectedChips button { max-inline-size: 100%; overflow-wrap: anywhere; }
#filterModal .filter-search-empty { border: 1px dashed var(--muted); border-radius: 8px; padding: 12px; }
#filterModal mark { background: var(--ink); color: var(--card); }
#filterSummary { margin-block-start: 20px; }
#filterClearAll, #filterModalDone { inline-size: calc(50% - 6px); vertical-align: top; }
#filterModalDone { margin-inline-start: 8px; }
#filterClearAll { border-color: var(--muted); }

/* ST-PIE: existing palette, native controls retained while the chart updates. */
#overviewPie { margin-block-start: 24px; border-block-start: 1px solid var(--rule); padding-block-start: 16px; }
#overviewPie .pie-head { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
#pieTitle { margin: 0; flex: 1 1 auto; overflow-wrap: anywhere; }
#overviewPie .pie-controls { display: flex; flex: 0 1 320px; inline-size: 320px; gap: 8px; min-inline-size: 0; max-inline-size: 100%; }
#overviewPie label { display: flex; flex-direction: column; gap: 6px; flex: 1 1 0; min-inline-size: 0; font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
#overviewPie select { inline-size: 100%; min-inline-size: 0; min-block-size: 44px; border: 1px solid var(--muted); border-radius: 8px; padding: 8px 4px; margin-block-start: auto; font: inherit; color: var(--ink); background: var(--card); }
#overviewPie select:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
#overviewPie .pie-body { display: flex; align-items: center; flex-wrap: wrap; gap: 20px; margin-block-start: 16px; }
#pieChart { flex: 0 1 200px; max-inline-size: 100%; }
#pieChart svg { display: block; inline-size: 200px; max-inline-size: 100%; block-size: auto; }
#pieLegend { list-style: none; padding: 0; margin: 0; flex: 1 1 180px; min-inline-size: 0; color: var(--ink); font-size: 14px; }
#pieLegend li { display: flex; align-items: baseline; gap: 8px; margin-block: 10px; overflow-wrap: anywhere; }
#pieLegend li > span:last-child { min-inline-size: 0; }
#overviewPie .pie-swatch { inline-size: 12px; block-size: 12px; flex: 0 0 12px; border-radius: 2px; }
#pieEmpty { color: var(--ink); overflow-wrap: anywhere; }
@media (max-width: 760px) { #overviewPie .pie-controls { flex-basis: 100%; } }

:is(html:lang(en), html:lang(de), html:lang(fr), html:lang(es), html:lang(pt-BR)) #overviewPie label:first-child { flex-grow: 1.9; }

/* ST-COMBO: shared payment-method and category ARIA combobox. */
.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.combo { position: relative; min-inline-size: 0; }
.combo input { padding-inline-end: 3rem; }
html[data-theme] .combo > input { border-color: var(--ctl-border); }
.combo-clear {
  position: absolute;
  inset-block-start: 0;
  inset-inline-end: 0;
  inline-size: 44px;
  block-size: 44px;
  min-inline-size: 44px;
  min-block-size: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.combo-clear:hover { background: var(--paper-deep); }
.combo-clear:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }
.combo-listbox {
  position: absolute;
  inset-inline: 0;
  inset-block-start: calc(100% + 4px);
  z-index: 20;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-block-size: calc(6 * 44px + 8px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--ctl-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.combo-option {
  display: flex;
  align-items: center;
  min-block-size: 44px;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.combo-option:hover,
.combo-option.is-active { background: var(--paper-deep); color: var(--ink); }
.combo input:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ST-ROW r1.5: overview period + filter share one row (logical properties). */
.overview-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
  max-inline-size: 100%;
  min-inline-size: 0;
  margin-inline-start: auto;
}
.overview-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 6px;
  min-inline-size: 0;
  max-inline-size: 100%;
}
.overview-controls .period-toggle {
  flex: 0 1 auto;
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow: visible;
}
.overview-controls .period-btn {
  flex: 0 0 auto;
  inline-size: auto;
  min-inline-size: 44px;
  max-inline-size: 100%;
  white-space: nowrap;
  overflow-wrap: normal;
}
.overview-controls .filter-trigger {
  flex: 0 0 auto;
  min-inline-size: 44px;
  block-size: 50px;
  min-block-size: 50px;
  box-sizing: border-box;
  white-space: nowrap;
}
.overview-controls .filter-trigger {
  inline-size: auto;
  block-size: auto;
  min-block-size: 44px;
  align-self: stretch;
  border-color: var(--ctl-border);
}

/* ST-ROW r1.5: masthead title block and account stay on one row. */
.masthead h1 {
  white-space: nowrap;
}
.masthead-account {
  margin-top: 0;
  flex: 0 1 auto;
  min-width: 0;
}
.masthead-account .account,
.masthead-account .account-in {
  flex: 0 1 auto;
  min-width: 0;
}
.masthead-account .account-email {
  min-inline-size: 0;
}

/* ST-ROW r1.5: clear-all joins the search bar at its inline-end. */
#filterModal .filter-search {
  align-items: center;
  flex-wrap: nowrap;
}
#filterModal .filter-search input {
  flex: 1 1 0;
  min-inline-size: 0;
}
#filterModal .filter-search #filterClearAll {
  inline-size: auto;
  flex: 0 0 auto;
  margin-inline-start: 0;
  min-inline-size: 44px;
  min-block-size: 44px;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .masthead-top {
    gap: 0.25rem;
  }
  .masthead-top:has(#accountSignedIn:not([hidden])) {
    flex-wrap: nowrap;
  }
  .masthead-top:has(#accountSignedIn:not([hidden])) .masthead-title {
    flex: 0 0 auto;
  }
  .masthead-top:has(#accountSignedIn:not([hidden])) .masthead-account,
  .masthead-top:has(#accountSignedIn:not([hidden])) .account,
  .masthead-top:has(#accountSignedIn:not([hidden])) .account-in {
    flex: 1 1 0;
    min-inline-size: 0;
    overflow: hidden;
  }
  .masthead-top:has(#accountSignedIn:not([hidden])) .account-in {
    justify-content: flex-end;
  }
  .masthead-top:has(#accountSignedIn:not([hidden])) .account-email {
    flex: 1 1 0;
    min-inline-size: 0;
    max-inline-size: none;
  }
  .masthead-top:has(#accountSignedIn:not([hidden])) .btn-header {
    flex: 0 0 auto;
  }
  .masthead-account .btn-header {
    padding-inline: 0.4rem;
  }
  .overview-controls {
    gap: 6px;
  }
  .overview-controls .period-btn,
  .overview-controls .filter-trigger {
    padding-inline: 0.6rem;
  }
}

@media (max-width: 400px) {
  .masthead-account .btn-header {
    min-inline-size: 44px;
    padding-inline: 0;
  }
  .theme-quick-btn::after {
    inset: 0;
  }
}

/* ST responsive masthead: narrow viewport + 200% root text (ChatGPT patch) */

@media (max-width:400px) {
  .masthead-top {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    column-gap: 4px;
    row-gap: 4px;
    min-inline-size: 0;
  }

  .masthead-title {
    flex: 1 1 0;
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  .masthead h1 {
    font-size: clamp(14px, 3.6vw, 16px);
    letter-spacing: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
    block-size: auto;
    min-block-size: 0;
    max-block-size: none;
    overflow: visible;
    text-overflow: clip;
  }

  .masthead-controls {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
    min-inline-size: 0;
  }

  .masthead-account {
    flex: 0 0 auto;
    min-inline-size: 0;
    margin-top: 0;
  }
}

/* ST-ROW: narrow-phone title fit */
@media (max-width:370px) {
  .masthead h1 {
    font-size: clamp(12px, 3.4vw, 14px);
    letter-spacing: 0;
  }

  .masthead-account .btn-header {
    padding-inline: 2px;
    min-inline-size: 44px;
  }
}

/* Text-scale-safe fallback, independent of media-query rem behavior */
@media (max-width: 400px) {
  .period-btn {
    max-inline-size: 100%;
    min-inline-size: 0;
    min-block-size: 44px;
    overflow-wrap: anywhere;
  }
}

/* ST-PERIOD r1.1: compact three-period selector (ChatGPT patch B4) */
@media (max-width:400px){
  .overview-controls{
    display:flex;
    flex-wrap:wrap;
    align-items:center;
    gap:8px;
    min-inline-size:0;
    max-inline-size:100%;
  }

  .overview-controls .period-toggle{
    display:inline-flex;
    flex:0 1 auto;
    flex-wrap:wrap;
    justify-content:center;
    align-items:center;
    min-inline-size:0;
    max-inline-size:100%;
    padding:2px;
    box-sizing:border-box;
  }

  .overview-controls .period-btn{
    flex:0 0 auto;
    inline-size:auto;
    min-inline-size:44px;
    min-block-size:44px;
    max-inline-size:100%;
    padding-inline:0;
    white-space:nowrap;
    overflow-wrap:normal;
  }

  .overview-controls .filter-trigger{
    flex:0 0 auto;
    inline-size:auto;
    min-inline-size:44px;
    min-block-size:50px;
    block-size:50px;
    padding-inline:2px;
    text-align:center;
    box-sizing:border-box;
  }

  .overview-controls .filter-button-text{
    white-space:nowrap;
  }
}

/* ST-PERIOD: rectangular hit-test area inside period buttons */
.period-btn {
  position: relative;
}

.period-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: auto;
}

/* ST-IPHONE r1.3: Prevent iOS Safari focus auto-zoom. */
#filterSearch,
#pieMode,
#pieScope,
#subName,
#subCategorySelect,
#subCategoryCustom,
#subAmount,
#subCurrency,
#subCycle,
#subCustomDays,
#subRenewal,
#subRenewalMode,
#subEndBilling,
#subPaymentSelect,
#subPaymentCustom,
#subNotes,
#categoryName {
  font-size: 16px;
}

/* ST-IPHONE r1.3: Keep overview filter physically left, including RTL. */
.overview-controls {
  direction: ltr;
  flex-direction: row;
}

/* ST-IPHONE r1.3: Match overview controls to subscription-list pills. */
.overview-controls .period-toggle,
.overview-controls .period-btn,
.overview-controls .filter-trigger {
  border-radius: 999px;
  min-block-size: 44px;
}

.overview-controls .filter-trigger {
  align-self: center;
}

/* ST-IPHONE r1.3: Full-width notebook on iPhone-sized viewports. */
@media (max-width: 430px) {
  html,
  body {
    overflow-x: hidden;
  }

  .notebook {
    margin: 0;
    border-radius: 0;
    min-height: 100dvh;
  }

  .binding {
    display: none;
  }

  .notebook::before {
    display: none;
  }

  .page {
    padding: 0.75rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    padding-left: max(0.75rem, env(safe-area-inset-left));
  }

  .notebook,
  .page,
  .stack {
    max-inline-size: 100%;
  }
}

/* ST-IPHONE r1.3: Override inherited 14px form controls on iOS. */
#filterModal .filter-search input#filterSearch {
  font: inherit;
  font-size: 16px;
}

#subRenewalMode,
#subEndBilling {
  font: inherit;
  font-size: 16px;
}

#overviewPie select#pieMode,
#overviewPie select#pieScope {
  font: inherit;
  font-size: 16px;
}


/* ST-PAYSEL r1.1: inline custom inputs revealed only by the Other/Add category options. */
.sub-custom-field {
  margin-block-start: 0.5rem;
}
