.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 210ms ease;
}

.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: min(100%, 440px);
  max-height: min(82svh, 760px);
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(102%);
  transition: transform 270ms var(--ease);
  padding:
    8px
    18px
    max(18px, calc(12px + env(safe-area-inset-bottom)));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.overlay.open .sheet {
  transform: translateY(0);
}

.sheet-handle-wrap {
  display: flex;
  justify-content: center;
  padding: 2px 0 10px;
  flex: 0 0 auto;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-strong);
}

.sheet-view {
  min-height: 0;
  display: flex;
  flex-direction: column;
  opacity: 1;
  transform: translateX(0);
  transition:
    opacity 130ms ease,
    transform 180ms var(--ease);
}

.sheet-view.switching {
  opacity: 0;
  transform: translateX(6px);
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0 14px;
  flex: 0 0 auto;
}

.sheet-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
  font-weight: 690;
  letter-spacing: -0.04em;
}

.sheet-subtitle {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 520;
}

.icon-button {
  appearance: none;
  border: 0;
  background: var(--surface-2);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  transition:
    transform 100ms ease,
    background-color 120ms ease;
}

.icon-button:active {
  transform: scale(.96);
}

.close-icon {
  line-height: 1;
  transform: translateY(-1px);
  display: block;
}

.entries {
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 2px 0 10px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  min-height: 118px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  padding: 24px 18px;
  background: var(--surface-2);
  border-radius: 18px;
}

.entry {
  appearance: none;
  border: 0;
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  text-align: left;
  padding: 16px;
  border-radius: 18px;
  cursor: pointer;
  transition:
    background-color 100ms ease,
    transform 100ms ease;
}

.entry:active {
  transform: scale(.99);
  background: var(--surface-3);
}

.entry-amount {
  font-size: 18px;
  line-height: 1.1;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  display: block;
}

.entry-comment {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  margin-top: 5px;
  overflow-wrap: anywhere;
  display: block;
}

.entry-meta {
  color: var(--muted-2);
  font-size: 18px;
  line-height: 1;
  align-self: center;
  padding-left: 8px;
}

.sheet-footer {
  padding-top: 6px;
  flex: 0 0 auto;
}

.add-entry {
  appearance: none;
  border: 0;
  width: 100%;
  min-height: 48px;
  background: var(--text);
  color: var(--bg);
  border-radius: 14px;
  font-size: 14px;
  font-weight: 660;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition:
    transform 100ms ease,
    opacity 100ms ease;
}

.add-entry:active {
  transform: scale(.985);
  opacity: .88;
}

.form-header {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 56px;
  align-items: center;
  padding: 2px 0 14px;
}

.form-header .sheet-title {
  text-align: center;
  font-size: 18px;
}

.back-button,
.save-button {
  appearance: none;
  border: 0;
  background: transparent;
  min-width: 44px;
  min-height: 38px;
  padding: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 620;
  cursor: pointer;
}

.save-button {
  text-align: right;
  color: var(--text);
}

.back-button {
  text-align: left;
  font-size: 24px;
  font-weight: 400;
}

.form {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  padding: 14px;
  background: var(--surface-2);
  border-radius: 18px;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 600;
  margin-bottom: 9px;
}

.amount-wrap {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.amount-input,
.comment-input {
  appearance: none;
  border: 0;
  outline: 0;
  width: 100%;
  background: transparent;
  color: var(--text);
  padding: 0;
  resize: none;
}

.amount-input {
  min-width: 0;
  font-size: 38px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
}

.amount-currency {
  font-size: 24px;
  color: var(--muted);
  font-weight: 600;
  flex: 0 0 auto;
}

.comment-input {
  min-height: 76px;
  max-height: 160px;
  font-size: 16px;
  line-height: 1.42;
}

.amount-input::placeholder,
.comment-input::placeholder {
  color: var(--muted-2);
  opacity: 1;
}

.field-error {
  min-height: 16px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  padding-top: 7px;
  opacity: 0;
  transition: opacity 120ms ease;
}

.field-error.visible {
  opacity: 1;
}

.form-actions {
  padding-top: 4px;
}

.delete-entry {
  appearance: none;
  border: 0;
  width: 100%;
  background: transparent;
  color: var(--danger);
  min-height: 46px;
  font-size: 14px;
  font-weight: 620;
  cursor: pointer;
  opacity: .78;
}

.delete-confirm {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 8px;
}

.delete-confirm.visible {
  display: grid;
}

.confirm-button {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
  min-height: 44px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 640;
  cursor: pointer;
}

.confirm-button.primary {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}

@media (min-width: 700px) {
  .overlay {
    align-items: center;
  }

  .sheet {
    border-radius: 24px;
    margin: 20px;
    padding-bottom: 18px;
  }
}
