:root {
  --bg: #f3f7f6;
  --bg-accent: #e7f2ef;
  --surface: #ffffff;
  --ink: #16302c;
  --muted: #5d736e;
  --line: #d7e4e0;
  --teal: #0f766e;
  --teal-deep: #0b5c56;
  --teal-soft: #d8f3ef;
  --income: #e93030;
  --expense: #00b42a;
  --shadow: 0 12px 32px rgba(15, 48, 44, 0.08);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Outfit", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top right, #c8ebe4 0%, transparent 36%),
    linear-gradient(180deg, #edf6f3 0%, var(--bg) 42%, #eef3f1 100%);
  color: var(--ink);
}

body {
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
}

.app {
  width: min(960px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 calc(40px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 0;
  max-width: min(52vw, 260px);
}

.user-hello {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.ledger-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 0 2px 4px;
}

.ledger-tab {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 0.35rem 0.45rem 0.35rem 0.35rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ledger-tab:hover {
  background: #f3f8f6;
}

.ledger-tab.active {
  background: var(--teal-soft);
  border-color: #b7e4dc;
  color: var(--teal-deep);
}

.ledger-tab .tab-main {
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  padding: 0.4rem 0.4rem;
  cursor: pointer;
}

.ledger-tab .tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-tab .tab-tag {
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.75;
}

.ledger-tab .tab-ops {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  flex: 0 0 auto;
  min-width: 4.6rem;
}

.ledger-tab .tab-default {
  font-size: 0.7rem;
  padding: 0.12rem 0.35rem;
  border-radius: 999px;
  background: #e7f2ef;
  color: var(--teal-deep);
  text-align: center;
  line-height: 1.2;
}

.ledger-tab .tab-default-spacer {
  visibility: hidden;
}

.ledger-tab.active .tab-default {
  background: rgba(15, 118, 110, 0.16);
}

.ledger-tab .tab-set-default {
  appearance: none;
  border: none;
  background: #e8f3ff;
  color: #1d4ed8;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.28rem 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.ledger-tab .tab-set-default:hover:not(:disabled) {
  background: #dbeafe;
}

.ledger-tab .tab-set-default.is-current,
.ledger-tab .tab-set-default:disabled {
  background: #e7f2ef;
  color: var(--teal-deep);
  cursor: default;
}

.more-menu {
  position: relative;
  flex: 0 0 auto;
}

.btn-avatar {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(145deg, #14b8a6, var(--teal-deep));
  color: #fff;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
  align-self: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.btn-avatar.is-default {
  border-radius: 14px;
}

.btn-avatar.has-photo {
  border-radius: 50%;
  background: #e7f2ef;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.2);
}

.btn-avatar-mark {
  display: none;
  position: absolute;
  inset: 14px 13px 16px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-top: none;
  border-right: none;
  transform: rotate(-40deg);
}

.btn-avatar.is-default .btn-avatar-mark {
  display: block;
}

.btn-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.btn-avatar-img[hidden] {
  display: none !important;
}

.btn-avatar:hover,
.more-menu.open .btn-avatar {
  filter: brightness(1.05);
}

.account-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-avatar-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  flex: 0 0 auto;
}

.account-avatar-actions .btn {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.account-page[hidden] {
  display: none !important;
}

.account-page {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at top right, #c8ebe4 0%, transparent 36%),
    linear-gradient(180deg, #edf6f3 0%, var(--bg) 42%, #eef3f1 100%);
}

.account-page-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 12px 10px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  flex: 0 0 auto;
}

.account-page-bar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.account-page-bar-spacer {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
}

.account-back-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  font-size: 1.85rem;
  line-height: 1;
  background: #e7f2ef;
  color: var(--ink);
  border: 1px solid #cfe6e1;
  box-shadow: 0 2px 8px rgba(15, 48, 44, 0.08);
  position: relative;
  z-index: 2;
}

.account-page-body {
  width: min(560px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0 calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}

body.drawer-open,
body.account-page-open,
body.lightbox-open {
  overscroll-behavior: none;
}

body.account-page-open .app {
  visibility: hidden;
  pointer-events: none;
}

.account-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 12px;
  border-radius: 12px;
  background: #f3faf8;
}

.account-card-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
}

.account-card strong {
  font-size: 1rem;
  line-height: 1.2;
}

.account-ledger {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: #f7fbfa;
  border: 1px solid #e7f0ed;
}

.more-danger {
  color: #b42318;
}

.more-section-title {
  padding: 0 2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.more-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.more-actions-grid .more-item {
  width: auto;
  min-width: 0;
  justify-content: center;
  text-align: center;
  padding: 0.62rem 0.4rem;
  font-size: 0.84rem;
  background: #fff;
  border: 1px solid var(--line);
}

.more-actions-grid .more-check {
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 0.62rem 0.55rem;
}

.more-actions-grid .more-check input {
  flex-shrink: 0;
  margin: 0;
}

.more-actions-grid .more-check span {
  min-width: 0;
  white-space: nowrap;
}

.more-item {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  text-align: left;
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: block;
  box-sizing: border-box;
  text-decoration: none;
}

a.more-item.more-download {
  color: var(--teal-deep);
}

.more-item:hover,
.more-check:hover {
  background: #eef7f4;
}

.more-actions-grid .more-item:hover,
.more-actions-grid .more-check:hover {
  border-color: #9bb8b1;
  background: #fff;
}

.more-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.more-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
}

.more-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.display-prefs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.display-prefs .more-check {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 0.55rem 0.25rem;
  font-size: 0.78rem;
  line-height: 1.25;
  background: #fff;
  border: 1px solid var(--line);
}

.display-prefs .more-check span {
  max-width: 100%;
}

.more-logout {
  text-align: center;
  background: #fdecec;
  border: 1px solid #f3c6c2;
  margin-top: 2px;
}

.more-logout:hover {
  background: #fbe0dd;
}


.ledger-hint[hidden] {
  display: none !important;
}

.team-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: auto;
}

.team-current {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.team-current strong {
  font-size: 1.05rem;
}

.team-current span,
.member-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.invite-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.invite-row input {
  flex: 1;
  min-width: 0;
}

.invite-row .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.member-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7fbfa;
}

.member-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.member-item strong {
  display: block;
}

.member-perms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.member-perm {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
}

.member-perm input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.member-perm-readonly {
  color: var(--muted);
  font-size: 0.82rem;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(145deg, #14b8a6, var(--teal-deep));
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.28);
  position: relative;
  flex: 0 0 auto;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 12px 11px 14px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-top: none;
  border-right: none;
  transform: rotate(-40deg);
}

.auth-brand.brand {
  flex-direction: row;
  align-items: center;
  gap: 14px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  letter-spacing: 0.02em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.ledger-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  text-align: right;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.72rem 1.15rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #14b8a6, var(--teal));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0d9488, var(--teal-deep));
}

.btn-secondary {
  background: var(--teal-soft);
  color: var(--teal-deep);
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-block {
  width: 100%;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.summary-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px;
  box-shadow: var(--shadow);
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  margin-bottom: 6px;
}

.summary-item strong {
  font-size: clamp(1.05rem, 2.8vw, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.summary-item.income strong { color: var(--income); }
.summary-item.expense strong { color: var(--expense); }
.summary-item.balance strong { color: var(--teal-deep); }

.filters,
.list-panel {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 16px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.filters {
  margin-bottom: 16px;
  padding: 10px 14px 14px;
}

.filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
  min-width: 0;
}

.filters-head-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
  max-width: 46%;
}

.filters-summary {
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  text-align: right;
}

.filters-toggle-icon {
  flex: 0 0 auto;
  border: none;
  color: var(--teal-deep);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.32rem 0.65rem;
  border-radius: 999px;
  background: var(--teal-soft);
  cursor: pointer;
  white-space: nowrap;
}

.filters-body {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filters.is-collapsed {
  padding-bottom: 10px;
}

.filters.is-collapsed .filters-body {
  display: none;
}

.filter-section {
  padding-top: 12px;
  border-top: 1px solid #e6efec;
}

.filter-section:first-child {
  padding-top: 0;
  border-top: none;
}

.quick-ledger-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-width: 0;
  flex: 1 1 auto;
}

.quick-ledger-tabs::-webkit-scrollbar {
  display: none;
}

.quick-ledger-tab {
  appearance: none;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #f7fbfa;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.28rem 0.55rem 0.28rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 11em;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.quick-ledger-tab .tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.quick-ledger-tab:hover {
  border-color: #9bb8b1;
}

.quick-ledger-tab.active {
  background: linear-gradient(135deg, #14b8a6, var(--teal));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 10px rgba(15, 118, 110, 0.2);
}

.quick-ledger-tab .tab-tag {
  flex: 0 0 auto;
  font-size: 0.66rem;
  font-weight: 700;
  opacity: 0.9;
  padding: 0.08rem 0.35rem;
  border-radius: 999px;
  background: rgba(15, 48, 44, 0.06);
  color: var(--muted);
}

.quick-ledger-tab.active .tab-tag {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.quick-ledger-empty {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.1rem 0;
  white-space: nowrap;
}

.date-filter-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.date-filter-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: #eef6f4;
  flex: 0 0 auto;
}

.date-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 9px;
  padding: 0.5rem 0.2rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.date-tab:hover {
  color: var(--ink);
}

.date-tab.active {
  background: #fff;
  color: var(--teal-deep);
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.12);
}

.date-filter-panels {
  min-width: 0;
  flex: 1 1 auto;
}

.date-panel[hidden] {
  display: none;
}

.date-all-hint {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  color: var(--muted);
  font-size: 0.84rem;
}

.filter-inline {
  gap: 0;
}

.custom-date-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.date-range-sep {
  color: var(--muted);
  font-size: 0.84rem;
  flex: 0 0 auto;
}

.filter-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.filter-grid label span {
  font-size: 0.78rem;
}

.filter-grid input,
.filter-grid select,
.date-filter input,
.date-filter select {
  padding: 0.62rem 0.75rem;
  border-radius: 10px;
}

.filter-keyword {
  grid-column: 1 / -1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 0.84rem;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.72rem 0.85rem;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus, select:focus {
  border-color: #5eead4;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
}

.filter-month .month-picker,
.filter-year .month-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-month .month-picker select,
.filter-year .month-picker select {
  flex: 1 1 auto;
  min-width: 0;
}

.filter-month .month-picker-unit,
.filter-year .month-picker-unit {
  color: var(--muted);
  font-size: 0.9rem;
  flex: 0 0 auto;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 0;
}

.filter-day input[type="date"] {
  width: 100%;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.list-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.list-head span {
  color: var(--muted);
  font-size: 0.88rem;
}

.record-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
}

.record-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff, #f7fbfa);
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.record-item:hover {
  border-color: #9bb8b1;
  box-shadow: 0 6px 16px rgba(15, 48, 44, 0.06);
}

.record-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.record-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-weight: 600;
  min-width: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.income {
  background: #fdecec;
  color: var(--income);
}

.badge.expense {
  background: #e8f9ed;
  color: var(--expense);
}

.badge.voided {
  background: #eef1f0;
  color: #6b7c78;
}

.record-item.is-voided {
  opacity: 0.62;
}

.record-item.is-voided .record-amount {
  text-decoration: line-through;
}

.record-meta {
  color: var(--muted);
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
}

.record-amount {
  font-weight: 700;
  font-size: 1.05rem;
  text-align: right;
}

.record-amount.income { color: var(--income); }
.record-amount.expense { color: var(--expense); }

.record-creator {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
  max-width: 7.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
}

.btn-record {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 0.28rem 0.55rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  color: #fff;
}

.btn-record-edit {
  background: #3b82f6;
}

.btn-record-void {
  background: #9ca3af;
}

.btn-record-delete {
  background: #ef4444;
}

.btn-record-restore {
  background: #14b8a6;
}

.btn-record:hover {
  filter: brightness(0.95);
}

.btn-record:active {
  filter: brightness(0.9);
}

.empty, .error {
  margin: auto;
  padding: 36px 12px;
  text-align: center;
  color: var(--muted);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
}

.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(12, 30, 28, 0.42);
  z-index: 40;
  -webkit-tap-highlight-color: transparent;
}

.drawer-mask[hidden] {
  display: none !important;
}

.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 100%;
  max-height: min(92dvh, var(--drawer-max-height, 92vh));
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 0 16px;
  padding-bottom: 0;
  z-index: 50;
  transform: translate3d(0, 110%, 0);
  transition: transform 0.28s ease;
  box-shadow: 0 -16px 40px rgba(15, 48, 44, 0.18);
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

.drawer.open {
  transform: translate3d(0, 0, 0);
}

.drawer.keyboard-open {
  border-radius: 0;
  max-height: none;
}

.drawer-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  flex: 0 0 auto;
}

.drawer-handle::before {
  content: "";
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #d5e2de;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex: 0 0 auto;
}

.drawer-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

/* 团队管理：全屏页，高于账号页，避免顶部/返回被遮挡 */
.team-mask.drawer-mask {
  z-index: 95;
  background: rgba(8, 24, 22, 0.35);
}

.team-drawer.drawer {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: none;
  border-radius: 0;
  padding: 0;
  z-index: 96;
  transform: translate3d(100%, 0, 0);
  box-shadow: none;
  background:
    radial-gradient(circle at top right, #c8ebe4 0%, transparent 36%),
    linear-gradient(180deg, #edf6f3 0%, var(--bg) 42%, #eef3f1 100%);
}

.team-drawer.drawer.open {
  transform: translate3d(0, 0, 0);
}

.team-drawer.drawer.keyboard-open {
  border-radius: 0;
  max-height: none;
  height: 100%;
}

.team-drawer-head {
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) 12px 10px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  flex: 0 0 auto;
}

.team-drawer-head h2 {
  flex: 1 1 auto;
  text-align: center;
  font-size: 1.05rem;
}

.team-drawer .team-panel {
  width: min(560px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0 calc(24px + var(--safe-bottom));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.drawer-open .account-page {
  pointer-events: none;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg-accent);
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1;
  min-height: 0;
}

.form-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0 12px;
}

.form-footer {
  flex: 0 0 auto;
  padding: 10px 0 calc(12px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), #fff 36%);
  border-top: 1px solid rgba(215, 228, 224, 0.8);
}

.team-drawer .team-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.drawer-open,
body.account-page-open {
  overflow: hidden;
  touch-action: none;
}

body.drawer-open .app {
  pointer-events: none;
}

body.drawer-open .drawer,
body.drawer-open .drawer-mask,
body.drawer-open .lightbox {
  pointer-events: auto;
  touch-action: auto;
}

.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  background: var(--bg-accent);
  border-radius: 14px;
}

.type-btn {
  border: none;
  border-radius: 12px;
  padding: 0.7rem;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.type-btn.active[data-type="expense"] {
  background: #fff;
  color: var(--expense);
  box-shadow: 0 4px 12px rgba(0, 180, 42, 0.16);
}

.type-btn.active[data-type="income"] {
  background: #fff;
  color: var(--income);
  box-shadow: 0 4px 12px rgba(233, 48, 48, 0.16);
}

.image-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.image-field > span {
  color: var(--muted);
  font-size: 0.84rem;
}

.image-upload {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.image-picker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 1px dashed #9bb8b1;
  border-radius: 12px;
  background: #f7fbfa;
  color: var(--teal-deep);
  font-weight: 600;
  cursor: pointer;
}

.image-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.image-preview-list[hidden] {
  display: none !important;
}

.image-preview-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.image-preview-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #fff;
  aspect-ratio: 1;
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

.image-preview-item .btn-remove-image {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 999px;
  background: rgba(8, 24, 22, 0.72);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.record-thumbs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
  margin-left: 4px;
}

.record-thumb {
  width: 40px;
  height: 40px;
  max-width: 40px;
  max-height: 40px;
  flex: 0 0 40px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  vertical-align: middle;
  cursor: zoom-in;
}

.record-thumb-more {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--teal-deep);
  background: var(--teal-soft);
  border-radius: 999px;
  padding: 0.18rem 0.4rem;
}

.lightbox[hidden] {
  display: none !important;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 24, 22, 0.82);
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  pointer-events: auto;
}

body.lightbox-open .record-detail-mask,
body.lightbox-open .ledger-sheet-mask,
body.lightbox-open .confirm-mask,
body.lightbox-open .drawer,
body.lightbox-open .drawer-mask {
  z-index: 70;
}

body.lightbox-open .lightbox {
  z-index: 10000;
}

.lightbox img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(86dvh, 86vh);
  border-radius: 14px;
  object-fit: contain;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.92);
  z-index: 1;
  width: 42px;
  height: 42px;
  font-size: 1.6rem;
  line-height: 1;
}

.lightbox-prev {
  left: max(12px, env(safe-area-inset-left));
}

.lightbox-next {
  right: max(12px, env(safe-area-inset-right));
}

.lightbox-counter {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
}

.lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  background: rgba(255, 255, 255, 0.92);
  z-index: 1;
}

.record-detail-mask[hidden] {
  display: none !important;
}

.record-detail-mask {
  position: fixed;
  inset: 0;
  z-index: 76;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(8, 24, 22, 0.45);
}

.record-detail-sheet {
  width: min(440px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px 20px 16px 16px;
  padding: 14px 14px 18px;
  box-shadow: 0 20px 48px rgba(15, 48, 44, 0.2);
}

.record-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px 10px;
  border-bottom: 1px solid #e6efec;
}

.record-detail-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.record-detail-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 14px;
}

.record-detail-hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 14px;
  border-radius: 14px;
  background: #f3faf8;
}

.record-detail-hero .record-detail-amount {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
}

.record-detail-hero .record-detail-amount.income { color: var(--income); }
.record-detail-hero .record-detail-amount.expense { color: var(--expense); }

.record-detail-hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.record-detail-rows {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.record-detail-row {
  display: grid;
  grid-template-columns: 4.5em minmax(0, 1fr);
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid #eef4f2;
  align-items: start;
}

.record-detail-row:first-child {
  border-top: none;
}

.record-detail-row dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.record-detail-row dd {
  margin: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  word-break: break-word;
}

.record-detail-images {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.record-detail-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  cursor: pointer;
  background: #f7fbfa;
}

.record-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.record-detail-actions .btn-record {
  flex: 1 1 auto;
  min-width: 4.5em;
  padding: 0.55rem 0.75rem;
  font-size: 0.86rem;
  text-align: center;
}

.ledger-sheet-mask[hidden] {
  display: none !important;
}

.ledger-sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(8, 24, 22, 0.45);
}

.ledger-sheet {
  width: min(420px, 100%);
  max-height: min(72vh, 560px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px 20px 16px 16px;
  padding: 14px 12px 16px;
  box-shadow: 0 20px 48px rgba(15, 48, 44, 0.2);
}

.ledger-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 4px;
}

.ledger-sheet-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.ledger-sheet-tip {
  margin: 0 4px 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.ledger-sheet-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ledger-sheet-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f7fbfa;
  padding: 4px;
}

.ledger-sheet-item.active {
  border-color: #b7e4dc;
  background: var(--teal-soft);
}

.ledger-sheet-item.is-default {
  border-color: #9fd0c6;
}

.ledger-sheet-main {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.ledger-sheet-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-sheet-main span {
  color: var(--muted);
  font-size: 0.78rem;
}

.ledger-sheet-ops {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  flex: 0 0 auto;
}

.ledger-sheet-default {
  appearance: none;
  border: none;
  background: #e8f3ff;
  color: #1d4ed8;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  border-radius: 10px;
  white-space: nowrap;
  text-align: center;
}

.ledger-sheet-default:hover {
  background: #dbeafe;
}

.ledger-sheet-default.is-current {
  background: #e7f2ef;
  color: var(--teal-deep);
  cursor: default;
}

.ledger-sheet-delete {
  appearance: none;
  border: none;
  background: #fdecec;
  color: #b42318;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  border-radius: 10px;
  white-space: nowrap;
}

.ledger-sheet-delete:hover {
  background: #fbe0dd;
}

.confirm-mask[hidden] {
  display: none !important;
}

.confirm-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 24, 22, 0.45);
}

.confirm-dialog {
  width: min(360px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px 18px 16px;
  box-shadow: 0 20px 48px rgba(15, 48, 44, 0.2);
}

.confirm-dialog h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.confirm-input-wrap[hidden] {
  display: none !important;
}

.confirm-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

.confirm-input-wrap span {
  color: var(--muted);
  font-size: 0.84rem;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.password-tip {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.password-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.password-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.password-form label span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.password-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  background: #fff;
}

.password-form input:focus {
  outline: 2px solid rgba(20, 184, 166, 0.25);
  border-color: #14b8a6;
}

.password-form .confirm-actions {
  margin-top: 6px;
}

.confirm-dialog.is-danger #btnConfirmOk {
  background: #b42318;
  color: #fff;
}

.team-delete-btn {
  align-self: flex-start;
  margin-top: 8px;
  color: #b42318;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #16302c;
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 999px;
  z-index: 10001;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

@media (min-width: 768px) {
  .app {
    padding-top: 40px;
  }

  .date-filter-row {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .date-filter-tabs {
    width: min(380px, 48%);
    flex: 0 0 auto;
  }

  .filter-fields {
    flex-direction: row;
    align-items: flex-end;
    gap: 12px;
  }

  .filter-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    flex: 1 1 auto;
  }

  .filter-keyword {
    grid-column: 1 / -1;
  }

  .filter-actions {
    margin-top: 0;
    flex: 0 0 auto;
    padding-bottom: 2px;
  }

  .drawer-handle {
    display: none;
  }

  .drawer:not(.team-drawer) {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(520px, calc(100vw - 48px));
    height: auto;
    max-height: min(88vh, 760px);
    border-radius: 24px;
    padding: 18px;
    transform: translate(-50%, -46%) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s ease, opacity 0.22s ease;
  }

  .drawer.open:not(.team-drawer),
  .drawer.keyboard-open:not(.team-drawer) {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
    border-radius: 24px;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    height: auto;
    width: min(520px, calc(100vw - 48px));
  }

  .form-footer {
    padding-bottom: 0;
    border-top: none;
  }

  .team-drawer.drawer,
  .team-drawer.drawer.open,
  .team-drawer.drawer.keyboard-open {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    padding: 0;
    opacity: 1;
    pointer-events: auto;
    transform: translate3d(100%, 0, 0);
  }

  .team-drawer.drawer.open,
  .team-drawer.drawer.keyboard-open {
    transform: translate3d(0, 0, 0);
  }

  .team-drawer .team-panel {
    padding-bottom: calc(24px + var(--safe-bottom));
  }

  body.drawer-open {
    touch-action: auto;
  }
}

@media (max-width: 767px) {
  .app {
    width: min(100% - 20px, 960px);
    padding-top: 14px;
    padding-bottom: calc(28px + var(--safe-bottom));
  }

  .topbar {
    align-items: center;
    gap: 10px;
  }

  .topbar-left {
    gap: 10px;
  }

  .topbar-actions .btn {
    padding: 0.62rem 0.9rem;
  }

  .brand h1 {
    font-size: 1.35rem;
  }

  .btn-avatar {
    width: 48px;
    height: 48px;
  }

  .btn-avatar-mark {
    inset: 13px 12px 15px;
  }

  .summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .summary-item {
    padding: 12px 8px;
    text-align: center;
    min-width: 0;
  }

  .summary-item span {
    margin-bottom: 4px;
    font-size: 0.78rem;
  }

  .summary-item strong {
    font-size: clamp(0.92rem, 3.6vw, 1.12rem);
    word-break: break-all;
  }

  .drawer {
    max-height: min(94dvh, var(--drawer-max-height, 94vh));
  }

  .drawer .form {
    max-height: inherit;
  }

  .team-drawer.drawer {
    max-height: none;
    height: 100%;
  }

  /* 防止 iOS 聚焦输入框自动放大页面 */
  .drawer input,
  .drawer select,
  .drawer textarea {
    font-size: 16px;
  }

  .invite-row {
    flex-direction: column;
  }

  .invite-row .btn {
    width: 100%;
  }

  .toast {
    left: 16px;
    right: 16px;
    transform: none;
    width: auto;
    text-align: center;
    border-radius: 14px;
  }
}
