.app {
  padding-bottom: max(92px, calc(78px + env(safe-area-inset-bottom)));
}

.app-page {
  display: none;
  width: 100%;
  min-width: 0;
}

.app-page.active {
  display: flex;
  flex-direction: column;
}

.debts-page {
  min-height: calc(100svh - 128px);
}

.debts-topbar {
  min-height: 52px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 34px;
}

.debts-page-title {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.045em;
}

.debts-page-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.debts-add {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  width: 38px;
  height: 38px;
  padding: 7px;
  margin: -4px -7px 0 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: .82;
  transition: opacity 120ms ease, transform 100ms ease;
}

.debts-add svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
}

.debts-add:active {
  opacity: .48;
  transform: scale(.93);
}

.debts-summary {
  margin-bottom: 20px;
}

.debts-page.empty .debts-summary {
  display: none;
}

.debts-summary-label {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  font-weight: 530;
  letter-spacing: -0.01em;
  margin-bottom: 7px;
}

.debts-summary-value {
  font-size: clamp(38px, 11vw, 48px);
  line-height: .98;
  font-weight: 710;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.debts-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.debts-page.empty .debts-list {
  border-top: 0;
  padding-top: 0;
}

.debt-list-row {
  appearance: none;
  border: 0;
  width: calc(100% + 16px);
  margin-left: -8px;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 12px 8px 13px;
  border-radius: 14px;
  text-align: left;
  cursor: pointer;
  transition: background-color 100ms ease, transform 100ms ease;
}

.debt-list-row:active {
  background: var(--press);
  transform: scale(.995);
}

.debt-list-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.debt-list-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  line-height: 1.22;
  font-weight: 590;
  letter-spacing: -0.02em;
}

.debt-list-date {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 480;
  letter-spacing: -0.005em;
}

.debt-list-amount {
  white-space: nowrap;
  font-size: 16px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

.debts-empty {
  margin: 52px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 500;
  text-align: center;
}

.overdue {
  color: #a34040 !important;
}

@media (prefers-color-scheme: dark) {
  .overdue {
    color: #e17979 !important;
  }
}

.tab-bar {
  position: fixed;
  z-index: 24;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  width: 142px;
  height: 58px;
  transform: translateX(-50%);
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  align-items: stretch;
  border: 1px solid rgba(17, 17, 18, .07);
  border-radius: 24px;
  background: rgba(232, 232, 230, .82);
  box-shadow:
    0 10px 32px rgba(0, 0, 0, .10),
    0 1px 2px rgba(0, 0, 0, .05);
  backdrop-filter: blur(28px) saturate(1.4);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
}

@media (prefers-color-scheme: dark) {
  .tab-bar {
    border-color: rgba(255, 255, 255, .08);
    background: rgba(31, 31, 34, .82);
    box-shadow:
      0 12px 34px rgba(0, 0, 0, .32),
      0 1px 2px rgba(0, 0, 0, .22);
  }
}

.tab-item {
  appearance: none;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--muted-2);
  min-width: 0;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    color 140ms ease,
    background-color 140ms ease,
    box-shadow 140ms ease,
    transform 100ms ease,
    opacity 100ms ease;
}

.tab-item.active {
  color: var(--text);
  background: rgba(255, 255, 255, .82);
  box-shadow:
    0 1px 4px rgba(0, 0, 0, .08),
    inset 0 0 0 1px rgba(17, 17, 18, .025);
}

@media (prefers-color-scheme: dark) {
  .tab-item.active {
    background: rgba(255, 255, 255, .095);
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, .04),
      0 1px 4px rgba(0, 0, 0, .22);
  }
}

.tab-item:active {
  opacity: .62;
  transform: scale(.94);
}

.tab-icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab-item.active .tab-icon {
  stroke-width: 2;
}

.debt-detail {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 2px 2px 4px;
}

.debt-hero {
  padding: 8px 0 4px;
}

.debt-hero-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 540;
  margin-bottom: 7px;
}

.debt-hero-value {
  font-size: 42px;
  line-height: .98;
  font-weight: 710;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
}

.debt-detail-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px 34px;
  padding: 2px 0;
}

.debt-detail-cell {
  min-width: 110px;
}

.debt-detail-cell span,
.debt-note > span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 540;
  margin-bottom: 6px;
}

.debt-detail-cell strong {
  font-size: 15px;
  line-height: 1.25;
  font-weight: 620;
}

.debt-note {
  padding: 2px 0;
}

.debt-note p {
  margin: 0;
  font-size: 15px;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.debt-pay-button {
  margin-top: 2px;
}

.text-input,
.date-input {
  appearance: none;
  border: 0;
  outline: 0;
  width: 100%;
  background: transparent;
  color: var(--text);
  padding: 0;
  font-size: 17px;
  line-height: 1.35;
  font-weight: 560;
}

.date-input {
  color-scheme: light dark;
}

.field-hint {
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1.2;
  margin-top: 7px;
}

.payment-person {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  font-weight: 540;
  padding: 0 4px 2px;
}

.debt-toggle {
  position: relative;
  min-height: 64px;
  padding: 13px 58px 13px 14px;
  border-radius: 18px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  cursor: pointer;
}

.debt-toggle strong,
.debt-toggle small {
  display: block;
}

.debt-toggle strong {
  font-size: 14px;
  line-height: 1.25;
  font-weight: 630;
}

.debt-toggle small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.debt-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-ui {
  position: absolute;
  right: 14px;
  top: 50%;
  width: 38px;
  height: 23px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--surface-3);
  transition: background-color 140ms ease;
}

.toggle-ui::after {
  content: '';
  position: absolute;
  width: 19px;
  height: 19px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 5px rgba(0,0,0,.14);
  transition: transform 160ms var(--ease);
}

.debt-toggle input:checked + .toggle-ui {
  background: var(--text);
}

.debt-toggle input:checked + .toggle-ui::after {
  transform: translateX(15px);
}

.payment-note {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  padding: 0 4px;
}

@media (max-width: 360px) {
  .debts-page-title {
    font-size: 28px;
  }

  .debts-summary-value {
    font-size: 38px;
  }

  .debt-list-row {
    gap: 12px;
  }

  .tab-bar {
    width: 134px;
    height: 56px;
  }
}

@media (min-width: 700px) {
  .tab-bar {
    bottom: 28px;
  }
}
